@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
package/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Connexup
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
in the Software without restriction, including without limitation the rights
|
|
7
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
furnished to do so, subject to the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
SOFTWARE.
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
require "json"
|
|
2
|
+
|
|
3
|
+
package = JSON.parse(File.read(File.join(__dir__, "package.json")))
|
|
4
|
+
|
|
5
|
+
Pod::Spec.new do |s|
|
|
6
|
+
s.name = "NativeSquareMobilePaymentSDK"
|
|
7
|
+
s.version = package["version"]
|
|
8
|
+
s.summary = package["description"]
|
|
9
|
+
s.homepage = package["homepage"]
|
|
10
|
+
s.license = package["license"]
|
|
11
|
+
s.authors = package["author"]
|
|
12
|
+
|
|
13
|
+
s.platforms = { :ios => [min_ios_version_supported, "16.0"].max }
|
|
14
|
+
s.source = { :git => package["repository"]["url"], :tag => "#{s.version}" }
|
|
15
|
+
|
|
16
|
+
s.dependency "MockReaderUI", "~> 2.3.1"
|
|
17
|
+
s.dependency "SquareMobilePaymentsSDK", "~> 2.3.1"
|
|
18
|
+
|
|
19
|
+
s.source_files = "ios/**/*.{h,m,mm,swift,cpp}"
|
|
20
|
+
s.private_header_files = "ios/**/*.h"
|
|
21
|
+
|
|
22
|
+
install_modules_dependencies(s)
|
|
23
|
+
end
|
package/README.md
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# react-native-square-mobile-payment-sdk
|
|
2
|
+
|
|
3
|
+
Mobile Payments SDK for React Native
|
|
4
|
+
|
|
5
|
+
* [iOS](https://developer.squareup.com/docs/mobile-payments-sdk/ios#1-install-the-sdk-and-dependencies)
|
|
6
|
+
* [Android](https://developer.squareup.com/docs/mobile-payments-sdk/android#1-install-the-sdk-and-dependencies)
|
|
7
|
+
|
|
8
|
+
## Review requirements
|
|
9
|
+
Before getting started, please review the Requirements and Limitations and Device Compatibility sections to ensure that the SDK can be used in your project:
|
|
10
|
+
* Android: [Requirements and Limitations](https://developer.squareup.com/docs/mobile-payments-sdk/android#requirements-and-limitations), [Device Compatibility](https://developer.squareup.com/docs/mobile-payments-sdk/android#device-permissions)
|
|
11
|
+
* iOS: [Requirements and Limitations](https://developer.squareup.com/docs/mobile-payments-sdk/ios#requirements-and-limitations), [Device Compatibility](https://developer.squareup.com/docs/mobile-payments-sdk/ios#device-permissions)
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
```sh
|
|
15
|
+
yarn add react-native-square-mobile-payment-sdk
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Before you start
|
|
19
|
+
* You will need a Square account enabled for payment processing. If you have not enabled payment processing on your account (or you are not sure), visit [squareup.com/activate](https://squareup.com/activate).
|
|
20
|
+
* Set-up your React Native environment by following the [official guide](https://reactnative.dev/docs/set-up-your-environment).
|
|
21
|
+
|
|
22
|
+
For iOS:
|
|
23
|
+
1. Make sure you run `pod install` in the `ios` folder of the sample application to install the SDK and all the dependencies.
|
|
24
|
+
2. On your application targets’ `Build Phases` settings tab, click the + icon and choose `New Run Script Phase`. Create a Run Script in which you specify your shell (ex: /bin/sh), and add the following contents to the script area below the shell:
|
|
25
|
+
```
|
|
26
|
+
SETUP_SCRIPT=${BUILT_PRODUCTS_DIR}/${FRAMEWORKS_FOLDER_PATH}"/SquareMobilePaymentsSDK.framework/setup"
|
|
27
|
+
if [ -f "$SETUP_SCRIPT" ]; then
|
|
28
|
+
"$SETUP_SCRIPT"
|
|
29
|
+
fi
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Make sure this build phase is after any `[CP] Embed Pods Frameworks` or `Embed Frameworks` Build Phase.
|
|
33
|
+
|
|
34
|
+
For Android:
|
|
35
|
+
1. Modify your `/android/build.gradle`
|
|
36
|
+
Add `maven { url 'https://sdk.squareup.com/public/android/' }` inside the `allprojects`'s `repositories {...}` block
|
|
37
|
+
2. Disable Proguard by adding the following to your `/android/app/build.gradle`:
|
|
38
|
+
```gradle
|
|
39
|
+
android {
|
|
40
|
+
buildTypes {
|
|
41
|
+
release {
|
|
42
|
+
minifyEnabled false
|
|
43
|
+
shrinkResources false
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Documentation
|
|
50
|
+
* [Mobile Payments SDK Overview](https://developer.squareup.com/docs/mobile-payments-sdk)
|
|
51
|
+
* [iOS Tech Reference](https://developer.squareup.com/docs/sdk/mobile-payments/ios)
|
|
52
|
+
* [Android Tech Reference](https://developer.squareup.com/docs/sdk/mobile-payments/android)
|
|
53
|
+
|
|
54
|
+
## Contributing
|
|
55
|
+
|
|
56
|
+
- [Development workflow](CONTRIBUTING.md#development-workflow)
|
|
57
|
+
- [Sending a pull request](CONTRIBUTING.md#sending-a-pull-request)
|
|
58
|
+
- [Code of conduct](CODE_OF_CONDUCT.md)
|
|
59
|
+
|
|
60
|
+
## License
|
|
61
|
+
|
|
62
|
+
MIT
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
Made with [create-react-native-library](https://github.com/callstack/react-native-builder-bob)
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
buildscript {
|
|
2
|
+
ext.getExtOrDefault = {name ->
|
|
3
|
+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['NativeSquareMobilePaymentSDK_' + name]
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
repositories {
|
|
7
|
+
google()
|
|
8
|
+
mavenCentral()
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
dependencies {
|
|
12
|
+
classpath "com.android.tools.build:gradle:8.7.2"
|
|
13
|
+
// noinspection DifferentKotlinGradleVersion
|
|
14
|
+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${getExtOrDefault('kotlinVersion')}"
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
apply plugin: "com.android.library"
|
|
20
|
+
apply plugin: "kotlin-android"
|
|
21
|
+
|
|
22
|
+
apply plugin: "com.facebook.react"
|
|
23
|
+
|
|
24
|
+
def getExtOrIntegerDefault(name) {
|
|
25
|
+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["NativeSquareMobilePaymentSDK_" + name]).toInteger()
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
android {
|
|
29
|
+
namespace "com.connexup.square.mobilepayment"
|
|
30
|
+
|
|
31
|
+
compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
|
|
32
|
+
|
|
33
|
+
defaultConfig {
|
|
34
|
+
minSdkVersion getExtOrIntegerDefault("minSdkVersion")
|
|
35
|
+
targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
buildFeatures {
|
|
39
|
+
buildConfig true
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
buildTypes {
|
|
43
|
+
release {
|
|
44
|
+
minifyEnabled false
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
lint {
|
|
49
|
+
disable "GradleCompatible"
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
compileOptions {
|
|
53
|
+
sourceCompatibility JavaVersion.VERSION_1_8
|
|
54
|
+
targetCompatibility JavaVersion.VERSION_1_8
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
sourceSets {
|
|
58
|
+
main {
|
|
59
|
+
java.srcDirs += [
|
|
60
|
+
"generated/java",
|
|
61
|
+
"generated/jni"
|
|
62
|
+
]
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
repositories {
|
|
68
|
+
mavenCentral()
|
|
69
|
+
google()
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
def kotlin_version = getExtOrDefault("kotlinVersion")
|
|
73
|
+
|
|
74
|
+
dependencies {
|
|
75
|
+
implementation "com.facebook.react:react-android"
|
|
76
|
+
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
77
|
+
implementation 'com.google.code.gson:gson:2.8.5'
|
|
78
|
+
def squareSdkVersion = "2.3.4"
|
|
79
|
+
implementation "com.squareup.sdk:mobile-payments-sdk:$squareSdkVersion"
|
|
80
|
+
implementation "com.squareup.sdk:mockreader-ui:$squareSdkVersion"
|
|
81
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
package com.connexup.square.mobilepayment;
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Description:
|
|
5
|
+
*
|
|
6
|
+
* @author lukechen@chancetop.com
|
|
7
|
+
* @date 2023/11/20
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import java.text.DateFormat;
|
|
11
|
+
import java.text.SimpleDateFormat;
|
|
12
|
+
import java.util.Date;
|
|
13
|
+
|
|
14
|
+
public class DateFormatUtils {
|
|
15
|
+
|
|
16
|
+
private static final ThreadLocal<DateFormat> ISO_8601 = new ThreadLocal<DateFormat>() {
|
|
17
|
+
@Override
|
|
18
|
+
protected DateFormat initialValue() {
|
|
19
|
+
return new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
public static String formatISO8601UTC(Date date) {
|
|
24
|
+
if (date == null) {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
return ISO_8601.get().format(date);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
package com.connexup.square.mobilepayment
|
|
2
|
+
|
|
3
|
+
import com.google.gson.GsonBuilder
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Description:
|
|
7
|
+
* @author lukechen@chancetop.com
|
|
8
|
+
* @date 2023/11/16
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
private const val JSON_PLACE_HOLDER = "{'message': 'failed to serialize error'}"
|
|
12
|
+
|
|
13
|
+
const val UNKNOWN_ERROR = "UNKNOWN_ERROR"
|
|
14
|
+
const val PARAMS_ERROR = "PARAMS_ERROR"
|
|
15
|
+
|
|
16
|
+
object RNMobilePaymentErrorUtilities {
|
|
17
|
+
|
|
18
|
+
private val gson by lazy {
|
|
19
|
+
GsonBuilder().create()
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
fun createNativeModuleError(
|
|
23
|
+
code: String?,
|
|
24
|
+
message: String = String.format(
|
|
25
|
+
"Something went wrong. Please contact the developer of this application and provide them with this error code: %s",
|
|
26
|
+
code
|
|
27
|
+
),
|
|
28
|
+
debugCode: String? = null,
|
|
29
|
+
debugMessage: String? = null
|
|
30
|
+
): String? {
|
|
31
|
+
return serializeErrorToJson(
|
|
32
|
+
code,
|
|
33
|
+
message,
|
|
34
|
+
debugCode,
|
|
35
|
+
debugMessage,
|
|
36
|
+
)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
fun serializeErrorToJson(
|
|
40
|
+
code: String?,
|
|
41
|
+
message: String?,
|
|
42
|
+
debugCode: String? = null,
|
|
43
|
+
debugMessage: String? = null
|
|
44
|
+
): String? {
|
|
45
|
+
val errorMap = hashMapOf<String, String?>()
|
|
46
|
+
errorMap["code"] = code
|
|
47
|
+
errorMap["message"] = message
|
|
48
|
+
errorMap["debugCode"] = debugCode
|
|
49
|
+
errorMap["debugMessage"] = debugMessage
|
|
50
|
+
return try {
|
|
51
|
+
gson.toJson(errorMap) ?: JSON_PLACE_HOLDER
|
|
52
|
+
} catch (e: MobilePaymentException) {
|
|
53
|
+
JSON_PLACE_HOLDER
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
package com.connexup.square.mobilepayment
|
|
2
|
+
|
|
3
|
+
import com.connexup.square.mobilepayment.convert.jsonValue
|
|
4
|
+
import com.connexup.square.mobilepayment.convert.writableMap
|
|
5
|
+
import com.facebook.react.bridge.Promise
|
|
6
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
7
|
+
import com.facebook.react.bridge.WritableMap
|
|
8
|
+
import com.squareup.sdk.mobilepayments.MobilePaymentsSdk
|
|
9
|
+
import com.squareup.sdk.mobilepayments.authorization.AuthorizationState
|
|
10
|
+
import com.squareup.sdk.mobilepayments.authorization.AuthorizeErrorCode
|
|
11
|
+
import com.squareup.sdk.mobilepayments.core.CallbackReference
|
|
12
|
+
import com.squareup.sdk.mobilepayments.core.Result
|
|
13
|
+
import kotlinx.coroutines.CoroutineScope
|
|
14
|
+
import kotlinx.coroutines.Dispatchers
|
|
15
|
+
import kotlinx.coroutines.SupervisorJob
|
|
16
|
+
import kotlinx.coroutines.launch
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Description:
|
|
20
|
+
* @author lukechen@chancetop.com
|
|
21
|
+
* @date 2026/1/30
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
private const val AUTHORIZATION_ERROR_NO_NETWORK = "AUTHORIZATION_ERROR_NO_NETWORK"
|
|
25
|
+
private const val AUTHORIZATION_ERROR_ALREADY_AUTHORIZED = "AUTHORIZATION_ERROR_ALREADY_AUTHORIZED"
|
|
26
|
+
private const val AUTHORIZATION_ERROR_ALREADY_IN_PROGRESS =
|
|
27
|
+
"AUTHORIZATION_ERROR_ALREADY_IN_PROGRESS"
|
|
28
|
+
private const val AUTHORIZATION_ERROR_DEAUTHORIZATION_IN_PROGRESS =
|
|
29
|
+
"AUTHORIZATION_ERROR_DEAUTHORIZATION_IN_PROGRESS"
|
|
30
|
+
private const val AUTHORIZATION_ERROR_AUTHORIZATION_CODE_ALREADY_REDEEMED =
|
|
31
|
+
"AUTHORIZATION_ERROR_AUTHORIZATION_CODE_ALREADY_REDEEMED"
|
|
32
|
+
private const val AUTHORIZATION_ERROR_EXPIRED_AUTHORIZATION_CODE =
|
|
33
|
+
"AUTHORIZATION_ERROR_EXPIRED_AUTHORIZATION_CODE"
|
|
34
|
+
private const val AUTHORIZATION_ERROR_INVALID_AUTHORIZATION_CODE =
|
|
35
|
+
"AUTHORIZATION_ERROR_INVALID_AUTHORIZATION_CODE"
|
|
36
|
+
private const val AUTHORIZATION_ERROR_INVALID_ACCESS_TOKEN =
|
|
37
|
+
"AUTHORIZATION_ERROR_INVALID_ACCESS_TOKEN"
|
|
38
|
+
private const val AUTHORIZATION_ERROR_EMPTY_ACCESS_TOKEN = "AUTHORIZATION_ERROR_EMPTY_ACCESS_TOKEN"
|
|
39
|
+
private const val AUTHORIZATION_ERROR_INVALID_LOCATION_ID =
|
|
40
|
+
"AUTHORIZATION_ERROR_INVALID_LOCATION_ID"
|
|
41
|
+
private const val AUTHORIZATION_ERROR_LOCATION_NOT_ACTIVATED_FOR_CARD_PROCESSING =
|
|
42
|
+
"AUTHORIZATION_ERROR_LOCATION_NOT_ACTIVATED_FOR_CARD_PROCESSING"
|
|
43
|
+
private const val AUTHORIZATION_ERROR_EMPTY_LOCATION_ID = "AUTHORIZATION_ERROR_EMPTY_LOCATION_ID"
|
|
44
|
+
private const val AUTHORIZATION_ERROR_UNSUPPORTED_COUNTRY =
|
|
45
|
+
"AUTHORIZATION_ERROR_UNSUPPORTED_COUNTRY"
|
|
46
|
+
private const val AUTHORIZATION_ERROR_UNEXPECTED = "AUTHORIZATION_ERROR_UNEXPECTED"
|
|
47
|
+
|
|
48
|
+
class MobilePaymentAuthorization(reactContext: ReactApplicationContext) :
|
|
49
|
+
NativeMobilePaymentAuthorizationSpec(reactContext) {
|
|
50
|
+
|
|
51
|
+
private val scope: CoroutineScope by lazy {
|
|
52
|
+
CoroutineScope(
|
|
53
|
+
SupervisorJob() + Dispatchers.Main
|
|
54
|
+
)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
@Volatile
|
|
58
|
+
private var authorizationStateChangedCallbackRef: CallbackReference? = null
|
|
59
|
+
|
|
60
|
+
private var authorizeCallbackRef: CallbackReference? = null
|
|
61
|
+
private var deauthorizeCallbackRef: CallbackReference? = null
|
|
62
|
+
|
|
63
|
+
@Volatile
|
|
64
|
+
private var deauthorizePromise: Promise? = null
|
|
65
|
+
|
|
66
|
+
private var initializeListener: InitializeListener? = null
|
|
67
|
+
|
|
68
|
+
override fun initialize() {
|
|
69
|
+
super.initialize()
|
|
70
|
+
this.initializeListener = MobilePaymentSDK.addInitializeListener {
|
|
71
|
+
onSDKInitialize()
|
|
72
|
+
}
|
|
73
|
+
if (MobilePaymentSDK.isInitialize) {
|
|
74
|
+
initializeListener?.onInitialize()
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
override fun invalidate() {
|
|
79
|
+
initializeListener?.let {
|
|
80
|
+
MobilePaymentSDK.removeInitializeListener(it)
|
|
81
|
+
}
|
|
82
|
+
initializeListener = null
|
|
83
|
+
authorizationStateChangedCallbackRef?.clear()
|
|
84
|
+
authorizationStateChangedCallbackRef = null
|
|
85
|
+
authorizeCallbackRef?.clear()
|
|
86
|
+
authorizeCallbackRef = null
|
|
87
|
+
deauthorizeCallbackRef?.clear()
|
|
88
|
+
deauthorizeCallbackRef = null
|
|
89
|
+
super.invalidate()
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
private fun onSDKInitialize() {
|
|
93
|
+
authorizationStateChangedCallbackRef?.clear()
|
|
94
|
+
authorizationStateChangedCallbackRef =
|
|
95
|
+
MobilePaymentsSdk.authorizationManager().setAuthorizationStateChangedCallback {
|
|
96
|
+
if (deauthorizePromise != null && it == AuthorizationState.newUnauthorizedState()) {
|
|
97
|
+
deauthorizePromise?.resolve(null)
|
|
98
|
+
deauthorizePromise = null
|
|
99
|
+
}
|
|
100
|
+
emitOnAuthorizationStateChange(it.jsonValue)
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
override fun authorize(
|
|
105
|
+
accessToken: String,
|
|
106
|
+
locationID: String,
|
|
107
|
+
promise: Promise
|
|
108
|
+
) {
|
|
109
|
+
scope.launch {
|
|
110
|
+
if (authorizeCallbackRef != null) {
|
|
111
|
+
promise.reject(
|
|
112
|
+
AUTHORIZATION_ERROR_ALREADY_IN_PROGRESS,
|
|
113
|
+
RNMobilePaymentErrorUtilities.createNativeModuleError(
|
|
114
|
+
AUTHORIZATION_ERROR_ALREADY_IN_PROGRESS,
|
|
115
|
+
),
|
|
116
|
+
null
|
|
117
|
+
)
|
|
118
|
+
return@launch
|
|
119
|
+
}
|
|
120
|
+
authorizeCallbackRef =
|
|
121
|
+
MobilePaymentsSdk.authorizationManager().authorize(accessToken, locationID) {
|
|
122
|
+
authorizeCallbackRef?.clear()
|
|
123
|
+
authorizeCallbackRef = null
|
|
124
|
+
|
|
125
|
+
when (it) {
|
|
126
|
+
is Result.Failure -> {
|
|
127
|
+
val errorCode = when (it.errorCode) {
|
|
128
|
+
AuthorizeErrorCode.NO_NETWORK -> AUTHORIZATION_ERROR_NO_NETWORK
|
|
129
|
+
AuthorizeErrorCode.USAGE_ERROR -> AUTHORIZATION_ERROR_UNEXPECTED
|
|
130
|
+
AuthorizeErrorCode.UNSUPPORTED_COUNTRY -> AUTHORIZATION_ERROR_UNSUPPORTED_COUNTRY
|
|
131
|
+
}
|
|
132
|
+
promise.reject(
|
|
133
|
+
errorCode,
|
|
134
|
+
RNMobilePaymentErrorUtilities.serializeErrorToJson(
|
|
135
|
+
code = errorCode,
|
|
136
|
+
message = it.errorMessage,
|
|
137
|
+
debugCode = it.debugCode,
|
|
138
|
+
debugMessage = it.debugMessage
|
|
139
|
+
),
|
|
140
|
+
MobilePaymentException(it.errorMessage),
|
|
141
|
+
)
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
is Result.Success -> {
|
|
145
|
+
promise.resolve(null)
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
override fun deauthorize(promise: Promise) {
|
|
153
|
+
scope.launch {
|
|
154
|
+
if (MobilePaymentsSdk.authorizationManager().authorizationState == AuthorizationState.newUnauthorizedState()) {
|
|
155
|
+
promise.resolve(null)
|
|
156
|
+
return@launch
|
|
157
|
+
}
|
|
158
|
+
//TODO improve
|
|
159
|
+
if (MobilePaymentsSdk.authorizationManager().authorizationState == AuthorizationState.newInProgressState()) {
|
|
160
|
+
promise.reject(
|
|
161
|
+
AUTHORIZATION_ERROR_DEAUTHORIZATION_IN_PROGRESS,
|
|
162
|
+
RNMobilePaymentErrorUtilities.createNativeModuleError(
|
|
163
|
+
AUTHORIZATION_ERROR_DEAUTHORIZATION_IN_PROGRESS,
|
|
164
|
+
),
|
|
165
|
+
null
|
|
166
|
+
)
|
|
167
|
+
return@launch
|
|
168
|
+
}
|
|
169
|
+
deauthorizePromise = promise
|
|
170
|
+
MobilePaymentsSdk.authorizationManager().deauthorize()
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
override fun state(): String {
|
|
175
|
+
return MobilePaymentsSdk.authorizationManager().authorizationState.jsonValue
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
override fun location(): WritableMap? {
|
|
179
|
+
return MobilePaymentsSdk.authorizationManager().location?.writableMap
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
companion object {
|
|
183
|
+
const val NAME = NativeMobilePaymentAuthorizationSpec.NAME
|
|
184
|
+
}
|
|
185
|
+
}
|