Skip to main content

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.

Request#

Parameter NameType
productProduct
completion(PurchaseResultInfo?, PurchaseCode) -> Void

Response#

Parameter NameType
purchaseResultPurchaseResultInfo?
purchaseCodePurchaseCode
PurchaseClient.shared.makePurchase(with: product) { purchaseResult, purchaseCode in    if purchaseResult != nil {        print(purchaseResult)    } else {        print(purchaseCode)    }}

Consume Purchase#

Once 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.

Request#

Parameter NameType
purchaseTokenString purchaseToken
completion (ConsumePurchaseResponse?, GenericError?) -> Void)

Response#

Parameter NameType
responseConsumePurchaseResponse?
errorGenericError?
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)    }}

Unsubscribe#

Once 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.

PurchaseClient.shared.unsubscribe()