@xbenjii/react-native-braintree-dropin-ui 2.0.0 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,265 +1,318 @@
1
- package com.xbenjii.RNBraintreeDropIn;
2
-
3
- import android.app.Activity;
4
-
5
- import androidx.annotation.NonNull;
6
- import androidx.fragment.app.FragmentActivity;
7
-
8
- import com.braintreepayments.api.BraintreeClient;
9
- import com.braintreepayments.api.Card;
10
- import com.braintreepayments.api.CardClient;
11
- import com.braintreepayments.api.DropInClient;
12
- import com.braintreepayments.api.DropInListener;
13
- import com.braintreepayments.api.DropInPaymentMethod;
14
- import com.braintreepayments.api.ThreeDSecureRequest;
15
- import com.braintreepayments.api.UserCanceledException;
16
- import com.facebook.react.bridge.ReactApplicationContext;
17
- import com.facebook.react.bridge.ReactContextBaseJavaModule;
18
- import com.facebook.react.bridge.ReactMethod;
19
- import com.facebook.react.bridge.ReadableMap;
20
- import com.facebook.react.bridge.Arguments;
21
- import com.facebook.react.bridge.WritableMap;
22
- import com.facebook.react.bridge.Promise;
23
- import com.braintreepayments.api.DropInRequest;
24
- import com.braintreepayments.api.DropInResult;
25
- import com.braintreepayments.api.PaymentMethodNonce;
26
- import com.braintreepayments.api.CardNonce;
27
- import com.braintreepayments.api.ThreeDSecureInfo;
28
- import com.braintreepayments.api.GooglePayRequest;
29
- import com.google.android.gms.wallet.TransactionInfo;
30
- import com.google.android.gms.wallet.WalletConstants;
31
-
32
- import java.util.Objects;
33
-
34
- public class RNBraintreeDropInModule extends ReactContextBaseJavaModule {
35
- private boolean isVerifyingThreeDSecure = false;
36
- private static DropInClient dropInClient = null;
37
- private static String clientToken = null;
38
-
39
- public static void initDropInClient(FragmentActivity activity) {
40
- dropInClient = new DropInClient(activity, callback -> {
41
- if (clientToken != null) {
42
- callback.onSuccess(clientToken);
43
- } else {
44
- callback.onFailure(new Exception("Client token is null"));
45
- }
46
- });
47
- }
48
-
49
- public RNBraintreeDropInModule(ReactApplicationContext reactContext) {
50
- super(reactContext);
51
- }
52
-
53
- @ReactMethod
54
- public void show(final ReadableMap options, final Promise promise) {
55
- isVerifyingThreeDSecure = false;
56
-
57
- if (!options.hasKey("clientToken")) {
58
- promise.reject("NO_CLIENT_TOKEN", "You must provide a client token");
59
- return;
60
- }
61
-
62
- FragmentActivity currentActivity = (FragmentActivity) getCurrentActivity();
63
- if (currentActivity == null) {
64
- promise.reject("NO_ACTIVITY", "There is no current activity");
65
- return;
66
- }
67
-
68
- DropInRequest dropInRequest = new DropInRequest();
69
-
70
- if(options.hasKey("vaultManager")) {
71
- dropInRequest.setVaultManagerEnabled(options.getBoolean("vaultManager"));
72
- }
73
-
74
- if(options.hasKey("googlePay") && options.getBoolean("googlePay")){
75
- GooglePayRequest googlePayRequest = new GooglePayRequest();
76
- googlePayRequest.setTransactionInfo(TransactionInfo.newBuilder()
77
- .setTotalPrice(Objects.requireNonNull(options.getString("orderTotal")))
78
- .setTotalPriceStatus(WalletConstants.TOTAL_PRICE_STATUS_FINAL)
79
- .setCurrencyCode(Objects.requireNonNull(options.getString("currencyCode")))
80
- .build());
81
- googlePayRequest.setBillingAddressRequired(true);
82
- googlePayRequest.setGoogleMerchantId(options.getString("googlePayMerchantId"));
83
-
84
- dropInRequest.setGooglePayDisabled(false);
85
- dropInRequest.setGooglePayRequest(googlePayRequest);
86
- }else{
87
- dropInRequest.setGooglePayDisabled(true);
88
- }
89
-
90
- if(options.hasKey("cardDisabled")) {
91
- dropInRequest.setCardDisabled(options.getBoolean("cardDisabled"));
92
- }
93
-
94
- if (options.hasKey("threeDSecure")) {
95
- final ReadableMap threeDSecureOptions = options.getMap("threeDSecure");
96
- if (threeDSecureOptions == null || !threeDSecureOptions.hasKey("amount")) {
97
- promise.reject("NO_3DS_AMOUNT", "You must provide an amount for 3D Secure");
98
- return;
99
- }
100
-
101
- isVerifyingThreeDSecure = true;
102
-
103
- ThreeDSecureRequest threeDSecureRequest = new ThreeDSecureRequest();
104
- threeDSecureRequest.setAmount(threeDSecureOptions.getString("amount"));
105
-
106
- dropInRequest.setThreeDSecureRequest(threeDSecureRequest);
107
- }
108
-
109
- dropInRequest.setPayPalDisabled(!options.hasKey("payPal") || !options.getBoolean("payPal"));
110
-
111
- clientToken = options.getString("clientToken");
112
-
113
- if (dropInClient == null) {
114
- promise.reject(
115
- "DROP_IN_CLIENT_UNINITIALIZED",
116
- "Did you forget to call RNBraintreeDropInModule.initDropInClient(this) in MainActivity.onCreate?"
117
- );
118
- return;
119
- }
120
- dropInClient.setListener(new DropInListener() {
121
- @Override
122
- public void onDropInSuccess(@NonNull DropInResult dropInResult) {
123
- PaymentMethodNonce paymentMethodNonce = dropInResult.getPaymentMethodNonce();
124
-
125
- if (isVerifyingThreeDSecure && paymentMethodNonce instanceof CardNonce) {
126
- CardNonce cardNonce = (CardNonce) paymentMethodNonce;
127
- ThreeDSecureInfo threeDSecureInfo = cardNonce.getThreeDSecureInfo();
128
- if (!threeDSecureInfo.isLiabilityShiftPossible()) {
129
- promise.reject("3DSECURE_NOT_ABLE_TO_SHIFT_LIABILITY", "3D Secure liability cannot be shifted");
130
- } else if (!threeDSecureInfo.isLiabilityShifted()) {
131
- promise.reject("3DSECURE_LIABILITY_NOT_SHIFTED", "3D Secure liability was not shifted");
132
- } else {
133
- resolvePayment(dropInResult, promise);
134
- }
135
- } else {
136
- resolvePayment(dropInResult, promise);
137
- }
138
- }
139
-
140
- @Override
141
- public void onDropInFailure(@NonNull Exception exception) {
142
- if (exception instanceof UserCanceledException) {
143
- promise.reject("USER_CANCELLATION", "The user cancelled");
144
- } else {
145
- promise.reject(exception.getMessage(), exception.getMessage());
146
- }
147
- }
148
- });
149
- dropInClient.launchDropIn(dropInRequest);
150
- }
151
-
152
- @ReactMethod
153
- public void fetchMostRecentPaymentMethod(final String clientToken, final Promise promise) {
154
- FragmentActivity currentActivity = (FragmentActivity) getCurrentActivity();
155
-
156
- if (currentActivity == null) {
157
- promise.reject("NO_ACTIVITY", "There is no current activity");
158
- return;
159
- }
160
-
161
- if (dropInClient == null) {
162
- promise.reject(
163
- "DROP_IN_CLIENT_UNINITIALIZED",
164
- "Did you forget to call RNBraintreeDropInModule.initDropInClient(this) in MainActivity.onCreate?"
165
- );
166
- return;
167
- }
168
-
169
- RNBraintreeDropInModule.clientToken = clientToken;
170
-
171
- dropInClient.fetchMostRecentPaymentMethod(currentActivity, (dropInResult, error) -> {
172
- if (error != null) {
173
- promise.reject(error.getMessage(), error.getMessage());
174
- } else if (dropInResult == null) {
175
- promise.reject("NO_DROP_IN_RESULT", "dropInResult is null");
176
- } else {
177
- resolvePayment(dropInResult, promise);
178
- }
179
- });
180
- }
181
-
182
- @ReactMethod
183
- public void tokenizeCard(final String clientToken, final ReadableMap cardInfo, final Promise promise) {
184
- if (clientToken == null) {
185
- promise.reject("NO_CLIENT_TOKEN", "You must provide a client token");
186
- return;
187
- }
188
-
189
- if (
190
- !cardInfo.hasKey("number") ||
191
- !cardInfo.hasKey("expirationMonth") ||
192
- !cardInfo.hasKey("expirationYear") ||
193
- !cardInfo.hasKey("cvv") ||
194
- !cardInfo.hasKey("postalCode")
195
- ) {
196
- promise.reject("INVALID_CARD_INFO", "Invalid card info");
197
- return;
198
- }
199
-
200
- Activity currentActivity = getCurrentActivity();
201
-
202
- if (currentActivity == null) {
203
- promise.reject("NO_ACTIVITY", "There is no current activity");
204
- return;
205
- }
206
-
207
- BraintreeClient braintreeClient = new BraintreeClient(getCurrentActivity(), clientToken);
208
- CardClient cardClient = new CardClient(braintreeClient);
209
-
210
- Card card = new Card();
211
- card.setNumber(cardInfo.getString("number"));
212
- card.setExpirationMonth(cardInfo.getString("expirationMonth"));
213
- card.setExpirationYear(cardInfo.getString("expirationYear"));
214
- card.setCvv(cardInfo.getString("cvv"));
215
- card.setPostalCode(cardInfo.getString("postalCode"));
216
-
217
- cardClient.tokenize(card, (cardNonce, error) -> {
218
- if (error != null) {
219
- promise.reject(error.getMessage(), error.getMessage());
220
- } else if (cardNonce == null) {
221
- promise.reject("NO_CARD_NONCE", "Card nonce is null");
222
- } else {
223
- promise.resolve(cardNonce.getString());
224
- }
225
- });
226
- }
227
-
228
- private void resolvePayment(DropInResult dropInResult, Promise promise) {
229
- String deviceData = dropInResult.getDeviceData();
230
- PaymentMethodNonce paymentMethodNonce = dropInResult.getPaymentMethodNonce();
231
-
232
- WritableMap jsResult = Arguments.createMap();
233
-
234
- if (paymentMethodNonce == null) {
235
- promise.resolve(null);
236
- return;
237
- }
238
-
239
- Activity currentActivity = getCurrentActivity();
240
- if (currentActivity == null) {
241
- promise.reject("NO_ACTIVITY", "There is no current activity");
242
- return;
243
- }
244
-
245
- DropInPaymentMethod dropInPaymentMethod = dropInResult.getPaymentMethodType();
246
- if (dropInPaymentMethod == null) {
247
- promise.reject("NO_PAYMENT_METHOD", "There is no payment method");
248
- return;
249
- }
250
-
251
- jsResult.putString("nonce", paymentMethodNonce.getString());
252
- jsResult.putString("type", currentActivity.getString(dropInPaymentMethod.getLocalizedName()));
253
- jsResult.putString("description", dropInResult.getPaymentDescription());
254
- jsResult.putBoolean("isDefault", paymentMethodNonce.isDefault());
255
- jsResult.putString("deviceData", deviceData);
256
-
257
- promise.resolve(jsResult);
258
- }
259
-
260
- @NonNull
261
- @Override
262
- public String getName() {
263
- return "RNBraintreeDropIn";
264
- }
265
- }
1
+ package com.xbenjii.RNBraintreeDropIn;
2
+
3
+ import android.app.Activity;
4
+
5
+ import androidx.annotation.NonNull;
6
+ import androidx.fragment.app.FragmentActivity;
7
+
8
+ import com.braintreepayments.api.BraintreeClient;
9
+ import com.braintreepayments.api.DataCollector;
10
+ import com.braintreepayments.api.Card;
11
+ import com.braintreepayments.api.CardClient;
12
+ import com.braintreepayments.api.DropInClient;
13
+ import com.braintreepayments.api.DropInListener;
14
+ import com.braintreepayments.api.DropInPaymentMethod;
15
+ import com.braintreepayments.api.ThreeDSecureRequest;
16
+ import com.braintreepayments.api.UserCanceledException;
17
+ import com.braintreepayments.api.PayPalAccountNonce;
18
+ import com.braintreepayments.api.GooglePayCardNonce;
19
+ import com.braintreepayments.api.PostalAddress;
20
+ import com.facebook.react.bridge.ReactApplicationContext;
21
+ import com.facebook.react.bridge.ReactContextBaseJavaModule;
22
+ import com.facebook.react.bridge.ReactMethod;
23
+ import com.facebook.react.bridge.ReadableMap;
24
+ import com.facebook.react.bridge.Arguments;
25
+ import com.facebook.react.bridge.WritableMap;
26
+ import com.facebook.react.bridge.Promise;
27
+ import com.braintreepayments.api.DropInRequest;
28
+ import com.braintreepayments.api.DropInResult;
29
+ import com.braintreepayments.api.PaymentMethodNonce;
30
+ import com.braintreepayments.api.CardNonce;
31
+ import com.braintreepayments.api.ThreeDSecureInfo;
32
+ import com.braintreepayments.api.GooglePayRequest;
33
+ import com.google.android.gms.wallet.TransactionInfo;
34
+ import com.google.android.gms.wallet.WalletConstants;
35
+
36
+ import java.util.Objects;
37
+
38
+ public class RNBraintreeDropInModule extends ReactContextBaseJavaModule {
39
+ private boolean isVerifyingThreeDSecure = false;
40
+ private static DropInClient dropInClient = null;
41
+ private static String clientToken = null;
42
+ public static final int GPAY_BILLING_ADDRESS_FORMAT_FULL = 1;
43
+
44
+ public static void initDropInClient(FragmentActivity activity) {
45
+ dropInClient = new DropInClient(activity, callback -> {
46
+ if (clientToken != null) {
47
+ callback.onSuccess(clientToken);
48
+ } else {
49
+ callback.onFailure(new Exception("Client token is null"));
50
+ }
51
+ });
52
+ }
53
+
54
+ public RNBraintreeDropInModule(ReactApplicationContext reactContext) {
55
+ super(reactContext);
56
+ }
57
+
58
+ @ReactMethod
59
+ public void show(final ReadableMap options, final Promise promise) {
60
+ isVerifyingThreeDSecure = false;
61
+
62
+ if (!options.hasKey("clientToken")) {
63
+ promise.reject("NO_CLIENT_TOKEN", "You must provide a client token");
64
+ return;
65
+ }
66
+
67
+ FragmentActivity currentActivity = (FragmentActivity) getCurrentActivity();
68
+ if (currentActivity == null) {
69
+ promise.reject("NO_ACTIVITY", "There is no current activity");
70
+ return;
71
+ }
72
+
73
+ DropInRequest dropInRequest = new DropInRequest();
74
+
75
+ if(options.hasKey("vaultManager")) {
76
+ dropInRequest.setVaultManagerEnabled(options.getBoolean("vaultManager"));
77
+ }
78
+
79
+ if(options.hasKey("googlePay") && options.getBoolean("googlePay")){
80
+ GooglePayRequest googlePayRequest = new GooglePayRequest();
81
+ googlePayRequest.setTransactionInfo(TransactionInfo.newBuilder()
82
+ .setTotalPrice(Objects.requireNonNull(options.getString("orderTotal")))
83
+ .setTotalPriceStatus(WalletConstants.TOTAL_PRICE_STATUS_FINAL)
84
+ .setCurrencyCode(Objects.requireNonNull(options.getString("currencyCode")))
85
+ .build());
86
+ googlePayRequest.setBillingAddressRequired(true);
87
+ googlePayRequest.setEmailRequired(true);
88
+ googlePayRequest.setBillingAddressFormat(GPAY_BILLING_ADDRESS_FORMAT_FULL);
89
+ googlePayRequest.setGoogleMerchantId(options.getString("googlePayMerchantId"));
90
+
91
+ dropInRequest.setGooglePayDisabled(false);
92
+ dropInRequest.setGooglePayRequest(googlePayRequest);
93
+ }else{
94
+ dropInRequest.setGooglePayDisabled(true);
95
+ }
96
+
97
+ if(options.hasKey("cardDisabled")) {
98
+ dropInRequest.setCardDisabled(options.getBoolean("cardDisabled"));
99
+ }
100
+
101
+ if (options.hasKey("threeDSecure")) {
102
+ final ReadableMap threeDSecureOptions = options.getMap("threeDSecure");
103
+ if (threeDSecureOptions == null || !threeDSecureOptions.hasKey("amount")) {
104
+ promise.reject("NO_3DS_AMOUNT", "You must provide an amount for 3D Secure");
105
+ return;
106
+ }
107
+
108
+ isVerifyingThreeDSecure = true;
109
+
110
+ ThreeDSecureRequest threeDSecureRequest = new ThreeDSecureRequest();
111
+ threeDSecureRequest.setAmount(threeDSecureOptions.getString("amount"));
112
+
113
+ dropInRequest.setThreeDSecureRequest(threeDSecureRequest);
114
+ }
115
+
116
+ dropInRequest.setPayPalDisabled(!options.hasKey("payPal") || !options.getBoolean("payPal"));
117
+
118
+ clientToken = options.getString("clientToken");
119
+
120
+ if (dropInClient == null) {
121
+ promise.reject(
122
+ "DROP_IN_CLIENT_UNINITIALIZED",
123
+ "Did you forget to call RNBraintreeDropInModule.initDropInClient(this) in MainActivity.onCreate?"
124
+ );
125
+ return;
126
+ }
127
+ dropInClient.setListener(new DropInListener() {
128
+ @Override
129
+ public void onDropInSuccess(@NonNull DropInResult dropInResult) {
130
+ PaymentMethodNonce paymentMethodNonce = dropInResult.getPaymentMethodNonce();
131
+
132
+ if (isVerifyingThreeDSecure && paymentMethodNonce instanceof CardNonce) {
133
+ CardNonce cardNonce = (CardNonce) paymentMethodNonce;
134
+ ThreeDSecureInfo threeDSecureInfo = cardNonce.getThreeDSecureInfo();
135
+ if (!threeDSecureInfo.isLiabilityShiftPossible()) {
136
+ promise.reject("3DSECURE_NOT_ABLE_TO_SHIFT_LIABILITY", "3D Secure liability cannot be shifted");
137
+ } else if (!threeDSecureInfo.isLiabilityShifted()) {
138
+ promise.reject("3DSECURE_LIABILITY_NOT_SHIFTED", "3D Secure liability was not shifted");
139
+ } else {
140
+ resolvePayment(dropInResult, promise);
141
+ }
142
+ } else {
143
+ resolvePayment(dropInResult, promise);
144
+ }
145
+ }
146
+
147
+ @Override
148
+ public void onDropInFailure(@NonNull Exception exception) {
149
+ if (exception instanceof UserCanceledException) {
150
+ promise.reject("USER_CANCELLATION", "The user cancelled");
151
+ } else {
152
+ promise.reject(exception.getMessage(), exception.getMessage());
153
+ }
154
+ }
155
+ });
156
+ dropInClient.launchDropIn(dropInRequest);
157
+ }
158
+
159
+ @ReactMethod
160
+ public void getDeviceData(final String clientToken, final Promise promise) {
161
+ BraintreeClient braintreeClient = new BraintreeClient(getCurrentActivity(), clientToken);
162
+ DataCollector dataCollector = new DataCollector(braintreeClient);
163
+ dataCollector.collectDeviceData(getCurrentActivity(), (deviceData, error) -> {
164
+ if (error != null) {
165
+ promise.reject("ERROR", "Error collecting device data");
166
+ } else {
167
+ promise.resolve(deviceData);
168
+ }
169
+ });
170
+ }
171
+
172
+ @ReactMethod
173
+ public void fetchMostRecentPaymentMethod(final String clientToken, final Promise promise) {
174
+ FragmentActivity currentActivity = (FragmentActivity) getCurrentActivity();
175
+
176
+ if (currentActivity == null) {
177
+ promise.reject("NO_ACTIVITY", "There is no current activity");
178
+ return;
179
+ }
180
+
181
+ if (dropInClient == null) {
182
+ promise.reject(
183
+ "DROP_IN_CLIENT_UNINITIALIZED",
184
+ "Did you forget to call RNBraintreeDropInModule.initDropInClient(this) in MainActivity.onCreate?"
185
+ );
186
+ return;
187
+ }
188
+
189
+ RNBraintreeDropInModule.clientToken = clientToken;
190
+
191
+ dropInClient.fetchMostRecentPaymentMethod(currentActivity, (dropInResult, error) -> {
192
+ if (error != null) {
193
+ promise.reject(error.getMessage(), error.getMessage());
194
+ } else if (dropInResult == null) {
195
+ promise.reject("NO_DROP_IN_RESULT", "dropInResult is null");
196
+ } else {
197
+ resolvePayment(dropInResult, promise);
198
+ }
199
+ });
200
+ }
201
+
202
+ @ReactMethod
203
+ public void tokenizeCard(final String clientToken, final ReadableMap cardInfo, final Promise promise) {
204
+ if (clientToken == null) {
205
+ promise.reject("NO_CLIENT_TOKEN", "You must provide a client token");
206
+ return;
207
+ }
208
+
209
+ if (
210
+ !cardInfo.hasKey("number") ||
211
+ !cardInfo.hasKey("expirationMonth") ||
212
+ !cardInfo.hasKey("expirationYear") ||
213
+ !cardInfo.hasKey("cvv") ||
214
+ !cardInfo.hasKey("postalCode")
215
+ ) {
216
+ promise.reject("INVALID_CARD_INFO", "Invalid card info");
217
+ return;
218
+ }
219
+
220
+ Activity currentActivity = getCurrentActivity();
221
+
222
+ if (currentActivity == null) {
223
+ promise.reject("NO_ACTIVITY", "There is no current activity");
224
+ return;
225
+ }
226
+
227
+ BraintreeClient braintreeClient = new BraintreeClient(getCurrentActivity(), clientToken);
228
+ CardClient cardClient = new CardClient(braintreeClient);
229
+
230
+ Card card = new Card();
231
+ card.setNumber(cardInfo.getString("number"));
232
+ card.setExpirationMonth(cardInfo.getString("expirationMonth"));
233
+ card.setExpirationYear(cardInfo.getString("expirationYear"));
234
+ card.setCvv(cardInfo.getString("cvv"));
235
+ card.setPostalCode(cardInfo.getString("postalCode"));
236
+
237
+ cardClient.tokenize(card, (cardNonce, error) -> {
238
+ if (error != null) {
239
+ promise.reject(error.getMessage(), error.getMessage());
240
+ } else if (cardNonce == null) {
241
+ promise.reject("NO_CARD_NONCE", "Card nonce is null");
242
+ } else {
243
+ promise.resolve(cardNonce.getString());
244
+ }
245
+ });
246
+ }
247
+
248
+ private void resolvePayment(DropInResult dropInResult, Promise promise) {
249
+ String deviceData = dropInResult.getDeviceData();
250
+ PaymentMethodNonce paymentMethodNonce = dropInResult.getPaymentMethodNonce();
251
+
252
+ WritableMap jsResult = Arguments.createMap();
253
+
254
+ if (paymentMethodNonce == null) {
255
+ promise.resolve(null);
256
+ return;
257
+ }
258
+
259
+ Activity currentActivity = getCurrentActivity();
260
+ if (currentActivity == null) {
261
+ promise.reject("NO_ACTIVITY", "There is no current activity");
262
+ return;
263
+ }
264
+
265
+ DropInPaymentMethod dropInPaymentMethod = dropInResult.getPaymentMethodType();
266
+ if (dropInPaymentMethod == null) {
267
+ promise.reject("NO_PAYMENT_METHOD", "There is no payment method");
268
+ return;
269
+ }
270
+
271
+ PostalAddress billingAddress = null;
272
+ if(paymentMethodNonce instanceof PayPalAccountNonce) {
273
+ PayPalAccountNonce payPalAccountNonce = (PayPalAccountNonce) paymentMethodNonce;
274
+ jsResult.putString("firstName", payPalAccountNonce.getFirstName());
275
+ jsResult.putString("lastName", payPalAccountNonce.getLastName());
276
+ jsResult.putString("email", payPalAccountNonce.getEmail());
277
+ billingAddress = payPalAccountNonce.getBillingAddress();
278
+ } else if (paymentMethodNonce instanceof GooglePayCardNonce) {
279
+ GooglePayCardNonce googlePayCardNonce = (GooglePayCardNonce) paymentMethodNonce;
280
+ billingAddress = googlePayCardNonce.getBillingAddress();
281
+ jsResult.putString("email", googlePayCardNonce.getEmail());
282
+ if(billingAddress != null) {
283
+ String name = billingAddress.getRecipientName();
284
+ if(!name.equals("")) {
285
+ short lastIndexOfSpace = (short) name.lastIndexOf(" ");
286
+ if(lastIndexOfSpace == -1) {
287
+ jsResult.putString("firstName", name.trim());
288
+ } else {
289
+ jsResult.putString("firstName", name.substring(0, lastIndexOfSpace));
290
+ jsResult.putString("lastName", name.substring(lastIndexOfSpace));
291
+ }
292
+ }
293
+ }
294
+ }
295
+ if(billingAddress != null) {
296
+ jsResult.putString("addressLine1", billingAddress.getStreetAddress());
297
+ jsResult.putString("addressLine2", billingAddress.getExtendedAddress());
298
+ jsResult.putString("city", billingAddress.getLocality());
299
+ jsResult.putString("state", billingAddress.getRegion());
300
+ jsResult.putString("country", billingAddress.getCountryCodeAlpha2());
301
+ jsResult.putString("zip1", billingAddress.getPostalCode());
302
+ }
303
+
304
+ jsResult.putString("nonce", paymentMethodNonce.getString());
305
+ jsResult.putString("type", currentActivity.getString(dropInPaymentMethod.getLocalizedName()));
306
+ jsResult.putString("description", dropInResult.getPaymentDescription());
307
+ jsResult.putBoolean("isDefault", paymentMethodNonce.isDefault());
308
+ jsResult.putString("deviceData", deviceData);
309
+
310
+ promise.resolve(jsResult);
311
+ }
312
+
313
+ @NonNull
314
+ @Override
315
+ public String getName() {
316
+ return "RNBraintreeDropIn";
317
+ }
318
+ }
@@ -1,27 +1,27 @@
1
- package com.xbenjii.RNBraintreeDropIn;
2
-
3
- import java.util.Arrays;
4
- import java.util.Collections;
5
- import java.util.List;
6
-
7
- import com.facebook.react.ReactPackage;
8
- import com.facebook.react.bridge.NativeModule;
9
- import com.facebook.react.bridge.ReactApplicationContext;
10
- import com.facebook.react.uimanager.ViewManager;
11
- import com.facebook.react.bridge.JavaScriptModule;
12
- public class RNBraintreeDropInPackage implements ReactPackage {
13
- @Override
14
- public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
15
- return Arrays.<NativeModule>asList(new RNBraintreeDropInModule(reactContext));
16
- }
17
-
18
- // Deprecated from RN 0.47
19
- public List<Class<? extends JavaScriptModule>> createJSModules() {
20
- return Collections.emptyList();
21
- }
22
-
23
- @Override
24
- public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
25
- return Collections.emptyList();
26
- }
27
- }
1
+ package com.xbenjii.RNBraintreeDropIn;
2
+
3
+ import java.util.Arrays;
4
+ import java.util.Collections;
5
+ import java.util.List;
6
+
7
+ import com.facebook.react.ReactPackage;
8
+ import com.facebook.react.bridge.NativeModule;
9
+ import com.facebook.react.bridge.ReactApplicationContext;
10
+ import com.facebook.react.uimanager.ViewManager;
11
+ import com.facebook.react.bridge.JavaScriptModule;
12
+ public class RNBraintreeDropInPackage implements ReactPackage {
13
+ @Override
14
+ public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
15
+ return Arrays.<NativeModule>asList(new RNBraintreeDropInModule(reactContext));
16
+ }
17
+
18
+ // Deprecated from RN 0.47
19
+ public List<Class<? extends JavaScriptModule>> createJSModules() {
20
+ return Collections.emptyList();
21
+ }
22
+
23
+ @Override
24
+ public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
25
+ return Collections.emptyList();
26
+ }
27
+ }