react-native-hyperpay-sdk 0.25.0 → 0.27.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/android/build.gradle +13 -2
- package/android/src/main/java/com/reactnativehyperpay/HyperPayModule.java +77 -3
- package/ios/HyperPay.m +7 -5
- package/lib/typescript/index.d.ts +6 -1
- package/package.json +1 -1
- package/src/hooks/index.ts +1 -0
- package/src/hooks/useTransactionLoading.ts +22 -0
- package/src/index.tsx +17 -22
- package/src/utils/EventEmitter.ts +4 -0
- package/src/utils/NativeModules.ts +18 -0
- package/src/utils/index.ts +2 -0
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,15 +1,35 @@
|
|
|
1
1
|
package com.reactnativehyperpay;
|
|
2
2
|
|
|
3
|
+
import android.content.Context;
|
|
4
|
+
import android.util.Log;
|
|
5
|
+
|
|
3
6
|
import androidx.annotation.NonNull;
|
|
4
7
|
|
|
5
8
|
import com.facebook.react.bridge.Promise;
|
|
6
9
|
import com.facebook.react.bridge.ReactApplicationContext;
|
|
7
10
|
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
|
8
11
|
import com.facebook.react.bridge.ReactMethod;
|
|
12
|
+
import com.facebook.react.bridge.ReadableMap;
|
|
9
13
|
import com.facebook.react.module.annotations.ReactModule;
|
|
14
|
+
import com.oppwa.mobile.connect.exception.PaymentError;
|
|
15
|
+
import com.oppwa.mobile.connect.exception.PaymentException;
|
|
16
|
+
import com.oppwa.mobile.connect.payment.BrandsValidation;
|
|
17
|
+
import com.oppwa.mobile.connect.payment.CheckoutInfo;
|
|
18
|
+
import com.oppwa.mobile.connect.payment.ImagesRequest;
|
|
19
|
+
import com.oppwa.mobile.connect.payment.PaymentParams;
|
|
20
|
+
import com.oppwa.mobile.connect.payment.card.CardPaymentParams;
|
|
21
|
+
import com.oppwa.mobile.connect.provider.Connect;
|
|
22
|
+
import com.oppwa.mobile.connect.provider.ITransactionListener;
|
|
23
|
+
import com.oppwa.mobile.connect.provider.OppPaymentProvider;
|
|
10
24
|
import com.oppwa.mobile.connect.provider.Transaction;
|
|
25
|
+
|
|
11
26
|
@ReactModule(name = HyperPayModule.NAME)
|
|
12
27
|
public class HyperPayModule extends ReactContextBaseJavaModule {
|
|
28
|
+
private Context appContext;
|
|
29
|
+
private String shopperResultURL;
|
|
30
|
+
private String merchantIdentifier;
|
|
31
|
+
private String countryCode;
|
|
32
|
+
private String mode;
|
|
13
33
|
public static final String NAME = "HyperPay";
|
|
14
34
|
|
|
15
35
|
public HyperPayModule(ReactApplicationContext reactContext) {
|
|
@@ -22,13 +42,67 @@ public class HyperPayModule extends ReactContextBaseJavaModule {
|
|
|
22
42
|
return NAME;
|
|
23
43
|
}
|
|
24
44
|
|
|
25
|
-
|
|
26
45
|
// Example method
|
|
27
46
|
// See https://reactnative.dev/docs/native-modules-android
|
|
47
|
+
|
|
48
|
+
@ReactMethod
|
|
49
|
+
public ReadableMap setup(ReadableMap params, Promise promise) {
|
|
50
|
+
if (!params.getString("shopperResultURL").isEmpty())
|
|
51
|
+
shopperResultURL = params.getString("shopperResultURL");
|
|
52
|
+
if (!params.getString("merchantIdentifier").isEmpty())
|
|
53
|
+
merchantIdentifier = params.getString("merchantIdentifier");
|
|
54
|
+
if (!params.getString("countryCode").isEmpty())
|
|
55
|
+
countryCode = params.getString("countryCode");
|
|
56
|
+
if (!params.getString("mode").isEmpty())
|
|
57
|
+
countryCode = params.getString("mode");
|
|
58
|
+
return params;
|
|
59
|
+
}
|
|
60
|
+
|
|
28
61
|
@ReactMethod
|
|
29
|
-
public void
|
|
30
|
-
|
|
62
|
+
public void createPaymentTransaction(ReadableMap params, Promise promise) {
|
|
63
|
+
|
|
64
|
+
// PaymentParams paymentParams = new CardPaymentParams(
|
|
65
|
+
// params.getString("checkoutID"),
|
|
66
|
+
// params.getString("paymentBrand"),
|
|
67
|
+
// params.getString("cardNumber"),
|
|
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());
|
|
103
|
+
|
|
31
104
|
}
|
|
32
105
|
|
|
33
106
|
public static native int nativeMultiply(int a, int b);
|
|
107
|
+
|
|
34
108
|
}
|
package/ios/HyperPay.m
CHANGED
|
@@ -24,7 +24,7 @@ RCT_EXPORT_MODULE(HyperPay)
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
- (NSArray<NSString *> *)supportedEvents {
|
|
27
|
-
return @[@"onTransactionComplete"];
|
|
27
|
+
return @[@"onTransactionComplete",@"onProgress"];
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
/**
|
|
@@ -59,7 +59,7 @@ RCT_EXPORT_METHOD(createPaymentTransaction: (NSDictionary*)options resolver:(RCT
|
|
|
59
59
|
expiryYear:[options valueForKey:@"expiryYear"]
|
|
60
60
|
CVV:[options valueForKey:@"cvv"]
|
|
61
61
|
error:&error];
|
|
62
|
-
|
|
62
|
+
|
|
63
63
|
if (error) {
|
|
64
64
|
NSLog(@"%s", "error");
|
|
65
65
|
reject(@"createTransaction",error.localizedDescription, error);
|
|
@@ -109,7 +109,7 @@ RCT_EXPORT_METHOD(applePay:(NSString*)checkoutID resolver:(RCTPromiseResolveBloc
|
|
|
109
109
|
|
|
110
110
|
[checkoutProvider presentCheckoutWithPaymentBrand:@"APPLEPAY"
|
|
111
111
|
loadingHandler:^(BOOL inProgress) {
|
|
112
|
-
|
|
112
|
+
[self sendEventWithName:@"onProgress" body:@(inProgress)];
|
|
113
113
|
// Executed whenever SDK sends request to the server or receives the response.
|
|
114
114
|
// You can start or stop loading animation based on inProgress parameter.
|
|
115
115
|
} completionHandler:^(OPPTransaction * _Nullable transaction, NSError * _Nullable error) {
|
|
@@ -118,8 +118,10 @@ RCT_EXPORT_METHOD(applePay:(NSString*)checkoutID resolver:(RCTPromiseResolveBloc
|
|
|
118
118
|
reject(@"applePay",error.localizedDescription, error);
|
|
119
119
|
// See code attribute (OPPErrorCode) and NSLocalizedDescription to identify the reason of failure.
|
|
120
120
|
} else {
|
|
121
|
-
|
|
122
|
-
|
|
121
|
+
if (transaction.redirectURL)
|
|
122
|
+
resolve(@{@"redirectURL": transaction.redirectURL.absoluteString});
|
|
123
|
+
else
|
|
124
|
+
resolve(@{@"resourcePath": transaction.resourcePath});
|
|
123
125
|
}
|
|
124
126
|
} cancelHandler:^{
|
|
125
127
|
reject(@"applePay",@"Executed if the shopper closes the payment page prematurely.",NULL);
|
|
@@ -59,10 +59,11 @@ export default class HyperPay {
|
|
|
59
59
|
|
|
60
60
|
/**
|
|
61
61
|
* @param {string} checkoutID
|
|
62
|
+
* @param {(isProgress: boolean) => void} onProgress
|
|
62
63
|
* @returns ```Promise<{ redirectURL?: string,
|
|
63
64
|
resourcePath?: string}>```
|
|
64
65
|
*/
|
|
65
|
-
static applePay(checkoutID: string): Promise<ApplePayCallback>;
|
|
66
|
+
static applePay(checkoutID: string, onProgress?: (isProgress: boolean) => void): Promise<ApplePayCallback>;
|
|
66
67
|
|
|
67
68
|
/**
|
|
68
69
|
* @param {string} paymentBrand
|
|
@@ -81,6 +82,8 @@ export default class HyperPay {
|
|
|
81
82
|
|
|
82
83
|
static createPaymentTransaction(params: CreateTransactionParams): Promise<CreateTransactionResponseType>;
|
|
83
84
|
|
|
85
|
+
|
|
86
|
+
|
|
84
87
|
/**
|
|
85
88
|
* @param {string} statusCode
|
|
86
89
|
* @returns```{ code: string, description: string, status: 'successfully' |
|
|
@@ -90,4 +93,6 @@ export default class HyperPay {
|
|
|
90
93
|
static getPaymentStatus(status: string): PaymentStatus
|
|
91
94
|
|
|
92
95
|
}
|
|
96
|
+
export type { PaymentStatus }
|
|
93
97
|
|
|
98
|
+
export declare function useTransactionLoading(): void
|
package/package.json
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useTransactionLoading } from './useTransactionLoading'
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
import { eventEmitter } from '../utils';
|
|
3
|
+
|
|
4
|
+
let isCalledTransactionLoading: boolean = false
|
|
5
|
+
|
|
6
|
+
export function useTransactionLoading() {
|
|
7
|
+
const [loading, setLoading] = useState(false)
|
|
8
|
+
useEffect(() => {
|
|
9
|
+
if (!isCalledTransactionLoading) {
|
|
10
|
+
const _event = eventEmitter.addListener('onProgress', (isLoading: boolean) => {
|
|
11
|
+
setLoading(isLoading)
|
|
12
|
+
if (!isLoading) _event.remove(); isCalledTransactionLoading = false
|
|
13
|
+
})
|
|
14
|
+
isCalledTransactionLoading = true
|
|
15
|
+
}
|
|
16
|
+
}, [isCalledTransactionLoading])
|
|
17
|
+
return loading
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
package/src/index.tsx
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
NativeModules,
|
|
3
|
-
Platform
|
|
4
|
-
} from 'react-native';
|
|
5
1
|
import type {
|
|
6
2
|
CreateTransactionResponseType,
|
|
7
3
|
CreateTransactionParams,
|
|
@@ -11,22 +7,8 @@ import {
|
|
|
11
7
|
getPaymentStatus
|
|
12
8
|
} from './paymentStatus'
|
|
13
9
|
import type { ApplePayCallback } from '../'
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
|
|
17
|
-
'- You rebuilt the app after installing the package\n' +
|
|
18
|
-
'- You are not using Expo managed workflow\n';
|
|
19
|
-
|
|
20
|
-
const HyperPaySDK = NativeModules.HyperPay
|
|
21
|
-
? NativeModules.HyperPay
|
|
22
|
-
: new Proxy(
|
|
23
|
-
{},
|
|
24
|
-
{
|
|
25
|
-
get() {
|
|
26
|
-
throw new Error(LINKING_ERROR);
|
|
27
|
-
},
|
|
28
|
-
}
|
|
29
|
-
);
|
|
10
|
+
import { HyperPaySDK, eventEmitter } from './utils';
|
|
11
|
+
|
|
30
12
|
export function init(params: Config): Config {
|
|
31
13
|
return HyperPaySDK.setup(params);
|
|
32
14
|
}
|
|
@@ -37,7 +19,17 @@ export function createPaymentTransaction(params: CreateTransactionParams):
|
|
|
37
19
|
}
|
|
38
20
|
|
|
39
21
|
|
|
40
|
-
|
|
22
|
+
|
|
23
|
+
export function applePay(checkoutID: string,
|
|
24
|
+
onProgress?: (isProgress: boolean) => void): Promise<ApplePayCallback> {
|
|
25
|
+
|
|
26
|
+
if (onProgress) {
|
|
27
|
+
const _event = eventEmitter.addListener('onProgress', (isLoading: boolean) => {
|
|
28
|
+
onProgress(isLoading)
|
|
29
|
+
if (!isLoading) _event.remove()
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
41
33
|
return HyperPaySDK.applePay(checkoutID);
|
|
42
34
|
}
|
|
43
35
|
|
|
@@ -45,8 +37,11 @@ const Hyperpay = {
|
|
|
45
37
|
init,
|
|
46
38
|
applePay,
|
|
47
39
|
createPaymentTransaction,
|
|
48
|
-
getPaymentStatus
|
|
40
|
+
getPaymentStatus,
|
|
49
41
|
}
|
|
42
|
+
export {
|
|
43
|
+
useTransactionLoading
|
|
44
|
+
} from './hooks'
|
|
50
45
|
|
|
51
46
|
|
|
52
47
|
export default Hyperpay
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { NativeModules, Platform } from "react-native";
|
|
2
|
+
|
|
3
|
+
const LINKING_ERROR =
|
|
4
|
+
`The package 'react-native-hyperpay-sdk' doesn't seem to be linked. Make sure: \n\n` +
|
|
5
|
+
Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
|
|
6
|
+
'- You rebuilt the app after installing the package\n' +
|
|
7
|
+
'- You are not using Expo managed workflow\n';
|
|
8
|
+
|
|
9
|
+
export const HyperPaySDK = NativeModules.HyperPay
|
|
10
|
+
? NativeModules.HyperPay
|
|
11
|
+
: new Proxy(
|
|
12
|
+
{},
|
|
13
|
+
{
|
|
14
|
+
get() {
|
|
15
|
+
throw new Error(LINKING_ERROR);
|
|
16
|
+
},
|
|
17
|
+
}
|
|
18
|
+
);
|