Developer Console

Tiered Subscriptions, Methods, and Events for Unity

The Amazon Appstore SDK provides developers with the ability to offer Tiered Subscription functionality to their Unity apps.

To use tiered subscriptions in your Unity project, you must first manually create subscriptions, tiers, and terms in the developer console as IAP items. Enter data about these IAP items one at a time, and submit each subscription. In this way, you will be able to use them in your app. You can update your IAP items at any time.

Read Setting Up Tiered Subscriptions in Developer Console before getting started.

This document gives an overview of the available methods and events to Modify Tiered Subscriptions for the Unity plugin. It also provides you with some examples to help get started.

Unity Plugin Modify Subscription Methods

Requests are initiated by the developer as method calls. Parameters and events are described in the Supporting Data Objects table below.

Return Type Method Method Summary Event
RequestOutput ModifySubscription(ModifySubscriptionInput input) Initiates a request to modify subscription for a term sku with a given proration mode. ModifySubscriptionResponse

Modify Subscription Supporting Data Objects

Objects used as method and event parameters are described in the following table.

Object Members Description
ModifySubscriptionInput SkuInput skuInput SkuInput for the subscription term.
string prorationMode ProrationMode specifies when the modification takes effect with the value of IMMEDIATE or DEFERRED.
ModifySubscriptionResponse string requestId The request ID originally returned by ModifySubscription.
AmazonUserData amazonUserData See AmazonUserData.
List receipts See PurchaseReceipt.
string status Same as PurchaseResponse status.
PurchaseReceipt string receiptId A receipt ID, which is a unique identifier of a purchase.
long cancelDate The cancel date for the purchase, in milliseconds since January 1, 1970, 00:00:00 GMT, or 0 if it is not canceled.
long purchaseDate The purchase date for the purchase, in milliseconds since January 1, 1970, 00:00:00 GMT.
string productType The type of product. Can be CONSUMABLE, ENTITLED or SUBSCRIPTION. See Understanding In-App Purchasing for more information.
long deferredDate Date for deferred modification if modified in deferred proration mode. See Deferred ProrationMode for more information.
string deferredSku The Sku the customer will be switching from in deferred mode.
string termSku New Sku the customer will switch to.

Proration Modes

When you modify a subscription, there are two proration modes defined that determines behaviour when the modification intended becomes effective.

Proration mode Description
IMMEDIATE The customer’s current subscription plan ends, and the new plan takes effect immediately. See IMMEDIATE ProrationMode.
DEFERRED The subscription plan changes at the time of the upcoming renewal. See DEFERRED ProrationMode.

Modify Subscription API Sample Code

If you aren't familiar with calling methods and handling events in Unity, see Initiate method calls and Handle events in Unity.

ModifySubscription

ModifySubscription Initiates a request to modify subscription for a term sku with a given proration mode.

using com.amazon.device.iap.cpt;

// Obtain object used to interact with pluginIAmazonIapV2 
iapService = AmazonIapV2Impl.Instance;

// Construct object passed to operation as input
ModifySubscriptionInput request = new ModifySubscriptionInput();

// Set input sku value
SkuInput skuInput = new SkuInput();
skuInput.Sku = "sku";
request.SkuInput = skuInput;

// Set the proration mode IMMEDIATE or deferred
request.ProrationMode = "deferred";

// Call synchronous operation with input object
RequestOutput response = iapService.ModifySubscription(input);

ModifySubscriptionResponse

ModifySubscriptionResponse returns the response from the ModifySubscription call.

using com.amazon.device.iap.cpt;

// Obtain object used to interact with plugin
IAmazonIapV2 iapService = AmazonIapV2Impl.Instance;

// Define event handler
private void EventHandler(ModifySubscriptionResponse args)
{  
    string requestId = args.RequestId;
    string status = args.Status;
    List<PurchaseReceipt> receipts = args.Receipts;
    
    // for each purchase receipt you can get the following values
    string receiptId = receipts[0].ReceiptId;
    long cancelDate = receipts[0].CancelDate;
    long purchaseDate = receipts[0].PurchaseDate;
    string sku = receipts[0].Sku;
    string productType = receipts[0].ProductType;
    string deferredDate = receipts[0].DeferredDate;
    string deferredSku = receipts[0].DeferredSku;
    string termSku = receipts[0].TermSku;
    
}

// Register for an event
iapService.AddModifySubscriptionResponseListener(EventHandler);

Last updated: Dec 03, 2024