Skip to content

Commit 8e8f84f

Browse files
authored
UPDATE react-native-hms-iap 5.1.0-300 (#101)
* UPDATE react-native-hms-iap 5.1.0-300
1 parent 57fd5c4 commit 8e8f84f

52 files changed

Lines changed: 2409 additions & 3430 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
-318 KB
Binary file not shown.
-257 KB
Binary file not shown.
-353 KB
Binary file not shown.

react-native-hms-iap/README.md

Lines changed: 24 additions & 1060 deletions
Large diffs are not rendered by default.

react-native-hms-iap/THIRD PARTY OPEN SOURCE SOFTWARE NOTICE.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ APPLICABLE LICENSES FOR MORE DETAILS.
1212
Copyright Notice and License Texts
1313

1414

15-
Software: gson 2.8.5
15+
Software: com.google.code.gson:gson 2.8.5
1616
----------------------------------------------------------------------
1717

1818
Copyright notice:

react-native-hms-iap/android/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ buildscript {
77
}
88
dependencies {
99
classpath 'com.android.tools.build:gradle:3.6.0'
10-
classpath 'com.huawei.agconnect:agcp:1.4.1.300'
10+
classpath 'com.huawei.agconnect:agcp:1.4.2.301'
1111
}
1212
}
1313

@@ -45,9 +45,9 @@ dependencies {
4545
//noinspection GradleDynamicVersion
4646
implementation 'com.facebook.react:react-native:+' // From node_modules
4747
// AGCONNECT
48-
implementation "com.huawei.agconnect:agconnect-core:1.4.1.300"
48+
implementation "com.huawei.agconnect:agconnect-core:1.4.2.301"
4949
// IAP
50-
implementation "com.huawei.hms:iap:5.0.2.300"
50+
implementation "com.huawei.hms:iap:5.1.0.300"
5151
// GSON
5252
implementation "com.google.code.gson:gson:2.8.5"
5353
}

react-native-hms-iap/android/gradlew

100755100644
File mode changed.

react-native-hms-iap/android/src/main/java/com/huawei/hms/rn/iap/HmsIapModule.java renamed to react-native-hms-iap/android/src/main/java/com/huawei/hms/rn/iap/HMSIapModule.java

Lines changed: 49 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2020. Huawei Technologies Co., Ltd. All rights reserved.
2+
Copyright 2020-2021. Huawei Technologies Co., Ltd. All rights reserved.
33
44
Licensed under the Apache License, Version 2.0 (the "License")
55
you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@
1717

1818
import android.app.Activity;
1919
import android.content.Intent;
20+
import android.content.IntentSender;
2021
import android.util.Log;
2122

2223
import androidx.annotation.NonNull;
@@ -45,18 +46,25 @@
4546
import com.huawei.hms.iap.entity.PurchaseResultInfo;
4647
import com.huawei.hms.iap.entity.StartIapActivityReq;
4748
import com.huawei.hms.iap.entity.StartIapActivityResult;
49+
import com.huawei.hms.iap.util.IapClientHelper;
4850
import com.huawei.hms.rn.iap.client.Helper;
4951
import com.huawei.hms.rn.iap.client.utils.Constants;
5052
import com.huawei.hms.rn.iap.client.utils.ExceptionHandler;
5153
import com.huawei.hms.rn.iap.client.utils.DataUtils;
54+
import com.huawei.hms.rn.iap.client.utils.MapUtil;
5255
import com.huawei.hms.rn.iap.client.viewmodel.Service;
5356
import com.huawei.hms.rn.iap.client.viewmodel.ViewModel;
57+
import com.huawei.hms.support.api.client.Status;
5458

55-
import java.util.Map;
59+
import org.json.JSONException;
60+
import org.json.JSONObject;
5661

