diff --git a/ios/RNIapIosSk2.m b/ios/RNIapIosSk2.m index a4fa1364d..42de8a045 100644 --- a/ios/RNIapIosSk2.m +++ b/ios/RNIapIosSk2.m @@ -40,6 +40,7 @@ @interface RCT_EXTERN_MODULE (RNIapIosSk2, NSObject) RCT_EXTERN_METHOD(buyProduct: (NSString*)sku requestJSONString:(NSString*)requestJSONString + useACOM:(BOOL)useACOM andDangerouslyFinishTransactionAutomatically:(BOOL)andDangerouslyFinishTransactionAutomatically appAccountToken:(NSString*)appAccountToken quantity:(NSInteger)quantity diff --git a/ios/RNIapIosSk2.swift b/ios/RNIapIosSk2.swift index 4c5e15ff3..a1fbd4a9c 100644 --- a/ios/RNIapIosSk2.swift +++ b/ios/RNIapIosSk2.swift @@ -34,6 +34,7 @@ protocol Sk2Delegate { func buyProduct( _ sku: String, requestJSONString: String?, + useACOM: Bool, andDangerouslyFinishTransactionAutomatically: Bool, appAccountToken: String?, quantity: Int, @@ -157,6 +158,7 @@ class DummySk2: Sk2Delegate { func buyProduct( _ sku: String, requestJSONString: String?, + useACOM: Bool, andDangerouslyFinishTransactionAutomatically: Bool, appAccountToken: String?, quantity: Int, @@ -333,6 +335,7 @@ class RNIapIosSk2: RCTEventEmitter, Sk2Delegate { @objc public func buyProduct( _ sku: String, requestJSONString: String?, + useACOM: Bool, andDangerouslyFinishTransactionAutomatically: Bool, appAccountToken: String?, quantity: Int, @@ -343,6 +346,7 @@ class RNIapIosSk2: RCTEventEmitter, Sk2Delegate { delegate.buyProduct( sku, requestJSONString: requestJSONString, + useACOM: useACOM, andDangerouslyFinishTransactionAutomatically: andDangerouslyFinishTransactionAutomatically, appAccountToken: appAccountToken, quantity: quantity, @@ -704,6 +708,7 @@ class RNIapIosSk2iOS15: Sk2Delegate { public func buyProduct( _ sku: String, requestJSONString: String?, + useACOM: Bool, andDangerouslyFinishTransactionAutomatically: Bool, appAccountToken: String?, quantity: Int, @@ -720,7 +725,11 @@ class RNIapIosSk2iOS15: Sk2Delegate { if let requestJSONString = requestJSONString { let requestData = Data(requestJSONString.utf8) - options.insert(Product.PurchaseOption.custom(key: "requestData", value: requestData)) + if useACOM { + options.insert(Product.PurchaseOption.custom(key: "advancedCommerceData", value: requestData)) + } else { + options.insert(Product.PurchaseOption.custom(key: "requestData", value: requestData)) + } } else { if quantity > -1 { options.insert(.quantity(quantity)) diff --git a/src/iap.ts b/src/iap.ts index 97e43a2ea..dd2e0c407 100644 --- a/src/iap.ts +++ b/src/iap.ts @@ -598,6 +598,7 @@ export const requestPurchase = ( quantity, withOffer, requestJSONString, + useACOM, } = request; if (andDangerouslyFinishTransactionAutomaticallyIOS) { @@ -612,6 +613,7 @@ export const requestPurchase = ( await RNIapIosSk2.buyProduct( sku, requestJSONString, + useACOM === true, andDangerouslyFinishTransactionAutomaticallyIOS, appAccountToken, quantity ?? -1, @@ -620,6 +622,9 @@ export const requestPurchase = ( ); return Promise.resolve(purchase); } else { + if (useACOM === true) { + throw new Error('ACOM cannot be used with storekit v1'); + } return RNIapIos.buyProduct( sku, requestJSONString, @@ -757,6 +762,7 @@ export const requestSubscription = ( quantity, withOffer, requestJSONString, + useACOM, } = request; if (andDangerouslyFinishTransactionAutomaticallyIOS) { @@ -772,6 +778,7 @@ export const requestSubscription = ( await RNIapIosSk2.buyProduct( sku, requestJSONString, + useACOM === true, andDangerouslyFinishTransactionAutomaticallyIOS, appAccountToken, quantity ?? -1, @@ -780,6 +787,9 @@ export const requestSubscription = ( ); return Promise.resolve(purchase); } else { + if (useACOM === true) { + throw new Error('ACOM cannot be used with storekit v1'); + } return RNIapIos.buyProduct( sku, requestJSONString, diff --git a/src/modules/iosSk2.ts b/src/modules/iosSk2.ts index f7f66a29f..0fd0de76b 100644 --- a/src/modules/iosSk2.ts +++ b/src/modules/iosSk2.ts @@ -22,6 +22,7 @@ type getAvailableItems = ( export type BuyProduct = ( sku: Sku, requestJSONString: string | undefined, + useACOM: boolean, andDangerouslyFinishTransactionAutomaticallyIOS: boolean, applicationUsername: string | undefined, quantity: number, diff --git a/src/types/index.ts b/src/types/index.ts index 22e455bc2..ecac4546d 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -231,6 +231,7 @@ export interface RequestPurchaseIOS { sku: Sku; andDangerouslyFinishTransactionAutomaticallyIOS?: boolean; requestJSONString?: string; + useACOM?: boolean; /** * UUID representing user account */