Skip to content

Commit 67c9d9a

Browse files
Merge pull request #27 from apphud/feature/ahs-62
feat: added sdk type. updated sdk versions
2 parents bb318f2 + e1d0c0b commit 67c9d9a

File tree

12 files changed

+158
-80
lines changed

12 files changed

+158
-80
lines changed

android/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,6 @@ dependencies {
127127
// noinspection GradleDynamicVersion
128128
api 'com.facebook.react:react-native:+'
129129
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
130-
implementation 'com.github.apphud:ApphudSDK-Android:0.8.5'
131-
implementation 'com.android.billingclient:billing:3.0.0'
130+
implementation 'com.github.apphud:ApphudSDK-Android:1.5.5'
131+
implementation 'com.android.billingclient:billing:4.0.0'
132132
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
package com.reactnativeapphudsdk
2+
3+
import com.android.billingclient.api.SkuDetails
4+
import com.apphud.sdk.ApphudPurchaseResult
5+
import com.apphud.sdk.domain.ApphudNonRenewingPurchase
6+
import com.apphud.sdk.domain.ApphudProduct
7+
import com.apphud.sdk.domain.ApphudSubscription
8+
import com.facebook.react.bridge.WritableNativeMap
9+
10+
class ApphudDataTransformer {
11+
companion object {
12+
fun getSubscriptionMap(subscription: ApphudSubscription): WritableNativeMap {
13+
val result: WritableNativeMap = WritableNativeMap();
14+
result.putString("productId", subscription.productId);
15+
result.putString("expiresAt", subscription.expiresAt.toString());
16+
result.putString("statedAt", subscription.startedAt.toString());
17+
result.putString("cancelledAt", subscription.cancelledAt.toString());
18+
result.putBoolean("isInRetryBilling", subscription.isInRetryBilling);
19+
result.putBoolean("isAutoRenewEnabled", subscription.isAutoRenewEnabled);
20+
result.putBoolean("isIntroductoryActivated", subscription.isIntroductoryActivated);
21+
result.putBoolean("isActive", subscription.isActive());
22+
result.putString("kind", subscription.kind.toString());
23+
result.putString("status", subscription.status.toString());
24+
return result;
25+
}
26+
27+
fun getNonRenewingPurchaseMap(purchase: ApphudNonRenewingPurchase): WritableNativeMap {
28+
val item: WritableNativeMap = WritableNativeMap();
29+
item.putString("productId", purchase.productId);
30+
item.putString("purchasedAt", purchase.purchasedAt.toString());
31+
item.putString("canceledAt", purchase.canceledAt.toString());
32+
item.putBoolean("isActive", purchase.isActive());
33+
return item;
34+
}
35+
36+
fun getPurchaseMap(result: ApphudPurchaseResult): WritableNativeMap {
37+
val item: WritableNativeMap = WritableNativeMap();
38+
val purchase = result.purchase;
39+
if (purchase != null) {
40+
item.putString("orderId", purchase.orderId);
41+
item.putString("originalJson", purchase.originalJson);
42+
item.putString("packageName", purchase.packageName);
43+
item.putInt("purchaseState", purchase.purchaseState as Int);
44+
item.putInt("purchaseTime", purchase.purchaseTime.toInt());
45+
item.putString("purchaseToken", purchase.purchaseToken);
46+
item.putString("signature", purchase.signature);
47+
item.putString("sku", purchase.skus.first());
48+
}
49+
return item;
50+
}
51+
52+
fun getProductMap(product: SkuDetails): WritableNativeMap {
53+
val item = WritableNativeMap();
54+
55+
item.putString("id", product.sku);
56+
item.putString("description", product.description);
57+
item.putString("freeTrialPeriod", product.freeTrialPeriod);
58+
item.putString("introductoryPrice", product.introductoryPrice);
59+
item.putInt("introductoryPriceAmountMicros", product.introductoryPriceAmountMicros.toInt());
60+
item.putInt("introductoryPriceCycles", product.introductoryPriceCycles);
61+
item.putString("introductoryPricePeriod", product.introductoryPricePeriod);
62+
item.putInt("priceAmountMicros", product.priceAmountMicros.toInt());
63+
item.putString("priceCurrencyCode", product.priceCurrencyCode);
64+
item.putString("subscriptionPeriod", product.subscriptionPeriod);
65+
item.putString("title", product.title);
66+
item.putString("originalPrice", product.originalPrice);
67+
item.putString("price", product.price);
68+
item.putString("currencyCode", product.priceCurrencyCode);
69+
item.putInt("originalPriceAmountMicros", product.originalPriceAmountMicros.toInt());
70+
item.putString("type", product.type);
71+
72+
return item;
73+
}
74+
}
75+
}

android/src/main/java/com/reactnativeapphudsdk/ApphudSdkModule.kt

Lines changed: 40 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ package com.reactnativeapphudsdk
22
import com.apphud.sdk.Apphud
33
import com.apphud.sdk.ApphudAttributionProvider
44
import com.apphud.sdk.ApphudUserPropertyKey
5+
import com.apphud.sdk.managers.HeadersInterceptor
56
import com.facebook.react.bridge.*
6-
import java.lang.Error
7+
import com.facebook.react.modules.core.DeviceEventManagerModule.RCTDeviceEventEmitter
8+
79

810
class ApphudSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) {
911

@@ -13,6 +15,18 @@ class ApphudSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
1315
return "ApphudSdk"
1416
}
1517

