When you launch 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 defer the next payment date of the user. The user can continue to use the paid service and content and will not be charged during the deferral period. HUAWEI IAP updates the subscription renewal date. You can perform the following operations by deferring billing:
The billing date can be deferred by at least one day and at most 365 days. You can call the API again before the new billing date arrives to defer the billing again.
Your app may need to notify users by email or in the app that their payment date has been deferred.
Protocol | HTTPS POST |
|---|---|
Direction | Developer server -> Huawei IAP server |
URL | {rootUrl}/sub/applications/v2/purchases/delay NOTE: 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 |
Request Header
Parameter | Mandatory | Type | Description |
|---|---|---|---|
Content-Type | Yes | String | Value: application/json; charset=UTF-8 |
Authorization | Yes | String | Authentication information, which should contain data generated based on the access token for authentication by the Huawei IAP server. The access token is obtained through the Huawei public API for OAuth 2.0-based authentication. The authentication information format is described in Overview, and for details about how to obtain the access token, please refer to API for Obtaining an App-Level Access Token. |
Request Body
Parameter | Mandatory | Type | Description |
|---|---|---|---|
subscriptionId | Yes | String | Subscription ID. |
purchaseToken | Yes | String | Purchase token of a product, which you can obtain from the information returned after a purchase or a subscription query. |
currentExpirationTime | Yes | Long | End time of the current subscription period, in UTC. |
desiredExpirationTime | Yes | Long | End time of the subscription period after a billing deferral, in UTC. The value must be greater than currentExpirationTime. The billing date can be deferred by at least one day and at most 365 days. |
POST /sub/applications/v2/purchases/delay
Content-Type: application/json; charset=UTF-8
Authorization: Basic QVQ6Q1YzQ1NPbVlBaGwrZUtRWExtMTBVV2pyWXZHTVF4MmYvcVMya1B0ZElLY3UwaFJrdFNTMmxwdk1FQkIyYldXWGt0REVaR3I4UjFUTTRLMVlmNXdwWU80RG04THdXQWxjaFhEYjBMUjBNTUJtWnFYcGFtazc3THN3UnFJbkhHK28xekdqRzNSMg==
Accept: application/json
Content-Length: 261
{
"purchaseToken": "00000173741056a37eef310dff9c6a86fec57efafe318ae478e52d9c4261994d64c8f6fc8ea1abbdx5347.5.3089",
"subscriptionId": "1581789719266.D40972AC.3089",
"currentExpirationTime": 1597678570777,
"desiredExpirationTime": 1597679570777
} Response Header
Response Body
Parameter | Mandatory | Type | Description |
|---|---|---|---|
responseCode | Yes | String | Result code. The options are as follows:
|
responseMessage | No | String | Response description. |
newExpirationTime | No | Long | End time of the subscription period after a billing deferral, in UTC. |
HTTP/1.1 200 OK
Content-Type: application/json; charset=UTF-8
Content-Length: 68
{
"responseCode": "0",
"newExpirationTime": "1597679570777"
}
After a payment is complete, your app obtains InAppPurchaseData, a string in JSON format that contains details about this purchase.
You can find sample code of more languages in Server Sample Code. Download the sample code you need to check its libraries and methods in detail.
Java
public class SubscriptionService {
// TODO: Replace ip:port with the actual IP address and port number. Process logic related to certificate authentication when HTTPS is used.
public static final String TOC_SITE_URL = "https://ip:port";
public static void delaySubscription(String subscriptionId, String purchaseToken, Long currentExpirationTime,
Long desiredExpirationTime) throws Exception {
// Obtain the app-level access token.
String appAt = AtDemo.getAppAT();
// Add authorization information to the request header.
Map<String, String> headers = AtDemo.buildAuthorization(appAt);
// Generate the request body.
Map<String, Object> bodyMap = new HashMap<>();
bodyMap.put("subscriptionId", subscriptionId);
bodyMap.put("purchaseToken", purchaseToken);
bodyMap.put("currentExpirationTime", currentExpirationTime);
bodyMap.put("desiredExpirationTime", desiredExpirationTime);
String msgBody = JSONObject.toJSONString(bodyMap);
// In the demo, 5000 is used as the timeout interval. You can adjust the value as required.
String response = AtDemo.httpPost(TOC_SITE_URL + "/sub/applications/v2/purchases/delay",
"application/json; charset=UTF-8", msgBody, 5000, 5000, headers, true);
// TODO: Show the response as a character string in the console. You can change the processing method based on the service logic.
System.out.println(response);
}
} Python
class SubscriptionService:
def __init__(self):
# TODO: Replace ip:port with the actual IP address and port number. Process logic related to certificate authentication when HTTPS is used.
self.TOC_SITE_URL = "https://ip:port"
self.delaySubscriptionUrl = "%s/sub/applications/v2/purchases/delay"
def delaySubscription(self, subscriptionId, purchaseToken, currentExpirationTime, desiredExpirationTime):
# Obtain the app-level access token.
appAt = AtDemo.getAppAT()
if appAt is None or appAt == "":
return
# Add authorization information to the request header.
headers = AtDemo.buildAuthorization(appAt)
# Generate the request body.
bodyDict = {"subscriptionId": subscriptionId, "purchaseToken": purchaseToken,
"currentExpirationTime": currentExpirationTime, "desiredExpirationTime": desiredExpirationTime}
data = json.dumps(bodyDict)
response = AtDemo.httpPost(self.delaySubscriptionUrl % self.TOC_SITE_URL, str.encode(data), headers)
# TODO: Show the response as a character string in the console. You can change the processing method based on the service logic.
print(response) Go
type SubscriptionClient struct {
}
// TODO: Replace ip:port with the actual IP address and port number. Process logic related to certificate authentication when HTTPS is used.
const TOC_SITE_URL = "https://ip:port"
var SubscriptionDemo = &SubscriptionClient{}
func (subscriptionDemo *SubscriptionClient) DelaySubscription(subscriptionId, purchaseToken string, currentExpirationTime, desiredExpirationTime int64) {
bodyMap := map[string]string{
"subscriptionId": subscriptionId,
"purchaseToken": purchaseToken,
"currentExpirationTime": fmt.Sprintf("%v", currentExpirationTime),
"desiredExpirationTime": fmt.Sprintf("%v", desiredExpirationTime),
}
url := TOC_SITE_URL + "/sub/applications/v2/purchases/delay"
bodyBytes, err := SendRequest(url, bodyMap)
if err != nil {
log.Printf("err is %s", err)
}
// TODO: Show the response as a character string in the console. You can change the processing method based on the service logic.
log.Printf("%s", bodyBytes)
}