react-native-hyperpay-sdk 0.26.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.
|
package/android/build.gradle
CHANGED
|
@@ -19,7 +19,7 @@ def safeExtGet(prop, fallback) {
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
android {
|
|
22
|
-
compileSdkVersion safeExtGet('HyperPay_compileSdkVersion',
|
|
22
|
+
compileSdkVersion safeExtGet('HyperPay_compileSdkVersion', 31)
|
|
23
23
|
defaultConfig {
|
|
24
24
|
minSdkVersion safeExtGet('HyperPay_minSdkVersion', 21)
|
|
25
25
|
targetSdkVersion safeExtGet('HyperPay_targetSdkVersion', 29)
|
|
@@ -54,8 +54,19 @@ repositories {
|
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
dependencies {
|
|
57
|
-
implementation fileTree(include: ["*.aar"], dir: "libs")
|
|
58
57
|
|
|
58
|
+
if (project.gradle.startParameter.taskNames.any { it.toLowerCase().contains('release') }) {
|
|
59
|
+
compileOnly files('libs/ipworks3ds_sdk_deploy.aar')
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
compileOnly files('libs/ipworks3ds_sdk.aar')
|
|
63
|
+
}
|
|
64
|
+
compileOnly files('libs/oppwa.mobile-4.5.0-release.aar')
|
|
65
|
+
implementation "androidx.appcompat:appcompat:1.4.2"
|
|
66
|
+
implementation "androidx.lifecycle:lifecycle-extensions:2.2.0"
|
|
67
|
+
implementation "androidx.browser:browser:1.4.0"
|
|
68
|
+
implementation "androidx.fragment:fragment:1.5.5"
|
|
69
|
+
implementation "com.google.android.material:material:1.6.1"
|
|
59
70
|
//noinspection GradleDynamicVersion
|
|
60
71
|
implementation "com.facebook.react:react-native:+" // From node_modules
|
|
61
72
|
|
|
@@ -1,19 +1,44 @@
|
|
|
1
1
|
package com.reactnativehyperpay;
|
|
2
2
|
|
|
3
|
+
import android.content.Context;
|
|
4
|
+
import android.util.Log;
|
|
3
5
|
import androidx.annotation.NonNull;
|
|
4
|
-
|
|
6
|
+
import com.facebook.react.bridge.Arguments;
|
|
5
7
|
import com.facebook.react.bridge.Promise;
|
|
6
8
|
import com.facebook.react.bridge.ReactApplicationContext;
|
|
7
9
|
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
|
8
10
|
import com.facebook.react.bridge.ReactMethod;
|
|
11
|
+
import com.facebook.react.bridge.ReadableMap;
|
|
12
|
+
import com.facebook.react.bridge.WritableMap;
|
|
9
13
|
import com.facebook.react.module.annotations.ReactModule;
|
|
14
|
+
import com.facebook.react.modules.core.DeviceEventManagerModule;
|
|
15
|
+
import com.oppwa.mobile.connect.exception.PaymentError;
|
|
16
|
+
import com.oppwa.mobile.connect.exception.PaymentException;
|
|
17
|
+
import com.oppwa.mobile.connect.payment.BrandsValidation;
|
|
18
|
+
import com.oppwa.mobile.connect.payment.CheckoutInfo;
|
|
19
|
+
import com.oppwa.mobile.connect.payment.ImagesRequest;
|
|
20
|
+
import com.oppwa.mobile.connect.payment.PaymentParams;
|
|
21
|
+
import com.oppwa.mobile.connect.payment.card.CardPaymentParams;
|
|
22
|
+
import com.oppwa.mobile.connect.provider.Connect;
|
|
23
|
+
import com.oppwa.mobile.connect.provider.ITransactionListener;
|
|
24
|
+
import com.oppwa.mobile.connect.provider.OppPaymentProvider;
|
|
10
25
|
import com.oppwa.mobile.connect.provider.Transaction;
|
|
26
|
+
import com.oppwa.mobile.connect.provider.TransactionType;
|
|
27
|
+
|
|
11
28
|
@ReactModule(name = HyperPayModule.NAME)
|
|
12
|
-
public class HyperPayModule extends ReactContextBaseJavaModule {
|
|
29
|
+
public class HyperPayModule extends ReactContextBaseJavaModule implements ITransactionListener {
|
|
13
30
|
public static final String NAME = "HyperPay";
|
|
14
31
|
|
|
32
|
+
private Context appContext;
|
|
33
|
+
private Promise promisePaymentTransaction;
|
|
34
|
+
private String shopperResultURL;
|
|
35
|
+
private String merchantIdentifier;
|
|
36
|
+
private String countryCode;
|
|
37
|
+
private String mode;
|
|
38
|
+
|
|
15
39
|
public HyperPayModule(ReactApplicationContext reactContext) {
|
|
16
40
|
super(reactContext);
|
|
41
|
+
appContext = reactContext.getApplicationContext();
|
|
17
42
|
}
|
|
18
43
|
|
|
19
44
|
@Override
|
|
@@ -22,13 +47,129 @@ public class HyperPayModule extends ReactContextBaseJavaModule {
|
|
|
22
47
|
return NAME;
|
|
23
48
|
}
|
|
24
49
|
|
|
50
|
+
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
51
|
+
public WritableMap setup(ReadableMap params) {
|
|
52
|
+
WritableMap config = Arguments.createMap();
|
|
53
|
+
if (params.hasKey("shopperResultURL"))
|
|
54
|
+
shopperResultURL = params.getString("shopperResultURL");
|
|
55
|
+
if (params.hasKey("merchantIdentifier"))
|
|
56
|
+
merchantIdentifier = params.getString("merchantIdentifier");
|
|
57
|
+
if (params.hasKey("countryCode"))
|
|
58
|
+
countryCode = params.getString("countryCode");
|
|
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;
|
|
66
|
+
}
|
|
25
67
|
|
|
26
|
-
// Example method
|
|
27
|
-
// See https://reactnative.dev/docs/native-modules-android
|
|
28
68
|
@ReactMethod
|
|
29
|
-
public void
|
|
30
|
-
|
|
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
|
+
}
|
|
133
|
+
|
|
134
|
+
@Override
|
|
135
|
+
public void brandsValidationRequestSucceeded(@NonNull BrandsValidation brandsValidation) {
|
|
136
|
+
ITransactionListener.super.brandsValidationRequestSucceeded(brandsValidation);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
@Override
|
|
140
|
+
public void brandsValidationRequestFailed(@NonNull PaymentError paymentError) {
|
|
141
|
+
ITransactionListener.super.brandsValidationRequestFailed(paymentError);
|
|
142
|
+
}
|
|
143
|
+
|
|
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();
|
|
31
173
|
}
|
|
32
174
|
|
|
33
|
-
public static native int nativeMultiply(int a, int b);
|
|
34
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
|
|