18+
init {
19+
HeadersInterceptor.X_SDK = "reactnative";
20+
HeadersInterceptor.X_SDK_VERSION = "1.0.7";
21+
Apphud.productsFetchCallback {
22+
var arr: WritableNativeArray = WritableNativeArray();
23+
it.map { s -> arr.pushMap(ApphudDataTransformer.getProductMap(s)) }
24+
reactContext
25+
.getJSModule(RCTDeviceEventEmitter::class.java)
26+
.emit("productFetchCallback", arr);
27+
}
28+
}
29+
1630
@ReactMethod
1731
fun start(options: ReadableMap, promise: Promise) {
1832

@@ -59,18 +73,7 @@ class ApphudSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
5973
val subscriptions = Apphud.subscriptions();
6074
val result: WritableNativeArray = WritableNativeArray();
6175
for (subscription in subscriptions) {
62-
val item: WritableNativeMap = WritableNativeMap();
63-
item.putString("status", subscription.status.toString());
64-
item.putString("productId", subscription.productId);
65-
item.putString("expiresAt", subscription.expiresAt.toString());
66-
item.putString("startedAt", subscription.startedAt.toString());
67-
item.putString("cancelledAt", subscription.cancelledAt.toString());
68-
item.putBoolean("isAutoRenewEnabled", subscription.isAutoRenewEnabled);
69-
item.putBoolean("isInRetryBilling", subscription.isInRetryBilling);
70-
item.putBoolean("isIntroductoryActivated", subscription.isIntroductoryActivated);
71-
item.putBoolean("isActive", subscription.isActive());
72-
item.putString("kind", subscription.kind.toString());
73-
result.pushMap(item)
76+
result.pushMap(ApphudDataTransformer.getSubscriptionMap(subscription));
7477
}
7578
promise.resolve(result);
7679
}
@@ -79,20 +82,9 @@ class ApphudSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
7982
fun purchase(productIdentifier: String, promise: Promise) {
8083
this.currentActivity?.let {
8184
try {
82-
Apphud.purchase(it, productIdentifier ) { res ->
85+
Apphud.purchase(it, productIdentifier) { res ->
8386
val result: WritableNativeArray = WritableNativeArray();
84-
for (purchase in res) {
85-
val item: WritableNativeMap = WritableNativeMap();
86-
item.putString("orderId", purchase.orderId);
87-
item.putString("originalJson", purchase.originalJson);
88-
item.putString("packageName", purchase.packageName);
89-
item.putInt("purchaseState", purchase.purchaseState);
90-
item.putInt("purchaseTime", purchase.purchaseTime.toInt());
91-
item.putString("purchaseToken", purchase.purchaseToken);
92-
item.putString("signature", purchase.signature);
93-
item.putString("sku", purchase.sku);
94-
result.pushMap(item);
95-
}
87+
result.pushMap(ApphudDataTransformer.getPurchaseMap(res));
9688
promise.resolve(result);
9789
}
9890
} catch (error: Error) {
@@ -135,11 +127,7 @@ class ApphudSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
135127
val products = Apphud.products();
136128
if (products != null) {
137129
for (product in products) {
138-
val item = WritableNativeMap();
139-
item.putString("id", product.sku);
140-
item.putString("price", product.price);
141-
item.putString("currencyCode", product.priceCurrencyCode);
142-
result.pushMap(item);
130+
result.pushMap(ApphudDataTransformer.getProductMap(product));
143131
}
144132
}
145133
promise.resolve(result);
@@ -150,16 +138,7 @@ class ApphudSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
150138
val subscription = Apphud.subscription();
151139
val result: WritableNativeMap = WritableNativeMap();
152140
if (subscription !== null) {
153-
result.putString("productId", subscription.productId);
154-
result.putString("expiresAt", subscription.expiresAt.toString());
155-
result.putString("statedAt", subscription.startedAt.toString());
156-
result.putString("cancelledAt", subscription.cancelledAt.toString());
157-
result.putBoolean("isInRetryBilling", subscription.isInRetryBilling);
158-
result.putBoolean("isAutoRenewEnabled", subscription.isAutoRenewEnabled);
159-
result.putBoolean("isIntroductoryActivated", subscription.isIntroductoryActivated);
160-
result.putBoolean("isActive", subscription.isActive());
161-
result.putString("kind", subscription.kind.toString());
162-
result.putString("status", subscription.status.toString());
141+
result.merge(ApphudDataTransformer.getSubscriptionMap(subscription));
163142
}
164143
promise.resolve(result);
165144
}
@@ -168,12 +147,7 @@ class ApphudSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
168147
fun nonRenewingPurchases(promise: Promise) {
169148
val result: WritableNativeArray = WritableNativeArray();
170149
for (purchase in Apphud.nonRenewingPurchases()) {
171-
val item: WritableNativeMap = WritableNativeMap();
172-
item.putString("productId", purchase.productId);
173-
item.putString("purchasedAt", purchase.purchasedAt.toString());
174-
item.putString("canceledAt", purchase.canceledAt.toString());
175-
item.putBoolean("isActive", purchase.isActive());
176-
result.pushMap(item);
150+
result.pushMap(ApphudDataTransformer.getNonRenewingPurchaseMap(purchase));
177151
}
178152
promise.resolve(result);
179153
}
@@ -182,11 +156,7 @@ class ApphudSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
182156
fun product(productIdentifier: String, promise: Promise) {
183157
val product = Apphud.product(productIdentifier);
184158
if (product != null) {
185-
val item = WritableNativeMap();
186-
item.putString("id", product.sku);
187-
item.putString("price", product.price);
188-
item.putString("currencyCode", product.priceCurrencyCode);
189-
promise.resolve(item);
159+
promise.resolve(ApphudDataTransformer.getProductMap(product));
190160
} else {
191161
promise.reject("product", "product not found");
192162
}
@@ -200,7 +170,7 @@ class ApphudSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
200170
}
201171

202172
@ReactMethod
203-
fun setUserProperty(key: String, value: String, setOnce: Boolean, promise: Promise) {
173+
fun setUserProperty(key: String, value: String, setOnce: Boolean, promise: Promise) {
204174
val label = getUserPropertyKey(key);
205175
Apphud.setUserProperty(label, value, setOnce);
206176
promise.resolve(true);
@@ -215,7 +185,23 @@ class ApphudSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
215185

216186
@ReactMethod
217187
fun restorePurchases(promise: Promise) {
218-
promise.reject(this.unSupportMethodMsg);
188+
Apphud.restorePurchases { apphudSubscriptionList, apphudNonRenewingPurchaseList, error ->
189+
val resultMap: WritableNativeMap = WritableNativeMap();
190+
apphudSubscriptionList.let {
191+
val arr: WritableNativeArray = WritableNativeArray();
192+
it?.map { obj -> arr.pushMap(ApphudDataTransformer.getSubscriptionMap(obj)) }
193+
resultMap.putArray("subscriptions", arr);
194+
}
195+
apphudNonRenewingPurchaseList.let {
196+
val arr: WritableNativeArray = WritableNativeArray();
197+
it?.map { obj -> arr.pushMap(ApphudDataTransformer.getNonRenewingPurchaseMap(obj)) }
198+
resultMap.putArray("nonRenewingPurchases", arr);
199+
}
200+
error.let {
201+
resultMap.putString("error", it?.message)
202+
}
203+
promise.resolve(resultMap);
204+
}
219205
}
220206

221207
private fun getUserPropertyKey(key: String): ApphudUserPropertyKey {

example/android/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ buildscript {
66
minSdkVersion = 16
77
compileSdkVersion = 29
88
targetSdkVersion = 29
9+
kotlinVersion = '1.5.0'
910
}
1011
repositories {
1112
google()

example/ios/ApphudSdkExample.xcodeproj/project.pbxproj

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,6 @@
309309
TestTargetID = 13B07F861A680F5B00A75B9A;
310310
};
311311
13B07F861A680F5B00A75B9A = {
312-
DevelopmentTeam = SZ57DYCTKD;
313312
LastSwiftMigration = 1120;
314313
};
315314
2D02E47A1E0B4A5D006451C7 = {
@@ -618,7 +617,7 @@
618617
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
619618
CLANG_ENABLE_MODULES = YES;
620619
CURRENT_PROJECT_VERSION = 1;
621-
DEVELOPMENT_TEAM = SZ57DYCTKD;
620+
DEVELOPMENT_TEAM = "";
622621
ENABLE_BITCODE = NO;
623622
INFOPLIST_FILE = ApphudSdkExample/Info.plist;
624623
IPHONEOS_DEPLOYMENT_TARGET = 11.2;
@@ -647,7 +646,7 @@
647646
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
648647
CLANG_ENABLE_MODULES = YES;
649648
CURRENT_PROJECT_VERSION = 1;
650-
DEVELOPMENT_TEAM = SZ57DYCTKD;
649+
DEVELOPMENT_TEAM = "";
651650
INFOPLIST_FILE = ApphudSdkExample/Info.plist;
652651
IPHONEOS_DEPLOYMENT_TARGET = 11.2;
653652
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";

example/ios/Podfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ target 'ApphudSdkExample' do
1515
#
1616
# Note that if you have use_frameworks! enabled, Flipper will not work and
1717
# you should disable these next few lines.
18-
use_flipper!
18+
use_flipper!({ 'Flipper-Folly' => '2.3.0' })
1919
pod 'RNVectorIcons', :path => '../node_modules/react-native-vector-icons'
2020

2121
post_install do |installer|

example/ios/Podfile.lock

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
PODS:
2-
- ApphudSDK (1.2)
2+
- ApphudSDK (2.5.7)
33
- boost-for-react-native (1.63.0)
44
- CocoaAsyncSocket (7.6.5)
55
- CocoaLibEvent (1.0.0)
@@ -24,8 +24,8 @@ PODS:
2424
- OpenSSL-Universal (= 1.0.2.20)
2525
- Flipper-Glog (0.3.6)
2626
- Flipper-PeerTalk (0.0.4)
27-
- Flipper-RSocket (1.1.0):
28-
- Flipper-Folly (~> 2.2)
27+
- Flipper-RSocket (1.1.1):
28+
- Flipper-Folly (~> 2.3)
2929
- FlipperKit (0.54.0):
3030
- FlipperKit/Core (= 0.54.0)
3131
- FlipperKit/Core (0.54.0):
@@ -237,8 +237,8 @@ PODS:
237237
- React-cxxreact (= 0.63.4)
238238
- React-jsi (= 0.63.4)
239239
- React-jsinspector (0.63.4)
240-
- react-native-apphud-sdk (1.0.5):
241-
- ApphudSDK (= 1.2)
240+
- react-native-apphud-sdk (1.0.7):
241+
- ApphudSDK (= 2.5.7)
242242
- React-Core
243243
- react-native-safe-area-context (3.1.9):
244244
- React-Core
@@ -323,7 +323,7 @@ DEPENDENCIES:
323323
- FBReactNativeSpec (from `../node_modules/react-native/Libraries/FBReactNativeSpec`)
324324
- Flipper (~> 0.54.0)
325325
- Flipper-DoubleConversion (= 1.1.7)
326-
- Flipper-Folly (~> 2.2)
326+
- Flipper-Folly (= 2.3.0)
327327
- Flipper-Glog (= 0.3.6)
328328
- Flipper-PeerTalk (~> 0.0.4)
329329
- Flipper-RSocket (~> 1.1)
@@ -461,11 +461,11 @@ EXTERNAL SOURCES:
461461

462462
CHECKOUT OPTIONS:
463463
ApphudSDK:
464-
:commit: 340afa60fe63c57c7168f9a9b2dcee2e3e27dc5f
464+
:commit: 1cd697a40d8a4bce468a5565d7927f694fece1c8
465465
:git: https://github.com/apphud/ApphudSDK.git
466466

467467
SPEC CHECKSUMS:
468-
ApphudSDK: 5bc202682320443ce60040f5155d838e54840289
468+
ApphudSDK: 55201c311a0a24ede1040664ca0a17f188305e54
469469
boost-for-react-native: 39c7adb57c4e60d6c5479dd8623128eb5b3f0f2c
470470
CocoaAsyncSocket: 065fd1e645c7abab64f7a6a2007a48038fdc6a99
471471
CocoaLibEvent: 2fab71b8bd46dd33ddb959f7928ec5909f838e3f
@@ -477,7 +477,7 @@ SPEC CHECKSUMS:
477477
Flipper-Folly: e4493b013c02d9347d5e0cb4d128680239f6c78a
478478
Flipper-Glog: 1dfd6abf1e922806c52ceb8701a3599a79a200a6
479479
Flipper-PeerTalk: 116d8f857dc6ef55c7a5a75ea3ceaafe878aadc9
480-
Flipper-RSocket: 64e7431a55835eb953b0bf984ef3b90ae9fdddd7
480+
Flipper-RSocket: a3acb8812d6adf127deb0a5edae2793b97e6b641
481481
FlipperKit: ab353d41aea8aae2ea6daaf813e67496642f3d7d
482482
Folly: b73c3869541e86821df3c387eb0af5f65addfab4
483483
glog: 40a13f7840415b9a77023fbcae0f1e6f43192af3
@@ -492,7 +492,7 @@ SPEC CHECKSUMS:
492492
React-jsi: a0418934cf48f25b485631deb27c64dc40fb4c31
493493
React-jsiexecutor: 93bd528844ad21dc07aab1c67cb10abae6df6949
494494
React-jsinspector: 58aef7155bc9a9683f5b60b35eccea8722a4f53a
495-
react-native-apphud-sdk: 89b0dcd5264ed11aea17d0ccec4c36af348322cc
495+
react-native-apphud-sdk: 5e68c514b47cf37e7c59bd2cb895a12d6139ee92
496496
react-native-safe-area-context: b6e0e284002381d2ff29fa4fff42b4d8282e3c94
497497
React-RCTActionSheet: 89a0ca9f4a06c1f93c26067af074ccdce0f40336
498498
React-RCTAnimation: 1bde3ecc0c104c55df246eda516e0deb03c4e49b
@@ -512,6 +512,6 @@ SPEC CHECKSUMS:
512512
Yoga: 4bd86afe9883422a7c4028c00e34790f560923d6
513513
YogaKit: f782866e155069a2cca2517aafea43200b01fd5a
514514

515-
PODFILE CHECKSUM: 737cb7c06400c7c9bbabbc940216d7f55b26f71e
515+
PODFILE CHECKSUM: f780c45eee855d325247de0c3fa0e07b0296d758
516516

517-
COCOAPODS: 1.9.3
517+
COCOAPODS: 1.10.1

0 commit comments

Comments
 (0)