@connexup/react-native-square-mobile-payment-sdk 0.1.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/LICENSE +20 -0
- package/NativeSquareMobilePaymentSDK.podspec +23 -0
- package/README.md +66 -0
- package/android/build.gradle +81 -0
- package/android/gradle.properties +5 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/com/connexup/square/mobilepayment/DateFormatUtils.java +29 -0
- package/android/src/main/java/com/connexup/square/mobilepayment/ErrorUtilities.kt +56 -0
- package/android/src/main/java/com/connexup/square/mobilepayment/MobilePaymentAuthorization.kt +185 -0
- package/android/src/main/java/com/connexup/square/mobilepayment/MobilePaymentException.kt +8 -0
- package/android/src/main/java/com/connexup/square/mobilepayment/MobilePaymentPayment.kt +542 -0
- package/android/src/main/java/com/connexup/square/mobilepayment/MobilePaymentReader.kt +344 -0
- package/android/src/main/java/com/connexup/square/mobilepayment/MobilePaymentSDK.kt +47 -0
- package/android/src/main/java/com/connexup/square/mobilepayment/MobilePaymentSDKPackage.kt +77 -0
- package/android/src/main/java/com/connexup/square/mobilepayment/MobilePaymentSetting.kt +144 -0
- package/android/src/main/java/com/connexup/square/mobilepayment/convert/AdditionalPaymentMethodConvert.kt +46 -0
- package/android/src/main/java/com/connexup/square/mobilepayment/convert/AuthorizationStateConvert.kt +26 -0
- package/android/src/main/java/com/connexup/square/mobilepayment/convert/CardConvert.kt +53 -0
- package/android/src/main/java/com/connexup/square/mobilepayment/convert/CardDetailsConvert.kt +74 -0
- package/android/src/main/java/com/connexup/square/mobilepayment/convert/CardEntryMethodConvert.kt +31 -0
- package/android/src/main/java/com/connexup/square/mobilepayment/convert/CashPaymentDetailsConvert.kt +18 -0
- package/android/src/main/java/com/connexup/square/mobilepayment/convert/CurrencyCodeConvert.kt +204 -0
- package/android/src/main/java/com/connexup/square/mobilepayment/convert/DelayActionConvert.kt +33 -0
- package/android/src/main/java/com/connexup/square/mobilepayment/convert/DeniedReasonConvert.kt +28 -0
- package/android/src/main/java/com/connexup/square/mobilepayment/convert/DigitalWalletDetailsConvert.kt +18 -0
- package/android/src/main/java/com/connexup/square/mobilepayment/convert/ErrorDetailsConvert.kt +32 -0
- package/android/src/main/java/com/connexup/square/mobilepayment/convert/ExternalPaymentDetailsConvert.kt +25 -0
- package/android/src/main/java/com/connexup/square/mobilepayment/convert/LocationConvert.kt +31 -0
- package/android/src/main/java/com/connexup/square/mobilepayment/convert/MoneyConvert.kt +31 -0
- package/android/src/main/java/com/connexup/square/mobilepayment/convert/OfflineStatusConvert.kt +21 -0
- package/android/src/main/java/com/connexup/square/mobilepayment/convert/PaymentConvert.kt +93 -0
- package/android/src/main/java/com/connexup/square/mobilepayment/convert/PaymentProcessingFeeConvert.kt +39 -0
- package/android/src/main/java/com/connexup/square/mobilepayment/convert/PaymentSettingsConvert.kt +26 -0
- package/android/src/main/java/com/connexup/square/mobilepayment/convert/ProcessingModeConvert.kt +28 -0
- package/android/src/main/java/com/connexup/square/mobilepayment/convert/ReaderBatteryStatusConvert.kt +19 -0
- package/android/src/main/java/com/connexup/square/mobilepayment/convert/ReaderChangeEventConvert.kt +75 -0
- package/android/src/main/java/com/connexup/square/mobilepayment/convert/ReaderConnectionTypeConvert.kt +17 -0
- package/android/src/main/java/com/connexup/square/mobilepayment/convert/ReaderInfoConvert.kt +51 -0
- package/android/src/main/java/com/connexup/square/mobilepayment/convert/ReaderModalConvert.kt +18 -0
- package/android/src/main/java/com/connexup/square/mobilepayment/convert/ReaderStateConvert.kt +51 -0
- package/android/src/main/java/com/connexup/square/mobilepayment/convert/ReaderStatusConvert.kt +51 -0
- package/android/src/main/java/com/connexup/square/mobilepayment/convert/SdkSettingsConvert.kt +30 -0
- package/android/src/main/java/com/connexup/square/mobilepayment/convert/SquareAccountDetailsConvert.kt +20 -0
- package/android/src/main/java/com/connexup/square/mobilepayment/convert/TrackingConsentStateConvert.kt +17 -0
- package/android/src/main/java/com/connexup/square/mobilepayment/convert/WalletBrandConvert.kt +41 -0
- package/ios/Converters/AdditionalPaymentMethod+Extension.swift +17 -0
- package/ios/Converters/AdditionalPaymentMethodType+Extension.swift +44 -0
- package/ios/Converters/AuthorizationState+Extension.swift +22 -0
- package/ios/Converters/BatteryLevel+Extension.swift +27 -0
- package/ios/Converters/Card+Extension.swift +33 -0
- package/ios/Converters/CardBrand+Extension.swift +47 -0
- package/ios/Converters/CardCoBrand+Extension.swift +24 -0
- package/ios/Converters/CardEntryMethod+Extension.swift +30 -0
- package/ios/Converters/CardInputMethods+Extension.swift +35 -0
- package/ios/Converters/CardInsertionStatus+Extension.swift +24 -0
- package/ios/Converters/CardPaymentDetails+Extensions.swift +31 -0
- package/ios/Converters/CardPaymentStatus+Extension.swift +28 -0
- package/ios/Converters/Currency+Extension.swift +50 -0
- package/ios/Converters/Location+Extension.swift +19 -0
- package/ios/Converters/MoneyAmount+Extension.swift +30 -0
- package/ios/Converters/Payment+Extension.swift +44 -0
- package/ios/Converters/PaymentSettings+Extension.swift +19 -0
- package/ios/Converters/PaymentStatus+Extension.swift +53 -0
- package/ios/Converters/ProcessingMode+Extension.swift +37 -0
- package/ios/Converters/ReaderBatteryStatus+Extension.swift +19 -0
- package/ios/Converters/ReaderChange+Extension.swift +41 -0
- package/ios/Converters/ReaderConnectionFailureInfo+Extension.swift +20 -0
- package/ios/Converters/ReaderConnectionFailureReason+Extension.swift +40 -0
- package/ios/Converters/ReaderConnectionFailureRecoverySuggestion+Extension.swift +30 -0
- package/ios/Converters/ReaderConnectionInfo+Extension.swift +18 -0
- package/ios/Converters/ReaderConnectionStatus+Extension.swift +26 -0
- package/ios/Converters/ReaderFirmwareInfo+Extension.swift +19 -0
- package/ios/Converters/ReaderInfo+Extension.swift +30 -0
- package/ios/Converters/ReaderModel+Extension.swift +28 -0
- package/ios/Converters/ReaderState+Extension.swift +30 -0
- package/ios/Converters/ReaderStatus+Extension.swift +60 -0
- package/ios/Converters/ReaderStatusInfo+Extension.swift +22 -0
- package/ios/Converters/SDKSettings+Extension.swift +25 -0
- package/ios/Converters/SourceType+Extension.swift +32 -0
- package/ios/Converters/TrackingConsentState+Extension.swift +25 -0
- package/ios/ErrorUtilities.swift +41 -0
- package/ios/MobilePaymentAuthorization.swift +154 -0
- package/ios/MobilePaymentDateFormatter.swift +15 -0
- package/ios/MobilePaymentPayment.swift +478 -0
- package/ios/MobilePaymentReader.swift +248 -0
- package/ios/MobilePaymentSDK.swift +36 -0
- package/ios/MobilePaymentSetting.swift +86 -0
- package/ios/MockReaderUIManage.swift +52 -0
- package/ios/Models/NativeErrorInfo.swift +22 -0
- package/ios/Models/RCTPaymentMoneyParameter.swift +20 -0
- package/ios/Models/RCTPaymentParameters.swift +50 -0
- package/ios/Models/RCTPromptParameters.swift +20 -0
- package/ios/NotificationKeys.swift +9 -0
- package/ios/NotificationUtils.swift +21 -0
- package/ios/RCTMobilePaymentAuthorization.h +12 -0
- package/ios/RCTMobilePaymentAuthorization.mm +78 -0
- package/ios/RCTMobilePaymentPayment.h +12 -0
- package/ios/RCTMobilePaymentPayment.mm +116 -0
- package/ios/RCTMobilePaymentReader.h +12 -0
- package/ios/RCTMobilePaymentReader.mm +114 -0
- package/ios/RCTMobilePaymentSetting.h +10 -0
- package/ios/RCTMobilePaymentSetting.mm +94 -0
- package/ios/UIColor+Extension.swift +81 -0
- package/lib/module/authorization/NativeMobilePaymentAuthorization.js +60 -0
- package/lib/module/authorization/NativeMobilePaymentAuthorization.js.map +1 -0
- package/lib/module/authorization/index.js +44 -0
- package/lib/module/authorization/index.js.map +1 -0
- package/lib/module/index.js +7 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/payment/NativeMobilePaymentPayment.js +138 -0
- package/lib/module/payment/NativeMobilePaymentPayment.js.map +1 -0
- package/lib/module/payment/index.js +113 -0
- package/lib/module/payment/index.js.map +1 -0
- package/lib/module/reader/NativeMobilePaymentReader.js +151 -0
- package/lib/module/reader/NativeMobilePaymentReader.js.map +1 -0
- package/lib/module/reader/index.js +109 -0
- package/lib/module/reader/index.js.map +1 -0
- package/lib/module/setting/NativeMobilePaymentSetting.js +5 -0
- package/lib/module/setting/NativeMobilePaymentSetting.js.map +1 -0
- package/lib/module/setting/index.js +74 -0
- package/lib/module/setting/index.js.map +1 -0
- package/lib/module/type.js +27 -0
- package/lib/module/type.js.map +1 -0
- package/lib/module/util.js +32 -0
- package/lib/module/util.js.map +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/authorization/NativeMobilePaymentAuthorization.d.ts +82 -0
- package/lib/typescript/src/authorization/NativeMobilePaymentAuthorization.d.ts.map +1 -0
- package/lib/typescript/src/authorization/index.d.ts +14 -0
- package/lib/typescript/src/authorization/index.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +5 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/payment/NativeMobilePaymentPayment.d.ts +725 -0
- package/lib/typescript/src/payment/NativeMobilePaymentPayment.d.ts.map +1 -0
- package/lib/typescript/src/payment/index.d.ts +13 -0
- package/lib/typescript/src/payment/index.d.ts.map +1 -0
- package/lib/typescript/src/reader/NativeMobilePaymentReader.d.ts +318 -0
- package/lib/typescript/src/reader/NativeMobilePaymentReader.d.ts.map +1 -0
- package/lib/typescript/src/reader/index.d.ts +19 -0
- package/lib/typescript/src/reader/index.d.ts.map +1 -0
- package/lib/typescript/src/setting/NativeMobilePaymentSetting.d.ts +49 -0
- package/lib/typescript/src/setting/NativeMobilePaymentSetting.d.ts.map +1 -0
- package/lib/typescript/src/setting/index.d.ts +17 -0
- package/lib/typescript/src/setting/index.d.ts.map +1 -0
- package/lib/typescript/src/type.d.ts +23 -0
- package/lib/typescript/src/type.d.ts.map +1 -0
- package/lib/typescript/src/util.d.ts +3 -0
- package/lib/typescript/src/util.d.ts.map +1 -0
- package/package.json +178 -0
- package/src/authorization/NativeMobilePaymentAuthorization.ts +297 -0
- package/src/authorization/index.ts +60 -0
- package/src/index.ts +4 -0
- package/src/payment/NativeMobilePaymentPayment.ts +1220 -0
- package/src/payment/index.ts +161 -0
- package/src/reader/NativeMobilePaymentReader.ts +463 -0
- package/src/reader/index.ts +140 -0
- package/src/setting/NativeMobilePaymentSetting.ts +254 -0
- package/src/setting/index.ts +91 -0
- package/src/type.ts +35 -0
- package/src/util.ts +31 -0
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import type { EventSubscription } from 'react-native';
|
|
2
|
+
import {
|
|
3
|
+
createMobilePaymentError,
|
|
4
|
+
createMobilePaymentErrorFromCallback,
|
|
5
|
+
} from '../util';
|
|
6
|
+
import type {
|
|
7
|
+
PairingStatusChangeEvent,
|
|
8
|
+
PairingStatusListener,
|
|
9
|
+
ReaderInfo,
|
|
10
|
+
ReaderListener,
|
|
11
|
+
Spec,
|
|
12
|
+
} from './NativeMobilePaymentReader';
|
|
13
|
+
import { NativeMobilePaymentReader } from './NativeMobilePaymentReader';
|
|
14
|
+
|
|
15
|
+
class MobilePaymentReader
|
|
16
|
+
implements
|
|
17
|
+
Omit<Spec, 'getConstants' | 'onReaderChange' | 'onReaderPairingStatus'>
|
|
18
|
+
{
|
|
19
|
+
private readonly readerManage: Spec;
|
|
20
|
+
private pairingSubscription?: EventSubscription | null;
|
|
21
|
+
|
|
22
|
+
constructor(readerManage: Spec) {
|
|
23
|
+
this.readerManage = readerManage;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async bink(readerId: string): Promise<void> {
|
|
27
|
+
try {
|
|
28
|
+
return await this.readerManage.bink(readerId);
|
|
29
|
+
} catch (e) {
|
|
30
|
+
throw createMobilePaymentError(e);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async forget(readerId: string): Promise<void> {
|
|
35
|
+
try {
|
|
36
|
+
return await this.readerManage.forget(readerId);
|
|
37
|
+
} catch (e) {
|
|
38
|
+
throw createMobilePaymentError(e);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
readers(): ReaderInfo[] {
|
|
43
|
+
try {
|
|
44
|
+
return this.readerManage.readers();
|
|
45
|
+
} catch (e) {
|
|
46
|
+
throw createMobilePaymentError(e);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async retryConnection(readerId: string): Promise<void> {
|
|
51
|
+
try {
|
|
52
|
+
return await this.readerManage.retryConnection(readerId);
|
|
53
|
+
} catch (e) {
|
|
54
|
+
throw createMobilePaymentError(e);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async startPairing(listener?: PairingStatusListener): Promise<void> {
|
|
59
|
+
this.pairingSubscription?.remove();
|
|
60
|
+
this.pairingSubscription = null;
|
|
61
|
+
if (listener) {
|
|
62
|
+
this.pairingSubscription = this.addPairingStatusListener(listener);
|
|
63
|
+
}
|
|
64
|
+
try {
|
|
65
|
+
return await this.readerManage.startPairing();
|
|
66
|
+
} catch (e) {
|
|
67
|
+
this.pairingSubscription?.remove();
|
|
68
|
+
this.pairingSubscription = null;
|
|
69
|
+
throw createMobilePaymentError(e);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
async stopPairing(): Promise<boolean> {
|
|
74
|
+
try {
|
|
75
|
+
return await this.readerManage.stopPairing();
|
|
76
|
+
} catch (e) {
|
|
77
|
+
throw createMobilePaymentError(e);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
isPairingInProgress(): boolean {
|
|
82
|
+
try {
|
|
83
|
+
return this.readerManage.isPairingInProgress();
|
|
84
|
+
} catch (e) {
|
|
85
|
+
throw createMobilePaymentError(e);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
addReaderListener(listener: ReaderListener): EventSubscription {
|
|
90
|
+
return this.readerManage.onReaderChange((event) => {
|
|
91
|
+
switch (event.name) {
|
|
92
|
+
case 'readerWasAdded':
|
|
93
|
+
if (listener.readerWasAdded) {
|
|
94
|
+
listener.readerWasAdded(event.readerInfo);
|
|
95
|
+
}
|
|
96
|
+
break;
|
|
97
|
+
case 'readerWasRemoved':
|
|
98
|
+
if (listener.readerWasRemoved) {
|
|
99
|
+
listener.readerWasRemoved(event.readerInfo);
|
|
100
|
+
}
|
|
101
|
+
break;
|
|
102
|
+
case 'readerDidChange':
|
|
103
|
+
if (listener.readerDidChange) {
|
|
104
|
+
listener.readerDidChange(event.readerInfo, event.readerChange!);
|
|
105
|
+
}
|
|
106
|
+
break;
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
addPairingStatusListener(listener: PairingStatusListener): EventSubscription {
|
|
112
|
+
return this.readerManage.onReaderPairingStatus(
|
|
113
|
+
(event: PairingStatusChangeEvent) => {
|
|
114
|
+
switch (event.name) {
|
|
115
|
+
case 'didBegin':
|
|
116
|
+
if (listener.didBegin) {
|
|
117
|
+
listener.didBegin();
|
|
118
|
+
}
|
|
119
|
+
break;
|
|
120
|
+
case 'didSucceed':
|
|
121
|
+
if (listener.didSucceed) {
|
|
122
|
+
listener.didSucceed();
|
|
123
|
+
}
|
|
124
|
+
break;
|
|
125
|
+
case 'didFail':
|
|
126
|
+
if (listener.didFail) {
|
|
127
|
+
listener.didFail(
|
|
128
|
+
createMobilePaymentErrorFromCallback(event.error)
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
break;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export const mobilePaymentReader = new MobilePaymentReader(
|
|
139
|
+
NativeMobilePaymentReader
|
|
140
|
+
);
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
import { type TurboModule, TurboModuleRegistry } from 'react-native';
|
|
2
|
+
|
|
3
|
+
export interface Spec extends TurboModule {
|
|
4
|
+
initialize(applicationId: string): Promise<boolean>;
|
|
5
|
+
|
|
6
|
+
applicationId(): string | null;
|
|
7
|
+
|
|
8
|
+
sdkSettings(): SdkSettings;
|
|
9
|
+
|
|
10
|
+
paymentSettings(): PaymentSettings;
|
|
11
|
+
|
|
12
|
+
trackingConsentState(): TrackingConsentState;
|
|
13
|
+
|
|
14
|
+
updateTrackingConsent(granted: boolean): Promise<void>;
|
|
15
|
+
|
|
16
|
+
presentSettings(): Promise<void>;
|
|
17
|
+
|
|
18
|
+
//only sandbox
|
|
19
|
+
presentMockReaderUI(): Promise<void>;
|
|
20
|
+
|
|
21
|
+
dismissMockReaderUI(): Promise<void>;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export const NativeMobilePaymentSetting =
|
|
25
|
+
TurboModuleRegistry.getEnforcing<Spec>('NativeMobilePaymentSetting');
|
|
26
|
+
|
|
27
|
+
export type TrackingConsentState =
|
|
28
|
+
| 'PENDING'
|
|
29
|
+
| 'GRANTED'
|
|
30
|
+
| 'DENIED'
|
|
31
|
+
| 'NOT_REQUIRED'
|
|
32
|
+
| 'UNKNOWN';
|
|
33
|
+
|
|
34
|
+
export interface SdkSettings {
|
|
35
|
+
environment: 'PRODUCTION' | 'SANDBOX' | 'UNKNOWN';
|
|
36
|
+
version: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface PaymentSettings {
|
|
40
|
+
/**
|
|
41
|
+
* Whether taking payments offline is allowed for the current seller.
|
|
42
|
+
*/
|
|
43
|
+
isOfflineProcessingAllowed: boolean;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* The maximum transaction amount that can be processed in a single offline payment.
|
|
47
|
+
* A payment that exceeds this limit will be ineligible for offline processing.
|
|
48
|
+
* This will be <code>nil</code> if offline processing is not allowed.
|
|
49
|
+
*/
|
|
50
|
+
offlineTransactionAmountLimit: Money | null;
|
|
51
|
+
/**
|
|
52
|
+
* The total allowable amount of all offline payments combined on this device.
|
|
53
|
+
* A payment that would exceed the total limit will be ineligible for offline processing.
|
|
54
|
+
* This will be null if offline processing is not allowed.
|
|
55
|
+
*/
|
|
56
|
+
offlineTotalStoredAmountLimit: Money | null;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export interface Money {
|
|
60
|
+
/**
|
|
61
|
+
* The amount of money in the smallest denomination of the currency.
|
|
62
|
+
* For example, when currency is .usd, the amount is in cents.
|
|
63
|
+
*/
|
|
64
|
+
amount: number;
|
|
65
|
+
/**
|
|
66
|
+
* The currency code.
|
|
67
|
+
*/
|
|
68
|
+
currency: Currency;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export type Currency =
|
|
72
|
+
| 'AUD'
|
|
73
|
+
| 'CAD'
|
|
74
|
+
| 'EUR'
|
|
75
|
+
| 'GBP'
|
|
76
|
+
| 'JPY'
|
|
77
|
+
| 'USD'
|
|
78
|
+
| 'AED'
|
|
79
|
+
| 'AFN'
|
|
80
|
+
| 'ALL'
|
|
81
|
+
| 'AMD'
|
|
82
|
+
| 'ANG'
|
|
83
|
+
| 'AOA'
|
|
84
|
+
| 'ARS'
|
|
85
|
+
| 'AWG'
|
|
86
|
+
| 'AZN'
|
|
87
|
+
| 'BAM'
|
|
88
|
+
| 'BBD'
|
|
89
|
+
| 'BDT'
|
|
90
|
+
| 'BGN'
|
|
91
|
+
| 'BHD'
|
|
92
|
+
| 'BIF'
|
|
93
|
+
| 'BMD'
|
|
94
|
+
| 'BND'
|
|
95
|
+
| 'BOB'
|
|
96
|
+
| 'BOV'
|
|
97
|
+
| 'BRL'
|
|
98
|
+
| 'BSD'
|
|
99
|
+
| 'BTN'
|
|
100
|
+
| 'BWP'
|
|
101
|
+
| 'BYR'
|
|
102
|
+
| 'BZD'
|
|
103
|
+
| 'CDF'
|
|
104
|
+
| 'CHE'
|
|
105
|
+
| 'CHF'
|
|
106
|
+
| 'CHW'
|
|
107
|
+
| 'CLF'
|
|
108
|
+
| 'CLP'
|
|
109
|
+
| 'CNY'
|
|
110
|
+
| 'COP'
|
|
111
|
+
| 'COU'
|
|
112
|
+
| 'CRC'
|
|
113
|
+
| 'CUC'
|
|
114
|
+
| 'CUP'
|
|
115
|
+
| 'CVE'
|
|
116
|
+
| 'CZK'
|
|
117
|
+
| 'DJF'
|
|
118
|
+
| 'DKK'
|
|
119
|
+
| 'DOP'
|
|
120
|
+
| 'DZD'
|
|
121
|
+
| 'EGP'
|
|
122
|
+
| 'ERN'
|
|
123
|
+
| 'ETB'
|
|
124
|
+
| 'FJD'
|
|
125
|
+
| 'FKP'
|
|
126
|
+
| 'GEL'
|
|
127
|
+
| 'GHS'
|
|
128
|
+
| 'GIP'
|
|
129
|
+
| 'GMD'
|
|
130
|
+
| 'GNF'
|
|
131
|
+
| 'GTQ'
|
|
132
|
+
| 'GYD'
|
|
133
|
+
| 'HKD'
|
|
134
|
+
| 'HNL'
|
|
135
|
+
| 'HRK'
|
|
136
|
+
| 'HTG'
|
|
137
|
+
| 'HUF'
|
|
138
|
+
| 'IDR'
|
|
139
|
+
| 'ILS'
|
|
140
|
+
| 'INR'
|
|
141
|
+
| 'IQD'
|
|
142
|
+
| 'IRR'
|
|
143
|
+
| 'ISK'
|
|
144
|
+
| 'JMD'
|
|
145
|
+
| 'JOD'
|
|
146
|
+
| 'KES'
|
|
147
|
+
| 'KGS'
|
|
148
|
+
| 'KHR'
|
|
149
|
+
| 'KMF'
|
|
150
|
+
| 'KPW'
|
|
151
|
+
| 'KRW'
|
|
152
|
+
| 'KWD'
|
|
153
|
+
| 'KYD'
|
|
154
|
+
| 'KZT'
|
|
155
|
+
| 'LAK'
|
|
156
|
+
| 'LBP'
|
|
157
|
+
| 'LKR'
|
|
158
|
+
| 'LRD'
|
|
159
|
+
| 'LSL'
|
|
160
|
+
| 'LTL'
|
|
161
|
+
| 'LVL'
|
|
162
|
+
| 'LYD'
|
|
163
|
+
| 'MAD'
|
|
164
|
+
| 'MDL'
|
|
165
|
+
| 'MGA'
|
|
166
|
+
| 'MKD'
|
|
167
|
+
| 'MMK'
|
|
168
|
+
| 'MNT'
|
|
169
|
+
| 'MOP'
|
|
170
|
+
| 'MRO'
|
|
171
|
+
| 'MUR'
|
|
172
|
+
| 'MVR'
|
|
173
|
+
| 'MWK'
|
|
174
|
+
| 'MXN'
|
|
175
|
+
| 'MXV'
|
|
176
|
+
| 'MYR'
|
|
177
|
+
| 'MZN'
|
|
178
|
+
| 'NAD'
|
|
179
|
+
| 'NGN'
|
|
180
|
+
| 'NIO'
|
|
181
|
+
| 'NOK'
|
|
182
|
+
| 'NPR'
|
|
183
|
+
| 'NZD'
|
|
184
|
+
| 'OMR'
|
|
185
|
+
| 'PAB'
|
|
186
|
+
| 'PEN'
|
|
187
|
+
| 'PGK'
|
|
188
|
+
| 'PHP'
|
|
189
|
+
| 'PKR'
|
|
190
|
+
| 'PLN'
|
|
191
|
+
| 'PYG'
|
|
192
|
+
| 'QAR'
|
|
193
|
+
| 'RON'
|
|
194
|
+
| 'RSD'
|
|
195
|
+
| 'RUB'
|
|
196
|
+
| 'RWF'
|
|
197
|
+
| 'SAR'
|
|
198
|
+
| 'SBD'
|
|
199
|
+
| 'SCR'
|
|
200
|
+
| 'SDG'
|
|
201
|
+
| 'SEK'
|
|
202
|
+
| 'SGD'
|
|
203
|
+
| 'SHP'
|
|
204
|
+
| 'SLL'
|
|
205
|
+
| 'SOS'
|
|
206
|
+
| 'SRD'
|
|
207
|
+
| 'SSP'
|
|
208
|
+
| 'STD'
|
|
209
|
+
| 'SVC'
|
|
210
|
+
| 'SYP'
|
|
211
|
+
| 'SZL'
|
|
212
|
+
| 'THB'
|
|
213
|
+
| 'TJS'
|
|
214
|
+
| 'TMT'
|
|
215
|
+
| 'TND'
|
|
216
|
+
| 'TOP'
|
|
217
|
+
| 'TRY'
|
|
218
|
+
| 'TTD'
|
|
219
|
+
| 'TWD'
|
|
220
|
+
| 'TZS'
|
|
221
|
+
| 'UAH'
|
|
222
|
+
| 'UGX'
|
|
223
|
+
| 'USN'
|
|
224
|
+
| 'USS'
|
|
225
|
+
| 'UYI'
|
|
226
|
+
| 'UYU'
|
|
227
|
+
| 'UZS'
|
|
228
|
+
| 'VEF'
|
|
229
|
+
| 'VND'
|
|
230
|
+
| 'VUV'
|
|
231
|
+
| 'WST'
|
|
232
|
+
| 'XAF'
|
|
233
|
+
| 'XAG'
|
|
234
|
+
| 'XAU'
|
|
235
|
+
| 'XBA'
|
|
236
|
+
| 'XBB'
|
|
237
|
+
| 'XBC'
|
|
238
|
+
| 'XBD'
|
|
239
|
+
| 'XCD'
|
|
240
|
+
| 'XDR'
|
|
241
|
+
| 'XOF'
|
|
242
|
+
| 'XPD'
|
|
243
|
+
| 'XPF'
|
|
244
|
+
| 'XPT'
|
|
245
|
+
| 'XTS'
|
|
246
|
+
| 'XXX'
|
|
247
|
+
| 'YER'
|
|
248
|
+
| 'ZAR'
|
|
249
|
+
| 'ZMK'
|
|
250
|
+
| 'ZMW'
|
|
251
|
+
| 'BTC'
|
|
252
|
+
| 'XUS'
|
|
253
|
+
| 'SLE'
|
|
254
|
+
| 'UNKNOWN';
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { NativeMobilePaymentSetting } from './NativeMobilePaymentSetting';
|
|
2
|
+
import type {
|
|
3
|
+
PaymentSettings,
|
|
4
|
+
SdkSettings,
|
|
5
|
+
Spec,
|
|
6
|
+
TrackingConsentState,
|
|
7
|
+
} from './NativeMobilePaymentSetting';
|
|
8
|
+
import { createMobilePaymentError } from '../util';
|
|
9
|
+
|
|
10
|
+
class MobilePaymentSetting implements Omit<Spec, 'getConstants'> {
|
|
11
|
+
private readonly settingsManage: Spec;
|
|
12
|
+
|
|
13
|
+
constructor(settingsManage: Spec) {
|
|
14
|
+
this.settingsManage = settingsManage;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async initialize(applicationId: string): Promise<boolean> {
|
|
18
|
+
try {
|
|
19
|
+
return await this.settingsManage.initialize(applicationId);
|
|
20
|
+
} catch (e) {
|
|
21
|
+
throw createMobilePaymentError(e);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
applicationId(): string | null {
|
|
25
|
+
try {
|
|
26
|
+
return this.settingsManage.applicationId();
|
|
27
|
+
} catch (e) {
|
|
28
|
+
throw createMobilePaymentError(e);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
sdkSettings(): SdkSettings {
|
|
33
|
+
try {
|
|
34
|
+
return this.settingsManage.sdkSettings();
|
|
35
|
+
} catch (e) {
|
|
36
|
+
throw createMobilePaymentError(e);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
paymentSettings(): PaymentSettings {
|
|
41
|
+
try {
|
|
42
|
+
return this.settingsManage.paymentSettings();
|
|
43
|
+
} catch (e) {
|
|
44
|
+
throw createMobilePaymentError(e);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
trackingConsentState(): TrackingConsentState {
|
|
49
|
+
try {
|
|
50
|
+
return this.settingsManage.trackingConsentState();
|
|
51
|
+
} catch (e) {
|
|
52
|
+
throw createMobilePaymentError(e);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async updateTrackingConsent(granted: boolean): Promise<void> {
|
|
57
|
+
try {
|
|
58
|
+
return await this.settingsManage.updateTrackingConsent(granted);
|
|
59
|
+
} catch (e) {
|
|
60
|
+
throw createMobilePaymentError(e);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async presentSettings(): Promise<void> {
|
|
65
|
+
try {
|
|
66
|
+
return await this.settingsManage.presentSettings();
|
|
67
|
+
} catch (e) {
|
|
68
|
+
throw createMobilePaymentError(e);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
async presentMockReaderUI(): Promise<void> {
|
|
73
|
+
try {
|
|
74
|
+
return await this.settingsManage.presentMockReaderUI();
|
|
75
|
+
} catch (e) {
|
|
76
|
+
throw createMobilePaymentError(e);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
async dismissMockReaderUI(): Promise<void> {
|
|
81
|
+
try {
|
|
82
|
+
return await this.settingsManage.dismissMockReaderUI();
|
|
83
|
+
} catch (e) {
|
|
84
|
+
throw createMobilePaymentError(e);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export const mobilePaymentSetting = new MobilePaymentSetting(
|
|
90
|
+
NativeMobilePaymentSetting
|
|
91
|
+
);
|
package/src/type.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export const PARAMS_ERROR = 'PARAMS_ERROR';
|
|
2
|
+
export const UNKNOWN_ERROR = 'UNKNOWN_ERROR';
|
|
3
|
+
|
|
4
|
+
export abstract class Exception {
|
|
5
|
+
/**
|
|
6
|
+
* @param message is JavaScript original message, in English usually.
|
|
7
|
+
* In prod environment, you are not advised to display the error message directly to end-user.
|
|
8
|
+
*/
|
|
9
|
+
protected constructor(public message: string) {}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface SquareExceptionProps {
|
|
13
|
+
code?: string;
|
|
14
|
+
message: string;
|
|
15
|
+
debugCode?: string;
|
|
16
|
+
debugMessage?: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export class SquareException extends Exception {
|
|
20
|
+
code?: string;
|
|
21
|
+
debugCode?: string;
|
|
22
|
+
debugMessage?: string;
|
|
23
|
+
|
|
24
|
+
constructor({
|
|
25
|
+
message,
|
|
26
|
+
code,
|
|
27
|
+
debugCode,
|
|
28
|
+
debugMessage,
|
|
29
|
+
}: SquareExceptionProps) {
|
|
30
|
+
super(message);
|
|
31
|
+
this.code = code;
|
|
32
|
+
this.debugCode = debugCode;
|
|
33
|
+
this.debugMessage = debugMessage;
|
|
34
|
+
}
|
|
35
|
+
}
|
package/src/util.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { SquareException } from './type';
|
|
2
|
+
|
|
3
|
+
export function createMobilePaymentErrorFromCallback(ex: any) {
|
|
4
|
+
try {
|
|
5
|
+
const errorDetails = JSON.parse(ex);
|
|
6
|
+
return new SquareException({
|
|
7
|
+
code: errorDetails.code,
|
|
8
|
+
message: errorDetails.message,
|
|
9
|
+
debugCode: errorDetails?.debugCode,
|
|
10
|
+
debugMessage: errorDetails?.debugMessage,
|
|
11
|
+
});
|
|
12
|
+
} catch (parseEx) {
|
|
13
|
+
ex.parseEx = parseEx;
|
|
14
|
+
return ex;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function createMobilePaymentError(ex: any) {
|
|
19
|
+
try {
|
|
20
|
+
const errorDetails = JSON.parse(ex.message);
|
|
21
|
+
return new SquareException({
|
|
22
|
+
code: errorDetails.code,
|
|
23
|
+
message: errorDetails.message,
|
|
24
|
+
debugCode: errorDetails?.debugCode,
|
|
25
|
+
debugMessage: errorDetails?.debugMessage,
|
|
26
|
+
});
|
|
27
|
+
} catch (parseEx) {
|
|
28
|
+
ex.parseEx = parseEx;
|
|
29
|
+
return ex;
|
|
30
|
+
}
|
|
31
|
+
}
|