目录

Function

This API is used to postpone the settlement date of a user.

Scenario

When you launch some preferential activities using your app, for example, rewarding users with product use duration, you can call the API provided by the Huawei IAP server to postpone the settlement date of the user. The user can continue to use the paid service and content and will not be charged during the postponed period. HUAWEI IAP updates the subscription renewal date. You can perform the following operations by postponing settlement:

The settlement date can be postponed by at least one day and at most one year (365 days). You can call the API again before the new settlement date arrives for postponing again. After the postponing, the next renewal starts after the new settlement date ends.

Your app may need to notify users by email or in the app that their settlement date has been postponed.

Prototype

Protocol                 

HTTPS POST

Direction                 

Developer server -> Huawei IAP server

URL                 

{rootUrl}/sub/applications/{apiVersion}/purchases/delay

The value of rootUrl varies depending on the site. You must select the subscription service address of the nearest site for access. For details, please refer to Site Information and Site Selection.

Data Format                 

Request: Content-Type: application/json

Response: Content-Type: application/json

Input Parameters

Parameter                 

Mandatory(M)/Optional (O)                 

Type                 

Description                 

subscriptionId

M

String

Subscription ID.

purchaseToken

M

String

Purchase token of a product. This parameter is returned when an app initiates a purchase request or queries subscription information.

currentExpirationTime

M

Long

Subscription validity period. The value is a standard timestamp and must be the same as the current expiration time.

desiredExpirationTime

M

Long

Subscription validity period after postponing. The value is a standard timestamp and must be greater than the current subscription validity period. The settlement date can be postponed by at least one day and at most 365 days.

Output Parameters

Parameter                 

Mandatory(M)/Optional (O)                 

Type                 

Description                 

responseCode

M

String

Result code. The options are as follows:

● 0: success

● Other values: failure. 

For details about the result codes, please refer to API Result Codes.

responseMessage

O

String

Response description.

newExpirationTime

O

Long

Subscription validity period after postponing. The value is a standard timestamp.

Example

  1. public class SubscriptionService {
  2.    // TODO: replace the (ip:port) to the real one, and if the protocol is https, you should deal with the license
  3.    // yourself.
  4.    public static final String TOC_SITE_URL = "http://ip:port";
  5.    // site for telecom carrier
  6.    public static final String TOBTOC_SITE_URL = "https://subscr-at-dre.iap.dbankcloud.com";
  7.    public static String getRootUrl(Integer accountFlag) {
  8.        if (accountFlag != null && accountFlag == 1) {
  9.            return TOBTOC_SITE_URL;
  10.        }
  11.        return TOC_SITE_URL;
  12.    }
  13.    public static void delaySubscription(String subscriptionId, String purchaseToken, Long currentExpirationTime,
  14.        Long desiredExpirationTime, Integer accountFlag) throws Exception {
  15.        // fetch the App Level AccessToken
  16.        String appAt = AtDemo.getAppAT();
  17.        // construct the Authorization in Header
  18.        Map<String, String> headers = AtDemo.buildAuthorization(appAt);
  19.        // pack the request body
  20.        Map<String, Object> bodyMap = new HashMap<>();
  21.        bodyMap.put("subscriptionId", subscriptionId);
  22.        bodyMap.put("purchaseToken", purchaseToken);
  23.        bodyMap.put("currentExpirationTime", currentExpirationTime);
  24.        bodyMap.put("desiredExpirationTime", desiredExpirationTime);
  25.        String msgBody = JSONObject.toJSONString(bodyMap);
  26.        String response = AtDemo.httpPost(getRootUrl(accountFlag) + "/sub/applications/v2/purchases/delay",
  27.            "application/json; charset=UTF-8", msgBody, 5000, 5000, headers);
  28.        // TODO: display the response as string in console, you can replace it with your business logic.
  29.        System.out.println(response);
  30.    }
  31. }