62+
import java.util.Map;
63+
import java.util.Objects;
5764
import static com.huawei.hms.rn.iap.client.Helper.toIAPObject;
5865
import static com.huawei.hms.rn.iap.client.utils.Constants.CONSTANTS;
5966
import static com.huawei.hms.rn.iap.client.utils.Constants.REQ_CODE_PURCHASE_INTENT;
67+
import static com.huawei.hms.rn.iap.client.utils.DataUtils.getMapFromIsEnvReadyResult;
6068
import static com.huawei.hms.rn.iap.client.utils.MapUtil.createWritableMapWithSuccessStatus;
6169
import static com.huawei.hms.rn.iap.client.utils.MapUtil.getKeyByValue;
6270
import static com.huawei.hms.rn.iap.client.utils.MapUtil.toWritableMap;
@@ -66,9 +74,9 @@
6674
*
6775
* @since v.5.0.0
6876
*/
69-
public class HmsIapModule extends ReactContextBaseJavaModule implements Service.View {
77+
public class HMSIapModule extends ReactContextBaseJavaModule implements Service.View {
7078

71-
private final String TAG = HmsIapModule.class.getSimpleName();
79+
private final String TAG = HMSIapModule.class.getSimpleName();
7280
private IapClient iapClient;
7381
private Service.Presenter viewModel;
7482
private Promise mPickerPromise;
@@ -87,36 +95,24 @@ public void onActivityResult(Activity activity, int requestCode, int resultCode,
8795
PurchaseResultInfo purchaseIntentResult= Iap.getIapClient(getActivity())
8896
.parsePurchaseResultInfoFromIntent(intent);
8997
WritableMap purchaseIntentResultMap = DataUtils.getMapCreatePurchaseIntent(purchaseIntentResult);
90-
switch (purchaseIntentResult.getReturnCode()) {
91-
case OrderStatusCode.ORDER_STATE_CANCEL:
92-
String message = getKeyByValue(CONSTANTS, OrderStatusCode.ORDER_STATE_CANCEL);
93-
assert message != null;
94-
Log.i(TAG, message);
95-
mPickerPromise.resolve(purchaseIntentResultMap);
96-
break;
97-
case OrderStatusCode.ORDER_STATE_FAILED:
98-
message = getKeyByValue(CONSTANTS, OrderStatusCode.ORDER_STATE_FAILED);
99-
assert message != null;
100-
Log.i(TAG, message);
101-
mPickerPromise.resolve(purchaseIntentResultMap);
102-
break;
103-
case OrderStatusCode.ORDER_PRODUCT_OWNED:
104-
message = getKeyByValue(CONSTANTS, OrderStatusCode.ORDER_PRODUCT_OWNED);
105-
assert message != null;
106-
Log.i(TAG, message);
107-
mPickerPromise.resolve(purchaseIntentResultMap);
108-
break;
109-
case OrderStatusCode.ORDER_STATE_SUCCESS:
110-
message = getKeyByValue(CONSTANTS, OrderStatusCode.ORDER_STATE_SUCCESS);
111-
assert message != null;
112-
Log.i(TAG, message);
113-
mPickerPromise.resolve(purchaseIntentResultMap);
114-
break;
115-
default:
116-
message = "Order unknown error.";
117-
Log.i(TAG, message);
118-
mPickerPromise.resolve(purchaseIntentResultMap);
119-
break;
98+
mPickerPromise.resolve(purchaseIntentResultMap);
99+
Log.i(TAG, String.valueOf(purchaseIntentResult.getReturnCode()));
100+
}
101+
if(requestCode == Constants.REQ_IS_ENVIRONMENT_READY) {
102+
Log.i(TAG, "onActivityResult from isEnvReady");
103+
final int accountFlag = IapClientHelper.parseAccountFlagFromIntent(intent);
104+
final int returnCode = IapClientHelper.parseRespCodeFromIntent(intent);
105+
if (returnCode == 0) {
106+
WritableMap writableMap = null;
107+
try {
108+
JSONObject j = new JSONObject();
109+
j.put("accountFlag", accountFlag);
110+
j.put("returnCode", returnCode);
111+
writableMap = MapUtil.toWritableMap(j);
112+
mPickerPromise.resolve(writableMap);
113+
} catch (JSONException e) {
114+
Log.e(TAG, Objects.requireNonNull(e.getMessage()));
115+
}
120116
}
121117
}
122118
mPickerPromise = null;
@@ -129,7 +125,7 @@ public void onNewIntent(Intent intent) {
129125
}
130126
};
131127

132-
HmsIapModule(ReactApplicationContext context) {
128+
HMSIapModule(ReactApplicationContext context) {
133129
super(context);
134130
this.context = context;
135131
initializeIapClient(this.context);
@@ -195,7 +191,24 @@ public void disableLogger(Promise promise) {
195191
*/
196192
@ReactMethod
197193
public void isEnvironmentReady(final Promise promise) {
198-
viewModel.isEnvironmentReady(iapClient, new IapReqHelper(promise));
194+
viewModel.isEnvironmentReady(iapClient, new Service.IAPResultListener<IsEnvReadyResult>() {
195+
@Override
196+
public void onSuccess(IsEnvReadyResult result) {
197+
promise.resolve(DataUtils.getMapFromIsEnvReadyResult(result));
198+
}
199+
200+
@Override
201+
public void onFail(Exception exception) {
202+
if (exception instanceof IapApiException) {
203+
IapApiException apiException = (IapApiException) exception;
204+
Status status = apiException.getStatus();
205+
mPickerPromise = promise;
206+
if (status.getStatusCode() == OrderStatusCode.ORDER_HWID_NOT_LOGIN) {
207+
Helper.startResolutionForResult(getActivity(), status, Constants.REQ_IS_ENVIRONMENT_READY);
208+
}
209+
}
210+
}
211+
});
199212
}
200213

201214
/**

react-native-hms-iap/android/src/main/java/com/huawei/hms/rn/iap/HmsIapPackage.java renamed to react-native-hms-iap/android/src/main/java/com/huawei/hms/rn/iap/HMSIapPackage.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2020. Huawei Technologies Co., Ltd. All rights reserved.
2+
Copyright 2020-2021. Huawei Technologies Co., Ltd. All rights reserved.
33
44
Licensed under the Apache License, Version 2.0 (the "License")
55
you may not use this file except in compliance with the License.
@@ -27,7 +27,7 @@
2727
import java.util.Collections;
2828
import java.util.List;
2929

30-
public class HmsIapPackage implements ReactPackage {
30+
public class HMSIapPackage implements ReactPackage {
3131
/**
3232
* The last step within Java is to register
3333
* the Module; this happens in the createNativeModules
@@ -41,7 +41,7 @@ public class HmsIapPackage implements ReactPackage {
4141
@Override
4242
public List<NativeModule> createNativeModules(@NonNull ReactApplicationContext reactContext) {
4343
List<NativeModule> modules = new ArrayList<>();
44-
modules.add(new HmsIapModule(reactContext));
44+
modules.add(new HMSIapModule(reactContext));
4545
return modules;
4646
}
4747

react-native-hms-iap/android/src/main/java/com/huawei/hms/rn/iap/client/Helper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2020. Huawei Technologies Co., Ltd. All rights reserved.
2+
Copyright 2020-2021. Huawei Technologies Co., Ltd. All rights reserved.
33
44
Licensed under the Apache License, Version 2.0 (the "License")
55
you may not use this file except in compliance with the License.

0 commit comments

Comments
 (0)