com.amazonaws.mobileconnectors.pinpoint.analytics.monetization.CustomMonetizationEventBuilder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of aws-android-sdk-pinpoint Show documentation
Show all versions of aws-android-sdk-pinpoint Show documentation
The AWS Android SDK for Amazon Pinpoint module holds the client classes that are used for communicating with Amazon Pinpoint Service
/**
* Copyright 2016-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
package com.amazonaws.mobileconnectors.pinpoint.analytics.monetization;
import org.apache.commons.logging.LogFactory;
import com.amazonaws.mobileconnectors.pinpoint.analytics.AnalyticsClient;
/**
* Builds monetization events representing a purchase from an IAP framework not
* defined by a specific builder. The store attribute must be set by the user.
* This Builder will return null if the Store, ProductId, Quantity, Price and Currency are not set.
*
* The example below demonstrates how to create a monetization event after you
* receive a purchase confirmation from the IAP framework you are using. You are
* responsible for storing and making sure that the bare minimum attributes
* required to build a Custom Purchase Event are available for use at this time.
* Note that the builder will maintain the values of its internal variables
* between builds.
*
* Example:
* // create a builder that can record purchase events for the IAP Framework you
* // are using
* CustomMonetizationEventBuilder builder = CustomMonetizationEventBuilder.create(pinpointManager.getAnalyticsClient());
*
* // build the monetization event with at minimum the store, product id, quantity,
* // and price information
* // The price information can be supplied in either of the following ways:
* // - The price as a double (i.e. 1.99) and the currency as a currency code (i.e.
* // "USD"). This method is preferred as it provides more accuracy in the
* // monetization reports
* // - The formatted localized price of the item as a string (i.e. "$1.99")
* // You may also build with any additional available attributes that the IAP
* // Framework provides such as Transaction ID
*
* // Price and currency
* Event purchaseEvent = builder.withStore("Custom Store").withProductId("com.yourgame.sword")
* .withItemPrice(1.99).withCurrency("USD").withQuantity(1).build();
*
* // Formatted Price
* purchaseEvent = builder.withStore("Custom Store").withProductId("com.yourgame.sword")
* .withFormattedItemPrice("$1.99").withQuantity(1).build();
*
* // record the monetization event
* pinpointManager.getAnalyticsClient().recordEvent(purchaseEvent);
*/
public class CustomMonetizationEventBuilder extends MonetizationEventBuilder {
private static final org.apache.commons.logging.Log log = LogFactory.getLog(CustomMonetizationEventBuilder.class);
/**
* Construct a CustomMonetizationEventBuilder with the specified EventClient
*
* @param analyticsClient The EventClient to use when building the event
*/
protected CustomMonetizationEventBuilder(AnalyticsClient analyticsClient) {
super(analyticsClient);
}
/**
* Create a CustomMonetizationEventBuilder with the specified Event client
*
* @param analyticsClient The event client to use when creating monetization
* events
* @return a CustomMonetizationEventBuilder to build monetization events
* from a Non-Specific IAP Framework
*/
public static CustomMonetizationEventBuilder create(AnalyticsClient analyticsClient) {
return new CustomMonetizationEventBuilder(analyticsClient);
}
/**
* Sets the store in which the transaction is taking place (Required)
*
* @param store The store in which the transaction is taking place
* @return this for chaining
*/
public CustomMonetizationEventBuilder withStore(String store) {
setStore(store);
return this;
}
/**
* Sets the product identifier field of the item being purchased (Required)
*
* @param productId The product id representing the item being purchased
* @return this for chaining
*/
public CustomMonetizationEventBuilder withProductId(String productId) {
setProductId(productId);
return this;
}
/**
* Sets the quantity of the item being purchased (Required)
*
* @param quantity The quantity of the item being purchased
* @return this for chaining
*/
public CustomMonetizationEventBuilder withQuantity(Double quantity) {
setQuantity(quantity);
return this;
}
/**
* Sets the formatted localized price of the item being purchased
*
* @param formattedItemPrice The formatted localized price of the item
* @return this for chaining
* @deprecated Will be removed. Please set Currency and Item Price. Replaced by
* {@link #withCurrency(String)} and {@link #withItemPrice(double)
*/
@Deprecated
public CustomMonetizationEventBuilder withFormattedItemPrice(String formattedItemPrice) {
setFormattedItemPrice(formattedItemPrice);
return this;
}
/**
* Sets the numerical price of the item being purchased (Required)
*
* @param itemPrice The numerical price of the item
* @return this for chaining
*/
public CustomMonetizationEventBuilder withItemPrice(double itemPrice) {
setItemPrice(itemPrice);
return this;
}
/**
* Sets the currency of the item being purchased (Required)
*
* @param currency The currency code of the currency used to purchase this
* item (i.e. "USD")
* @return this for chaining
*/
public CustomMonetizationEventBuilder withCurrency(String currency) {
setCurrency(currency);
return this;
}
/**
* The transaction identifier of the purchase (Optional)
*
* @param transactionId The transaction id of the purchase
* @return this for chaining
*/
public CustomMonetizationEventBuilder withTransactionId(String transactionId) {
setTransactionId(transactionId);
return this;
}
@Override
protected boolean isValid() {
// we must always have the store, product id, quantity, item price and currency
if (getStore() == null) {
log.warn("Custom Monetization event is not valid: it is missing the store");
return false;
}
if (getProductId() == null) {
log.warn("Custom Monetization event is not valid: it is missing the product id");
return false;
}
if (getQuantity() == null) {
log.warn("Custom Monetization event is not valid: it is missing the quantity");
return false;
}
if (getCurrency() == null || getItemPrice() == null) {
log.warn("Custom Monetization event is not valid: it requires the formatted " +
"localized price or the currency and price");
return false;
}
return true;
}
}