react-native-hyperpay-sdk 0.27.0 → 0.28.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
CHANGED
|
@@ -11,49 +11,46 @@ npm i react-native-hyperpay-sdk
|
|
|
11
11
|
## Usage
|
|
12
12
|
|
|
13
13
|
```js
|
|
14
|
-
import
|
|
15
|
-
|
|
14
|
+
import HyperPay from 'react-native-hyperpay-sdk'
|
|
16
15
|
|
|
17
16
|
// the firt step , set default configiration
|
|
18
17
|
// 1- shopperResultURL to redirect to this url after the payment completed
|
|
19
18
|
// 2- select your country code from list
|
|
20
19
|
// 3- merchantIdentifier is for apply pay only
|
|
21
|
-
|
|
20
|
+
|
|
21
|
+
HyperPay.init({
|
|
22
22
|
shopperResultURL:"shopperResultURL",
|
|
23
23
|
countryCode:"SA",
|
|
24
24
|
merchantIdentifier:"merchantIdentifier",
|
|
25
25
|
mode:"TestMode"
|
|
26
26
|
})
|
|
27
|
+
|
|
27
28
|
// ...
|
|
28
29
|
// to pay with apple
|
|
29
|
-
const result = await
|
|
30
|
+
const result = await HyperPay.applePay("CheckoutId")
|
|
30
31
|
|
|
31
32
|
// to pay with any brand
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
33
|
+
const result=await HyperPay.createPaymentTransaction(
|
|
34
|
+
{ paymentBrand: "VISA",
|
|
35
|
+
holderName: "Test Test",
|
|
36
|
+
cardNumber: '4111111111111111',
|
|
37
|
+
expiryYear: '2027',
|
|
38
|
+
expiryMonth: '12',
|
|
39
|
+
cvv: '123',
|
|
40
|
+
checkoutID: `${res.data?.checkout_id}`,
|
|
41
|
+
shopperResultURL: "[YOUR_APP_IDENTIFIER]://[URL_SCHEMES]"
|
|
41
42
|
})
|
|
42
43
|
|
|
43
|
-
|
|
44
44
|
// get payment status
|
|
45
|
-
|
|
46
|
-
// result={
|
|
47
|
-
// "code": "000.000.000",
|
|
48
|
-
// "description": "Transaction succeeded",
|
|
49
|
-
// "status": "successfully"
|
|
50
|
-
// }
|
|
45
|
+
const result=await hyperPay.getPaymentStatus("000.000.000")
|
|
46
|
+
// result={
|
|
47
|
+
// "code": "000.000.000",
|
|
48
|
+
// "description": "Transaction succeeded",
|
|
49
|
+
// "status": "successfully"
|
|
50
|
+
// }
|
|
51
51
|
```
|
|
52
|
-
|
|
53
52
|
```
|
|
54
53
|
|
|
55
|
-
|
|
56
|
-
|
|
57
54
|
## Contributing
|
|
58
55
|
|
|
59
56
|
See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.
|
|
@@ -2,15 +2,16 @@ package com.reactnativehyperpay;
|
|
|
2
2
|
|
|
3
3
|
import android.content.Context;
|
|
4
4
|
import android.util.Log;
|
|
5
|
-
|
|
6
5
|
import androidx.annotation.NonNull;
|
|
7
|
-
|
|
6
|
+
import com.facebook.react.bridge.Arguments;
|
|
8
7
|
import com.facebook.react.bridge.Promise;
|
|
9
8
|
import com.facebook.react.bridge.ReactApplicationContext;
|
|
10
9
|
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
|
11
10
|
import com.facebook.react.bridge.ReactMethod;
|
|
12
11
|
import com.facebook.react.bridge.ReadableMap;
|
|
12
|
+
import com.facebook.react.bridge.WritableMap;
|
|
13
13
|
import com.facebook.react.module.annotations.ReactModule;
|
|
14
|
+
import com.facebook.react.modules.core.DeviceEventManagerModule;
|
|
14
15
|
import com.oppwa.mobile.connect.exception.PaymentError;
|
|
15
16
|
import com.oppwa.mobile.connect.exception.PaymentException;
|
|
16
17
|
import com.oppwa.mobile.connect.payment.BrandsValidation;
|
|
@@ -22,18 +23,22 @@ import com.oppwa.mobile.connect.provider.Connect;
|
|
|
22
23
|
import com.oppwa.mobile.connect.provider.ITransactionListener;
|
|
23
24
|
import com.oppwa.mobile.connect.provider.OppPaymentProvider;
|
|
24
25
|
import com.oppwa.mobile.connect.provider.Transaction;
|
|
26
|
+
import com.oppwa.mobile.connect.provider.TransactionType;
|
|
25
27
|
|
|
26
28
|
@ReactModule(name = HyperPayModule.NAME)
|
|
27
|
-
public class HyperPayModule extends ReactContextBaseJavaModule {
|
|
29
|
+
public class HyperPayModule extends ReactContextBaseJavaModule implements ITransactionListener {
|
|
30
|
+
public static final String NAME = "HyperPay";
|
|
31
|
+
|
|
28
32
|
private Context appContext;
|
|
33
|
+
private Promise promisePaymentTransaction;
|
|
29
34
|
private String shopperResultURL;
|
|
30
35
|
private String merchantIdentifier;
|
|
31
36
|
private String countryCode;
|
|
32
37
|
private String mode;
|
|
33
|
-
public static final String NAME = "HyperPay";
|
|
34
38
|
|
|
35
39
|
public HyperPayModule(ReactApplicationContext reactContext) {
|
|
36
40
|
super(reactContext);
|
|
41
|
+
appContext = reactContext.getApplicationContext();
|
|
37
42
|
}
|
|
38
43
|
|
|
39
44
|
@Override
|
|
@@ -42,67 +47,129 @@ public class HyperPayModule extends ReactContextBaseJavaModule {
|
|
|
42
47
|
return NAME;
|
|
43
48
|
}
|
|
44
49
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
public ReadableMap setup(ReadableMap params, Promise promise) {
|
|
50
|
-
if (!params.getString("shopperResultURL").isEmpty())
|
|
50
|
+
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
51
|
+
public WritableMap setup(ReadableMap params) {
|
|
52
|
+
WritableMap config = Arguments.createMap();
|
|
53
|
+
if (params.hasKey("shopperResultURL"))
|
|
51
54
|
shopperResultURL = params.getString("shopperResultURL");
|
|
52
|
-
if (
|
|
55
|
+
if (params.hasKey("merchantIdentifier"))
|
|
53
56
|
merchantIdentifier = params.getString("merchantIdentifier");
|
|
54
|
-
if (
|
|
57
|
+
if (params.hasKey("countryCode"))
|
|
55
58
|
countryCode = params.getString("countryCode");
|
|
56
|
-
if (
|
|
57
|
-
|
|
58
|
-
|
|
59
|
+
if (params.hasKey("mode"))
|
|
60
|
+
mode = params.getString("mode");
|
|
61
|
+
config.putString("shopperResultURL", shopperResultURL);
|
|
62
|
+
config.putString("merchantIdentifier", merchantIdentifier);
|
|
63
|
+
config.putString("countryCode", countryCode);
|
|
64
|
+
config.putString("mode", mode);
|
|
65
|
+
return config;
|
|
59
66
|
}
|
|
60
67
|
|
|
61
68
|
@ReactMethod
|
|
62
69
|
public void createPaymentTransaction(ReadableMap params, Promise promise) {
|
|
70
|
+
promisePaymentTransaction = promise;
|
|
71
|
+
this.emitListeners("onProgress", true);
|
|
72
|
+
try {
|
|
73
|
+
PaymentParams paymentParams = new CardPaymentParams(
|
|
74
|
+
params.getString("checkoutID"),
|
|
75
|
+
params.getString("paymentBrand"),
|
|
76
|
+
params.getString("cardNumber"),
|
|
77
|
+
params.getString("holderName"),
|
|
78
|
+
params.getString("expiryMonth"),
|
|
79
|
+
params.getString("expiryYear"),
|
|
80
|
+
params.getString("cvv"));
|
|
81
|
+
|
|
82
|
+
if (params.hasKey("shopperResultURL")) {
|
|
83
|
+
shopperResultURL = params.getString("shopperResultURL");
|
|
84
|
+
}
|
|
85
|
+
paymentParams.setShopperResultUrl(shopperResultURL);
|
|
86
|
+
Transaction transaction = null;
|
|
87
|
+
|
|
88
|
+
try {
|
|
89
|
+
OppPaymentProvider paymentProvider = new OppPaymentProvider(appContext, Connect.ProviderMode.TEST);
|
|
90
|
+
|
|
91
|
+
if (mode.equals("LiveMode")) {
|
|
92
|
+
paymentProvider.setProviderMode(Connect.ProviderMode.LIVE);
|
|
93
|
+
}
|
|
94
|
+
transaction = new Transaction(paymentParams);
|
|
95
|
+
paymentProvider.submitTransaction(transaction, this);
|
|
96
|
+
} catch (PaymentException e) {
|
|
97
|
+
this.emitListeners("onProgress", false);
|
|
98
|
+
promisePaymentTransaction.reject(e);
|
|
99
|
+
}
|
|
100
|
+
} catch (PaymentException e) {
|
|
101
|
+
this.emitListeners("onProgress", false);
|
|
102
|
+
promisePaymentTransaction.reject(e);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
private void emitListeners(String eventName, boolean isLoading) {
|
|
107
|
+
getReactApplicationContext().getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
|
|
108
|
+
.emit("onProgress", isLoading);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
@Override
|
|
112
|
+
public void transactionCompleted(@NonNull Transaction transaction) {
|
|
113
|
+
this.emitListeners("onProgress", false);
|
|
114
|
+
|
|
115
|
+
WritableMap paymentResponse = Arguments.createMap();
|
|
116
|
+
paymentResponse.putString("checkoutId", transaction.getPaymentParams().getCheckoutId());
|
|
117
|
+
|
|
118
|
+
if (transaction.getTransactionType() == TransactionType.SYNC) {
|
|
119
|
+
paymentResponse.putString("status", "completed");
|
|
120
|
+
} else {
|
|
121
|
+
paymentResponse.putString("status", "pending");
|
|
122
|
+
paymentResponse.putString("redirectURL", transaction.getRedirectUrl());
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
promisePaymentTransaction.resolve(paymentResponse);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
@Override
|
|
129
|
+
public void transactionFailed(@NonNull Transaction transaction, @NonNull PaymentError paymentError) {
|
|
130
|
+
this.emitListeners("onProgress", false);
|
|
131
|
+
promisePaymentTransaction.reject(paymentError.getErrorInfo());
|
|
132
|
+
}
|
|
63
133
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
// params.getString("holderName") ,
|
|
69
|
-
// params.getString("expiryMonth"),
|
|
70
|
-
// params.getString("expiryYear"),
|
|
71
|
-
// params.getString("cvv")
|
|
72
|
-
// );
|
|
73
|
-
|
|
74
|
-
// if (!params.getString("shopperResultURL").isEmpty()){
|
|
75
|
-
// shopperResultURL=params.getString("shopperResultURL");
|
|
76
|
-
// }
|
|
77
|
-
//
|
|
78
|
-
// paymentParams.setShopperResultUrl(shopperResultURL);
|
|
79
|
-
//
|
|
80
|
-
// Transaction transaction = null;
|
|
81
|
-
// ITransactionListener transactionListener = null;
|
|
82
|
-
//
|
|
83
|
-
//
|
|
84
|
-
// try {
|
|
85
|
-
// OppPaymentProvider paymentProvider = new OppPaymentProvider(appContext,
|
|
86
|
-
// Connect.ProviderMode.TEST);
|
|
87
|
-
//
|
|
88
|
-
// if (mode=="LiveMode"){
|
|
89
|
-
// paymentProvider.setProviderMode(Connect.ProviderMode.LIVE);
|
|
90
|
-
// }
|
|
91
|
-
//
|
|
92
|
-
// transaction = new Transaction(paymentParams);
|
|
93
|
-
// paymentProvider.submitTransaction(transaction, transactionListener);
|
|
94
|
-
// promise.resolve("Test");
|
|
95
|
-
//
|
|
96
|
-
|
|
97
|
-
//
|
|
98
|
-
// } catch (PaymentException e) {
|
|
99
|
-
// promise.reject(e);
|
|
100
|
-
// /* error occurred */
|
|
101
|
-
// }
|
|
102
|
-
Log.d("params", params.toString());
|
|
134
|
+
@Override
|
|
135
|
+
public void brandsValidationRequestSucceeded(@NonNull BrandsValidation brandsValidation) {
|
|
136
|
+
ITransactionListener.super.brandsValidationRequestSucceeded(brandsValidation);
|
|
137
|
+
}
|
|
103
138
|
|
|
139
|
+
@Override
|
|
140
|
+
public void brandsValidationRequestFailed(@NonNull PaymentError paymentError) {
|
|
141
|
+
ITransactionListener.super.brandsValidationRequestFailed(paymentError);
|
|
104
142
|
}
|
|
105
143
|
|
|
106
|
-
|
|
144
|
+
@Override
|
|
145
|
+
public void paymentConfigRequestSucceeded(@NonNull CheckoutInfo checkoutInfo) {
|
|
146
|
+
Log.d("paymentCond", checkoutInfo.getResourcePath());
|
|
147
|
+
ITransactionListener.super.paymentConfigRequestSucceeded(checkoutInfo);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
@Override
|
|
151
|
+
public void paymentConfigRequestFailed(@NonNull PaymentError paymentError) {
|
|
152
|
+
ITransactionListener.super.paymentConfigRequestFailed(paymentError);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
@Override
|
|
156
|
+
public void imagesRequestSucceeded(@NonNull ImagesRequest imagesRequest) {
|
|
157
|
+
ITransactionListener.super.imagesRequestSucceeded(imagesRequest);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
@Override
|
|
161
|
+
public void imagesRequestFailed() {
|
|
162
|
+
ITransactionListener.super.imagesRequestFailed();
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
@Override
|
|
166
|
+
public void binRequestSucceeded(@NonNull String[] strings) {
|
|
167
|
+
ITransactionListener.super.binRequestSucceeded(strings);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
@Override
|
|
171
|
+
public void binRequestFailed() {
|
|
172
|
+
ITransactionListener.super.binRequestFailed();
|
|
173
|
+
}
|
|
107
174
|
|
|
108
175
|
}
|
package/package.json
CHANGED
package/src/index.tsx
CHANGED
|
@@ -13,8 +13,15 @@ export function init(params: Config): Config {
|
|
|
13
13
|
return HyperPaySDK.setup(params);
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
export function createPaymentTransaction(params: CreateTransactionParams):
|
|
16
|
+
export function createPaymentTransaction(params: CreateTransactionParams, onProgress?: (isProgress: boolean) => void):
|
|
17
17
|
Promise<CreateTransactionResponseType> {
|
|
18
|
+
if (onProgress) {
|
|
19
|
+
eventEmitter.removeAllListeners("onProgress")
|
|
20
|
+
const _event = eventEmitter.addListener('onProgress', (isLoading: boolean) => {
|
|
21
|
+
onProgress(isLoading)
|
|
22
|
+
if (!isLoading) _event.remove()
|
|
23
|
+
});
|
|
24
|
+
}
|
|
18
25
|
return HyperPaySDK.createPaymentTransaction(params);
|
|
19
26
|
}
|
|
20
27
|
|