react-native-hyperpay-sdk 0.25.0 → 0.26.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/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
- NSDictionary *response = @{@"resourcePath": transaction.resourcePath,@"redirectURL": transaction.redirectURL};
122
- resolve(response);
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-hyperpay-sdk",
3
- "version": "0.25.0",
3
+ "version": "0.26.0",
4
4
  "description": "hyperpay",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
@@ -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
- const LINKING_ERROR =
15
- `The package 'react-native-hyperpay-sdk' doesn't seem to be linked. Make sure: \n\n` +
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
- export function applePay(checkoutID: string): Promise<ApplePayCallback> {
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,4 @@
1
+ import { NativeEventEmitter } from "react-native";
2
+ import { HyperPaySDK } from "../utils";
3
+
4
+ export const eventEmitter = new NativeEventEmitter(HyperPaySDK);
@@ -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
+ );
@@ -0,0 +1,2 @@
1
+ export { eventEmitter } from './EventEmitter'
2
+ export { HyperPaySDK } from './NativeModules'