react-native-payengine 1.0.5 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/.gradle/5.6.4/executionHistory/executionHistory.bin +0 -0
- package/android/.gradle/5.6.4/executionHistory/executionHistory.lock +0 -0
- package/android/.gradle/5.6.4/fileContent/fileContent.lock +0 -0
- package/android/.gradle/5.6.4/fileHashes/fileHashes.bin +0 -0
- package/android/.gradle/5.6.4/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/5.6.4/fileHashes/resourceHashesCache.bin +0 -0
- package/android/.gradle/5.6.4/javaCompile/classAnalysis.bin +0 -0
- package/android/.gradle/5.6.4/javaCompile/jarAnalysis.bin +0 -0
- package/android/.gradle/5.6.4/javaCompile/javaCompile.lock +0 -0
- package/android/.gradle/5.6.4/javaCompile/taskHistory.bin +0 -0
- package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
- package/android/.gradle/buildOutputCleanup/outputFiles.bin +0 -0
- package/android/.idea/compiler.xml +1 -1
- package/android/.idea/gradle.xml +1 -0
- package/android/.idea/misc.xml +1 -1
- package/android/build.gradle +24 -9
- package/android/src/legacy/AndroidManifest.xml +4 -0
- package/android/src/main/java/com/reactnativepayengine/GooglePayModule.java +196 -0
- package/android/src/main/java/com/reactnativepayengine/PayenginePackage.java +1 -0
- package/android/src/main/java/com/reactnativepayengine/collect/VGSCollectModule.java +22 -17
- package/android/src/main/java/com/reactnativepayengine/util/PaymentsUtil.java +113 -0
- package/ios/Payengine.m +18 -1
- package/ios/Payengine.swift +85 -2
- package/ios/Payengine.xcodeproj/project.pbxproj +16 -5
- package/ios/Payengine.xcodeproj/project.xcworkspace/xcuserdata/tringuyen.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- package/ios/Payengine.xcodeproj/xcuserdata/tringuyen.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +4 -4
- package/ios/Payengine.xcworkspace/xcuserdata/tringuyen.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- package/lib/commonjs/components/ApplePay/PayEngineApplePay.js +71 -0
- package/lib/commonjs/components/ApplePay/PayEngineApplePay.js.map +1 -0
- package/lib/commonjs/components/ApplePay/index.js +46 -0
- package/lib/commonjs/components/ApplePay/index.js.map +1 -0
- package/lib/commonjs/components/ApplePay/interfaces.js +2 -0
- package/lib/commonjs/components/ApplePay/interfaces.js.map +1 -0
- package/lib/commonjs/components/CreditCardForm/index.js +76 -0
- package/lib/commonjs/components/CreditCardForm/index.js.map +1 -0
- package/lib/commonjs/components/GooglePay/PayEngineGooglePay.js +65 -0
- package/lib/commonjs/components/GooglePay/PayEngineGooglePay.js.map +1 -0
- package/lib/commonjs/components/GooglePay/index.js +40 -0
- package/lib/commonjs/components/GooglePay/index.js.map +1 -0
- package/lib/commonjs/components/GooglePay/interfaces.js +2 -0
- package/lib/commonjs/components/GooglePay/interfaces.js.map +1 -0
- package/lib/commonjs/components/Legacy/CreditCardFormLegacy.js +323 -0
- package/lib/commonjs/components/Legacy/CreditCardFormLegacy.js.map +1 -0
- package/lib/commonjs/components/PayEngine.js.map +1 -1
- package/lib/commonjs/components/SecureFields/VGS/CollectManager.js +3 -8
- package/lib/commonjs/components/SecureFields/VGS/CollectManager.js.map +1 -1
- package/lib/commonjs/index.js +33 -4
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/interfaces/index.js +6 -0
- package/lib/commonjs/interfaces/index.js.map +1 -0
- package/lib/commonjs/utils/index.js +20 -8
- package/lib/commonjs/utils/index.js.map +1 -1
- package/lib/module/components/ApplePay/PayEngineApplePay.js +58 -0
- package/lib/module/components/ApplePay/PayEngineApplePay.js.map +1 -0
- package/lib/module/components/ApplePay/index.js +35 -0
- package/lib/module/components/ApplePay/index.js.map +1 -0
- package/lib/module/components/ApplePay/interfaces.js +2 -0
- package/lib/module/components/ApplePay/interfaces.js.map +1 -0
- package/lib/module/components/CreditCardForm/index.js +60 -0
- package/lib/module/components/CreditCardForm/index.js.map +1 -0
- package/lib/module/components/GooglePay/PayEngineGooglePay.js +52 -0
- package/lib/module/components/GooglePay/PayEngineGooglePay.js.map +1 -0
- package/lib/module/components/GooglePay/index.js +29 -0
- package/lib/module/components/GooglePay/index.js.map +1 -0
- package/lib/module/components/GooglePay/interfaces.js +2 -0
- package/lib/module/components/GooglePay/interfaces.js.map +1 -0
- package/lib/module/components/Legacy/CreditCardFormLegacy.js +302 -0
- package/lib/module/components/Legacy/CreditCardFormLegacy.js.map +1 -0
- package/lib/module/components/PayEngine.js.map +1 -1
- package/lib/module/components/SecureFields/VGS/CollectManager.js +3 -8
- package/lib/module/components/SecureFields/VGS/CollectManager.js.map +1 -1
- package/lib/module/index.js +6 -5
- package/lib/module/index.js.map +1 -1
- package/lib/module/interfaces/index.js +2 -0
- package/lib/module/interfaces/index.js.map +1 -0
- package/lib/module/utils/index.js +14 -8
- package/lib/module/utils/index.js.map +1 -1
- package/lib/typescript/components/ApplePay/PayEngineApplePay.d.ts +12 -0
- package/lib/typescript/components/ApplePay/index.d.ts +7 -0
- package/lib/typescript/components/ApplePay/interfaces.d.ts +20 -0
- package/lib/typescript/components/CreditCardForm/index.d.ts +3 -0
- package/lib/typescript/components/GooglePay/PayEngineGooglePay.d.ts +10 -0
- package/lib/typescript/components/GooglePay/index.d.ts +7 -0
- package/lib/typescript/components/GooglePay/interfaces.d.ts +38 -0
- package/lib/typescript/components/Legacy/CreditCardFormLegacy.d.ts +4 -0
- package/lib/typescript/components/PayEngine.d.ts +1 -1
- package/lib/typescript/components/SecureFields/VGS/CollectManager.d.ts +1 -1
- package/lib/typescript/index.d.ts +6 -2
- package/lib/typescript/interfaces/index.d.ts +33 -0
- package/lib/typescript/utils/index.d.ts +5 -6
- package/package.json +6 -5
- package/react-native-payengine.podspec +2 -2
- package/src/components/ApplePay/PayEngineApplePay.ts +61 -0
- package/src/components/ApplePay/index.ts +32 -0
- package/src/components/ApplePay/interfaces.ts +25 -0
- package/src/components/CreditCardForm/index.tsx +43 -0
- package/src/components/GooglePay/PayEngineGooglePay.ts +48 -0
- package/src/components/GooglePay/index.ts +39 -0
- package/src/components/GooglePay/interfaces.ts +42 -0
- package/src/components/Legacy/CreditCardFormLegacy.tsx +292 -0
- package/src/components/LoadingIndicator.tsx +28 -0
- package/src/components/PayEngine.tsx +121 -0
- package/src/components/SecureFields/VGS/CVCField.tsx +21 -0
- package/src/components/SecureFields/VGS/CardHolderNameField.tsx +21 -0
- package/src/components/SecureFields/VGS/CardNumberField.tsx +21 -0
- package/src/components/SecureFields/VGS/CollectManager.tsx +74 -0
- package/src/components/SecureFields/VGS/ExpDateField.tsx +21 -0
- package/src/components/SecureFields/VGS/TextField.tsx +27 -0
- package/src/components/SecureFields/VGS/ZipCodeField.tsx +21 -0
- package/src/components/SecureFields/index.ts +17 -0
- package/src/index.tsx +37 -0
- package/src/interfaces/index.ts +38 -0
- package/src/utils/index.ts +107 -0
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/android/.idea/gradle.xml
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
<option name="testRunner" value="GRADLE" />
|
|
8
8
|
<option name="distributionType" value="DEFAULT_WRAPPED" />
|
|
9
9
|
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
|
10
|
+
<option name="gradleJvm" value="adopt-11" />
|
|
10
11
|
<option name="modules">
|
|
11
12
|
<set>
|
|
12
13
|
<option value="$PROJECT_DIR$" />
|
package/android/.idea/misc.xml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
2
|
<project version="4">
|
|
3
3
|
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
|
4
|
-
<component name="ProjectRootManager" version="2" languageLevel="
|
|
4
|
+
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
|
5
5
|
<output url="file://$PROJECT_DIR$/build/classes" />
|
|
6
6
|
</component>
|
|
7
7
|
<component name="ProjectType">
|
package/android/build.gradle
CHANGED
|
@@ -9,8 +9,12 @@ buildscript {
|
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
+
def isAndroidXEnabled() {
|
|
13
|
+
return rootProject.hasProperty("android.useAndroidX") && rootProject.getProperty("android.useAndroidX") == "true"
|
|
14
|
+
}
|
|
15
|
+
|
|
12
16
|
def isNewArchitectureEnabled() {
|
|
13
|
-
return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
|
|
17
|
+
return isAndroidXEnabled() && rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
|
|
14
18
|
}
|
|
15
19
|
|
|
16
20
|
apply plugin: 'com.android.library'
|
|
@@ -49,6 +53,19 @@ android {
|
|
|
49
53
|
sourceCompatibility JavaVersion.VERSION_1_8
|
|
50
54
|
targetCompatibility JavaVersion.VERSION_1_8
|
|
51
55
|
}
|
|
56
|
+
|
|
57
|
+
if (!isAndroidXEnabled()) {
|
|
58
|
+
sourceSets {
|
|
59
|
+
main {
|
|
60
|
+
java {
|
|
61
|
+
srcDir 'src/legacy/java'
|
|
62
|
+
}
|
|
63
|
+
resources {
|
|
64
|
+
srcDir 'src/legacy/resources'
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
52
69
|
}
|
|
53
70
|
|
|
54
71
|
repositories {
|
|
@@ -126,14 +143,12 @@ dependencies {
|
|
|
126
143
|
//noinspection GradleDynamicVersion
|
|
127
144
|
implementation "com.facebook.react:react-native:+"
|
|
128
145
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
146
|
+
if (isAndroidXEnabled()) {
|
|
147
|
+
implementation "com.google.android.material:material:1.6.1"
|
|
148
|
+
releaseImplementation files('./vgscollect-1.7.2-debug.aar')
|
|
149
|
+
debugImplementation files('./vgscollect-1.7.2-debug.aar')
|
|
150
|
+
}
|
|
151
|
+
implementation 'com.google.android.gms:play-services-wallet:16.0.0'
|
|
137
152
|
|
|
138
153
|
// From node_modules
|
|
139
154
|
}
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
package com.reactnativepayengine;
|
|
2
|
+
|
|
3
|
+
import android.app.Activity;
|
|
4
|
+
import android.content.Intent;
|
|
5
|
+
import android.util.Log;
|
|
6
|
+
|
|
7
|
+
import com.facebook.react.bridge.ActivityEventListener;
|
|
8
|
+
import com.facebook.react.bridge.BaseActivityEventListener;
|
|
9
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
|
10
|
+
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
|
11
|
+
import com.facebook.react.bridge.ReactMethod;
|
|
12
|
+
import com.facebook.react.bridge.ReadableArray;
|
|
13
|
+
import com.facebook.react.bridge.ReadableMap;
|
|
14
|
+
import com.facebook.react.bridge.Promise;
|
|
15
|
+
|
|
16
|
+
import com.google.android.gms.wallet.PaymentsClient;
|
|
17
|
+
import com.google.android.gms.wallet.WalletConstants;
|
|
18
|
+
import com.google.android.gms.wallet.IsReadyToPayRequest;
|
|
19
|
+
import com.google.android.gms.wallet.AutoResolveHelper;
|
|
20
|
+
import com.google.android.gms.wallet.PaymentData;
|
|
21
|
+
import com.google.android.gms.wallet.PaymentDataRequest;
|
|
22
|
+
import com.google.android.gms.common.api.Status;
|
|
23
|
+
import com.google.android.gms.tasks.OnCompleteListener;
|
|
24
|
+
import com.google.android.gms.tasks.Task;
|
|
25
|
+
import com.reactnativepayengine.util.PaymentsUtil;
|
|
26
|
+
|
|
27
|
+
import androidx.annotation.NonNull;
|
|
28
|
+
|
|
29
|
+
import java.util.HashMap;
|
|
30
|
+
import java.util.Map;
|
|
31
|
+
|
|
32
|
+
import org.json.JSONException;
|
|
33
|
+
import org.json.JSONObject;
|
|
34
|
+
|
|
35
|
+
public class GooglePayModule extends ReactContextBaseJavaModule {
|
|
36
|
+
|
|
37
|
+
private static final String TAG = "ReactNative";
|
|
38
|
+
|
|
39
|
+
private static final String ENVIRONMENT_PRODUCTION_KEY = "ENVIRONMENT_PRODUCTION";
|
|
40
|
+
|
|
41
|
+
private static final String ENVIRONMENT_TEST_KEY = "ENVIRONMENT_TEST";
|
|
42
|
+
|
|
43
|
+
private final ReactApplicationContext reactContext;
|
|
44
|
+
|
|
45
|
+
private PaymentsClient mPaymentsClient;
|
|
46
|
+
|
|
47
|
+
private Promise requestPaymentPromise = null;
|
|
48
|
+
|
|
49
|
+
private static final int LOAD_PAYMENT_DATA_REQUEST_CODE = 991;
|
|
50
|
+
|
|
51
|
+
private final ActivityEventListener activityEventListener = new BaseActivityEventListener() {
|
|
52
|
+
@Override
|
|
53
|
+
public void onActivityResult(Activity activity, int requestCode, int resultCode, Intent data) {
|
|
54
|
+
switch (requestCode) {
|
|
55
|
+
// value passed in AutoResolveHelper
|
|
56
|
+
case LOAD_PAYMENT_DATA_REQUEST_CODE:
|
|
57
|
+
switch (resultCode) {
|
|
58
|
+
case Activity.RESULT_OK:
|
|
59
|
+
PaymentData paymentData = PaymentData.getFromIntent(data);
|
|
60
|
+
handlePaymentSuccess(paymentData);
|
|
61
|
+
break;
|
|
62
|
+
case Activity.RESULT_CANCELED:
|
|
63
|
+
requestPaymentPromise.reject("PAYMENT_RESULT_CANCELED", "Payment has been canceled");
|
|
64
|
+
break;
|
|
65
|
+
case AutoResolveHelper.RESULT_ERROR:
|
|
66
|
+
Status status = AutoResolveHelper.getStatusFromIntent(data);
|
|
67
|
+
int statusCode = status.getStatusCode();
|
|
68
|
+
String errorMessage = String.format("loadPaymentData failed. Error code: %d", statusCode);
|
|
69
|
+
Log.w(TAG, "[GooglePay] " + errorMessage);
|
|
70
|
+
requestPaymentPromise.reject("PAYMENT_RESULT_ERROR", errorMessage);
|
|
71
|
+
break;
|
|
72
|
+
default:
|
|
73
|
+
// Do nothing.
|
|
74
|
+
}
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
public GooglePayModule(ReactApplicationContext reactContext) {
|
|
81
|
+
super(reactContext);
|
|
82
|
+
this.reactContext = reactContext;
|
|
83
|
+
reactContext.addActivityEventListener(activityEventListener);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
@Override
|
|
87
|
+
public Map<String, Object> getConstants() {
|
|
88
|
+
final Map<String, Object> constants = new HashMap<>();
|
|
89
|
+
constants.put(ENVIRONMENT_PRODUCTION_KEY, WalletConstants.ENVIRONMENT_PRODUCTION);
|
|
90
|
+
constants.put(ENVIRONMENT_TEST_KEY, WalletConstants.ENVIRONMENT_TEST);
|
|
91
|
+
return constants;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
@ReactMethod
|
|
95
|
+
public void setEnvironment(int environment) {
|
|
96
|
+
final Activity activity = getCurrentActivity();
|
|
97
|
+
if (activity == null) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
mPaymentsClient = PaymentsUtil.createPaymentsClient(environment, activity);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
@ReactMethod
|
|
104
|
+
public void isReadyToPay(ReadableArray allowedCardNetworks, ReadableArray allowedCardAuthMethods, final Promise promise) {
|
|
105
|
+
final Activity activity = getCurrentActivity();
|
|
106
|
+
if (activity == null) {
|
|
107
|
+
Log.w(TAG, "[GooglePay] activity is null");
|
|
108
|
+
promise.resolve(false);
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
final JSONObject isReadyToPayJson = PaymentsUtil.getIsReadyToPayRequest(allowedCardNetworks.toArrayList(), allowedCardAuthMethods.toArrayList());
|
|
112
|
+
if (isReadyToPayJson == null) {
|
|
113
|
+
Log.w(TAG, "[GooglePay] isReadyToPayJson == null");
|
|
114
|
+
promise.resolve(false);
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
IsReadyToPayRequest request = IsReadyToPayRequest.fromJson(isReadyToPayJson.toString());
|
|
118
|
+
if (request == null) {
|
|
119
|
+
Log.w(TAG, "[GooglePay] IsReadyToPayRequest == null");
|
|
120
|
+
promise.resolve(false);
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// The call to isReadyToPay is asynchronous and returns a Task. We need to provide an
|
|
125
|
+
// OnCompleteListener to be triggered when the result of the call is known.
|
|
126
|
+
Task<Boolean> task = mPaymentsClient.isReadyToPay(request);
|
|
127
|
+
task.addOnCompleteListener(activity,
|
|
128
|
+
new OnCompleteListener<Boolean>() {
|
|
129
|
+
@Override
|
|
130
|
+
public void onComplete(@NonNull Task<Boolean> task) {
|
|
131
|
+
if (task.isSuccessful()) {
|
|
132
|
+
if (task.getResult()) {
|
|
133
|
+
promise.resolve(true);
|
|
134
|
+
} else {
|
|
135
|
+
Log.w(TAG, "[GooglePay] Not available");
|
|
136
|
+
promise.resolve(false);
|
|
137
|
+
}
|
|
138
|
+
} else {
|
|
139
|
+
Log.w(TAG, "[GooglePay] isReadyToPay failed. May add com.google.android.gms.wallet.api.enabled to your manifest?");
|
|
140
|
+
promise.resolve(false);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
@ReactMethod
|
|
147
|
+
public void requestPayment(ReadableMap requestData, final Promise promise) {
|
|
148
|
+
final Activity activity = getCurrentActivity();
|
|
149
|
+
if (activity == null) {
|
|
150
|
+
Log.w(TAG, "[GooglePay] activity is null");
|
|
151
|
+
promise.reject("NO_ACTIVITY", "activity is null");
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
JSONObject paymentDataRequestJson = PaymentsUtil.getPaymentDataRequest(requestData);
|
|
155
|
+
if (paymentDataRequestJson == null) {
|
|
156
|
+
promise.reject("PAYMENT_DATA_REQUEST_JSON", "paymentDataRequestJson is null");
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
this.requestPaymentPromise = promise;
|
|
161
|
+
|
|
162
|
+
PaymentDataRequest request = PaymentDataRequest.fromJson(paymentDataRequestJson.toString());
|
|
163
|
+
if (request != null) {
|
|
164
|
+
AutoResolveHelper.resolveTask(mPaymentsClient.loadPaymentData(request), activity, LOAD_PAYMENT_DATA_REQUEST_CODE);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
private void handlePaymentSuccess(PaymentData paymentData) {
|
|
169
|
+
String paymentInformation = paymentData.toJson();
|
|
170
|
+
|
|
171
|
+
// Token will be null if PaymentDataRequest was not constructed using fromJson(String).
|
|
172
|
+
if (paymentInformation == null) {
|
|
173
|
+
requestPaymentPromise.reject("NULL_PAYMENT_INFORMATION", "paymentInformation is null");
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
JSONObject paymentMethodData;
|
|
177
|
+
|
|
178
|
+
try {
|
|
179
|
+
paymentMethodData = new JSONObject(paymentInformation).getJSONObject("paymentMethodData");
|
|
180
|
+
// If the gateway is set to "example", no payment information is returned - instead, the
|
|
181
|
+
// token will only consist of "examplePaymentMethodToken".
|
|
182
|
+
|
|
183
|
+
// Logging token string.
|
|
184
|
+
String token = paymentMethodData.getJSONObject("tokenizationData").getString("token");
|
|
185
|
+
requestPaymentPromise.resolve(token);
|
|
186
|
+
} catch (JSONException e) {
|
|
187
|
+
Log.e(TAG, "[GooglePay] handlePaymentSuccess error: " + e.toString());
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
@Override
|
|
193
|
+
public String getName() {
|
|
194
|
+
return "GooglePay";
|
|
195
|
+
}
|
|
196
|
+
}
|
|
@@ -39,6 +39,7 @@ public class PayenginePackage implements ReactPackage, VGSCollectOnCreateViewIns
|
|
|
39
39
|
|
|
40
40
|
List<NativeModule> modules = new ArrayList<>();
|
|
41
41
|
modules.add(new PayengineModule(reactContext));
|
|
42
|
+
modules.add(new GooglePayModule(reactContext));
|
|
42
43
|
modules.add(module);
|
|
43
44
|
|
|
44
45
|
return modules;
|
|
@@ -33,6 +33,7 @@ public class VGSCollectModule extends ReactContextBaseJavaModule {
|
|
|
33
33
|
private static ReactApplicationContext reactContext;
|
|
34
34
|
|
|
35
35
|
private VGSCollect collect;
|
|
36
|
+
private String publicKey;
|
|
36
37
|
|
|
37
38
|
public VGSCollectModule(ReactApplicationContext c) {
|
|
38
39
|
super(c);
|
|
@@ -42,9 +43,9 @@ public class VGSCollectModule extends ReactContextBaseJavaModule {
|
|
|
42
43
|
@Override
|
|
43
44
|
public void initialize() {
|
|
44
45
|
super.initialize();
|
|
45
|
-
//
|
|
46
|
-
//
|
|
47
|
-
//
|
|
46
|
+
// Activity activity = reactContext.getCurrentActivity();
|
|
47
|
+
// collect = new VGSCollect.Builder(activity, "")
|
|
48
|
+
// .create();
|
|
48
49
|
}
|
|
49
50
|
|
|
50
51
|
@NonNull
|
|
@@ -54,17 +55,19 @@ public class VGSCollectModule extends ReactContextBaseJavaModule {
|
|
|
54
55
|
}
|
|
55
56
|
|
|
56
57
|
@ReactMethod
|
|
57
|
-
public void setConfiguration(String vaultId, String environment, String cname,
|
|
58
|
+
public void setConfiguration(String publicKey, String vaultId, String environment, String cname,
|
|
59
|
+
double vgsSatellitePort) {
|
|
58
60
|
Log.e("test", "Create event called with name: " + vaultId + " and location: " + environment + " cname: " + cname);
|
|
59
61
|
|
|
62
|
+
this.publicKey = publicKey;
|
|
60
63
|
VGSCollectLogger.INSTANCE.setLogLevel(VGSCollectLogger.Level.DEBUG);
|
|
61
64
|
|
|
62
65
|
Activity activity = reactContext.getCurrentActivity();
|
|
63
66
|
collect = new VGSCollect.Builder(activity, vaultId)
|
|
64
|
-
|
|
65
|
-
//
|
|
66
|
-
//
|
|
67
|
-
|
|
67
|
+
.setEnvironment(environment)
|
|
68
|
+
// .setHostname(cname)
|
|
69
|
+
// .setPort((int) Math.round(vgsSatellitePort))
|
|
70
|
+
.create();
|
|
68
71
|
|
|
69
72
|
}
|
|
70
73
|
|
|
@@ -85,8 +88,10 @@ public class VGSCollectModule extends ReactContextBaseJavaModule {
|
|
|
85
88
|
customData.put("merchant_id", merchantId);
|
|
86
89
|
}
|
|
87
90
|
|
|
91
|
+
String authHeader = "Signature key=\"" + this.publicKey
|
|
92
|
+
+ "\",algorithm=\"hmac-sha256\",identifier=\"secure-fields\",signature=\"\"";
|
|
88
93
|
HashMap<String, String> headers = new HashMap<>();
|
|
89
|
-
headers.put("
|
|
94
|
+
headers.put("Authorization", authHeader);
|
|
90
95
|
|
|
91
96
|
List<FieldState> states = collect.getAllStates();
|
|
92
97
|
|
|
@@ -95,9 +100,9 @@ public class VGSCollectModule extends ReactContextBaseJavaModule {
|
|
|
95
100
|
|
|
96
101
|
if (!state.isValid()) {
|
|
97
102
|
String message = new StringBuilder("Field ")
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
103
|
+
.append(state.getFieldName())
|
|
104
|
+
.append(" is not valid.")
|
|
105
|
+
.toString();
|
|
101
106
|
promise.reject("validation_error", message);
|
|
102
107
|
return;
|
|
103
108
|
}
|
|
@@ -110,11 +115,11 @@ public class VGSCollectModule extends ReactContextBaseJavaModule {
|
|
|
110
115
|
}
|
|
111
116
|
|
|
112
117
|
VGSRequest request = new VGSRequest.VGSRequestBuilder()
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
+
.setMethod(HTTPMethod.POST)
|
|
119
|
+
.setPath(path)
|
|
120
|
+
.setCustomHeader(headers)
|
|
121
|
+
.setCustomData(customData)
|
|
122
|
+
.build();
|
|
118
123
|
|
|
119
124
|
VGSResponse response = collect.submit(request);
|
|
120
125
|
Log.e("test", "response " + response.getBody());
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
package com.reactnativepayengine.util;
|
|
2
|
+
import android.app.Activity;
|
|
3
|
+
|
|
4
|
+
import com.google.android.gms.wallet.PaymentsClient;
|
|
5
|
+
import com.google.android.gms.wallet.Wallet;
|
|
6
|
+
|
|
7
|
+
import org.json.JSONArray;
|
|
8
|
+
import org.json.JSONException;
|
|
9
|
+
import org.json.JSONObject;
|
|
10
|
+
|
|
11
|
+
import java.util.ArrayList;
|
|
12
|
+
|
|
13
|
+
import com.facebook.react.bridge.ReadableMap;
|
|
14
|
+
|
|
15
|
+
public class PaymentsUtil {
|
|
16
|
+
|
|
17
|
+
private PaymentsUtil() {
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
private static JSONObject getBaseRequest() throws JSONException {
|
|
21
|
+
return new JSONObject().put("apiVersion", 2).put("apiVersionMinor", 0);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
private static JSONObject getBaseCardPaymentMethod(ArrayList allowedCardNetworks, ArrayList allowedCardAuthMethods) throws JSONException {
|
|
25
|
+
JSONObject cardPaymentMethod = new JSONObject();
|
|
26
|
+
cardPaymentMethod.put("type", "CARD");
|
|
27
|
+
|
|
28
|
+
JSONObject parameters = new JSONObject();
|
|
29
|
+
parameters.put("allowedAuthMethods", new JSONArray(allowedCardAuthMethods));
|
|
30
|
+
parameters.put("allowedCardNetworks", new JSONArray(allowedCardNetworks));
|
|
31
|
+
|
|
32
|
+
cardPaymentMethod.put("parameters", parameters);
|
|
33
|
+
|
|
34
|
+
return cardPaymentMethod;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
public static PaymentsClient createPaymentsClient(int environment, Activity activity) {
|
|
38
|
+
Wallet.WalletOptions walletOptions = new Wallet.WalletOptions.Builder().setEnvironment(environment).build();
|
|
39
|
+
return Wallet.getPaymentsClient(activity, walletOptions);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
public static JSONObject getIsReadyToPayRequest(ArrayList allowedCardNetworks, ArrayList allowedCardAuthMethods) {
|
|
43
|
+
try {
|
|
44
|
+
JSONObject isReadyToPayRequest = getBaseRequest();
|
|
45
|
+
JSONArray allowedPaymentMethods = new JSONArray().put(getBaseCardPaymentMethod(allowedCardNetworks, allowedCardAuthMethods));
|
|
46
|
+
isReadyToPayRequest.put("allowedPaymentMethods", allowedPaymentMethods);
|
|
47
|
+
return isReadyToPayRequest;
|
|
48
|
+
} catch (JSONException e) {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
private static JSONObject getTransactionInfo(ReadableMap transaction) throws JSONException {
|
|
54
|
+
JSONObject transactionInfo = new JSONObject();
|
|
55
|
+
transactionInfo.put("totalPrice", transaction.getString("totalPrice"));
|
|
56
|
+
transactionInfo.put("totalPriceStatus", transaction.getString("totalPriceStatus"));
|
|
57
|
+
transactionInfo.put("currencyCode", transaction.getString("currencyCode"));
|
|
58
|
+
|
|
59
|
+
return transactionInfo;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
private static JSONObject getMerchantInfo(String merchantName) throws JSONException {
|
|
63
|
+
return new JSONObject().put("merchantName", merchantName);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
private static JSONObject getTokenizationSpecification(final ReadableMap tokenizationSpecification) throws JSONException {
|
|
67
|
+
return new JSONObject() {{
|
|
68
|
+
put("type", tokenizationSpecification.getString("type"));
|
|
69
|
+
put("parameters", new JSONObject() {
|
|
70
|
+
{
|
|
71
|
+
if (tokenizationSpecification.hasKey("gateway")) {
|
|
72
|
+
put("gateway", tokenizationSpecification.getString("gateway"));
|
|
73
|
+
}
|
|
74
|
+
if (tokenizationSpecification.hasKey("gatewayMerchantId")) {
|
|
75
|
+
put("gatewayMerchantId", tokenizationSpecification.getString("gatewayMerchantId"));
|
|
76
|
+
}
|
|
77
|
+
if (tokenizationSpecification.hasKey("publicKey")) {
|
|
78
|
+
put("protocolVersion", "ECv2");
|
|
79
|
+
put("publicKey", tokenizationSpecification.getString("publicKey"));
|
|
80
|
+
}
|
|
81
|
+
if (tokenizationSpecification.hasKey("stripe")) {
|
|
82
|
+
final ReadableMap stripe = tokenizationSpecification.getMap("stripe");
|
|
83
|
+
put("stripe:publishableKey", stripe.getString("publishableKey"));
|
|
84
|
+
put("stripe:version", stripe.getString("version"));
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
}};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
private static JSONObject getCardPaymentMethod(ReadableMap cardPaymentMethodData) throws JSONException {
|
|
92
|
+
ArrayList allowedCardNetworks = cardPaymentMethodData.getArray("allowedCardNetworks").toArrayList();
|
|
93
|
+
ArrayList allowedCardAuthMethods = cardPaymentMethodData.getArray("allowedCardAuthMethods").toArrayList();
|
|
94
|
+
JSONObject cardPaymentMethod = getBaseCardPaymentMethod(allowedCardNetworks, allowedCardAuthMethods);
|
|
95
|
+
cardPaymentMethod.put("tokenizationSpecification", getTokenizationSpecification(cardPaymentMethodData.getMap("tokenizationSpecification")));
|
|
96
|
+
|
|
97
|
+
return cardPaymentMethod;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
public static JSONObject getPaymentDataRequest(ReadableMap requestData) {
|
|
101
|
+
try {
|
|
102
|
+
JSONObject paymentDataRequest = PaymentsUtil.getBaseRequest();
|
|
103
|
+
paymentDataRequest.put(
|
|
104
|
+
"allowedPaymentMethods", new JSONArray().put(PaymentsUtil.getCardPaymentMethod(requestData.getMap("cardPaymentMethod"))));
|
|
105
|
+
paymentDataRequest.put("transactionInfo", PaymentsUtil.getTransactionInfo(requestData.getMap("transaction")));
|
|
106
|
+
paymentDataRequest.put("merchantInfo", PaymentsUtil.getMerchantInfo(requestData.getString("merchantName")));
|
|
107
|
+
|
|
108
|
+
return paymentDataRequest;
|
|
109
|
+
} catch (JSONException e) {
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
package/ios/Payengine.m
CHANGED
|
@@ -8,6 +8,22 @@ RCT_EXTERN_METHOD(multiply:(float)a withB:(float)b
|
|
|
8
8
|
withResolver:(RCTPromiseResolveBlock)resolve
|
|
9
9
|
withRejecter:(RCTPromiseRejectBlock)reject)
|
|
10
10
|
|
|
11
|
+
+ (BOOL)requiresMainQueueSetup
|
|
12
|
+
{
|
|
13
|
+
return NO;
|
|
14
|
+
}
|
|
15
|
+
@end
|
|
16
|
+
|
|
17
|
+
@interface RCT_EXTERN_MODULE(ApplePay, NSObject)
|
|
18
|
+
|
|
19
|
+
RCT_EXTERN_METHOD(invokeApplePay:(NSDictionary)method details:(NSDictionary)details)
|
|
20
|
+
|
|
21
|
+
RCT_EXTERN_METHOD(initApplePay:(RCTPromiseResolveBlock)resolve
|
|
22
|
+
withRejecter:(RCTPromiseRejectBlock)reject)
|
|
23
|
+
|
|
24
|
+
RCT_EXTERN_METHOD(canMakePayments:(RCTPromiseResolveBlock)resolve
|
|
25
|
+
withRejecter:(RCTPromiseRejectBlock)reject)
|
|
26
|
+
|
|
11
27
|
+ (BOOL)requiresMainQueueSetup
|
|
12
28
|
{
|
|
13
29
|
return NO;
|
|
@@ -15,9 +31,10 @@ RCT_EXTERN_METHOD(multiply:(float)a withB:(float)b
|
|
|
15
31
|
|
|
16
32
|
@end
|
|
17
33
|
|
|
34
|
+
|
|
18
35
|
@interface RCT_EXTERN_MODULE(VGSCollectManager, RCTViewManager)
|
|
19
36
|
|
|
20
|
-
RCT_EXTERN_METHOD(setConfiguration: (NSString *)vaultId environment:(NSString *)environment hostname:(NSString *)hostname satellitePort:(NSInteger *)satellitePort);
|
|
37
|
+
RCT_EXTERN_METHOD(setConfiguration: (NSString *)pKey vaultId:(NSString *)vaultId environment:(NSString *)environment hostname:(NSString *)hostname satellitePort:(NSInteger *)satellitePort);
|
|
21
38
|
|
|
22
39
|
RCT_EXTERN_METHOD(createCard: (NSString *)merchantId resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject);
|
|
23
40
|
RCT_EXTERN_METHOD(createBankAccount: (NSString *)merchantId resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject);
|