@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.
Files changed (161) hide show
  1. package/LICENSE +20 -0
  2. package/NativeSquareMobilePaymentSDK.podspec +23 -0
  3. package/README.md +66 -0
  4. package/android/build.gradle +81 -0
  5. package/android/gradle.properties +5 -0
  6. package/android/src/main/AndroidManifest.xml +2 -0
  7. package/android/src/main/java/com/connexup/square/mobilepayment/DateFormatUtils.java +29 -0
  8. package/android/src/main/java/com/connexup/square/mobilepayment/ErrorUtilities.kt +56 -0
  9. package/android/src/main/java/com/connexup/square/mobilepayment/MobilePaymentAuthorization.kt +185 -0
  10. package/android/src/main/java/com/connexup/square/mobilepayment/MobilePaymentException.kt +8 -0
  11. package/android/src/main/java/com/connexup/square/mobilepayment/MobilePaymentPayment.kt +542 -0
  12. package/android/src/main/java/com/connexup/square/mobilepayment/MobilePaymentReader.kt +344 -0
  13. package/android/src/main/java/com/connexup/square/mobilepayment/MobilePaymentSDK.kt +47 -0
  14. package/android/src/main/java/com/connexup/square/mobilepayment/MobilePaymentSDKPackage.kt +77 -0
  15. package/android/src/main/java/com/connexup/square/mobilepayment/MobilePaymentSetting.kt +144 -0
  16. package/android/src/main/java/com/connexup/square/mobilepayment/convert/AdditionalPaymentMethodConvert.kt +46 -0
  17. package/android/src/main/java/com/connexup/square/mobilepayment/convert/AuthorizationStateConvert.kt +26 -0
  18. package/android/src/main/java/com/connexup/square/mobilepayment/convert/CardConvert.kt +53 -0
  19. package/android/src/main/java/com/connexup/square/mobilepayment/convert/CardDetailsConvert.kt +74 -0
  20. package/android/src/main/java/com/connexup/square/mobilepayment/convert/CardEntryMethodConvert.kt +31 -0
  21. package/android/src/main/java/com/connexup/square/mobilepayment/convert/CashPaymentDetailsConvert.kt +18 -0
  22. package/android/src/main/java/com/connexup/square/mobilepayment/convert/CurrencyCodeConvert.kt +204 -0
  23. package/android/src/main/java/com/connexup/square/mobilepayment/convert/DelayActionConvert.kt +33 -0
  24. package/android/src/main/java/com/connexup/square/mobilepayment/convert/DeniedReasonConvert.kt +28 -0
  25. package/android/src/main/java/com/connexup/square/mobilepayment/convert/DigitalWalletDetailsConvert.kt +18 -0
  26. package/android/src/main/java/com/connexup/square/mobilepayment/convert/ErrorDetailsConvert.kt +32 -0
  27. package/android/src/main/java/com/connexup/square/mobilepayment/convert/ExternalPaymentDetailsConvert.kt +25 -0
  28. package/android/src/main/java/com/connexup/square/mobilepayment/convert/LocationConvert.kt +31 -0
  29. package/android/src/main/java/com/connexup/square/mobilepayment/convert/MoneyConvert.kt +31 -0
  30. package/android/src/main/java/com/connexup/square/mobilepayment/convert/OfflineStatusConvert.kt +21 -0
  31. package/android/src/main/java/com/connexup/square/mobilepayment/convert/PaymentConvert.kt +93 -0
  32. package/android/src/main/java/com/connexup/square/mobilepayment/convert/PaymentProcessingFeeConvert.kt +39 -0
  33. package/android/src/main/java/com/connexup/square/mobilepayment/convert/PaymentSettingsConvert.kt +26 -0
  34. package/android/src/main/java/com/connexup/square/mobilepayment/convert/ProcessingModeConvert.kt +28 -0
  35. package/android/src/main/java/com/connexup/square/mobilepayment/convert/ReaderBatteryStatusConvert.kt +19 -0
  36. package/android/src/main/java/com/connexup/square/mobilepayment/convert/ReaderChangeEventConvert.kt +75 -0
  37. package/android/src/main/java/com/connexup/square/mobilepayment/convert/ReaderConnectionTypeConvert.kt +17 -0
  38. package/android/src/main/java/com/connexup/square/mobilepayment/convert/ReaderInfoConvert.kt +51 -0
  39. package/android/src/main/java/com/connexup/square/mobilepayment/convert/ReaderModalConvert.kt +18 -0
  40. package/android/src/main/java/com/connexup/square/mobilepayment/convert/ReaderStateConvert.kt +51 -0
  41. package/android/src/main/java/com/connexup/square/mobilepayment/convert/ReaderStatusConvert.kt +51 -0
  42. package/android/src/main/java/com/connexup/square/mobilepayment/convert/SdkSettingsConvert.kt +30 -0
  43. package/android/src/main/java/com/connexup/square/mobilepayment/convert/SquareAccountDetailsConvert.kt +20 -0
  44. package/android/src/main/java/com/connexup/square/mobilepayment/convert/TrackingConsentStateConvert.kt +17 -0
  45. package/android/src/main/java/com/connexup/square/mobilepayment/convert/WalletBrandConvert.kt +41 -0
  46. package/ios/Converters/AdditionalPaymentMethod+Extension.swift +17 -0
  47. package/ios/Converters/AdditionalPaymentMethodType+Extension.swift +44 -0
  48. package/ios/Converters/AuthorizationState+Extension.swift +22 -0
  49. package/ios/Converters/BatteryLevel+Extension.swift +27 -0
  50. package/ios/Converters/Card+Extension.swift +33 -0
  51. package/ios/Converters/CardBrand+Extension.swift +47 -0
  52. package/ios/Converters/CardCoBrand+Extension.swift +24 -0
  53. package/ios/Converters/CardEntryMethod+Extension.swift +30 -0
  54. package/ios/Converters/CardInputMethods+Extension.swift +35 -0
  55. package/ios/Converters/CardInsertionStatus+Extension.swift +24 -0
  56. package/ios/Converters/CardPaymentDetails+Extensions.swift +31 -0
  57. package/ios/Converters/CardPaymentStatus+Extension.swift +28 -0
  58. package/ios/Converters/Currency+Extension.swift +50 -0
  59. package/ios/Converters/Location+Extension.swift +19 -0
  60. package/ios/Converters/MoneyAmount+Extension.swift +30 -0
  61. package/ios/Converters/Payment+Extension.swift +44 -0
  62. package/ios/Converters/PaymentSettings+Extension.swift +19 -0
  63. package/ios/Converters/PaymentStatus+Extension.swift +53 -0
  64. package/ios/Converters/ProcessingMode+Extension.swift +37 -0
  65. package/ios/Converters/ReaderBatteryStatus+Extension.swift +19 -0
  66. package/ios/Converters/ReaderChange+Extension.swift +41 -0
  67. package/ios/Converters/ReaderConnectionFailureInfo+Extension.swift +20 -0
  68. package/ios/Converters/ReaderConnectionFailureReason+Extension.swift +40 -0
  69. package/ios/Converters/ReaderConnectionFailureRecoverySuggestion+Extension.swift +30 -0
  70. package/ios/Converters/ReaderConnectionInfo+Extension.swift +18 -0
  71. package/ios/Converters/ReaderConnectionStatus+Extension.swift +26 -0
  72. package/ios/Converters/ReaderFirmwareInfo+Extension.swift +19 -0
  73. package/ios/Converters/ReaderInfo+Extension.swift +30 -0
  74. package/ios/Converters/ReaderModel+Extension.swift +28 -0
  75. package/ios/Converters/ReaderState+Extension.swift +30 -0
  76. package/ios/Converters/ReaderStatus+Extension.swift +60 -0
  77. package/ios/Converters/ReaderStatusInfo+Extension.swift +22 -0
  78. package/ios/Converters/SDKSettings+Extension.swift +25 -0
  79. package/ios/Converters/SourceType+Extension.swift +32 -0
  80. package/ios/Converters/TrackingConsentState+Extension.swift +25 -0
  81. package/ios/ErrorUtilities.swift +41 -0
  82. package/ios/MobilePaymentAuthorization.swift +154 -0
  83. package/ios/MobilePaymentDateFormatter.swift +15 -0
  84. package/ios/MobilePaymentPayment.swift +478 -0
  85. package/ios/MobilePaymentReader.swift +248 -0
  86. package/ios/MobilePaymentSDK.swift +36 -0
  87. package/ios/MobilePaymentSetting.swift +86 -0
  88. package/ios/MockReaderUIManage.swift +52 -0
  89. package/ios/Models/NativeErrorInfo.swift +22 -0
  90. package/ios/Models/RCTPaymentMoneyParameter.swift +20 -0
  91. package/ios/Models/RCTPaymentParameters.swift +50 -0
  92. package/ios/Models/RCTPromptParameters.swift +20 -0
  93. package/ios/NotificationKeys.swift +9 -0
  94. package/ios/NotificationUtils.swift +21 -0
  95. package/ios/RCTMobilePaymentAuthorization.h +12 -0
  96. package/ios/RCTMobilePaymentAuthorization.mm +78 -0
  97. package/ios/RCTMobilePaymentPayment.h +12 -0
  98. package/ios/RCTMobilePaymentPayment.mm +116 -0
  99. package/ios/RCTMobilePaymentReader.h +12 -0
  100. package/ios/RCTMobilePaymentReader.mm +114 -0
  101. package/ios/RCTMobilePaymentSetting.h +10 -0
  102. package/ios/RCTMobilePaymentSetting.mm +94 -0
  103. package/ios/UIColor+Extension.swift +81 -0
  104. package/lib/module/authorization/NativeMobilePaymentAuthorization.js +60 -0
  105. package/lib/module/authorization/NativeMobilePaymentAuthorization.js.map +1 -0
  106. package/lib/module/authorization/index.js +44 -0
  107. package/lib/module/authorization/index.js.map +1 -0
  108. package/lib/module/index.js +7 -0
  109. package/lib/module/index.js.map +1 -0
  110. package/lib/module/package.json +1 -0
  111. package/lib/module/payment/NativeMobilePaymentPayment.js +138 -0
  112. package/lib/module/payment/NativeMobilePaymentPayment.js.map +1 -0
  113. package/lib/module/payment/index.js +113 -0
  114. package/lib/module/payment/index.js.map +1 -0
  115. package/lib/module/reader/NativeMobilePaymentReader.js +151 -0
  116. package/lib/module/reader/NativeMobilePaymentReader.js.map +1 -0
  117. package/lib/module/reader/index.js +109 -0
  118. package/lib/module/reader/index.js.map +1 -0
  119. package/lib/module/setting/NativeMobilePaymentSetting.js +5 -0
  120. package/lib/module/setting/NativeMobilePaymentSetting.js.map +1 -0
  121. package/lib/module/setting/index.js +74 -0
  122. package/lib/module/setting/index.js.map +1 -0
  123. package/lib/module/type.js +27 -0
  124. package/lib/module/type.js.map +1 -0
  125. package/lib/module/util.js +32 -0
  126. package/lib/module/util.js.map +1 -0
  127. package/lib/typescript/package.json +1 -0
  128. package/lib/typescript/src/authorization/NativeMobilePaymentAuthorization.d.ts +82 -0
  129. package/lib/typescript/src/authorization/NativeMobilePaymentAuthorization.d.ts.map +1 -0
  130. package/lib/typescript/src/authorization/index.d.ts +14 -0
  131. package/lib/typescript/src/authorization/index.d.ts.map +1 -0
  132. package/lib/typescript/src/index.d.ts +5 -0
  133. package/lib/typescript/src/index.d.ts.map +1 -0
  134. package/lib/typescript/src/payment/NativeMobilePaymentPayment.d.ts +725 -0
  135. package/lib/typescript/src/payment/NativeMobilePaymentPayment.d.ts.map +1 -0
  136. package/lib/typescript/src/payment/index.d.ts +13 -0
  137. package/lib/typescript/src/payment/index.d.ts.map +1 -0
  138. package/lib/typescript/src/reader/NativeMobilePaymentReader.d.ts +318 -0
  139. package/lib/typescript/src/reader/NativeMobilePaymentReader.d.ts.map +1 -0
  140. package/lib/typescript/src/reader/index.d.ts +19 -0
  141. package/lib/typescript/src/reader/index.d.ts.map +1 -0
  142. package/lib/typescript/src/setting/NativeMobilePaymentSetting.d.ts +49 -0
  143. package/lib/typescript/src/setting/NativeMobilePaymentSetting.d.ts.map +1 -0
  144. package/lib/typescript/src/setting/index.d.ts +17 -0
  145. package/lib/typescript/src/setting/index.d.ts.map +1 -0
  146. package/lib/typescript/src/type.d.ts +23 -0
  147. package/lib/typescript/src/type.d.ts.map +1 -0
  148. package/lib/typescript/src/util.d.ts +3 -0
  149. package/lib/typescript/src/util.d.ts.map +1 -0
  150. package/package.json +178 -0
  151. package/src/authorization/NativeMobilePaymentAuthorization.ts +297 -0
  152. package/src/authorization/index.ts +60 -0
  153. package/src/index.ts +4 -0
  154. package/src/payment/NativeMobilePaymentPayment.ts +1220 -0
  155. package/src/payment/index.ts +161 -0
  156. package/src/reader/NativeMobilePaymentReader.ts +463 -0
  157. package/src/reader/index.ts +140 -0
  158. package/src/setting/NativeMobilePaymentSetting.ts +254 -0
  159. package/src/setting/index.ts +91 -0
  160. package/src/type.ts +35 -0
  161. package/src/util.ts +31 -0
