react-amwal-pay 0.1.3 → 0.1.5
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 +113 -101
- package/ReactAmwalPay.podspec +21 -21
- package/android/build.gradle +93 -93
- package/ios/ReactAmwalPay.m +14 -0
- package/ios/ReactAmwalPay.swift +111 -0
- package/lib/module/AmwalPaySDK.js +8 -8
- package/lib/module/AmwalPaySDK.js.map +1 -1
- package/lib/module/NativeReactAmwalPay.js.map +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/network/NetworkClient.js.map +1 -1
- package/lib/module/utils/SecureHashUtil.js.map +1 -1
- package/package.json +173 -168
- package/src/AmwalPaySDK.ts +97 -97
- package/src/network/NetworkClient.ts +83 -83
- package/src/utils/SecureHashUtil.ts +44 -44
- package/ios/ReactAmwalPay.h +0 -14
- package/ios/ReactAmwalPay.mm +0 -141
- package/lib/AmwalPay.d.ts +0 -47
- package/lib/AmwalPay.js +0 -63
- package/lib/AmwalPay.js.map +0 -1
- package/lib/index.d.ts +0 -4
- package/lib/index.js +0 -4
- package/lib/index.js.map +0 -1
- package/lib/screens/PaymentScreen.d.ts +0 -2
- package/lib/screens/PaymentScreen.js +0 -133
- package/lib/screens/PaymentScreen.js.map +0 -1
- package/lib/services/NetworkClient.d.ts +0 -10
- package/lib/services/NetworkClient.js +0 -65
- package/lib/services/NetworkClient.js.map +0 -1
- package/lib/utils/SecureHashUtil.d.ts +0 -9
- package/lib/utils/SecureHashUtil.js +0 -37
- package/lib/utils/SecureHashUtil.js.map +0 -1
|
@@ -1,84 +1,84 @@
|
|
|
1
|
-
import { Alert } from 'react-native';
|
|
2
|
-
import { Environment } from '../NativeReactAmwalPay';
|
|
3
|
-
import SecureHashUtil from '../utils/SecureHashUtil';
|
|
4
|
-
|
|
5
|
-
class NetworkClient {
|
|
6
|
-
private static instance: NetworkClient;
|
|
7
|
-
|
|
8
|
-
private constructor() {}
|
|
9
|
-
|
|
10
|
-
static getInstance(): NetworkClient {
|
|
11
|
-
if (!NetworkClient.instance) {
|
|
12
|
-
NetworkClient.instance = new NetworkClient();
|
|
13
|
-
}
|
|
14
|
-
return NetworkClient.instance;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
private getWebhookUrl(env: Environment): string {
|
|
18
|
-
switch (env) {
|
|
19
|
-
case Environment.SIT:
|
|
20
|
-
return 'https://test.amwalpg.com:24443/';
|
|
21
|
-
case Environment.UAT:
|
|
22
|
-
return 'https://test.amwalpg.com:14443/';
|
|
23
|
-
case Environment.PROD:
|
|
24
|
-
return 'https://webhook.amwalpg.com/';
|
|
25
|
-
default:
|
|
26
|
-
return 'https://test.amwalpg.com:24443/';
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
async fetchSessionToken(
|
|
31
|
-
env: Environment,
|
|
32
|
-
merchantId: string,
|
|
33
|
-
customerId: string | null,
|
|
34
|
-
secureHashValue: string
|
|
35
|
-
): Promise<string | null> {
|
|
36
|
-
try {
|
|
37
|
-
const webhookUrl = this.getWebhookUrl(env);
|
|
38
|
-
|
|
39
|
-
const dataMap = {
|
|
40
|
-
merchantId,
|
|
41
|
-
customerId
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
const secureHash = SecureHashUtil.clearSecureHash(secureHashValue, dataMap);
|
|
45
|
-
|
|
46
|
-
const response = await fetch(`${webhookUrl}Membership/GetSDKSessionToken`, {
|
|
47
|
-
method: 'POST',
|
|
48
|
-
headers: {
|
|
49
|
-
'Accept': 'text/plain',
|
|
50
|
-
'Accept-Language': 'en-US,en;q=0.9',
|
|
51
|
-
'Content-Type': 'application/json',
|
|
52
|
-
},
|
|
53
|
-
body: JSON.stringify({
|
|
54
|
-
merchantId,
|
|
55
|
-
secureHashValue: secureHash,
|
|
56
|
-
customerId
|
|
57
|
-
})
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
const responseData = await response.json();
|
|
61
|
-
|
|
62
|
-
if (response.ok && responseData.success) {
|
|
63
|
-
return responseData.data.sessionToken;
|
|
64
|
-
} else {
|
|
65
|
-
const errorMessage = responseData.errorList?.join(',') || 'Unknown error';
|
|
66
|
-
this.showErrorDialog(errorMessage);
|
|
67
|
-
return null;
|
|
68
|
-
}
|
|
69
|
-
} catch (error) {
|
|
70
|
-
this.showErrorDialog('Something Went Wrong');
|
|
71
|
-
return null;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
private showErrorDialog(message: string): void {
|
|
76
|
-
Alert.alert(
|
|
77
|
-
'Error',
|
|
78
|
-
message,
|
|
79
|
-
[{ text: 'OK' }]
|
|
80
|
-
);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
1
|
+
import { Alert } from 'react-native';
|
|
2
|
+
import { Environment } from '../NativeReactAmwalPay';
|
|
3
|
+
import SecureHashUtil from '../utils/SecureHashUtil';
|
|
4
|
+
|
|
5
|
+
class NetworkClient {
|
|
6
|
+
private static instance: NetworkClient;
|
|
7
|
+
|
|
8
|
+
private constructor() {}
|
|
9
|
+
|
|
10
|
+
static getInstance(): NetworkClient {
|
|
11
|
+
if (!NetworkClient.instance) {
|
|
12
|
+
NetworkClient.instance = new NetworkClient();
|
|
13
|
+
}
|
|
14
|
+
return NetworkClient.instance;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
private getWebhookUrl(env: Environment): string {
|
|
18
|
+
switch (env) {
|
|
19
|
+
case Environment.SIT:
|
|
20
|
+
return 'https://test.amwalpg.com:24443/';
|
|
21
|
+
case Environment.UAT:
|
|
22
|
+
return 'https://test.amwalpg.com:14443/';
|
|
23
|
+
case Environment.PROD:
|
|
24
|
+
return 'https://webhook.amwalpg.com/';
|
|
25
|
+
default:
|
|
26
|
+
return 'https://test.amwalpg.com:24443/';
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async fetchSessionToken(
|
|
31
|
+
env: Environment,
|
|
32
|
+
merchantId: string,
|
|
33
|
+
customerId: string | null,
|
|
34
|
+
secureHashValue: string
|
|
35
|
+
): Promise<string | null> {
|
|
36
|
+
try {
|
|
37
|
+
const webhookUrl = this.getWebhookUrl(env);
|
|
38
|
+
|
|
39
|
+
const dataMap = {
|
|
40
|
+
merchantId,
|
|
41
|
+
customerId
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const secureHash = SecureHashUtil.clearSecureHash(secureHashValue, dataMap);
|
|
45
|
+
|
|
46
|
+
const response = await fetch(`${webhookUrl}Membership/GetSDKSessionToken`, {
|
|
47
|
+
method: 'POST',
|
|
48
|
+
headers: {
|
|
49
|
+
'Accept': 'text/plain',
|
|
50
|
+
'Accept-Language': 'en-US,en;q=0.9',
|
|
51
|
+
'Content-Type': 'application/json',
|
|
52
|
+
},
|
|
53
|
+
body: JSON.stringify({
|
|
54
|
+
merchantId,
|
|
55
|
+
secureHashValue: secureHash,
|
|
56
|
+
customerId
|
|
57
|
+
})
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
const responseData = await response.json();
|
|
61
|
+
|
|
62
|
+
if (response.ok && responseData.success) {
|
|
63
|
+
return responseData.data.sessionToken;
|
|
64
|
+
} else {
|
|
65
|
+
const errorMessage = responseData.errorList?.join(',') || 'Unknown error';
|
|
66
|
+
this.showErrorDialog(errorMessage);
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
} catch (error) {
|
|
70
|
+
this.showErrorDialog('Something Went Wrong');
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
private showErrorDialog(message: string): void {
|
|
76
|
+
Alert.alert(
|
|
77
|
+
'Error',
|
|
78
|
+
message,
|
|
79
|
+
[{ text: 'OK' }]
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
84
|
export default NetworkClient;
|
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
import HmacSHA256 from 'crypto-js/hmac-sha256';
|
|
2
|
-
import Hex from 'crypto-js/enc-hex';
|
|
3
|
-
|
|
4
|
-
type DataMap = { [key: string]: string | null };
|
|
5
|
-
|
|
6
|
-
class SecureHashUtil {
|
|
7
|
-
static clearSecureHash(secretKey: string, data: DataMap): string {
|
|
8
|
-
delete data.secureHashValue;
|
|
9
|
-
const concatenatedString = this.composeData(data);
|
|
10
|
-
return this.generateSecureHash(concatenatedString, secretKey);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
private static composeData(requestParameters: DataMap): string {
|
|
14
|
-
return Object.entries(requestParameters)
|
|
15
|
-
.sort(([keyA], [keyB]) => keyA.localeCompare(keyB))
|
|
16
|
-
.filter(([_, value]) => value != null && value !== '')
|
|
17
|
-
.map(([key, value]) => `${key}=${value}`)
|
|
18
|
-
.join('&');
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
private static generateSecureHash(message: string, secretKey: string): string {
|
|
22
|
-
try {
|
|
23
|
-
// Convert hex string to byte array
|
|
24
|
-
const keyBytes = secretKey.match(/.{2}/g)?.map(byte => parseInt(byte, 16));
|
|
25
|
-
|
|
26
|
-
if (!keyBytes) {
|
|
27
|
-
throw new Error('Invalid secret key format');
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// Convert key bytes to hex string for crypto-js
|
|
31
|
-
const keyHex = keyBytes.map(byte => byte.toString(16).padStart(2, '0')).join('');
|
|
32
|
-
|
|
33
|
-
// Generate HMAC-SHA256
|
|
34
|
-
const hash = HmacSHA256(message, Hex.parse(keyHex));
|
|
35
|
-
|
|
36
|
-
// Convert to uppercase hex string
|
|
37
|
-
return hash.toString(Hex).toUpperCase();
|
|
38
|
-
} catch (e) {
|
|
39
|
-
console.error('Error generating secure hash:', e);
|
|
40
|
-
return '';
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
1
|
+
import HmacSHA256 from 'crypto-js/hmac-sha256';
|
|
2
|
+
import Hex from 'crypto-js/enc-hex';
|
|
3
|
+
|
|
4
|
+
type DataMap = { [key: string]: string | null };
|
|
5
|
+
|
|
6
|
+
class SecureHashUtil {
|
|
7
|
+
static clearSecureHash(secretKey: string, data: DataMap): string {
|
|
8
|
+
delete data.secureHashValue;
|
|
9
|
+
const concatenatedString = this.composeData(data);
|
|
10
|
+
return this.generateSecureHash(concatenatedString, secretKey);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
private static composeData(requestParameters: DataMap): string {
|
|
14
|
+
return Object.entries(requestParameters)
|
|
15
|
+
.sort(([keyA], [keyB]) => keyA.localeCompare(keyB))
|
|
16
|
+
.filter(([_, value]) => value != null && value !== '')
|
|
17
|
+
.map(([key, value]) => `${key}=${value}`)
|
|
18
|
+
.join('&');
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
private static generateSecureHash(message: string, secretKey: string): string {
|
|
22
|
+
try {
|
|
23
|
+
// Convert hex string to byte array
|
|
24
|
+
const keyBytes = secretKey.match(/.{2}/g)?.map(byte => parseInt(byte, 16));
|
|
25
|
+
|
|
26
|
+
if (!keyBytes) {
|
|
27
|
+
throw new Error('Invalid secret key format');
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Convert key bytes to hex string for crypto-js
|
|
31
|
+
const keyHex = keyBytes.map(byte => byte.toString(16).padStart(2, '0')).join('');
|
|
32
|
+
|
|
33
|
+
// Generate HMAC-SHA256
|
|
34
|
+
const hash = HmacSHA256(message, Hex.parse(keyHex));
|
|
35
|
+
|
|
36
|
+
// Convert to uppercase hex string
|
|
37
|
+
return hash.toString(Hex).toUpperCase();
|
|
38
|
+
} catch (e) {
|
|
39
|
+
console.error('Error generating secure hash:', e);
|
|
40
|
+
return '';
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
45
|
export default SecureHashUtil;
|
package/ios/ReactAmwalPay.h
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
#import <ReactAmwalPaySpec/ReactAmwalPaySpec.h>
|
|
2
|
-
#import <React/RCTEventEmitter.h>
|
|
3
|
-
#import <amwalsdk/amwalsdk.h>
|
|
4
|
-
|
|
5
|
-
@interface ReactAmwalPay : RCTEventEmitter <NativeReactAmwalPaySpec>
|
|
6
|
-
|
|
7
|
-
- (AmwalEnvironment)getEnvironmentFromString:(NSString *)env;
|
|
8
|
-
- (AmwalLocale)getLocaleFromString:(NSString *)locale;
|
|
9
|
-
- (AmwalTransactionType)getTransactionTypeFromString:(NSString *)type;
|
|
10
|
-
- (void)sendResponseEvent:(NSDictionary *)response;
|
|
11
|
-
- (void)sendCustomerIdEvent:(NSString *)customerId;
|
|
12
|
-
- (void)sendErrorEvent:(NSString *)errorMessage;
|
|
13
|
-
|
|
14
|
-
@end
|
package/ios/ReactAmwalPay.mm
DELETED
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
#import "ReactAmwalPay.h"
|
|
2
|
-
#import <React/RCTBridgeModule.h>
|
|
3
|
-
#import <React/RCTEventEmitter.h>
|
|
4
|
-
#import <React/RCTUtils.h>
|
|
5
|
-
#import <amwalsdk/amwalsdk.h>
|
|
6
|
-
|
|
7
|
-
@implementation ReactAmwalPay
|
|
8
|
-
RCT_EXPORT_MODULE()
|
|
9
|
-
|
|
10
|
-
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
|
|
11
|
-
(const facebook::react::ObjCTurboModule::InitParams &)params
|
|
12
|
-
{
|
|
13
|
-
return std::make_shared<facebook::react::NativeReactAmwalPaySpecJSI>(params);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
- (AmwalEnvironment)getEnvironmentFromString:(NSString *)env {
|
|
17
|
-
if ([env isEqualToString:@"PROD"]) {
|
|
18
|
-
return AmwalEnvironmentPROD;
|
|
19
|
-
} else if ([env isEqualToString:@"UAT"]) {
|
|
20
|
-
return AmwalEnvironmentUAT;
|
|
21
|
-
}
|
|
22
|
-
return AmwalEnvironmentSIT;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
- (AmwalLocale)getLocaleFromString:(NSString *)locale {
|
|
26
|
-
if ([locale isEqualToString:@"ar"]) {
|
|
27
|
-
return AmwalLocaleAr;
|
|
28
|
-
}
|
|
29
|
-
return AmwalLocaleEn;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
- (AmwalTransactionType)getTransactionTypeFromString:(NSString *)type {
|
|
33
|
-
if ([type isEqualToString:@"NFC"]) {
|
|
34
|
-
return AmwalTransactionTypeNFC;
|
|
35
|
-
} else if ([type isEqualToString:@"APPLE_PAY"]) {
|
|
36
|
-
return AmwalTransactionTypeApplePay;
|
|
37
|
-
}
|
|
38
|
-
return AmwalTransactionTypeCardWallet;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
- (void)initiate:(JS::NativeReactAmwalPay::AmwalPayNativeConfig &)config {
|
|
42
|
-
dispatch_async(dispatch_get_main_queue(), ^{
|
|
43
|
-
UIViewController *rootViewController = RCTPresentedViewController();
|
|
44
|
-
if (!rootViewController) {
|
|
45
|
-
[self sendErrorEvent:@"Activity context is not available"];
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
@try {
|
|
50
|
-
// Get values using method calls
|
|
51
|
-
NSString *sessionToken = config.sessionToken();
|
|
52
|
-
NSString *amount = config.amount();
|
|
53
|
-
NSString *merchantId = config.merchantId();
|
|
54
|
-
NSString *terminalId = config.terminalId();
|
|
55
|
-
NSString *customerId = config.customerId();
|
|
56
|
-
NSString *environment = config.environment();
|
|
57
|
-
NSString *locale = config.locale();
|
|
58
|
-
NSString *transactionType = config.transactionType();
|
|
59
|
-
|
|
60
|
-
// Create config object with all required parameters
|
|
61
|
-
Config *sdkConfig = [[Config alloc] initWithEnvironment:[self getEnvironmentFromString:environment]
|
|
62
|
-
sessionToken:sessionToken
|
|
63
|
-
currency:AmwalCurrencyOMR
|
|
64
|
-
amount:amount
|
|
65
|
-
merchantId:merchantId
|
|
66
|
-
terminalId:terminalId
|
|
67
|
-
customerId:customerId
|
|
68
|
-
locale:[self getLocaleFromString:locale]
|
|
69
|
-
transactionType:[self getTransactionTypeFromString:transactionType]];
|
|
70
|
-
|
|
71
|
-
// Initialize AmwalSDK
|
|
72
|
-
AmwalSDK *amwalSDK = [[AmwalSDK alloc] init];
|
|
73
|
-
|
|
74
|
-
// Create and present the payment view controller
|
|
75
|
-
NSError *error = nil;
|
|
76
|
-
UIViewController *paymentVC = [amwalSDK createViewControllerWithConfig:sdkConfig
|
|
77
|
-
onResponse:^(NSString * _Nullable response) {
|
|
78
|
-
if (response) {
|
|
79
|
-
[self sendResponseEvent:@{@"response": response}];
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
onCustomerId:^(NSString *customerId) {
|
|
83
|
-
[self sendCustomerIdEvent:customerId];
|
|
84
|
-
}
|
|
85
|
-
error:&error];
|
|
86
|
-
|
|
87
|
-
if (error) {
|
|
88
|
-
[self sendErrorEvent:error.localizedDescription];
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
if (paymentVC) {
|
|
93
|
-
[rootViewController presentViewController:paymentVC animated:YES completion:nil];
|
|
94
|
-
} else {
|
|
95
|
-
[self sendErrorEvent:@"Failed to create payment view controller"];
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
} @catch (NSException *exception) {
|
|
99
|
-
[self sendErrorEvent:exception.reason];
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
#pragma mark - Helper Methods
|
|
105
|
-
|
|
106
|
-
- (void)sendResponseEvent:(NSDictionary *)response {
|
|
107
|
-
NSMutableDictionary *params = [NSMutableDictionary dictionary];
|
|
108
|
-
params[@"type"] = @"onResponse";
|
|
109
|
-
params[@"data"] = response;
|
|
110
|
-
|
|
111
|
-
[self sendEventWithName:@"AmwalPayEvent" body:params];
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
- (void)sendCustomerIdEvent:(NSString *)customerId {
|
|
115
|
-
NSMutableDictionary *params = [NSMutableDictionary dictionary];
|
|
116
|
-
params[@"type"] = @"onCustomerId";
|
|
117
|
-
params[@"data"] = customerId;
|
|
118
|
-
|
|
119
|
-
[self sendEventWithName:@"AmwalPayEvent" body:params];
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
- (void)sendErrorEvent:(NSString *)errorMessage {
|
|
123
|
-
NSMutableDictionary *params = [NSMutableDictionary dictionary];
|
|
124
|
-
params[@"type"] = @"onResponse";
|
|
125
|
-
|
|
126
|
-
NSMutableDictionary *errorData = [NSMutableDictionary dictionary];
|
|
127
|
-
errorData[@"status"] = @"ERROR";
|
|
128
|
-
errorData[@"message"] = errorMessage;
|
|
129
|
-
|
|
130
|
-
params[@"data"] = errorData;
|
|
131
|
-
|
|
132
|
-
[self sendEventWithName:@"AmwalPayEvent" body:params];
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
// Add this to ensure the module is properly initialized
|
|
136
|
-
+ (BOOL)requiresMainQueueSetup
|
|
137
|
-
{
|
|
138
|
-
return YES;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
@end
|
package/lib/AmwalPay.d.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
export type Environment = 'SIT' | 'UAT' | 'PROD';
|
|
2
|
-
export declare const Environment: {
|
|
3
|
-
SIT: Environment;
|
|
4
|
-
UAT: Environment;
|
|
5
|
-
PROD: Environment;
|
|
6
|
-
};
|
|
7
|
-
export type Currency = 'OMR';
|
|
8
|
-
export declare const Currency: {
|
|
9
|
-
OMR: "OMR";
|
|
10
|
-
};
|
|
11
|
-
export type TransactionType = 'NFC' | 'CARD_WALLET' | 'APPLE_PAY';
|
|
12
|
-
export declare const TransactionType: {
|
|
13
|
-
NFC: TransactionType;
|
|
14
|
-
CARD_WALLET: TransactionType;
|
|
15
|
-
APPLE_PAY: TransactionType;
|
|
16
|
-
};
|
|
17
|
-
export interface AmwalPayConfig {
|
|
18
|
-
environment: Environment;
|
|
19
|
-
secureHash: string;
|
|
20
|
-
currency: Currency;
|
|
21
|
-
amount: string;
|
|
22
|
-
merchantId: string;
|
|
23
|
-
terminalId: string;
|
|
24
|
-
locale: string;
|
|
25
|
-
customerId: string | null;
|
|
26
|
-
transactionType: TransactionType;
|
|
27
|
-
sessionToken?: string;
|
|
28
|
-
onResponse: (response: AmwalPayResponse) => void;
|
|
29
|
-
onCustomerIdResponse: (customerId: string) => void;
|
|
30
|
-
}
|
|
31
|
-
export interface AmwalPayResponse {
|
|
32
|
-
success: boolean;
|
|
33
|
-
transactionId?: string;
|
|
34
|
-
message?: string;
|
|
35
|
-
error?: string;
|
|
36
|
-
}
|
|
37
|
-
declare class AmwalPay {
|
|
38
|
-
private static instance;
|
|
39
|
-
private eventEmitter;
|
|
40
|
-
private constructor();
|
|
41
|
-
static getInstance(): AmwalPay;
|
|
42
|
-
private getSessionToken;
|
|
43
|
-
start(amwalPayConfig: AmwalPayConfig): Promise<void>;
|
|
44
|
-
private registerEventListeners;
|
|
45
|
-
removeEventListeners(): void;
|
|
46
|
-
}
|
|
47
|
-
export default AmwalPay;
|
package/lib/AmwalPay.js
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { NativeModules, NativeEventEmitter } from 'react-native';
|
|
2
|
-
import NetworkClient from './services/NetworkClient';
|
|
3
|
-
const { AmwalPaySDK } = NativeModules;
|
|
4
|
-
export const Environment = {
|
|
5
|
-
SIT: 'SIT',
|
|
6
|
-
UAT: 'UAT',
|
|
7
|
-
PROD: 'PROD'
|
|
8
|
-
};
|
|
9
|
-
export const Currency = {
|
|
10
|
-
OMR: 'OMR'
|
|
11
|
-
};
|
|
12
|
-
export const TransactionType = {
|
|
13
|
-
NFC: 'NFC',
|
|
14
|
-
CARD_WALLET: 'CARD_WALLET',
|
|
15
|
-
APPLE_PAY: 'APPLE_PAY'
|
|
16
|
-
};
|
|
17
|
-
class AmwalPay {
|
|
18
|
-
constructor() {
|
|
19
|
-
this.eventEmitter = new NativeEventEmitter(AmwalPaySDK);
|
|
20
|
-
}
|
|
21
|
-
static getInstance() {
|
|
22
|
-
if (!AmwalPay.instance) {
|
|
23
|
-
AmwalPay.instance = new AmwalPay();
|
|
24
|
-
}
|
|
25
|
-
return AmwalPay.instance;
|
|
26
|
-
}
|
|
27
|
-
async getSessionToken(config) {
|
|
28
|
-
const { environment, merchantId, customerId, secureHash } = config;
|
|
29
|
-
const sessionToken = await NetworkClient.getInstance().fetchSessionToken(environment, merchantId, customerId, secureHash);
|
|
30
|
-
return sessionToken;
|
|
31
|
-
}
|
|
32
|
-
async start(amwalPayConfig) {
|
|
33
|
-
const token = await this.getSessionToken(amwalPayConfig);
|
|
34
|
-
console.log(token);
|
|
35
|
-
if (token) {
|
|
36
|
-
amwalPayConfig.sessionToken = token;
|
|
37
|
-
try {
|
|
38
|
-
// Initialize the AmwalPay SDK
|
|
39
|
-
await AmwalPaySDK.initialize(amwalPayConfig);
|
|
40
|
-
// Register event listeners
|
|
41
|
-
this.registerEventListeners(amwalPayConfig);
|
|
42
|
-
}
|
|
43
|
-
catch (error) {
|
|
44
|
-
throw new Error(`Failed to initialize AmwalPay SDK: ${error}`);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
registerEventListeners(amwalPayConfig) {
|
|
49
|
-
this.eventEmitter.addListener('AmwalPayEvent', async (event) => {
|
|
50
|
-
if (event.type === 'onResponse') {
|
|
51
|
-
amwalPayConfig.onResponse(event.data);
|
|
52
|
-
}
|
|
53
|
-
else if (event.type === 'onCustomerId') {
|
|
54
|
-
amwalPayConfig.onCustomerIdResponse(event.data);
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
removeEventListeners() {
|
|
59
|
-
this.eventEmitter.removeAllListeners('AmwalPayEvent');
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
export default AmwalPay;
|
|
63
|
-
//# sourceMappingURL=AmwalPay.js.map
|
package/lib/AmwalPay.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AmwalPay.js","sourceRoot":"","sources":["../src/AmwalPay.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AACjE,OAAO,aAAa,MAAM,0BAA0B,CAAC;AAGrD,MAAM,EAAE,WAAW,EAAE,GAAG,aAAa,CAAC;AAItC,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,GAAG,EAAE,KAAoB;IACzB,GAAG,EAAE,KAAoB;IACzB,IAAI,EAAE,MAAqB;CAC5B,CAAC;AAGF,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB,GAAG,EAAE,KAAiB;CACvB,CAAC;AAGF,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,GAAG,EAAE,KAAwB;IAC7B,WAAW,EAAE,aAAgC;IAC7C,SAAS,EAAE,WAA8B;CAC1C,CAAC;AAwBF,MAAM,QAAQ;IAIZ;QACE,IAAI,CAAC,YAAY,GAAG,IAAI,kBAAkB,CAAC,WAAW,CAAC,CAAC;IAC1D,CAAC;IAEM,MAAM,CAAC,WAAW;QACvB,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE;YACtB,QAAQ,CAAC,QAAQ,GAAG,IAAI,QAAQ,EAAE,CAAC;SACpC;QACD,OAAO,QAAQ,CAAC,QAAQ,CAAC;IAC3B,CAAC;IAEO,KAAK,CAAC,eAAe,CAAC,MAAsB;QAClD,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,GAAG,MAAM,CAAC;QACnE,MAAM,YAAY,GAAG,MAAM,aAAa,CAAC,WAAW,EAAE,CAAC,iBAAiB,CACtE,WAAW,EACX,UAAU,EACV,UAAU,EACV,UAAU,CACX,CAAC;QACF,OAAO,YAAY,CAAC;IACtB,CAAC;IAEM,KAAK,CAAC,KAAK,CAAC,cAA8B;QAE/C,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,eAAe,CAAC,cAAc,CAAC,CAAC;QACzD,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QAEnB,IAAI,KAAK,EAAE;YACT,cAAc,CAAC,YAAY,GAAG,KAAK,CAAC;YAEpC,IAAI;gBACF,8BAA8B;gBAC9B,MAAM,WAAW,CAAC,UAAU,CAAC,cAAc,CAAC,CAAC;gBAE7C,2BAA2B;gBAC3B,IAAI,CAAC,sBAAsB,CAAC,cAAc,CAAC,CAAC;aAC7C;YAAC,OAAO,KAAK,EAAE;gBACd,MAAM,IAAI,KAAK,CAAC,sCAAsC,KAAK,EAAE,CAAC,CAAC;aAChE;SACF;IACH,CAAC;IAEO,sBAAsB,CAAC,cAA8B;QAC3D,IAAI,CAAC,YAAY,CAAC,WAAW,CAAC,eAAe,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE;YAC7D,IAAI,KAAK,CAAC,IAAI,KAAK,YAAY,EAAE;gBAC/B,cAAc,CAAC,UAAU,CAAC,KAAK,CAAC,IAAwB,CAAC,CAAC;aAC3D;iBAAM,IAAI,KAAK,CAAC,IAAI,KAAK,cAAc,EAAE;gBACxC,cAAc,CAAC,oBAAoB,CAAC,KAAK,CAAC,IAAc,CAAC,CAAC;aAC3D;QACH,CAAC,CAAC,CAAC;IACL,CAAC;IAEM,oBAAoB;QACzB,IAAI,CAAC,YAAY,CAAC,kBAAkB,CAAC,eAAe,CAAC,CAAC;IACxD,CAAC;CACF;AAED,eAAe,QAAQ,CAAC"}
|
package/lib/index.d.ts
DELETED
package/lib/index.js
DELETED
package/lib/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,EAAE,EACf,WAAW,EACX,QAAQ,EACR,eAAe,GAGhB,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAC,QAAQ,EAAE,WAAW,EAAE,QAAQ,EAAE,eAAe,EAAC,CAAC;AAG1D,eAAe,QAAQ,CAAC"}
|