Skip to content

Commit 5f529a8

Browse files
committed
Adding SK2 option
1 parent 99cd680 commit 5f529a8

File tree

4 files changed

+67
-2
lines changed

4 files changed

+67
-2
lines changed

android/src/main/includeConnector/com/appsflyer/reactnative/PCAppsFlyerModule.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ public void create(ReadableMap config) {
5151
boolean logInApps = config.getBoolean("logInApps");
5252
boolean sandbox = config.getBoolean("sandbox");
5353

54+
// Optional: Log that storeKitVersion is ignored on Android (for debugging purposes)
55+
if (config.hasKey("storeKitVersion")) {
56+
String storeKitVersion = config.getString("storeKitVersion");
57+
Log.d(TAG, "storeKitVersion (" + storeKitVersion + ") is ignored on Android.");
58+
}
59+
5460
MappedValidationResultListener arsListener = this.arsListener;
5561
MappedValidationResultListener viapListener = this.viapListener;
5662

index.d.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,16 @@ declare module "react-native-appsflyer" {
166166
/**
167167
* PurchaseConnector
168168
*/
169+
export const StoreKitVersion = {
170+
SK1: "SK1",
171+
SK2: "SK2",
172+
};
173+
169174
export interface PurchaseConnectorConfig {
170175
logSubscriptions: boolean;
171176
logInApps: boolean;
172177
sandbox: boolean;
178+
storeKitVersion?: keyof typeof StoreKitVersion; // Optional property
173179
}
174180

175181
export const AppsFlyerPurchaseConnectorConfig: {
@@ -180,6 +186,7 @@ declare module "react-native-appsflyer" {
180186
create(config: PurchaseConnectorConfig): void;
181187
startObservingTransactions(): void;
182188
stopObservingTransactions(): void;
189+
logConsumableTransaction(transactionId: string): void;
183190
onSubscriptionValidationResultSuccess(
184191
callback: (data:OnResponse<SubscriptionValidationResult>) => any
185192
): () => void;

index.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ const AppsFlyerPurchaseConnector = {};
1515
const pcEventsMap = {};
1616
const purchaseConnectorEventEmitter = new NativeEventEmitter(PCAppsFlyer);
1717

18+
export const StoreKitVersion = {
19+
SK1: "SK1",
20+
SK2: "SK2",
21+
};
22+
1823
function startObservingTransactions() {
1924
PCAppsFlyer.startObservingTransactions();
2025
}
@@ -197,12 +202,19 @@ AppsFlyerPurchaseConnector.OnReceivePurchaseRevenueValidationInfo = (
197202
};
198203
};
199204

205+
function logConsumableTransaction(transactionId){
206+
PCAppsFlyer.logConsumableTransaction(transactionId);
207+
};
208+
209+
AppsFlyerPurchaseConnector.logConsumableTransaction = logConsumableTransaction;
210+
200211
const AppsFlyerPurchaseConnectorConfig = {
201-
setConfig: ({ logSubscriptions, logInApps, sandbox }) => {
212+
setConfig: ({ logSubscriptions, logInApps, sandbox, storeKitVersion }) => {
202213
return {
203214
logSubscriptions,
204215
logInApps,
205216
sandbox,
217+
storeKitVersion: storeKitVersion || StoreKitVersion.SK1, // Default to SK1 if not provided
206218
};
207219
},
208220
};

ios/PCAppsFlyer.m

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ @implementation PCAppsFlyer
1414
static NSString *const logSubscriptionsKey = @"logSubscriptions";
1515
static NSString *const logInAppsKey = @"logInApps";
1616
static NSString *const sandboxKey = @"sandbox";
17+
static NSString *const storeKitKey = @"storeKitVersion";
1718
static NSString *const connectorAlreadyConfiguredMessage = @"Connector already configured";
1819
static NSString *const connectorNotConfiguredMessage = @"Connector not configured, did you call `create` first?";
1920

@@ -41,8 +42,18 @@ @implementation PCAppsFlyer
4142
BOOL logSubscriptions = [config[logSubscriptionsKey] boolValue];
4243
BOOL logInApps = [config[logInAppsKey] boolValue];
4344
BOOL sandbox = [config[sandboxKey] boolValue];
44-
45+
NSString *storeKitVersion = config[storeKitKey];
46+
4547
[connector setIsSandbox:sandbox];
48+
49+
// Set the StoreKitVersion (default to SK1 if not provided or invalid)
50+
if ([storeKitVersion isEqualToString:@"SK2"]) {
51+
[connector setStoreKitVersion:AFSDKStoreKitVersionSK2];
52+
NSLog(@"%@Configure PurchaseConnector with StoreKit2 Version", TAG);
53+
} else {
54+
[connector setStoreKitVersion:AFSDKStoreKitVersionSK1];
55+
NSLog(@"%@Configure PurchaseConnector with StoreKit1 Version", TAG);
56+
}
4657

4758
if (logSubscriptions && logInApps) {
4859
[connector setAutoLogPurchaseRevenue:AFSDKAutoLogPurchaseRevenueOptionsAutoRenewableSubscriptions | AFSDKAutoLogPurchaseRevenueOptionsInAppPurchases];
@@ -58,6 +69,35 @@ @implementation PCAppsFlyer
5869
resolve(nil);
5970
}
6071

72+
RCT_EXPORT_METHOD(logConsumableTransaction:(NSString *)transactionId
73+
resolver:(RCTPromiseResolveBlock)resolve
74+
rejecter:(RCTPromiseRejectBlock)reject) {
75+
NSLog(@"%@Logging consumable transaction with ID: %@", TAG, transactionId);
76+
77+
if (connector == nil) {
78+
reject(connectorNotConfiguredMessage, connectorNotConfiguredMessage, nil);
79+
return;
80+
}
81+
82+
// Call the Swift method via the TransactionFetcher class
83+
/*
84+
[TransactionFetcher fetchTransactionWithId:transactionId completion:^(AFSDKTransactionSK2 * _Nullable afTransaction) {
85+
if (afTransaction) {
86+
// Use the fetched transaction
87+
[connector logConsumableTransaction:afTransaction];
88+
NSLog(@"Logged transaction: %@", transactionId);
89+
resolve(nil);
90+
} else {
91+
// Handle the case where the transaction was not found
92+
NSError *error = [NSError errorWithDomain:@"PCAppsFlyer"
93+
code:404
94+
userInfo:@{NSLocalizedDescriptionKey: @"Transaction not found"}];
95+
reject(@"transaction_not_found", @"Transaction not found", error);
96+
}
97+
}];
98+
*/
99+
}
100+
61101
RCT_EXPORT_METHOD(startObservingTransactions:(RCTPromiseResolveBlock)resolve
62102
rejecter:(RCTPromiseRejectBlock)reject) {
63103
NSLog(@"%@Starting to observe transactions.", TAG);

0 commit comments

Comments
 (0)