Skip to content

Commit fb2e188

Browse files
committed
[subs] add useACOM boolean field to determine whether to use advancedCommerceData or requestData as the custom option key when purchasing
1 parent b9135dd commit fb2e188

File tree

5 files changed

+23
-1
lines changed

5 files changed

+23
-1
lines changed

ios/RNIapIosSk2.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ @interface RCT_EXTERN_MODULE (RNIapIosSk2, NSObject)
4040
RCT_EXTERN_METHOD(buyProduct:
4141
(NSString*)sku
4242
requestJSONString:(NSString*)requestJSONString
43+
useACOM:(BOOL)useACOM
4344
andDangerouslyFinishTransactionAutomatically:(BOOL)andDangerouslyFinishTransactionAutomatically
4445
appAccountToken:(NSString*)appAccountToken
4546
quantity:(NSInteger)quantity

ios/RNIapIosSk2.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ protocol Sk2Delegate {
3434
func buyProduct(
3535
_ sku: String,
3636
requestJSONString: String?,
37+
useACOM: Bool,
3738
andDangerouslyFinishTransactionAutomatically: Bool,
3839
appAccountToken: String?,
3940
quantity: Int,
@@ -157,6 +158,7 @@ class DummySk2: Sk2Delegate {
157158
func buyProduct(
158159
_ sku: String,
159160
requestJSONString: String?,
161+
useACOM: Bool,
160162
andDangerouslyFinishTransactionAutomatically: Bool,
161163
appAccountToken: String?,
162164
quantity: Int,
@@ -333,6 +335,7 @@ class RNIapIosSk2: RCTEventEmitter, Sk2Delegate {
333335
@objc public func buyProduct(
334336
_ sku: String,
335337
requestJSONString: String?,
338+
useACOM: Bool,
336339
andDangerouslyFinishTransactionAutomatically: Bool,
337340
appAccountToken: String?,
338341
quantity: Int,
@@ -343,6 +346,7 @@ class RNIapIosSk2: RCTEventEmitter, Sk2Delegate {
343346
delegate.buyProduct(
344347
sku,
345348
requestJSONString: requestJSONString,
349+
useACOM: useACOM,
346350
andDangerouslyFinishTransactionAutomatically: andDangerouslyFinishTransactionAutomatically,
347351
appAccountToken: appAccountToken,
348352
quantity: quantity,
@@ -704,6 +708,7 @@ class RNIapIosSk2iOS15: Sk2Delegate {
704708
public func buyProduct(
705709
_ sku: String,
706710
requestJSONString: String?,
711+
useACOM: Bool,
707712
andDangerouslyFinishTransactionAutomatically: Bool,
708713
appAccountToken: String?,
709714
quantity: Int,
@@ -720,7 +725,11 @@ class RNIapIosSk2iOS15: Sk2Delegate {
720725

721726
if let requestJSONString = requestJSONString {
722727
let requestData = Data(requestJSONString.utf8)
723-
options.insert(Product.PurchaseOption.custom(key: "requestData", value: requestData))
728+
if useACOM {
729+
options.insert(Product.PurchaseOption.custom(key: "advancedCommerceData", value: requestData))
730+
} else {
731+
options.insert(Product.PurchaseOption.custom(key: "requestData", value: requestData))
732+
}
724733
} else {
725734
if quantity > -1 {
726735
options.insert(.quantity(quantity))

src/iap.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,7 @@ export const requestPurchase = (
598598
quantity,
599599
withOffer,
600600
requestJSONString,
601+
useACOM,
601602
} = request;
602603

603604
if (andDangerouslyFinishTransactionAutomaticallyIOS) {
@@ -612,6 +613,7 @@ export const requestPurchase = (
612613
await RNIapIosSk2.buyProduct(
613614
sku,
614615
requestJSONString,
616+
useACOM === true,
615617
andDangerouslyFinishTransactionAutomaticallyIOS,
616618
appAccountToken,
617619
quantity ?? -1,
@@ -620,6 +622,9 @@ export const requestPurchase = (
620622
);
621623
return Promise.resolve(purchase);
622624
} else {
625+
if (useACOM === true) {
626+
throw new Error('ACOM cannot be used with storekit v1');
627+
}
623628
return RNIapIos.buyProduct(
624629
sku,
625630
requestJSONString,
@@ -757,6 +762,7 @@ export const requestSubscription = (
757762
quantity,
758763
withOffer,
759764
requestJSONString,
765+
useACOM,
760766
} = request;
761767

762768
if (andDangerouslyFinishTransactionAutomaticallyIOS) {
@@ -772,6 +778,7 @@ export const requestSubscription = (
772778
await RNIapIosSk2.buyProduct(
773779
sku,
774780
requestJSONString,
781+
useACOM === true,
775782
andDangerouslyFinishTransactionAutomaticallyIOS,
776783
appAccountToken,
777784
quantity ?? -1,
@@ -780,6 +787,9 @@ export const requestSubscription = (
780787
);
781788
return Promise.resolve(purchase);
782789
} else {
790+
if (useACOM === true) {
791+
throw new Error('ACOM cannot be used with storekit v1');
792+
}
783793
return RNIapIos.buyProduct(
784794
sku,
785795
requestJSONString,

src/modules/iosSk2.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ type getAvailableItems = (
2222
export type BuyProduct = (
2323
sku: Sku,
2424
requestJSONString: string | undefined,
25+
useACOM: boolean,
2526
andDangerouslyFinishTransactionAutomaticallyIOS: boolean,
2627
applicationUsername: string | undefined,
2728
quantity: number,

src/types/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ export interface RequestPurchaseIOS {
232232
sku: Sku;
233233
andDangerouslyFinishTransactionAutomaticallyIOS?: boolean;
234234
requestJSONString?: string;
235+
useACOM?: boolean;
235236
/**
236237
* UUID representing user account
237238
*/

0 commit comments

Comments
 (0)