package/package.json ADDED
@@ -0,0 +1,178 @@
1
+ {
2
+ "name": "@connexup/react-native-square-mobile-payment-sdk",
3
+ "version": "0.1.0",
4
+ "description": "Mobile Payments SDK for React Native",
5
+ "main": "./lib/module/index.js",
6
+ "types": "./lib/typescript/src/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "source": "./src/index.ts",
10
+ "types": "./lib/typescript/src/index.d.ts",
11
+ "default": "./lib/module/index.js"
12
+ },
13
+ "./package.json": "./package.json"
14
+ },
15
+ "files": [
16
+ "src",
17
+ "lib",
18
+ "android",
19
+ "ios",
20
+ "cpp",
21
+ "*.podspec",
22
+ "react-native.config.js",
23
+ "!ios/build",
24
+ "!android/build",
25
+ "!android/gradle",
26
+ "!android/gradlew",
27
+ "!android/gradlew.bat",
28
+ "!android/local.properties",
29
+ "!**/__tests__",
30
+ "!**/__fixtures__",
31
+ "!**/__mocks__",
32
+ "!**/.*"
33
+ ],
34
+ "scripts": {
35
+ "example": "yarn workspace react-native-square-mobile-payment-sdk-example",
36
+ "clean": "del-cli android/build example/android/build example/android/app/build example/ios/build lib",
37
+ "prepare": "bob build",
38
+ "typecheck": "tsc",
39
+ "lint": "eslint \"**/*.{js,ts,tsx}\"",
40
+ "test": "jest",
41
+ "release": "release-it --only-version"
42
+ },
43
+ "keywords": [
44
+ "react-native",
45
+ "ios",
46
+ "android"
47
+ ],
48
+ "repository": {
49
+ "type": "git",
50
+ "url": "git+https://github.com/chancetop-com/fbr-react-native-square-mobile-payment-sdk.git"
51
+ },
52
+ "author": "Luke Chen <lukechen@chancetop.com> (https://www.npmjs.com/~lukechen_ct)",
53
+ "license": "MIT",
54
+ "bugs": {
55
+ "url": "https://github.com/chancetop-com/fbr-react-native-square-mobile-payment-sdk/issues"
56
+ },
57
+ "homepage": "https://github.com/chancetop-com/fbr-react-native-square-mobile-payment-sdk#readme",
58
+ "publishConfig": {
59
+ "registry": "https://registry.npmjs.org/",
60
+ "access": "public"
61
+ },
62
+ "devDependencies": {
63
+ "@commitlint/config-conventional": "^19.8.1",
64
+ "@eslint/compat": "^1.3.2",
65
+ "@eslint/eslintrc": "^3.3.1",
66
+ "@eslint/js": "^9.35.0",
67
+ "@react-native/babel-preset": "0.83.0",
68
+ "@react-native/eslint-config": "0.83.0",
69
+ "@release-it/conventional-changelog": "^10.0.1",
70
+ "@types/jest": "^29.5.14",
71
+ "@types/react": "^19.2.0",
72
+ "commitlint": "^19.8.1",
73
+ "del-cli": "^6.0.0",
74
+ "eslint": "^9.35.0",
75
+ "eslint-config-prettier": "^10.1.8",
76
+ "eslint-plugin-prettier": "^5.5.4",
77
+ "jest": "^29.7.0",
78
+ "lefthook": "^2.0.3",
79
+ "prettier": "^2.8.8",
80
+ "react": "19.2.0",
81
+ "react-native": "0.83.0",
82
+ "react-native-builder-bob": "^0.40.13",
83
+ "release-it": "^19.0.4",
84
+ "turbo": "^2.5.6",
85
+ "typescript": "^5.9.2"
86
+ },
87
+ "peerDependencies": {
88
+ "react": "*",
89
+ "react-native": "*"
90
+ },
91
+ "workspaces": [
92
+ "example"
93
+ ],
94
+ "packageManager": "yarn@4.11.0",
95
+ "react-native-builder-bob": {
96
+ "source": "src",
97
+ "output": "lib",
98
+ "targets": [
99
+ [
100
+ "module",
101
+ {
102
+ "esm": true
103
+ }
104
+ ],
105
+ [
106
+ "typescript",
107
+ {
108
+ "project": "tsconfig.build.json"
109
+ }
110
+ ]
111
+ ]
112
+ },
113
+ "codegenConfig": {
114
+ "name": "NativeSquareMobilePaymentSDKSpec",
115
+ "type": "modules",
116
+ "jsSrcsDir": "src",
117
+ "android": {
118
+ "javaPackageName": "com.connexup.square.mobilepayment"
119
+ },
120
+ "ios": {
121
+ "modulesProvider": {
122
+ "NativeMobilePaymentAuthorization": "RCTMobilePaymentAuthorization",
123
+ "NativeMobilePaymentSetting": "RCTMobilePaymentSetting",
124
+ "NativeMobilePaymentReader": "RCTMobilePaymentReader",
125
+ "NativeMobilePaymentPayment": "RCTMobilePaymentPayment"
126
+ }
127
+ }
128
+ },
129
+ "prettier": {
130
+ "quoteProps": "consistent",
131
+ "singleQuote": true,
132
+ "tabWidth": 2,
133
+ "trailingComma": "es5",
134
+ "useTabs": false
135
+ },
136
+ "jest": {
137
+ "preset": "react-native",
138
+ "modulePathIgnorePatterns": [
139
+ "<rootDir>/example/node_modules",
140
+ "<rootDir>/lib/"
141
+ ]
142
+ },
143
+ "commitlint": {
144
+ "extends": [
145
+ "@commitlint/config-conventional"
146
+ ]
147
+ },
148
+ "release-it": {
149
+ "git": {
150
+ "commitMessage": "chore: release ${version}",
151
+ "tagName": "v${version}"
152
+ },
153
+ "npm": {
154
+ "publish": true
155
+ },
156
+ "github": {
157
+ "release": true
158
+ },
159
+ "plugins": {
160
+ "@release-it/conventional-changelog": {
161
+ "preset": {
162
+ "name": "angular"
163
+ }
164
+ }
165
+ }
166
+ },
167
+ "create-react-native-library": {
168
+ "type": "turbo-module",
169
+ "languages": "kotlin-objc",
170
+ "tools": [
171
+ "eslint",
172
+ "jest",
173
+ "lefthook",
174
+ "release-it"
175
+ ],
176
+ "version": "0.57.0"
177
+ }
178
+ }
@@ -0,0 +1,297 @@
1
+ import {
2
+ type CodegenTypes,
3
+ type TurboModule,
4
+ TurboModuleRegistry,
5
+ } from 'react-native';
6
+
7
+ export interface Spec extends TurboModule {
8
+ /**
9
+ * accessToken A Square access token
10
+ * ● An OAuth access token. See the OAuth API documentation (https://developer.squareup.com/docs/oauth-api/how-it-works) for instructions on how to get an access token.
11
+ * ● When requesting an OAuth access token, you will need to ask for the following permissions:
12
+ * ○ MERCHANT_PROFILE_READ is required get a list of all a merchant’s locations
13
+ * ○ PAYMENTS_WRITE and PAYMENTS_WRITE_IN_PERSON are required to take payments in ReaderSDK
14
+ * ○ PAYMENTS_WRITE_ADDITIONAL_RECIPIENTS is required to collect application fees (optional)
15
+ */
16
+ authorize(accessToken: string, locationID: string): Promise<void>;
17
+
18
+ deauthorize(): Promise<void>;
19
+
20
+ state(): AuthorizationState;
21
+
22
+ location(): Location | null;
23
+
24
+ readonly onAuthorizationStateChange: CodegenTypes.EventEmitter<AuthorizationState>;
25
+ }
26
+
27
+ export const NativeMobilePaymentAuthorization =
28
+ TurboModuleRegistry.getEnforcing<Spec>('NativeMobilePaymentAuthorization');
29
+
30
+ export type AuthorizationState =
31
+ | 'NOT_AUTHORIZED'
32
+ | 'AUTHORIZING'
33
+ | 'AUTHORIZED'
34
+ | 'UNKNOWN';
35
+
36
+ export interface Location {
37
+ id: string;
38
+ name: string;
39
+ mcc?: string; //only iOS
40
+ currency: Currency;
41
+ merchantId?: string; //only android
42
+ nickName?: string; //only android
43
+ cardProcessingActivated?: boolean; //only android
44
+ }
45
+
46
+ export type Currency =
47
+ | 'AUD'
48
+ | 'CAD'
49
+ | 'EUR'
50
+ | 'GBP'
51
+ | 'JPY'
52
+ | 'USD'
53
+ | 'AED'
54
+ | 'AFN'
55
+ | 'ALL'
56
+ | 'AMD'
57
+ | 'ANG'
58
+ | 'AOA'
59
+ | 'ARS'
60
+ | 'AWG'
61
+ | 'AZN'
62
+ | 'BAM'
63
+ | 'BBD'
64
+ | 'BDT'
65
+ | 'BGN'
66
+ | 'BHD'
67
+ | 'BIF'
68
+ | 'BMD'
69
+ | 'BND'
70
+ | 'BOB'
71
+ | 'BOV'
72
+ | 'BRL'
73
+ | 'BSD'
74
+ | 'BTN'
75
+ | 'BWP'
76
+ | 'BYR'
77
+ | 'BZD'
78
+ | 'CDF'
79
+ | 'CHE'
80
+ | 'CHF'
81
+ | 'CHW'
82
+ | 'CLF'
83
+ | 'CLP'
84
+ | 'CNY'
85
+ | 'COP'
86
+ | 'COU'
87
+ | 'CRC'
88
+ | 'CUC'
89
+ | 'CUP'
90
+ | 'CVE'
91
+ | 'CZK'
92
+ | 'DJF'
93
+ | 'DKK'
94
+ | 'DOP'
95
+ | 'DZD'
96
+ | 'EGP'
97
+ | 'ERN'
98
+ | 'ETB'
99
+ | 'FJD'
100
+ | 'FKP'
101
+ | 'GEL'
102
+ | 'GHS'
103
+ | 'GIP'
104
+ | 'GMD'
105
+ | 'GNF'
106
+ | 'GTQ'
107
+ | 'GYD'
108
+ | 'HKD'
109
+ | 'HNL'
110
+ | 'HRK'
111
+ | 'HTG'
112
+ | 'HUF'
113
+ | 'IDR'
114
+ | 'ILS'
115
+ | 'INR'
116
+ | 'IQD'
117
+ | 'IRR'
118
+ | 'ISK'
119
+ | 'JMD'
120
+ | 'JOD'
121
+ | 'KES'
122
+ | 'KGS'
123
+ | 'KHR'
124
+ | 'KMF'
125
+ | 'KPW'
126
+ | 'KRW'
127
+ | 'KWD'
128
+ | 'KYD'
129
+ | 'KZT'
130
+ | 'LAK'
131
+ | 'LBP'
132
+ | 'LKR'
133
+ | 'LRD'
134
+ | 'LSL'
135
+ | 'LTL'
136
+ | 'LVL'
137
+ | 'LYD'
138
+ | 'MAD'
139
+ | 'MDL'
140
+ | 'MGA'
141
+ | 'MKD'
142
+ | 'MMK'
143
+ | 'MNT'
144
+ | 'MOP'
145
+ | 'MRO'
146
+ | 'MUR'
147
+ | 'MVR'
148
+ | 'MWK'
149
+ | 'MXN'
150
+ | 'MXV'
151
+ | 'MYR'
152
+ | 'MZN'
153
+ | 'NAD'
154
+ | 'NGN'
155
+ | 'NIO'
156
+ | 'NOK'
157
+ | 'NPR'
158
+ | 'NZD'
159
+ | 'OMR'
160
+ | 'PAB'
161
+ | 'PEN'
162
+ | 'PGK'
163
+ | 'PHP'
164
+ | 'PKR'
165
+ | 'PLN'
166
+ | 'PYG'
167
+ | 'QAR'
168
+ | 'RON'
169
+ | 'RSD'
170
+ | 'RUB'
171
+ | 'RWF'
172
+ | 'SAR'
173
+ | 'SBD'
174
+ | 'SCR'
175
+ | 'SDG'
176
+ | 'SEK'
177
+ | 'SGD'
178
+ | 'SHP'
179
+ | 'SLL'
180
+ | 'SOS'
181
+ | 'SRD'
182
+ | 'SSP'
183
+ | 'STD'
184
+ | 'SVC'
185
+ | 'SYP'
186
+ | 'SZL'
187
+ | 'THB'
188
+ | 'TJS'
189
+ | 'TMT'
190
+ | 'TND'
191
+ | 'TOP'
192
+ | 'TRY'
193
+ | 'TTD'
194
+ | 'TWD'
195
+ | 'TZS'
196
+ | 'UAH'
197
+ | 'UGX'
198
+ | 'USN'
199
+ | 'USS'
200
+ | 'UYI'
201
+ | 'UYU'
202
+ | 'UZS'
203
+ | 'VEF'
204
+ | 'VND'
205
+ | 'VUV'
206
+ | 'WST'
207
+ | 'XAF'
208
+ | 'XAG'
209
+ | 'XAU'
210
+ | 'XBA'
211
+ | 'XBB'
212
+ | 'XBC'
213
+ | 'XBD'
214
+ | 'XCD'
215
+ | 'XDR'
216
+ | 'XOF'
217
+ | 'XPD'
218
+ | 'XPF'
219
+ | 'XPT'
220
+ | 'XTS'
221
+ | 'XXX'
222
+ | 'YER'
223
+ | 'ZAR'
224
+ | 'ZMK'
225
+ | 'ZMW'
226
+ | 'BTC'
227
+ | 'XUS'
228
+ | 'SLE'
229
+ | 'UNKNOWN';
230
+
231
+ export const AuthorizationErrorNoNetwork = 'AUTHORIZATION_ERROR_NO_NETWORK';
232
+ /**
233
+ * Device is already authorized with a Square account.
234
+ */
235
+ export const AuthorizationErrorAlreadyAuthorized =
236
+ 'AUTHORIZATION_ERROR_ALREADY_AUTHORIZED';
237
+ /**
238
+ * An unexpected error occurred. See the debug code and message for more information.
239
+ */
240
+ export const AuthorizationErrorAlreadyInProgress =
241
+ 'AUTHORIZATION_ERROR_ALREADY_IN_PROGRESS';
242
+
243
+ /**
244
+ * Authorization code has already been redeemed.
245
+ */
246
+ export const AuthorizationErrorAuthorizationCodeAlreadyRedeemed =
247
+ 'AUTHORIZATION_ERROR_AUTHORIZATION_CODE_ALREADY_REDEEMED';
248
+
249
+ /**
250
+ * Authorization code has expired.
251
+ */
252
+ export const AuthorizationErrorExpiredAuthorizationCode =
253
+ 'AUTHORIZATION_ERROR_EXPIRED_AUTHORIZATION_CODE';
254
+ /**
255
+ * Authorization code is invalid.
256
+ */
257
+ export const AuthorizationErrorInvalidAuthorizationCode =
258
+ 'AUTHORIZATION_ERROR_INVALID_AUTHORIZATION_CODE';
259
+ /**
260
+ * Access token is invalid.
261
+ */
262
+ export const AuthorizationErrorInvalidAccessToken =
263
+ 'AUTHORIZATION_ERROR_INVALID_ACCESS_TOKEN';
264
+ /**
265
+ * Access code is empty.
266
+ */
267
+ export const AuthorizationErrorEmptyAccessToken =
268
+ 'AUTHORIZATION_ERROR_EMPTY_ACCESS_TOKEN';
269
+ /**
270
+ * LocationID is invalid.
271
+ */
272
+ export const AuthorizationErrorInvalidLocationID =
273
+ 'AUTHORIZATION_ERROR_INVALID_LOCATION_ID';
274
+ /**
275
+ * Location is not authorized for card processing
276
+ */
277
+ export const AuthorizationErrorLocationNotActivatedForCardProcessing =
278
+ 'AUTHORIZATION_ERROR_LOCATION_NOT_ACTIVATED_FOR_CARD_PROCESSING';
279
+ /**
280
+ * LocationID is empty.
281
+ */
282
+ export const AuthorizationErrorEmptyLocationID =
283
+ 'AUTHORIZATION_ERROR_EMPTY_LOCATION_ID';
284
+ /**
285
+ * Country is not supported
286
+ */
287
+ export const AuthorizationErrorUnsupportedCountry =
288
+ 'AUTHORIZATION_ERROR_UNSUPPORTED_COUNTRY';
289
+ /**
290
+ * There is a discrepancy between the device time and the server time.
291
+ */
292
+ export const AuthorizationErrorDeviceTimeDoesNotMatchServerTime =
293
+ 'AUTHORIZATION_ERROR_DEVICE_TIME_DOES_NOT_MATCH_SERVER_TIME';
294
+ /**
295
+ * Unexpected authorization error.
296
+ */
297
+ export const AuthorizationErrorUnexpected = 'AUTHORIZATION_ERROR_UNEXPECTED';
@@ -0,0 +1,60 @@
1
+ import { createMobilePaymentError } from '../util';
2
+ import {
3
+ NativeMobilePaymentAuthorization,
4
+ type AuthorizationState,
5
+ type Location,
6
+ type Spec,
7
+ } from './NativeMobilePaymentAuthorization';
8
+ import type { EventSubscription } from 'react-native';
9
+
10
+ class MobilePaymentAuthorization implements Omit<Spec, 'getConstants'> {
11
+ private readonly authorizationManage: Spec;
12
+
13
+ constructor(authorizationManage: Spec) {
14
+ this.authorizationManage = authorizationManage;
15
+ }
16
+
17
+ state(): AuthorizationState {
18
+ try {
19
+ return this.authorizationManage.state();
20
+ } catch (e) {
21
+ throw createMobilePaymentError(e);
22
+ }
23
+ }
24
+
25
+ async authorize(accessToken: string, locationID: string): Promise<void> {
26
+ try {
27
+ return await this.authorizationManage.authorize(accessToken, locationID);
28
+ } catch (e) {
29
+ throw createMobilePaymentError(e);
30
+ }
31
+ }
32
+
33
+ location(): Location | null {
34
+ try {
35
+ return this.authorizationManage.location();
36
+ } catch (e) {
37
+ throw createMobilePaymentError(e);
38
+ }
39
+ }
40
+
41
+ async deauthorize(): Promise<void> {
42
+ try {
43
+ return await this.authorizationManage.deauthorize();
44
+ } catch (e) {
45
+ throw createMobilePaymentError(e);
46
+ }
47
+ }
48
+
49
+ onAuthorizationStateChange(
50
+ listener: (state: AuthorizationState) => void
51
+ ): EventSubscription {
52
+ return this.authorizationManage.onAuthorizationStateChange((payloads) => {
53
+ listener(payloads);
54
+ });
55
+ }
56
+ }
57
+
58
+ export const mobilePaymentAuthorization = new MobilePaymentAuthorization(
59
+ NativeMobilePaymentAuthorization
60
+ );
package/src/index.ts ADDED
@@ -0,0 +1,4 @@
1
+ export { mobilePaymentAuthorization as MobilePaymentAuthorization } from './authorization';
2
+ export { mobilePaymentReader as MobilePaymentReader } from './reader';
3
+ export { mobilePaymentPayment as MobilePaymentPayment } from './payment';
4
+ export { mobilePaymentSetting as MobilePaymentSetting } from './setting';