@jimrising/easymerchantsdk-react-native 2.0.9 → 2.1.0
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/README.md +149 -25
- package/ios/Classes/EasyMerchantSdk.m +2 -2
- package/ios/easymerchantsdk.podspec +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# EasyMerchantSdk React Native Implementation
|
|
2
2
|
|
|
3
|
-
This guide provides step-by-step instructions to integrate the EasyMerchantSdk into your React Native application for both Android and iOS platforms.
|
|
3
|
+
This guide provides step-by-step instructions to integrate the EasyMerchantSdk into your React Native application for both Android and iOS platforms. The SDK supports identical parameters for both platforms, with differences only in the method calls for initiating payments and handling responses.
|
|
4
4
|
|
|
5
5
|
## Prerequisites
|
|
6
6
|
|
|
@@ -18,7 +18,7 @@ Add the EasyMerchantSdk to your project by including it in your `package.json` f
|
|
|
18
18
|
|
|
19
19
|
```json
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@jimrising/easymerchantsdk-react-native": "^2.0
|
|
21
|
+
"@jimrising/easymerchantsdk-react-native": "^2.1.0"
|
|
22
22
|
}
|
|
23
23
|
```
|
|
24
24
|
|
|
@@ -40,12 +40,12 @@ allprojects {
|
|
|
40
40
|
mavenCentral()
|
|
41
41
|
maven { url 'https://jitpack.io' }
|
|
42
42
|
maven {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
43
|
+
url = uri(properties.getProperty('GITHUB_URL'))
|
|
44
|
+
credentials {
|
|
45
|
+
username = properties.getProperty('GITHUB_USERNAME')
|
|
46
|
+
password = properties.getProperty('GITHUB_PASSWORD')
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
51
|
```
|
|
@@ -131,10 +131,11 @@ pod install
|
|
|
131
131
|
|
|
132
132
|
## Usage in Your React Native App
|
|
133
133
|
|
|
134
|
-
To integrate the EasyMerchantSdk into your React Native application, you can use the provided `App.js` as a reference.
|
|
134
|
+
To integrate the EasyMerchantSdk into your React Native application, you can use the provided `App.js` as a reference. The parameters for Android and iOS are identical, but the method calls differ slightly.
|
|
135
|
+
|
|
136
|
+
### 1. Import Necessary Modules
|
|
135
137
|
|
|
136
|
-
|
|
137
|
-
Ensure you import the required React Native components and the EasyMerchantSdk NativeModules:
|
|
138
|
+
Ensure you import the required React Native components and the EasyMerchantSdk NativeModules:
|
|
138
139
|
|
|
139
140
|
```javascript
|
|
140
141
|
import React, { useState, useEffect } from 'react';
|
|
@@ -143,8 +144,9 @@ import { StyleSheet, Text, View, TextInput, Button, Alert, ScrollView, Platform,
|
|
|
143
144
|
const { RNEasymerchantsdk, EasyMerchantSdk } = NativeModules;
|
|
144
145
|
```
|
|
145
146
|
|
|
146
|
-
2.
|
|
147
|
-
|
|
147
|
+
### 2. Set Up Configuration
|
|
148
|
+
|
|
149
|
+
Define the configuration object for the SDK, which is shared between Android and iOS. The provided `App.js` includes a comprehensive `externalConfig` object that you can customize:
|
|
148
150
|
|
|
149
151
|
```javascript
|
|
150
152
|
const externalConfig = {
|
|
@@ -211,10 +213,10 @@ const externalConfig = {
|
|
|
211
213
|
recurringData: {
|
|
212
214
|
allowCycles: 2,
|
|
213
215
|
intervals: ['daily', 'weekly', 'monthly'],
|
|
214
|
-
recurringStartType:
|
|
216
|
+
recurringStartType: Platform.OS === 'android' ? 'Custom' : 'custom',
|
|
215
217
|
recurringStartDate: new Date().toLocaleDateString('en-US', { month: '2-digit', day: '2-digit', year: 'numeric' }),
|
|
216
218
|
},
|
|
217
|
-
|
|
219
|
+
configur: {
|
|
218
220
|
currency: 'usd',
|
|
219
221
|
saveCard: true,
|
|
220
222
|
saveAccount: true,
|
|
@@ -261,8 +263,122 @@ const externalConfig = {
|
|
|
261
263
|
};
|
|
262
264
|
```
|
|
263
265
|
|
|
264
|
-
3.
|
|
265
|
-
|
|
266
|
+
### 3. Handle Payments
|
|
267
|
+
|
|
268
|
+
The `handlePayment` function validates inputs and calls platform-specific billing functions. The parameters are identical for both platforms, but the method calls differ.
|
|
269
|
+
|
|
270
|
+
#### Android: `handleAndroidBilling`
|
|
271
|
+
|
|
272
|
+
```javascript
|
|
273
|
+
const handleAndroidBilling = async () => {
|
|
274
|
+
const { apiKey, secretKey } = apiKeys[environment];
|
|
275
|
+
const selectedPaymentMethods = [...configur.paymentMethod];
|
|
276
|
+
|
|
277
|
+
const config = {
|
|
278
|
+
amount,
|
|
279
|
+
apiKey,
|
|
280
|
+
secretKey,
|
|
281
|
+
jsonConfig: {
|
|
282
|
+
environment,
|
|
283
|
+
amount,
|
|
284
|
+
tokenOnly: false,
|
|
285
|
+
currency: configur.currency,
|
|
286
|
+
saveCard: configur.saveCard,
|
|
287
|
+
saveAccount: configur.saveAccount,
|
|
288
|
+
authenticatedACH: isAuthenticatedACH,
|
|
289
|
+
secureAuthentication: isSecureAuthentication,
|
|
290
|
+
showReceipt: configur.showReceipt,
|
|
291
|
+
showDonate: configur.showDonate,
|
|
292
|
+
showTotal: configur.showTotal,
|
|
293
|
+
showSubmitButton: configur.showSubmitButton,
|
|
294
|
+
paymentMethod: selectedPaymentMethods,
|
|
295
|
+
emailEditable,
|
|
296
|
+
email,
|
|
297
|
+
name,
|
|
298
|
+
fields: {
|
|
299
|
+
...configur.fields,
|
|
300
|
+
visibility: {
|
|
301
|
+
billing: isBillingVisible,
|
|
302
|
+
additional: isAdditionalVisible,
|
|
303
|
+
},
|
|
304
|
+
},
|
|
305
|
+
metadata,
|
|
306
|
+
...(isRecurring && {
|
|
307
|
+
recurring: {
|
|
308
|
+
enableRecurring: true,
|
|
309
|
+
recurringData,
|
|
310
|
+
},
|
|
311
|
+
}),
|
|
312
|
+
grailPayParams,
|
|
313
|
+
appearanceSettings: configur.appearanceSettings,
|
|
314
|
+
},
|
|
315
|
+
};
|
|
316
|
+
|
|
317
|
+
try {
|
|
318
|
+
const response = await RNEasymerchantsdk.makePayment(config);
|
|
319
|
+
const parsedResponse = {
|
|
320
|
+
...JSON.parse(response?.response || '{}'),
|
|
321
|
+
billingInfo: safeParseMaybeJSON(response?.billingInfo),
|
|
322
|
+
additional_info: safeParseMaybeJSON(response?.additional_info),
|
|
323
|
+
};
|
|
324
|
+
setResult(JSON.stringify(parsedResponse, null, 2));
|
|
325
|
+
} catch (error) {
|
|
326
|
+
setResult(`Error: ${error.message ?? JSON.stringify(error)}`);
|
|
327
|
+
Alert.alert('Payment Error', error.message ?? 'Unknown error');
|
|
328
|
+
} finally {
|
|
329
|
+
setLoading(false);
|
|
330
|
+
}
|
|
331
|
+
};
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
#### iOS: `handleIosBilling`
|
|
335
|
+
|
|
336
|
+
```javascript
|
|
337
|
+
const handleIosBilling = async () => {
|
|
338
|
+
const selectedPaymentMethodsIOS = [...configur.paymentMethod].map(method =>
|
|
339
|
+
method === 'card' ? 'Card' : method === 'ach' ? 'Bank' : method
|
|
340
|
+
);
|
|
341
|
+
|
|
342
|
+
try {
|
|
343
|
+
const result = await EasyMerchantSdk.billing(
|
|
344
|
+
amount,
|
|
345
|
+
'usd', // Default currency
|
|
346
|
+
billingInfo,
|
|
347
|
+
selectedPaymentMethodsIOS,
|
|
348
|
+
themeConfiguration,
|
|
349
|
+
false, // tokenOnly
|
|
350
|
+
true, // saveCard
|
|
351
|
+
true, // saveAccount
|
|
352
|
+
isAuthenticatedACH,
|
|
353
|
+
grailPayParams,
|
|
354
|
+
'Submit',
|
|
355
|
+
isRecurring,
|
|
356
|
+
isRecurring ? recurringData.allowCycles : 0,
|
|
357
|
+
isRecurring ? recurringData.intervals : [],
|
|
358
|
+
isRecurring ? recurringData.recurringStartType : '',
|
|
359
|
+
isRecurring ? recurringData.recurringStartDate : '',
|
|
360
|
+
isSecureAuthentication,
|
|
361
|
+
true, // showReceipt
|
|
362
|
+
true, // showTotal
|
|
363
|
+
true, // showSubmitButton
|
|
364
|
+
isEmail,
|
|
365
|
+
email,
|
|
366
|
+
name,
|
|
367
|
+
metadata
|
|
368
|
+
);
|
|
369
|
+
|
|
370
|
+
const refToken = result?.additionalInfo?.threeDSecureStatus?.data?.ref_token;
|
|
371
|
+
if (refToken) setReferenceToken(refToken);
|
|
372
|
+
setResult(JSON.stringify(result, null, 2));
|
|
373
|
+
} catch (error) {
|
|
374
|
+
setResult(`Billing Error: ${error.message || JSON.stringify(error)}`);
|
|
375
|
+
} finally {
|
|
376
|
+
setLoading(false);
|
|
377
|
+
}
|
|
378
|
+
};
|
|
379
|
+
```
|
|
380
|
+
|
|
381
|
+
#### Main Payment Handler
|
|
266
382
|
|
|
267
383
|
```javascript
|
|
268
384
|
const handlePayment = async () => {
|
|
@@ -275,6 +391,7 @@ const handlePayment = async () => {
|
|
|
275
391
|
}
|
|
276
392
|
|
|
277
393
|
setLoading(true);
|
|
394
|
+
const timeoutId = setTimeout(() => setLoading(false), 3000);
|
|
278
395
|
|
|
279
396
|
try {
|
|
280
397
|
if (Platform.OS === 'android') {
|
|
@@ -283,13 +400,15 @@ const handlePayment = async () => {
|
|
|
283
400
|
await handleIosBilling();
|
|
284
401
|
}
|
|
285
402
|
} finally {
|
|
403
|
+
clearTimeout(timeoutId);
|
|
286
404
|
setLoading(false);
|
|
287
405
|
}
|
|
288
406
|
};
|
|
289
407
|
```
|
|
290
408
|
|
|
291
|
-
4.
|
|
292
|
-
|
|
409
|
+
### 4. Event Listeners for Android
|
|
410
|
+
|
|
411
|
+
Set up event listeners for payment success, status, and errors using `NativeEventEmitter` (Android only):
|
|
293
412
|
|
|
294
413
|
```javascript
|
|
295
414
|
useEffect(() => {
|
|
@@ -319,19 +438,24 @@ useEffect(() => {
|
|
|
319
438
|
}, []);
|
|
320
439
|
```
|
|
321
440
|
|
|
322
|
-
5.
|
|
323
|
-
|
|
441
|
+
### 5. UI Components
|
|
442
|
+
|
|
443
|
+
The provided `App.js` includes custom components like `Dropdown` and `FilledButton` for a user-friendly interface. Customize the styles in the `StyleSheet` to match your app's design.
|
|
324
444
|
|
|
325
445
|
## Notes
|
|
326
446
|
|
|
327
|
-
- **Billing Info**: You can send `null` for
|
|
447
|
+
- **Billing Info**: You can send `null` for `billingInfo` if it is not available.
|
|
328
448
|
- **Environment Configuration**: The SDK supports `sandbox` and `staging` environments. Ensure you configure the correct API keys for each environment.
|
|
329
|
-
- **Payment Methods**: The SDK supports `card` and `ach` payment methods
|
|
449
|
+
- **Payment Methods**: The SDK supports `card` and `ach` payment methods (mapped to `Card` and `Bank` on iOS). Toggle them in the UI as needed.
|
|
330
450
|
- **Recurring Payments**: Ensure at least one interval (`daily`, `weekly`, `monthly`) is selected when enabling recurring payments.
|
|
331
|
-
- **Theming**: Customize the appearance using `themeConfiguration`
|
|
451
|
+
- **Theming**: Customize the appearance using `themeConfiguration` for iOS or `configur.appearanceSettings` for Android to match your app's branding. The parameters are identical for both platforms.
|
|
452
|
+
- **Method Differences**:
|
|
453
|
+
- **Android**: Use `RNEasymerchantsdk.makePayment(config)` with a JSON configuration object.
|
|
454
|
+
- **iOS**: Use `EasyMerchantSdk.billing(...)` with parameters passed directly.
|
|
455
|
+
- iOS supports an additional `paymentReference` method for checking payment status using a reference token.
|
|
332
456
|
|
|
333
457
|
## Troubleshooting
|
|
334
458
|
|
|
335
459
|
- **iOS Bridge Initialization**: If you see "Failed to retrieve EasyMerchantSdkPlugin instance" in the console, ensure the `easymerchantsdk` pod is correctly installed and linked.
|
|
336
|
-
- **Android Payment Issues**: Verify that `paymentMethod` is correctly formatted (`['card', 'ach']`) and that API keys are valid.
|
|
460
|
+
- **Android Payment Issues**: Verify that `paymentMethod` is correctly formatted (`['card', 'ach']`) and that API keys are valid. Ensure `GITHUB_URL`, `GITHUB_USERNAME`, and `GITHUB_PASSWORD` are correctly set in your Gradle properties.
|
|
337
461
|
- **Pod Installation**: If `pod install` fails, ensure Ruby 3.2.8 is installed and run `pod install --repo-update`.
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
#import <React/RCTLog.h>
|
|
3
3
|
#import <React/RCTBridgeModule.h>
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
#import <easymerchantsdk-Swift.h>
|
|
6
|
+
//#import <easymerchantsdk/easymerchantsdk-Swift.h>
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
@interface EasyMerchantSdk ()
|