Skip to content

Managing Subscriptions

Backendless provides two APIs for Android platform that allow retrieving the current subscription status of an application, and also cancelling an active subscription.

Signatures - Retrieve Subscription Status

Blocking API

public GooglePlaySubscriptionStatus getPlaySubscriptionsStatus( String packageName, String subscriptionId, String token )

where:

Argument                Description
packageName A package name of the application associated with an active in-app subscription purchase. (for example, 'com.some.thing').
subscriptionId ID of the purchased subscription (for example, 'com.some.thing.monthly001' - where monthly001 is the ID).
token A token provided to the application after the subscription purchase.

Non-blocking API

public void getPlaySubscriptionsStatus( String packageName, String subscriptionId, String token AsyncCallback<GooglePlaySubscriptionStatus> callback )

where:

Argument                Description
packageName A package name of the application associated with an active in-app subscription purchase. (for example, 'com.some.thing').
subscriptionId ID of the purchased subscription (for example, 'com.some.thing.monthly001' - where monthly001 is the ID).
token A token provided to the application after the subscription purchase.
callback Represents an object containing the result of the method invocation. If the request is successful, returns the GooglePlaySubscriptionStatus object. Otherwise, throws an exception.

Return Value

Returns the GooglePlaySubscriptionStatus object:

{  
  "autoRenewing": boolean,  
  "startTimeMillis": long,  
  "kind": string,  
  "expiryTimeMillis": long  
}

where:

Argument                Description
autoRenewing Indicates whether the next subscription is set for automatic renewal.
startTimeMillis Time when a subscription was purchased. Time is measured in milliseconds passed since the Unix epoch (1 January 1970 00:00:00 UT).
kind Represents the inappPurchase object in the androidpublisher service.
expiryTimeMillis Time when a subscription expires. Time is measured in milliseconds passed since the Unix epoch (1 January 1970 00:00:00 UT).

Example Blocking API

GooglePlaySubscriptionStatus googlePlaySubscriptionStatus = Backendless.Commerce.getPlaySubscriptionsStatus( packageName, subscriptionId, token );

Example Non-Blocking API

Backendless.Commerce.getPlaySubscriptionsStatus( packageName, subscriptionId, token, new AsyncCallback<GooglePlaySubscriptionStatus>()  
    {  
      @Override  
      public void handleResponse( GooglePlaySubscriptionStatus googlePlaySubscriptionStatus )  
      {  
        // result handling logic  
      }  
      @Override  
      public void handleFault( BackendlessFault backendlessFault )  
      {  
        // error handling logic  
      }  
    } );

Signatures - Cancel Subscription

Blocking API

public void cancelPlaySubscription( String packageName, String subscriptionId, String token )

where:

Argument                Description
packageName A package name of the application associated with an active in-app subscription purchase. (for example, 'com.some.thing').
subscriptionId ID of the purchased subscription (for example, 'com.some.thing.monthly001' - where monthly001 is the ID).
token A token provided to the application after the subscription purchase.

Non-blocking API

public void cancelPlaySubscription( String packageName, String subscriptionId, String token, AsyncCallback<Void> callback )

where:

Argument                Description
packageName A package name of the application associated with an active in-app subscription purchase. (for example, 'com.some.thing').
subscriptionId ID of the purchased subscription (for example, 'com.some.thing.monthly001' - where monthly001 is the ID).
token A token provided to the application after the subscription purchase.
callback Represents an object containing the result of the method invocation. If the request is successful, returns void. Otherwise, throws an exception.

Return Value

If the request is successful, nothing is returned. Otherwise, this method throws an exception.

Example Blocking API

Backendless.Commerce.cancelPlaySubscription( packageName, subscriptionId, token );

Example Non-Blocking API

Backendless.Commerce.cancelPlaySubscription( packageName, subscriptionId, token, new AsyncCallback<Void>()  
    {  
      @Override  
      public void handleResponse( Void unused )  
      {  
        // result handling logic  
      }  
      @Override  
      public void handleFault( BackendlessFault backendlessFault )  
      {  
        // error handling logic  
      }  
    } );