react-native-payengine 2.0.12 → 2.0.14
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 +117 -1
- package/android/.gradle/6.1.1/executionHistory/executionHistory.lock +0 -0
- package/android/.gradle/6.1.1/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
- package/android/.gradle/buildOutputCleanup/cache.properties +1 -1
- package/android/.gradle/checksums/checksums.lock +0 -0
- package/android/.gradle/checksums/md5-checksums.bin +0 -0
- package/android/.gradle/checksums/sha1-checksums.bin +0 -0
- package/android/.idea/gradle.xml +2 -2
- package/android/.idea/jarRepositories.xml +0 -5
- package/android/.idea/libraries/Gradle__android_arch_core_common_1_0_0.xml +11 -0
- package/android/.idea/libraries/Gradle__android_arch_lifecycle_common_1_0_0.xml +11 -0
- package/android/.idea/libraries/Gradle__android_arch_lifecycle_runtime_1_0_0_aar.xml +13 -0
- package/android/.idea/libraries/Gradle__androidx_annotation_annotation_1_1_0.xml +13 -0
- package/android/.idea/libraries/Gradle__androidx_appcompat_appcompat_1_0_2_aar.xml +16 -0
- package/android/.idea/libraries/Gradle__androidx_arch_core_core_common_2_0_0.xml +11 -0
- package/android/.idea/libraries/Gradle__androidx_arch_core_core_runtime_2_0_0_aar.xml +13 -0
- package/android/.idea/libraries/Gradle__androidx_asynclayoutinflater_asynclayoutinflater_1_0_0_aar.xml +13 -0
- package/android/.idea/libraries/Gradle__androidx_autofill_autofill_1_1_0_aar.xml +16 -0
- package/android/.idea/libraries/Gradle__androidx_collection_collection_1_0_0.xml +11 -0
- package/android/.idea/libraries/Gradle__androidx_coordinatorlayout_coordinatorlayout_1_0_0_aar.xml +16 -0
- package/android/.idea/libraries/Gradle__androidx_core_core_1_1_0_aar.xml +16 -0
- package/android/.idea/libraries/Gradle__androidx_cursoradapter_cursoradapter_1_0_0_aar.xml +13 -0
- package/android/.idea/libraries/Gradle__androidx_customview_customview_1_0_0_aar.xml +13 -0
- package/android/.idea/libraries/Gradle__androidx_documentfile_documentfile_1_0_0_aar.xml +13 -0
- package/android/.idea/libraries/Gradle__androidx_drawerlayout_drawerlayout_1_0_0_aar.xml +16 -0
- package/android/.idea/libraries/Gradle__androidx_fragment_fragment_1_0_0_aar.xml +16 -0
- package/android/.idea/libraries/Gradle__androidx_interpolator_interpolator_1_0_0_aar.xml +13 -0
- package/android/.idea/libraries/Gradle__androidx_legacy_legacy_support_core_ui_1_0_0_aar.xml +13 -0
- package/android/.idea/libraries/Gradle__androidx_legacy_legacy_support_core_utils_1_0_0_aar.xml +13 -0
- package/android/.idea/libraries/Gradle__androidx_lifecycle_lifecycle_common_2_0_0.xml +11 -0
- package/android/.idea/libraries/Gradle__androidx_lifecycle_lifecycle_livedata_2_0_0_aar.xml +13 -0
- package/android/.idea/libraries/Gradle__androidx_lifecycle_lifecycle_livedata_core_2_0_0_aar.xml +13 -0
- package/android/.idea/libraries/Gradle__androidx_lifecycle_lifecycle_runtime_2_0_0_aar.xml +13 -0
- package/android/.idea/libraries/Gradle__androidx_lifecycle_lifecycle_viewmodel_2_0_0_aar.xml +13 -0
- package/android/.idea/libraries/Gradle__androidx_loader_loader_1_0_0_aar.xml +13 -0
- package/android/.idea/libraries/Gradle__androidx_localbroadcastmanager_localbroadcastmanager_1_0_0_aar.xml +13 -0
- package/android/.idea/libraries/Gradle__androidx_print_print_1_0_0_aar.xml +16 -0
- package/android/.idea/libraries/Gradle__androidx_slidingpanelayout_slidingpanelayout_1_0_0_aar.xml +13 -0
- package/android/.idea/libraries/Gradle__androidx_swiperefreshlayout_swiperefreshlayout_1_0_0_aar.xml +16 -0
- package/android/.idea/libraries/Gradle__androidx_vectordrawable_vectordrawable_1_0_1_aar.xml +13 -0
- package/android/.idea/libraries/Gradle__androidx_vectordrawable_vectordrawable_animated_1_0_0_aar.xml +13 -0
- package/android/.idea/libraries/Gradle__androidx_versionedparcelable_versionedparcelable_1_1_0_aar.xml +13 -0
- package/android/.idea/libraries/Gradle__androidx_viewpager_viewpager_1_0_0_aar.xml +13 -0
- package/android/.idea/libraries/Gradle__com_android_support_support_annotations_26_1_0.xml +13 -0
- package/android/.idea/libraries/Gradle__com_android_support_support_compat_26_1_0_aar.xml +13 -0
- package/android/.idea/libraries/Gradle__com_android_support_support_core_ui_26_1_0_aar.xml +13 -0
- package/android/.idea/libraries/Gradle__com_android_support_support_core_utils_26_1_0_aar.xml +13 -0
- package/android/.idea/libraries/Gradle__com_android_support_support_fragment_26_1_0_aar.xml +13 -0
- package/android/.idea/libraries/Gradle__com_android_support_support_media_compat_26_1_0_aar.xml +13 -0
- package/android/.idea/libraries/Gradle__com_android_support_support_v4_26_1_0_aar.xml +13 -0
- package/android/.idea/libraries/Gradle__com_facebook_fbjni_fbjni_java_only_0_2_2.xml +13 -0
- package/android/.idea/libraries/Gradle__com_facebook_fresco_drawee_2_5_0_aar.xml +15 -0
- package/android/.idea/libraries/Gradle__com_facebook_fresco_fbcore_2_5_0_aar.xml +18 -0
- package/android/.idea/libraries/Gradle__com_facebook_fresco_fresco_2_5_0_aar.xml +18 -0
- package/android/.idea/libraries/Gradle__com_facebook_fresco_imagepipeline_2_5_0_aar.xml +18 -0
- package/android/.idea/libraries/Gradle__com_facebook_fresco_imagepipeline_base_2_5_0_aar.xml +18 -0
- package/android/.idea/libraries/Gradle__com_facebook_fresco_imagepipeline_native_2_5_0_aar.xml +15 -0
- package/android/.idea/libraries/Gradle__com_facebook_fresco_imagepipeline_okhttp3_2_5_0_aar.xml +15 -0
- package/android/.idea/libraries/Gradle__com_facebook_fresco_memory_type_ashmem_2_5_0_aar.xml +15 -0
- package/android/.idea/libraries/Gradle__com_facebook_fresco_memory_type_java_2_5_0_aar.xml +15 -0
- package/android/.idea/libraries/Gradle__com_facebook_fresco_memory_type_native_2_5_0_aar.xml +15 -0
- package/android/.idea/libraries/Gradle__com_facebook_fresco_nativeimagefilters_2_5_0_aar.xml +15 -0
- package/android/.idea/libraries/Gradle__com_facebook_fresco_nativeimagetranscoder_2_5_0_aar.xml +15 -0
- package/android/.idea/libraries/Gradle__com_facebook_fresco_ui_common_2_5_0_aar.xml +15 -0
- package/android/.idea/libraries/Gradle__com_facebook_infer_annotation_infer_annotation_0_18_0.xml +13 -0
- package/android/.idea/libraries/Gradle__com_facebook_react_react_native_0_68_2_aar.xml +16 -0
- package/android/.idea/libraries/Gradle__com_facebook_soloader_annotation_0_10_3.xml +13 -0
- package/android/.idea/libraries/Gradle__com_facebook_soloader_nativeloader_0_10_3.xml +13 -0
- package/android/.idea/libraries/Gradle__com_facebook_soloader_soloader_0_10_3_aar.xml +15 -0
- package/android/.idea/libraries/Gradle__com_facebook_yoga_proguard_annotations_1_19_0.xml +13 -0
- package/android/.idea/libraries/Gradle__com_google_android_gms_play_services_base_15_0_1_aar.xml +11 -0
- package/android/.idea/libraries/Gradle__com_google_android_gms_play_services_basement_15_0_1_aar.xml +11 -0
- package/android/.idea/libraries/Gradle__com_google_android_gms_play_services_identity_15_0_1_aar.xml +11 -0
- package/android/.idea/libraries/Gradle__com_google_android_gms_play_services_maps_15_0_1_aar.xml +11 -0
- package/android/.idea/libraries/Gradle__com_google_android_gms_play_services_tasks_15_0_1_aar.xml +11 -0
- package/android/.idea/libraries/Gradle__com_google_android_gms_play_services_wallet_16_0_0_aar.xml +11 -0
- package/android/.idea/libraries/Gradle__com_google_code_findbugs_jsr305_3_0_2.xml +13 -0
- package/android/.idea/libraries/Gradle__com_squareup_okhttp3_okhttp_4_9_2.xml +13 -0
- package/android/.idea/libraries/Gradle__com_squareup_okhttp3_okhttp_urlconnection_4_9_2.xml +13 -0
- package/android/.idea/libraries/Gradle__com_squareup_okio_okio_2_9_0.xml +13 -0
- package/android/.idea/libraries/Gradle__javax_inject_javax_inject_1.xml +13 -0
- package/android/.idea/libraries/Gradle__org_jetbrains_annotations_13_0.xml +13 -0
- package/android/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_annotations_jvm_1_3_72.xml +13 -0
- package/android/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_stdlib_1_4_10.xml +13 -0
- package/android/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_stdlib_common_1_4_10.xml +13 -0
- package/android/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_stdlib_jdk7_1_4_10.xml +13 -0
- package/android/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_stdlib_jdk8_1_4_10.xml +13 -0
- package/android/.idea/misc.xml +1 -2
- package/android/.idea/modules/android.androidTest.iml +114 -0
- package/android/.idea/modules/android.iml +40 -0
- package/android/.idea/modules/android.main.iml +122 -0
- package/android/.idea/modules/android.unitTest.iml +109 -0
- package/android/.idea/modules.xml +11 -0
- package/android/local.properties +2 -2
- package/ios/PayEngineSDK.xcframework/ios-arm64/PayEngineSDK.framework/Headers/PayEngineSDK-Swift.h +19 -3
- package/ios/PayEngineSDK.xcframework/ios-arm64/PayEngineSDK.framework/Info.plist +0 -0
- package/ios/PayEngineSDK.xcframework/ios-arm64/PayEngineSDK.framework/Modules/PayEngineSDK.swiftmodule/arm64-apple-ios.abi.json +1367 -3704
- package/ios/PayEngineSDK.xcframework/ios-arm64/PayEngineSDK.framework/Modules/PayEngineSDK.swiftmodule/arm64-apple-ios.private.swiftinterface +68 -59
- package/ios/PayEngineSDK.xcframework/ios-arm64/PayEngineSDK.framework/Modules/PayEngineSDK.swiftmodule/arm64-apple-ios.private.swiftinterface-e +68 -59
- package/ios/PayEngineSDK.xcframework/ios-arm64/PayEngineSDK.framework/Modules/PayEngineSDK.swiftmodule/arm64-apple-ios.swiftdoc +0 -0
- package/ios/PayEngineSDK.xcframework/ios-arm64/PayEngineSDK.framework/Modules/PayEngineSDK.swiftmodule/arm64-apple-ios.swiftinterface +68 -59
- package/ios/PayEngineSDK.xcframework/ios-arm64/PayEngineSDK.framework/Modules/PayEngineSDK.swiftmodule/arm64-apple-ios.swiftinterface-e +68 -59
- package/ios/PayEngineSDK.xcframework/ios-arm64/PayEngineSDK.framework/PayEngineSDK +0 -0
- package/ios/PayEngineSDK.xcframework/ios-arm64/PayEngineSDK.framework/VGSCollectSDK_VGSCollectSDK.bundle/Assets.car +0 -0
- package/ios/PayEngineSDK.xcframework/ios-arm64/PayEngineSDK.framework/VGSCollectSDK_VGSCollectSDK.bundle/Info.plist +0 -0
- package/ios/PayEngineSDK.xcframework/ios-arm64_x86_64-simulator/PayEngineSDK.framework/Headers/PayEngineSDK-Swift.h +38 -6
- package/ios/PayEngineSDK.xcframework/ios-arm64_x86_64-simulator/PayEngineSDK.framework/Info.plist +0 -0
- package/ios/PayEngineSDK.xcframework/ios-arm64_x86_64-simulator/PayEngineSDK.framework/Modules/PayEngineSDK.swiftmodule/arm64-apple-ios-simulator.abi.json +1367 -3704
- package/ios/PayEngineSDK.xcframework/ios-arm64_x86_64-simulator/PayEngineSDK.framework/Modules/PayEngineSDK.swiftmodule/arm64-apple-ios-simulator.private.swiftinterface +68 -59
- package/ios/PayEngineSDK.xcframework/ios-arm64_x86_64-simulator/PayEngineSDK.framework/Modules/PayEngineSDK.swiftmodule/arm64-apple-ios-simulator.private.swiftinterface-e +68 -59
- package/ios/PayEngineSDK.xcframework/ios-arm64_x86_64-simulator/PayEngineSDK.framework/Modules/PayEngineSDK.swiftmodule/arm64-apple-ios-simulator.swiftdoc +0 -0
- package/ios/PayEngineSDK.xcframework/ios-arm64_x86_64-simulator/PayEngineSDK.framework/Modules/PayEngineSDK.swiftmodule/arm64-apple-ios-simulator.swiftinterface +68 -59
- package/ios/PayEngineSDK.xcframework/ios-arm64_x86_64-simulator/PayEngineSDK.framework/Modules/PayEngineSDK.swiftmodule/arm64-apple-ios-simulator.swiftinterface-e +68 -59
- package/ios/PayEngineSDK.xcframework/ios-arm64_x86_64-simulator/PayEngineSDK.framework/Modules/PayEngineSDK.swiftmodule/x86_64-apple-ios-simulator.abi.json +1367 -3704
- package/ios/PayEngineSDK.xcframework/ios-arm64_x86_64-simulator/PayEngineSDK.framework/Modules/PayEngineSDK.swiftmodule/x86_64-apple-ios-simulator.private.swiftinterface +68 -59
- package/ios/PayEngineSDK.xcframework/ios-arm64_x86_64-simulator/PayEngineSDK.framework/Modules/PayEngineSDK.swiftmodule/x86_64-apple-ios-simulator.private.swiftinterface-e +68 -59
- package/ios/PayEngineSDK.xcframework/ios-arm64_x86_64-simulator/PayEngineSDK.framework/Modules/PayEngineSDK.swiftmodule/x86_64-apple-ios-simulator.swiftdoc +0 -0
- package/ios/PayEngineSDK.xcframework/ios-arm64_x86_64-simulator/PayEngineSDK.framework/Modules/PayEngineSDK.swiftmodule/x86_64-apple-ios-simulator.swiftinterface +68 -59
- package/ios/PayEngineSDK.xcframework/ios-arm64_x86_64-simulator/PayEngineSDK.framework/Modules/PayEngineSDK.swiftmodule/x86_64-apple-ios-simulator.swiftinterface-e +68 -59
- package/ios/PayEngineSDK.xcframework/ios-arm64_x86_64-simulator/PayEngineSDK.framework/PayEngineSDK +0 -0
- package/ios/PayEngineSDK.xcframework/ios-arm64_x86_64-simulator/PayEngineSDK.framework/VGSCollectSDK_VGSCollectSDK.bundle/Assets.car +0 -0
- package/ios/PayEngineSDK.xcframework/ios-arm64_x86_64-simulator/PayEngineSDK.framework/VGSCollectSDK_VGSCollectSDK.bundle/Info.plist +0 -0
- package/ios/Payengine.xcodeproj/project.xcworkspace/xcuserdata/trinvh.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- package/ios/Payengine.xcworkspace/xcuserdata/trinvh.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- package/ios/Sources/Classes/ApplePay/ApplePayUtils.swift +220 -0
- package/ios/Sources/Classes/ApplePay/RNPEApplePayButton.swift +232 -139
- package/ios/Sources/Classes/ApplePay/RNPEApplePayPaymentRequest.swift +83 -61
- package/ios/Sources/Classes/RNPEEventEmitter.swift +1 -1
- package/ios/Sources/Payengine.m +8 -1
- package/lib/commonjs/components/v2/ApplePay/PEApplePayButton.js +52 -3
- package/lib/commonjs/components/v2/ApplePay/PEApplePayButton.js.map +1 -1
- package/lib/commonjs/components/v2/ApplePay/PEApplePayInterfaces.js +40 -0
- package/lib/commonjs/components/v2/ApplePay/PEApplePayInterfaces.js.map +1 -0
- package/lib/commonjs/components/v2/PEPaymentRequest.js +3 -0
- package/lib/commonjs/components/v2/PEPaymentRequest.js.map +1 -1
- package/lib/commonjs/index.js +43 -32
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/components/v2/ApplePay/PEApplePayButton.js +53 -4
- package/lib/module/components/v2/ApplePay/PEApplePayButton.js.map +1 -1
- package/lib/module/components/v2/ApplePay/PEApplePayInterfaces.js +31 -0
- package/lib/module/components/v2/ApplePay/PEApplePayInterfaces.js.map +1 -0
- package/lib/module/components/v2/PEPaymentRequest.js +3 -0
- package/lib/module/components/v2/PEPaymentRequest.js.map +1 -1
- package/lib/module/index.js +6 -2
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/components/v2/ApplePay/PEApplePayButton.d.ts +38 -2
- package/lib/typescript/components/v2/ApplePay/PEApplePayInterfaces.d.ts +54 -0
- package/lib/typescript/components/v2/PEPaymentRequest.d.ts +8 -4
- package/lib/typescript/index.d.ts +4 -3
- package/package.json +1 -1
- package/src/components/v2/ApplePay/PEApplePayButton.tsx +181 -24
- package/src/components/v2/ApplePay/PEApplePayInterfaces.ts +63 -0
- package/src/components/v2/PEPaymentRequest.ts +12 -4
- package/src/index.tsx +11 -7
- package/android/.gradle/6.1.1/fileHashes/fileHashes.bin +0 -0
- package/android/.gradle/buildOutputCleanup/outputFiles.bin +0 -0
- package/android/.gradle/config.properties +0 -2
- package/android/.idea/caches/deviceStreaming.xml +0 -329
- package/android/.idea/kotlinc.xml +0 -6
- package/android/.idea/migrations.xml +0 -10
- package/ios/PayEngineSDK.xcframework/ios-arm64/PayEngineSDK.framework/Frameworks/libKountDataCollector.a +0 -0
- package/ios/PayEngineSDK.xcframework/ios-arm64_x86_64-simulator/PayEngineSDK.framework/Frameworks/libKountDataCollector.a +0 -0
- package/ios/Payengine.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +0 -34
- package/ios/Payengine.xcodeproj/project.xcworkspace/xcuserdata/tringuyen.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- package/ios/Payengine.xcodeproj/xcuserdata/tringuyen.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +0 -24
- package/ios/Payengine.xcworkspace/xcuserdata/tringuyen.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- package/ios/Pods/Pods.xcodeproj/xcuserdata/tringuyen.xcuserdatad/xcschemes/Pods-Payengine.xcscheme +0 -58
- package/ios/Pods/Pods.xcodeproj/xcuserdata/tringuyen.xcuserdatad/xcschemes/VGSCollectSDK-CardIcon.xcscheme +0 -58
- package/ios/Pods/Pods.xcodeproj/xcuserdata/tringuyen.xcuserdatad/xcschemes/VGSCollectSDK.xcscheme +0 -58
- package/ios/Pods/Pods.xcodeproj/xcuserdata/tringuyen.xcuserdatad/xcschemes/xcschememanagement.plist +0 -32
- package/lib/commonjs/components/v2/ApplePay/PEApplePayContact.js +0 -2
- package/lib/commonjs/components/v2/ApplePay/PEApplePayContact.js.map +0 -1
- package/lib/module/components/v2/ApplePay/PEApplePayContact.js +0 -2
- package/lib/module/components/v2/ApplePay/PEApplePayContact.js.map +0 -1
- package/lib/typescript/components/v2/ApplePay/PEApplePayContact.d.ts +0 -14
- package/src/components/v2/ApplePay/PEApplePayContact.ts +0 -14
- /package/ios/Payengine.xcodeproj/xcuserdata/{tringuyen.xcuserdatad → trinvh.xcuserdatad}/xcschemes/xcschememanagement.plist +0 -0
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Untitled.swift
|
|
3
|
+
// Pods
|
|
4
|
+
//
|
|
5
|
+
// Created by Tri Nguyen on 12/5/24.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
import PassKit
|
|
9
|
+
|
|
10
|
+
class ApplePayUtils {
|
|
11
|
+
|
|
12
|
+
/// Helper methods
|
|
13
|
+
internal class func dictionaryToString(_ dictionary: [String: Any]) -> String? {
|
|
14
|
+
guard let jsonData = try? JSONSerialization.data(withJSONObject: dictionary, options: .prettyPrinted),
|
|
15
|
+
let jsonString = String(data: jsonData, encoding: .utf8) else {
|
|
16
|
+
return nil
|
|
17
|
+
}
|
|
18
|
+
return jsonString
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
internal class func pkContactToJSONString(_ contact: PKContact) -> String? {
|
|
22
|
+
let contactDict: [String: Any] = pkContactToDict(contact)
|
|
23
|
+
|
|
24
|
+
// Convert dictionary to JSON string
|
|
25
|
+
guard let jsonData = try? JSONSerialization.data(withJSONObject: contactDict, options: .prettyPrinted),
|
|
26
|
+
let jsonString = String(data: jsonData, encoding: .utf8) else {
|
|
27
|
+
return nil
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return jsonString
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
internal class func pkContactToDict(_ contact: PKContact) -> [String: Any] {
|
|
34
|
+
var contactDict: [String: Any] = [:]
|
|
35
|
+
|
|
36
|
+
if let name = contact.name {
|
|
37
|
+
contactDict["givenName"] = name.givenName
|
|
38
|
+
contactDict["familyName"] = name.familyName
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Postal Address
|
|
42
|
+
if let postalAddress = contact.postalAddress {
|
|
43
|
+
var addressLines: [String] = []
|
|
44
|
+
|
|
45
|
+
addressLines.append(postalAddress.street)
|
|
46
|
+
contactDict["addressLines"] = addressLines
|
|
47
|
+
|
|
48
|
+
contactDict["locality"] = postalAddress.city
|
|
49
|
+
contactDict["administrativeArea"] = postalAddress.state
|
|
50
|
+
contactDict["postalCode"] = postalAddress.postalCode
|
|
51
|
+
contactDict["country"] = postalAddress.country
|
|
52
|
+
contactDict["countryCode"] = postalAddress.isoCountryCode
|
|
53
|
+
contactDict["subAdministrativeArea"] = postalAddress.subAdministrativeArea
|
|
54
|
+
contactDict["subLocality"] = postalAddress.subLocality
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Email Address
|
|
58
|
+
if let emailAddress = contact.emailAddress {
|
|
59
|
+
contactDict["emailAddress"] = emailAddress
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Phone Number
|
|
63
|
+
if let phoneNumber = contact.phoneNumber {
|
|
64
|
+
contactDict["phoneNumber"] = phoneNumber.stringValue
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return contactDict
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
internal class func pkPaymentMethodToDict(_ paymentMethod: PKPaymentMethod) -> [String: Any] {
|
|
71
|
+
var dict: [String: Any] = [:]
|
|
72
|
+
if let displayName = paymentMethod.displayName {
|
|
73
|
+
dict["displayName"] = displayName
|
|
74
|
+
}
|
|
75
|
+
if let network = paymentMethod.network {
|
|
76
|
+
dict["network"] = network.rawValue
|
|
77
|
+
}
|
|
78
|
+
dict["type"] = paymentMethod.type.rawValue
|
|
79
|
+
|
|
80
|
+
return dict
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
internal class func pkShippingMethodToDict(_ shippingMethod: PKShippingMethod) -> [String: Any] {
|
|
84
|
+
let dict = [
|
|
85
|
+
"identifier": shippingMethod.identifier ?? "",
|
|
86
|
+
"amount": shippingMethod.amount.floatValue,
|
|
87
|
+
"label": shippingMethod.label
|
|
88
|
+
] as [String : Any]
|
|
89
|
+
|
|
90
|
+
return dict
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
internal class func buildPaymentSummaryItems(items: [[String : Any]]?) throws -> [PKPaymentSummaryItem] {
|
|
94
|
+
var paymentSummaryItems: [PKPaymentSummaryItem] = []
|
|
95
|
+
if let items = items {
|
|
96
|
+
for item in items {
|
|
97
|
+
let paymentSummaryItem = try buildPaymentSummaryItem(item: item)
|
|
98
|
+
paymentSummaryItems.append(paymentSummaryItem)
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return paymentSummaryItems
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
internal class func buildPaymentSummaryItem(item: [String : Any]) throws -> PKPaymentSummaryItem {
|
|
108
|
+
let label = item["label"] as? String ?? ""
|
|
109
|
+
|
|
110
|
+
// Handle amount that could be either String or numeric type
|
|
111
|
+
let amount: NSDecimalNumber
|
|
112
|
+
if let amountStr = item["amount"] as? String {
|
|
113
|
+
amount = NSDecimalNumber(string: amountStr)
|
|
114
|
+
} else if let amountNum = item["amount"] as? NSNumber {
|
|
115
|
+
amount = NSDecimalNumber(decimal: amountNum.decimalValue)
|
|
116
|
+
} else {
|
|
117
|
+
throw ApplePayUtilsError.missingParameter(label, "amount")
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return PKPaymentSummaryItem(
|
|
121
|
+
label: label,
|
|
122
|
+
amount: amount
|
|
123
|
+
)
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
public class func buildShippingMethods(items: [[String : Any]]?) throws -> [PKShippingMethod] {
|
|
127
|
+
var shippingMethods: [PKShippingMethod] = []
|
|
128
|
+
if let items = items {
|
|
129
|
+
for item in items {
|
|
130
|
+
let shippingMethod = buildShippingMethod(item: item)
|
|
131
|
+
shippingMethods.append(shippingMethod)
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return shippingMethods
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
internal class func buildShippingMethod(item: [String : Any]) -> PKShippingMethod {
|
|
139
|
+
let label = item["label"] as? String ?? ""
|
|
140
|
+
|
|
141
|
+
// Handle amount that could be either String or numeric type
|
|
142
|
+
let amount: NSDecimalNumber
|
|
143
|
+
if let amountStr = item["amount"] as? String {
|
|
144
|
+
amount = NSDecimalNumber(string: amountStr)
|
|
145
|
+
} else if let amountNum = item["amount"] as? NSNumber {
|
|
146
|
+
amount = NSDecimalNumber(decimal: amountNum.decimalValue)
|
|
147
|
+
} else {
|
|
148
|
+
amount = NSDecimalNumber.zero
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
let shippingMethod = PKShippingMethod(
|
|
152
|
+
label: label,
|
|
153
|
+
amount: amount
|
|
154
|
+
)
|
|
155
|
+
shippingMethod.detail = item["detail"] as? String ?? ""
|
|
156
|
+
shippingMethod.identifier = item["identifier"] as? String ?? ""
|
|
157
|
+
|
|
158
|
+
return shippingMethod
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
public class func buildApplePayErrors(errorItems: [NSDictionary]) throws -> [Error] {
|
|
162
|
+
var shippingAddressErrors: [Error] = []
|
|
163
|
+
|
|
164
|
+
for item in errorItems {
|
|
165
|
+
let type = item["errorType"] as? String
|
|
166
|
+
let message = item["message"] as? String
|
|
167
|
+
switch type {
|
|
168
|
+
case "InvalidShippingAddress":
|
|
169
|
+
let field = item["field"] as? String ?? "street"
|
|
170
|
+
shippingAddressErrors.append(PKPaymentRequest.paymentShippingAddressInvalidError(withKey: field, localizedDescription: message))
|
|
171
|
+
case "UnserviceableShippingAddress":
|
|
172
|
+
shippingAddressErrors.append(PKPaymentRequest.paymentShippingAddressUnserviceableError(withLocalizedDescription: message))
|
|
173
|
+
default:
|
|
174
|
+
throw ApplePayUtilsError.invalidErrorType(String(describing: type))
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return shippingAddressErrors
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
enum ApplePayUtilsError : Error, Equatable {
|
|
182
|
+
case invalidCartSummaryItemType(String)
|
|
183
|
+
case missingParameter(String?, String)
|
|
184
|
+
case invalidTimeInterval(String)
|
|
185
|
+
case invalidPaymentNetwork(String)
|
|
186
|
+
case invalidErrorType(String)
|
|
187
|
+
case invalidUrl(String)
|
|
188
|
+
case invalidRequestType(String)
|
|
189
|
+
case missingMerchantId
|
|
190
|
+
case missingCountryCode
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
extension ApplePayUtilsError: LocalizedError {
|
|
194
|
+
public var errorDescription: String? {
|
|
195
|
+
switch self {
|
|
196
|
+
case .invalidCartSummaryItemType(let type):
|
|
197
|
+
return "Failed to ceate Apple Pay summary item. Expected `type` to be one of 'Immediate', 'Recurring', or 'Deferred', but received: \(type)"
|
|
198
|
+
case .missingParameter(let label, let parameter):
|
|
199
|
+
if let label = label {
|
|
200
|
+
return "Failed to create Apple Pay summary item with label: \(label). The \(parameter) item parameter is required, but none was provided."
|
|
201
|
+
} else {
|
|
202
|
+
return "The \(parameter) item parameter is required, but none was provided."
|
|
203
|
+
}
|
|
204
|
+
case .invalidTimeInterval(let providedInterval):
|
|
205
|
+
return "Failed to create Apple Pay summary item. \(providedInterval) is not a valid timeInterval, must be one of: minute, hour, day, month, or year."
|
|
206
|
+
case .invalidPaymentNetwork(let network):
|
|
207
|
+
return "Failed to create Apple Pay summary item. \(network) is not a valid/supported payment network."
|
|
208
|
+
case .invalidErrorType(let type):
|
|
209
|
+
return "Error type: '\(type)' is not supported."
|
|
210
|
+
case .missingMerchantId:
|
|
211
|
+
return "`merchantIdentifier` is required, but none was found. Ensure you are passing this to initStripe your StripeProvider."
|
|
212
|
+
case .missingCountryCode:
|
|
213
|
+
return "`merchantCountryCode` is a required param, but was not provided."
|
|
214
|
+
case .invalidUrl(let url):
|
|
215
|
+
return "Invalid URL: \(url)."
|
|
216
|
+
case .invalidRequestType(let tyoe):
|
|
217
|
+
return "Apple Pay request type `\(tyoe)` is not supported."
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
@@ -11,168 +11,261 @@ import PassKit
|
|
|
11
11
|
|
|
12
12
|
@objc(RNPEApplePayButton)
|
|
13
13
|
class RNPEApplePayButton: UIView {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
14
|
+
|
|
15
|
+
@objc var onPmSheetDidDismiss: RCTBubblingEventBlock?
|
|
16
|
+
@objc var onPmTokenDidReturn: RCTBubblingEventBlock?
|
|
17
|
+
@objc var onPmError: RCTBubblingEventBlock?
|
|
18
|
+
@objc var onPaymentMethodSelected: RCTBubblingEventBlock?
|
|
19
|
+
@objc var onShippingContactSelected: RCTBubblingEventBlock?
|
|
20
|
+
@objc var onShippingMethodSelected: RCTBubblingEventBlock?
|
|
21
|
+
private var onPaymentMethodSelectedCompletion: ((PKPaymentRequestPaymentMethodUpdate) -> Void)?
|
|
22
|
+
private var onShippingContactSelectedCompletion: ((PKPaymentRequestShippingContactUpdate) -> Void)?
|
|
23
|
+
private var onShippingMethodSelectedCompletion: ((PKPaymentRequestShippingMethodUpdate) -> Void)?
|
|
24
|
+
|
|
25
|
+
private var _button: UIButton?
|
|
26
|
+
private var _paymentRequest: RNPEApplePayPaymentRequest?
|
|
27
|
+
|
|
28
|
+
override init(frame: CGRect) {
|
|
29
|
+
super.init(frame: frame)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
required init?(coder: NSCoder) {
|
|
33
|
+
super.init(coder: coder)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
override func layoutSubviews() {
|
|
37
|
+
self._button?.frame = self.bounds
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
override func didSetProps(_ changedProps: [String]!) {
|
|
41
|
+
// debugPrint("didSetProps \(String(describing: changedProps))")
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
@objc var paymentRequest: String? = "" {
|
|
46
|
+
didSet {
|
|
47
|
+
guard let paymentRequest = self.paymentRequest else {
|
|
48
|
+
debugPrint("Unable to render apple pay button: Missing payment request")
|
|
49
|
+
return
|
|
50
|
+
}
|
|
51
|
+
debugPrint("Payment request: \(paymentRequest)")
|
|
52
|
+
if let paymentRequest: RNPEApplePayPaymentRequest = try? JSONDecoder().decode(RNPEApplePayPaymentRequest.self, from: paymentRequest.data(using: .utf8)!) {
|
|
53
|
+
self._paymentRequest = paymentRequest
|
|
54
|
+
setupView(applepayPaymentRequest: self._paymentRequest!.toNative())
|
|
55
|
+
} else {
|
|
56
|
+
debugPrint("Invalid payment request. Please try again")
|
|
57
|
+
}
|
|
23
58
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
@objc func updatePaymentSheet(summaryItems: NSArray,
|
|
62
|
+
shippingMethods: NSArray,
|
|
63
|
+
errors: [NSDictionary])
|
|
64
|
+
{
|
|
65
|
+
debugPrint("updatePlatformPaySheet is called \(summaryItems) \(shippingMethods) \(errors)")
|
|
66
|
+
if (self.onPaymentMethodSelectedCompletion == nil &&
|
|
67
|
+
self.onShippingContactSelectedCompletion == nil &&
|
|
68
|
+
self.onShippingMethodSelectedCompletion == nil) {
|
|
69
|
+
|
|
70
|
+
RNPEEventEmitter.emitter.sendEvent(withName: "onUpdatePaymentSheetResult", body: ["error": "You can use this method only after a selection callback is triggered"])
|
|
71
|
+
return
|
|
27
72
|
}
|
|
28
73
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
74
|
+
var applePaySummaryItems: [PKPaymentSummaryItem] = []
|
|
75
|
+
var applePayShippingMethods: [PKShippingMethod] = []
|
|
76
|
+
var applePayShippingErrors: [Error] = []
|
|
32
77
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
78
|
+
do {
|
|
79
|
+
applePaySummaryItems = try ApplePayUtils.buildPaymentSummaryItems(items: summaryItems as? [[String : Any]])
|
|
80
|
+
applePayShippingMethods = try ApplePayUtils.buildShippingMethods(items: shippingMethods as? [[String : Any]])
|
|
81
|
+
applePayShippingErrors = try ApplePayUtils.buildApplePayErrors(errorItems: errors)
|
|
82
|
+
|
|
83
|
+
if let completion = self.onPaymentMethodSelectedCompletion {
|
|
84
|
+
debugPrint("onPaymentMethodSelectedCompletion called")
|
|
85
|
+
let update = PKPaymentRequestPaymentMethodUpdate(paymentSummaryItems: applePaySummaryItems)
|
|
86
|
+
completion(update)
|
|
87
|
+
self.onPaymentMethodSelectedCompletion = nil
|
|
88
|
+
RNPEEventEmitter.emitter.sendEvent(withName: "onUpdatePaymentSheetResult", body: [:])
|
|
89
|
+
}
|
|
90
|
+
if let completion = self.onShippingContactSelectedCompletion {
|
|
91
|
+
debugPrint("onShippingContactSelectedCompletion called")
|
|
92
|
+
let update = PKPaymentRequestShippingContactUpdate(
|
|
93
|
+
errors: applePayShippingErrors,
|
|
94
|
+
paymentSummaryItems: applePaySummaryItems,
|
|
95
|
+
shippingMethods: applePayShippingMethods
|
|
96
|
+
)
|
|
97
|
+
completion(update)
|
|
98
|
+
self.onShippingContactSelectedCompletion = nil
|
|
99
|
+
RNPEEventEmitter.emitter.sendEvent(withName: "onUpdatePaymentSheetResult", body: [:])
|
|
100
|
+
}
|
|
101
|
+
if let completion = self.onShippingMethodSelectedCompletion {
|
|
102
|
+
debugPrint("onShippingMethodSelectedCompletion called")
|
|
103
|
+
applePaySummaryItems.map {
|
|
104
|
+
debugPrint("\($0.label): \($0.amount)")
|
|
37
105
|
}
|
|
106
|
+
let update = PKPaymentRequestShippingMethodUpdate(paymentSummaryItems: applePaySummaryItems)
|
|
107
|
+
completion(update)
|
|
108
|
+
self.onShippingMethodSelectedCompletion = nil
|
|
109
|
+
RNPEEventEmitter.emitter.sendEvent(withName: "onUpdatePaymentSheetResult", body: [:])
|
|
110
|
+
}
|
|
111
|
+
} catch {
|
|
112
|
+
debugPrint("Completion failed \(error)")
|
|
113
|
+
RNPEEventEmitter.emitter.sendEvent(withName: "onUpdatePaymentSheetResult", body: ["error": error.localizedDescription])
|
|
114
|
+
return
|
|
38
115
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
if let applepay = RNPayEngineNative.applePayInstance {
|
|
50
|
-
applepay.delegate = self
|
|
51
|
-
DispatchQueue.main.async {
|
|
52
|
-
if let button = applepay.setupApplePayButton(for: pePaymentRequest, type: .checkout) {
|
|
53
|
-
self._button = button
|
|
54
|
-
self._button!.layer.masksToBounds = true
|
|
55
|
-
self.addSubview(self._button!)
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
} else {
|
|
60
|
-
debugPrint("Invalid payment request. Please try again")
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
private func setupView(applepayPaymentRequest: ApplePayPaymentRequest) {
|
|
119
|
+
if let applepay = RNPayEngineNative.applePayInstance {
|
|
120
|
+
applepay.delegate = self
|
|
121
|
+
DispatchQueue.main.async {
|
|
122
|
+
if let button = applepay.setupApplePayButton(for: applepayPaymentRequest, type: .checkout) {
|
|
123
|
+
self._button = button
|
|
124
|
+
self._button!.layer.masksToBounds = true
|
|
125
|
+
self.addSubview(self._button!)
|
|
61
126
|
}
|
|
127
|
+
}
|
|
62
128
|
}
|
|
63
129
|
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
private func createSummaryItems() -> [PKPaymentSummaryItem] {
|
|
133
|
+
return [
|
|
134
|
+
PKPaymentSummaryItem(label: "Total", amount: NSDecimalNumber(value: _paymentRequest!.paymentAmount))
|
|
135
|
+
]
|
|
136
|
+
}
|
|
64
137
|
}
|
|
65
138
|
|
|
66
|
-
func dictionaryToString(_ dictionary: [String: Any]) -> String? {
|
|
67
|
-
guard let jsonData = try? JSONSerialization.data(withJSONObject: dictionary, options: .prettyPrinted),
|
|
68
|
-
let jsonString = String(data: jsonData, encoding: .utf8) else {
|
|
69
|
-
return nil
|
|
70
|
-
}
|
|
71
|
-
return jsonString
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
func pkContactToJSONString(_ contact: PKContact) -> String? {
|
|
75
|
-
var contactDict: [String: Any] = [:]
|
|
76
|
-
|
|
77
|
-
if let name = contact.name {
|
|
78
|
-
contactDict["givenName"] = name.givenName
|
|
79
|
-
contactDict["familyName"] = name.familyName
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// Postal Address
|
|
83
|
-
if let postalAddress = contact.postalAddress {
|
|
84
|
-
var addressLines: [String] = []
|
|
85
|
-
|
|
86
|
-
addressLines.append(postalAddress.street)
|
|
87
|
-
contactDict["addressLines"] = addressLines
|
|
88
|
-
|
|
89
|
-
contactDict["locality"] = postalAddress.city
|
|
90
|
-
contactDict["administrativeArea"] = postalAddress.state
|
|
91
|
-
contactDict["postalCode"] = postalAddress.postalCode
|
|
92
|
-
contactDict["country"] = postalAddress.country
|
|
93
|
-
contactDict["countryCode"] = postalAddress.isoCountryCode
|
|
94
|
-
contactDict["subAdministrativeArea"] = postalAddress.subAdministrativeArea
|
|
95
|
-
contactDict["subLocality"] = postalAddress.subLocality
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// Email Address
|
|
99
|
-
if let emailAddress = contact.emailAddress {
|
|
100
|
-
contactDict["emailAddress"] = emailAddress
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
// Phone Number
|
|
104
|
-
if let phoneNumber = contact.phoneNumber {
|
|
105
|
-
contactDict["phoneNumber"] = phoneNumber.stringValue
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
// Convert dictionary to JSON string
|
|
109
|
-
guard let jsonData = try? JSONSerialization.data(withJSONObject: contactDict, options: .prettyPrinted),
|
|
110
|
-
let jsonString = String(data: jsonData, encoding: .utf8) else {
|
|
111
|
-
return nil
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
return jsonString
|
|
115
|
-
}
|
|
116
139
|
|
|
117
140
|
extension RNPEApplePayButton: PEApplePayDelegate {
|
|
141
|
+
|
|
142
|
+
func paymentTokenDidReturn(token: String, metadata: [String : Any]?, billingContact: PKContact?, shippingContact: PKContact?, completion: @escaping (PayEngineSDK.PEApplePayResult) -> Void) {
|
|
118
143
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
"token": token
|
|
123
|
-
]
|
|
124
|
-
|
|
125
|
-
if (metadata != nil) {
|
|
126
|
-
data["metadata"] = dictionaryToString(metadata!)
|
|
127
|
-
}
|
|
128
|
-
if (billingContact != nil) {
|
|
129
|
-
data["billingContact"] = pkContactToJSONString(billingContact!)
|
|
130
|
-
}
|
|
131
|
-
if (shippingContact != nil) {
|
|
132
|
-
data["shippingContact"] = pkContactToJSONString(shippingContact!)
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
if self.onPmTokenDidReturn != nil {
|
|
136
|
-
self.onPmTokenDidReturn!(data)
|
|
137
|
-
}
|
|
138
|
-
completion(.success)
|
|
139
|
-
}
|
|
144
|
+
var data = [
|
|
145
|
+
"token": token
|
|
146
|
+
]
|
|
140
147
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
if self.onPmError != nil {
|
|
144
|
-
self.onPmError!(["error": error?.localizedDescription ?? "Payment token not available due to unexpected error"])
|
|
145
|
-
}
|
|
148
|
+
if (metadata != nil) {
|
|
149
|
+
data["metadata"] = ApplePayUtils.dictionaryToString(metadata!)
|
|
146
150
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
func paymentError(error: Error) {
|
|
150
|
-
debugPrint("payment error \(error)")
|
|
151
|
-
if self.onPmError != nil {
|
|
152
|
-
self.onPmError!(["error": error.localizedDescription])
|
|
153
|
-
}
|
|
151
|
+
if (billingContact != nil) {
|
|
152
|
+
data["billingContact"] = ApplePayUtils.pkContactToJSONString(billingContact!)
|
|
154
153
|
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
if self.onPmSheetDidDismiss != nil {
|
|
158
|
-
self.onPmSheetDidDismiss!(["token": "null"])
|
|
159
|
-
}
|
|
154
|
+
if (shippingContact != nil) {
|
|
155
|
+
data["shippingContact"] = ApplePayUtils.pkContactToJSONString(shippingContact!)
|
|
160
156
|
}
|
|
161
157
|
|
|
158
|
+
if self.onPmTokenDidReturn != nil {
|
|
159
|
+
self.onPmTokenDidReturn!(data)
|
|
160
|
+
}
|
|
161
|
+
completion(.success)
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
func paymentTokenNotAvailable(error: (Error)?) {
|
|
165
|
+
debugPrint("paymentTokenNotAvailable")
|
|
166
|
+
if self.onPmError != nil {
|
|
167
|
+
self.onPmError!(["error": error?.localizedDescription ?? "Payment token not available due to unexpected error"])
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
func paymentError(error: Error) {
|
|
173
|
+
debugPrint("payment error \(error)")
|
|
174
|
+
if self.onPmError != nil {
|
|
175
|
+
self.onPmError!(["error": error.localizedDescription])
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
func paymentSheetDidMDismiss() {
|
|
180
|
+
if self.onPmSheetDidDismiss != nil {
|
|
181
|
+
self.onPmSheetDidDismiss!(["token": "null"])
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
func didSelectPaymentMethod(_ paymentMethod: PKPaymentMethod, handler completion: @escaping (PKPaymentRequestPaymentMethodUpdate) -> Void) {
|
|
186
|
+
if let callback = self.onPaymentMethodSelected {
|
|
187
|
+
onPaymentMethodSelectedCompletion = completion
|
|
188
|
+
|
|
189
|
+
var data: [String: Any] = [:]
|
|
190
|
+
data["paymentMethod"] = ApplePayUtils.pkPaymentMethodToDict(paymentMethod)
|
|
191
|
+
callback(data)
|
|
192
|
+
|
|
193
|
+
let updatedSummaryItems = createSummaryItems()
|
|
194
|
+
let update = PKPaymentRequestPaymentMethodUpdate(paymentSummaryItems: updatedSummaryItems)
|
|
195
|
+
completion(update)
|
|
196
|
+
} else {
|
|
197
|
+
debugPrint("No payment method selected")
|
|
198
|
+
let updatedSummaryItems = createSummaryItems()
|
|
199
|
+
let update = PKPaymentRequestPaymentMethodUpdate(paymentSummaryItems: updatedSummaryItems)
|
|
200
|
+
completion(update)
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
func didSelectShippingContact(_ contact: PKContact, handler completion: @escaping (PKPaymentRequestShippingContactUpdate) -> Void) {
|
|
205
|
+
if let callback = self.onShippingContactSelected {
|
|
206
|
+
onShippingContactSelectedCompletion = completion
|
|
207
|
+
|
|
208
|
+
var data: [String: Any] = [:]
|
|
209
|
+
data["contact"] = ApplePayUtils.pkContactToDict(contact)
|
|
210
|
+
callback(data)
|
|
211
|
+
|
|
212
|
+
let updatedSummaryItems = createSummaryItems()
|
|
213
|
+
let update = PKPaymentRequestShippingContactUpdate(paymentSummaryItems: updatedSummaryItems)
|
|
214
|
+
completion(update)
|
|
215
|
+
} else {
|
|
216
|
+
debugPrint("No shippig contact selected")
|
|
217
|
+
let updatedSummaryItems = createSummaryItems()
|
|
218
|
+
let update = PKPaymentRequestShippingContactUpdate(paymentSummaryItems: updatedSummaryItems)
|
|
219
|
+
completion(update)
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
func didSelectShippingMethod(_ shippingMethod: PKShippingMethod, handler completion: @escaping (PKPaymentRequestShippingMethodUpdate) -> Void) {
|
|
224
|
+
if let callback = self.onShippingMethodSelected {
|
|
225
|
+
onShippingMethodSelectedCompletion = completion
|
|
226
|
+
|
|
227
|
+
var data: [String: Any] = [:]
|
|
228
|
+
data["shippingMethod"] = ApplePayUtils.pkShippingMethodToDict(shippingMethod)
|
|
229
|
+
callback(data)
|
|
230
|
+
|
|
231
|
+
let updatedSummaryItems = createSummaryItems()
|
|
232
|
+
let update = PKPaymentRequestShippingMethodUpdate(paymentSummaryItems: updatedSummaryItems)
|
|
233
|
+
completion(update)
|
|
234
|
+
} else {
|
|
235
|
+
debugPrint("No shippig method selected")
|
|
236
|
+
let updatedSummaryItems = createSummaryItems()
|
|
237
|
+
let update = PKPaymentRequestShippingMethodUpdate(paymentSummaryItems: updatedSummaryItems)
|
|
238
|
+
completion(update)
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
|
|
162
244
|
}
|
|
163
245
|
|
|
164
246
|
|
|
165
247
|
@objc(RNPEApplePayButtonManager)
|
|
166
248
|
class RNPEApplePayButtonManager: RCTViewManager {
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
249
|
+
|
|
250
|
+
var _view = RNPEApplePayButton()
|
|
251
|
+
|
|
252
|
+
@objc override static func requiresMainQueueSetup() -> Bool {
|
|
253
|
+
return true
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
override func view() -> UIView! {
|
|
257
|
+
return _view
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
@objc(updatePaymentSheet:summaryItems:shippingMethods:errors:)
|
|
261
|
+
func updatePaymentSheet(_ node: NSNumber, summaryItems: NSArray, shippingMethods: NSArray, errors: [NSDictionary])
|
|
262
|
+
{
|
|
263
|
+
debugPrint("updatePlatformPaySheet is called from manager")
|
|
264
|
+
DispatchQueue.main.async {
|
|
265
|
+
let component = self.bridge.uiManager.view(forReactTag: node) as! RNPEApplePayButton
|
|
266
|
+
component.updatePaymentSheet(summaryItems: summaryItems, shippingMethods: shippingMethods, errors: errors)
|
|
176
267
|
}
|
|
177
|
-
|
|
268
|
+
}
|
|
269
|
+
|
|
178
270
|
}
|
|
271
|
+
|