Making Purchases
When you want to make purchase transaction, you can simply call makePurchase method of the SDK. SDK will handle the rest of the transaction process. With just giving product to the makePurchase method, you can make purchase for the specified product.
#
RequestParameter Name | Type |
---|---|
product | Product |
completion | (PurchaseResultInfo?, PurchaseCode) -> Void |
#
ResponseParameter Name | Type |
---|---|
purchaseResult | PurchaseResultInfo? |
purchaseCode | PurchaseCode |
- Swift
- Objective-C
PurchaseClient.shared.makePurchase(with: product) { purchaseResult, purchaseCode in if purchaseResult != nil { print(purchaseResult) } else { print(purchaseCode) }}
[[PurchaseClient shared] makePurchaseWith:product completion:^(PurchaseResultInfo * purshaseResult, PurchaseCode purchaseCode) { if (purshaseResult != nil) { NSLog(@"%@", purshaseResult); } else { NSLog(@"%@", purchaseCode); }}];
#
Consume PurchaseOnce purchase is completed, as a part of purchase process you need to deliver a content with granting entitlement as a result of the user's purchase. For one-time consumable product, you need to call consumePurchase method of the SDK to indicate that your app has granted entitlement to the user. With consumption of the one-time consumable product, the product can be purchased again.
note
Because of the consume request can be failed, you might want to grant entitlement after consume request succeded to prevent granting entitlement multiple times for the same purchase.
#
RequestParameter Name | Type |
---|---|
purchaseToken | String purchaseToken |
completion | (ConsumePurchaseResponse?, GenericError?) -> Void) |
#
ResponseParameter Name | Type |
---|---|
response | ConsumePurchaseResponse? |
error | GenericError? |
- Swift
- Objective-C
PurchaseClient.shared.consumePurchaseWithPurchaseToken("purchaseToken") { response, error in if let response = response, response.result!.success { print(response) } else { print(error) }}
OR for multiple
PurchaseClient.shared.consumePurchasesWithPurchaseTokens(["purchaseToken1", "purchaseToken2"]) { response, error in if let response = response, response.result!.success { print(response) } else { print(error) }}
[[PurchaseClient shared] consumePurchaseWithPurchaseToken:@"purchaseToken" completion:^(ConsumePurchaseResponse * response, GenericError * error) { if (response != nil) { NSLog(@"%@", response); } else { NSLog(@"%@", error); }}];
OR for multiple
[[PurchaseClient shared] consumePurchasesWithPurchaseTokens:[NSArray arrayWithObjects:@"purchaseToken1", @"purchaseToken2", nil] completion:^(ConsumePurchaseResponse * response, GenericError * error) { if (response != nil) { NSLog(@"%@", response); } else { NSLog(@"%@", error); }}];
#
UnsubscribeOnce users subscribe to a product, they want to unscubscribe whenever they want. Developer can open Apple's subscription page to show all subscription of users. So, users can easily unsubscribe from a product. To open subscription page, you need to call unsubscribe() method of the SDK.
- Swift
- Objective-C
PurchaseClient.shared.unsubscribe()
[[PurchaseClient shared] unsubscribe];