react-native-payengine 2.0.17 → 2.0.18-alpha.1

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 (156) hide show
  1. package/README.md +96 -65
  2. package/android/.gradle/checksums/checksums.lock +0 -0
  3. package/android/.gradle/checksums/md5-checksums.bin +0 -0
  4. package/android/.gradle/checksums/sha1-checksums.bin +0 -0
  5. package/android/build.gradle +2 -2
  6. package/android/src/main/java/com/reactnativepayengine/v2/RNPayEngineNative.kt +65 -3
  7. package/android/src/main/java/com/reactnativepayengine/v2/securefields/RNPEEvents.kt +1 -0
  8. package/android/src/main/java/com/reactnativepayengine/v2/securefields/bankaccount/RNBankAccountViewManager.kt +16 -3
  9. package/android/src/main/java/com/reactnativepayengine/v2/securefields/creditcard/RNPECreditCardViewManager.kt +15 -4
  10. package/ios/PayEngineSDK.xcframework/Info.plist +5 -5
  11. package/ios/PayEngineSDK.xcframework/ios-arm64/PayEngineSDK.framework/Headers/KDataCollector.h +4 -25
  12. package/ios/PayEngineSDK.xcframework/ios-arm64/PayEngineSDK.framework/Headers/KountAnalyticsViewController.h +0 -20
  13. package/ios/PayEngineSDK.xcframework/ios-arm64/PayEngineSDK.framework/Headers/KountPrivate.h +61 -0
  14. package/ios/PayEngineSDK.xcframework/ios-arm64/PayEngineSDK.framework/Headers/PayEngineSDK-Swift.h +430 -149
  15. package/ios/PayEngineSDK.xcframework/ios-arm64/PayEngineSDK.framework/Info.plist +0 -0
  16. package/ios/PayEngineSDK.xcframework/ios-arm64/PayEngineSDK.framework/Modules/PayEngineSDK.swiftmodule/arm64-apple-ios.abi.json +1962 -5715
  17. package/ios/PayEngineSDK.xcframework/ios-arm64/PayEngineSDK.framework/Modules/PayEngineSDK.swiftmodule/arm64-apple-ios.private.swiftinterface +35 -129
  18. package/ios/PayEngineSDK.xcframework/ios-arm64/PayEngineSDK.framework/Modules/PayEngineSDK.swiftmodule/arm64-apple-ios.private.swiftinterface-e +35 -129
  19. package/ios/PayEngineSDK.xcframework/ios-arm64/PayEngineSDK.framework/Modules/PayEngineSDK.swiftmodule/arm64-apple-ios.swiftdoc +0 -0
  20. package/ios/PayEngineSDK.xcframework/ios-arm64/PayEngineSDK.framework/Modules/PayEngineSDK.swiftmodule/arm64-apple-ios.swiftinterface +35 -129
  21. package/ios/PayEngineSDK.xcframework/ios-arm64/PayEngineSDK.framework/Modules/PayEngineSDK.swiftmodule/arm64-apple-ios.swiftinterface-e +35 -129
  22. package/ios/PayEngineSDK.xcframework/ios-arm64/PayEngineSDK.framework/PayEngineSDK +0 -0
  23. package/ios/PayEngineSDK.xcframework/ios-arm64/PayEngineSDK.framework/VGSCollectSDK_VGSCollectSDK.bundle/Assets.car +0 -0
  24. package/ios/PayEngineSDK.xcframework/ios-arm64/PayEngineSDK.framework/VGSCollectSDK_VGSCollectSDK.bundle/Info.plist +0 -0
  25. package/ios/PayEngineSDK.xcframework/ios-arm64_x86_64-simulator/PayEngineSDK.framework/Headers/KDataCollector.h +4 -25
  26. package/ios/PayEngineSDK.xcframework/ios-arm64_x86_64-simulator/PayEngineSDK.framework/Headers/KountAnalyticsViewController.h +0 -20
  27. package/ios/PayEngineSDK.xcframework/ios-arm64_x86_64-simulator/PayEngineSDK.framework/Headers/KountPrivate.h +61 -0
  28. package/ios/PayEngineSDK.xcframework/ios-arm64_x86_64-simulator/PayEngineSDK.framework/Headers/PayEngineSDK-Swift.h +860 -298
  29. package/ios/PayEngineSDK.xcframework/ios-arm64_x86_64-simulator/PayEngineSDK.framework/Info.plist +0 -0
  30. package/ios/PayEngineSDK.xcframework/ios-arm64_x86_64-simulator/PayEngineSDK.framework/Modules/PayEngineSDK.swiftmodule/arm64-apple-ios-simulator.abi.json +1962 -5715
  31. package/ios/PayEngineSDK.xcframework/ios-arm64_x86_64-simulator/PayEngineSDK.framework/Modules/PayEngineSDK.swiftmodule/arm64-apple-ios-simulator.private.swiftinterface +35 -129
  32. package/ios/PayEngineSDK.xcframework/ios-arm64_x86_64-simulator/PayEngineSDK.framework/Modules/PayEngineSDK.swiftmodule/arm64-apple-ios-simulator.private.swiftinterface-e +35 -129
  33. package/ios/PayEngineSDK.xcframework/ios-arm64_x86_64-simulator/PayEngineSDK.framework/Modules/PayEngineSDK.swiftmodule/arm64-apple-ios-simulator.swiftdoc +0 -0
  34. package/ios/PayEngineSDK.xcframework/ios-arm64_x86_64-simulator/PayEngineSDK.framework/Modules/PayEngineSDK.swiftmodule/arm64-apple-ios-simulator.swiftinterface +35 -129
  35. package/ios/PayEngineSDK.xcframework/ios-arm64_x86_64-simulator/PayEngineSDK.framework/Modules/PayEngineSDK.swiftmodule/arm64-apple-ios-simulator.swiftinterface-e +35 -129
  36. package/ios/PayEngineSDK.xcframework/ios-arm64_x86_64-simulator/PayEngineSDK.framework/Modules/PayEngineSDK.swiftmodule/x86_64-apple-ios-simulator.abi.json +1962 -5715
  37. package/ios/PayEngineSDK.xcframework/ios-arm64_x86_64-simulator/PayEngineSDK.framework/Modules/PayEngineSDK.swiftmodule/x86_64-apple-ios-simulator.private.swiftinterface +35 -129
  38. package/ios/PayEngineSDK.xcframework/ios-arm64_x86_64-simulator/PayEngineSDK.framework/Modules/PayEngineSDK.swiftmodule/x86_64-apple-ios-simulator.private.swiftinterface-e +35 -129
  39. package/ios/PayEngineSDK.xcframework/ios-arm64_x86_64-simulator/PayEngineSDK.framework/Modules/PayEngineSDK.swiftmodule/x86_64-apple-ios-simulator.swiftdoc +0 -0
  40. package/ios/PayEngineSDK.xcframework/ios-arm64_x86_64-simulator/PayEngineSDK.framework/Modules/PayEngineSDK.swiftmodule/x86_64-apple-ios-simulator.swiftinterface +35 -129
  41. package/ios/PayEngineSDK.xcframework/ios-arm64_x86_64-simulator/PayEngineSDK.framework/Modules/PayEngineSDK.swiftmodule/x86_64-apple-ios-simulator.swiftinterface-e +35 -129
  42. package/ios/PayEngineSDK.xcframework/ios-arm64_x86_64-simulator/PayEngineSDK.framework/PayEngineSDK +0 -0
  43. package/ios/PayEngineSDK.xcframework/ios-arm64_x86_64-simulator/PayEngineSDK.framework/VGSCollectSDK_VGSCollectSDK.bundle/Info.plist +0 -0
  44. package/ios/Sources/Classes/RNPEEventEmitter.swift +1 -1
  45. package/ios/Sources/Classes/RNPayEngineNative.swift +125 -64
  46. package/ios/Sources/Classes/SecureFields/RNPEEvents.swift +1 -0
  47. package/ios/Sources/Payengine.m +6 -0
  48. package/lib/commonjs/components/PayEngine.js +1 -1
  49. package/lib/commonjs/components/PayEngine.js.map +1 -1
  50. package/lib/commonjs/components/v2/ApplePay/PEApplePayButton.js +124 -0
  51. package/lib/commonjs/components/v2/ApplePay/PEApplePayButton.js.map +1 -1
  52. package/lib/commonjs/components/v2/ApplePay/PEApplePayInterfaces.js +78 -0
  53. package/lib/commonjs/components/v2/ApplePay/PEApplePayInterfaces.js.map +1 -1
  54. package/lib/commonjs/components/v2/GooglePay/PEGooglePayAddress.js.map +1 -1
  55. package/lib/commonjs/components/v2/GooglePay/PEGooglePayButton.js +53 -0
  56. package/lib/commonjs/components/v2/GooglePay/PEGooglePayButton.js.map +1 -1
  57. package/lib/commonjs/components/v2/PEPaymentRequest.js +121 -0
  58. package/lib/commonjs/components/v2/PEPaymentRequest.js.map +1 -1
  59. package/lib/commonjs/components/v2/PayEngineNative.js +182 -4
  60. package/lib/commonjs/components/v2/PayEngineNative.js.map +1 -1
  61. package/lib/commonjs/components/v2/PayEngineProvider.js +52 -0
  62. package/lib/commonjs/components/v2/PayEngineProvider.js.map +1 -1
  63. package/lib/commonjs/components/v2/SecureFields/BankAccountView.js +71 -0
  64. package/lib/commonjs/components/v2/SecureFields/BankAccountView.js.map +1 -1
  65. package/lib/commonjs/components/v2/SecureFields/CreditCardView.js +82 -0
  66. package/lib/commonjs/components/v2/SecureFields/CreditCardView.js.map +1 -1
  67. package/lib/commonjs/components/v2/SecureFields/IPEField.js.map +1 -1
  68. package/lib/commonjs/components/v2/SecureFields/ITokenizationData.js.map +1 -1
  69. package/lib/commonjs/components/v2/SecureFields/PEBankAccount.js.map +1 -1
  70. package/lib/commonjs/components/v2/SecureFields/PECard.js.map +1 -1
  71. package/lib/commonjs/components/v2/SecureFields/PEKeyboardType.js +20 -3
  72. package/lib/commonjs/components/v2/SecureFields/PEKeyboardType.js.map +1 -1
  73. package/lib/commonjs/index.js +17 -13
  74. package/lib/commonjs/index.js.map +1 -1
  75. package/lib/commonjs/interfaces/index.js +20 -0
  76. package/lib/commonjs/interfaces/index.js.map +1 -1
  77. package/lib/commonjs/utils/index.js +26 -0
  78. package/lib/commonjs/utils/index.js.map +1 -1
  79. package/lib/module/components/PayEngine.js +1 -1
  80. package/lib/module/components/PayEngine.js.map +1 -1
  81. package/lib/module/components/v2/ApplePay/PEApplePayButton.js +124 -0
  82. package/lib/module/components/v2/ApplePay/PEApplePayButton.js.map +1 -1
  83. package/lib/module/components/v2/ApplePay/PEApplePayInterfaces.js +75 -0
  84. package/lib/module/components/v2/ApplePay/PEApplePayInterfaces.js.map +1 -1
  85. package/lib/module/components/v2/GooglePay/PEGooglePayAddress.js.map +1 -1
  86. package/lib/module/components/v2/GooglePay/PEGooglePayButton.js +53 -0
  87. package/lib/module/components/v2/GooglePay/PEGooglePayButton.js.map +1 -1
  88. package/lib/module/components/v2/PEPaymentRequest.js +119 -0
  89. package/lib/module/components/v2/PEPaymentRequest.js.map +1 -1
  90. package/lib/module/components/v2/PayEngineNative.js +184 -5
  91. package/lib/module/components/v2/PayEngineNative.js.map +1 -1
  92. package/lib/module/components/v2/PayEngineProvider.js +51 -0
  93. package/lib/module/components/v2/PayEngineProvider.js.map +1 -1
  94. package/lib/module/components/v2/SecureFields/BankAccountView.js +71 -0
  95. package/lib/module/components/v2/SecureFields/BankAccountView.js.map +1 -1
  96. package/lib/module/components/v2/SecureFields/CreditCardView.js +82 -0
  97. package/lib/module/components/v2/SecureFields/CreditCardView.js.map +1 -1
  98. package/lib/module/components/v2/SecureFields/IPEField.js.map +1 -1
  99. package/lib/module/components/v2/SecureFields/ITokenizationData.js.map +1 -1
  100. package/lib/module/components/v2/SecureFields/PEBankAccount.js.map +1 -1
  101. package/lib/module/components/v2/SecureFields/PECard.js.map +1 -1
  102. package/lib/module/components/v2/SecureFields/PEKeyboardType.js +16 -1
  103. package/lib/module/components/v2/SecureFields/PEKeyboardType.js.map +1 -1
  104. package/lib/module/index.js +10 -5
  105. package/lib/module/index.js.map +1 -1
  106. package/lib/module/interfaces/index.js +19 -0
  107. package/lib/module/interfaces/index.js.map +1 -1
  108. package/lib/module/utils/index.js +27 -0
  109. package/lib/module/utils/index.js.map +1 -1
  110. package/lib/typescript/components/PayEngine.d.ts +1 -1
  111. package/lib/typescript/components/v2/ApplePay/PEApplePayButton.d.ts +217 -12
  112. package/lib/typescript/components/v2/ApplePay/PEApplePayInterfaces.d.ts +180 -1
  113. package/lib/typescript/components/v2/GooglePay/PEGooglePayAddress.d.ts +30 -0
  114. package/lib/typescript/components/v2/GooglePay/PEGooglePayButton.d.ts +99 -0
  115. package/lib/typescript/components/v2/PEPaymentRequest.d.ts +130 -9
  116. package/lib/typescript/components/v2/PayEngineNative.d.ts +165 -7
  117. package/lib/typescript/components/v2/PayEngineProvider.d.ts +51 -0
  118. package/lib/typescript/components/v2/SecureFields/BankAccountView.d.ts +103 -0
  119. package/lib/typescript/components/v2/SecureFields/CreditCardView.d.ts +114 -0
  120. package/lib/typescript/components/v2/SecureFields/IPEField.d.ts +49 -0
  121. package/lib/typescript/components/v2/SecureFields/ITokenizationData.d.ts +14 -0
  122. package/lib/typescript/components/v2/SecureFields/PEBankAccount.d.ts +36 -0
  123. package/lib/typescript/components/v2/SecureFields/PECard.d.ts +44 -0
  124. package/lib/typescript/components/v2/SecureFields/PEKeyboardType.d.ts +16 -1
  125. package/lib/typescript/index.d.ts +11 -5
  126. package/lib/typescript/interfaces/index.d.ts +35 -1
  127. package/lib/typescript/utils/index.d.ts +21 -0
  128. package/package.json +6 -3
  129. package/src/components/PayEngine.tsx +1 -1
  130. package/src/components/v2/ApplePay/PEApplePayButton.tsx +225 -12
  131. package/src/components/v2/ApplePay/PEApplePayInterfaces.ts +221 -8
  132. package/src/components/v2/GooglePay/PEGooglePayAddress.ts +39 -1
  133. package/src/components/v2/GooglePay/PEGooglePayButton.tsx +113 -9
  134. package/src/components/v2/PEPaymentRequest.ts +151 -13
  135. package/src/components/v2/PayEngineNative.tsx +196 -9
  136. package/src/components/v2/PayEngineProvider.tsx +52 -1
  137. package/src/components/v2/SecureFields/BankAccountView.tsx +108 -1
  138. package/src/components/v2/SecureFields/CreditCardView.tsx +118 -1
  139. package/src/components/v2/SecureFields/IPEField.ts +55 -0
  140. package/src/components/v2/SecureFields/ITokenizationData.ts +17 -2
  141. package/src/components/v2/SecureFields/PEBankAccount.ts +42 -0
  142. package/src/components/v2/SecureFields/PECard.ts +52 -0
  143. package/src/components/v2/SecureFields/PEKeyboardType.ts +18 -1
  144. package/src/index.tsx +23 -5
  145. package/src/interfaces/index.ts +40 -2
  146. package/src/utils/index.ts +21 -0
  147. package/android/.gradle/6.1.1/executionHistory/executionHistory.lock +0 -0
  148. package/android/.gradle/6.1.1/fileChanges/last-build.bin +0 -0
  149. package/android/.gradle/6.1.1/fileHashes/fileHashes.lock +0 -0
  150. package/android/.gradle/6.1.1/gc.properties +0 -0
  151. package/ios/PayEngineSDK.xcframework/ios-arm64/PayEngineSDK.framework/Headers/CustomWindow.h +0 -25
  152. package/ios/PayEngineSDK.xcframework/ios-arm64/PayEngineSDK.framework/Headers/UIControl+CustomControl.h +0 -33
  153. package/ios/PayEngineSDK.xcframework/ios-arm64/PayEngineSDK.framework/Headers/UIViewController+TouchControl.h +0 -27
  154. package/ios/PayEngineSDK.xcframework/ios-arm64_x86_64-simulator/PayEngineSDK.framework/Headers/CustomWindow.h +0 -25
  155. package/ios/PayEngineSDK.xcframework/ios-arm64_x86_64-simulator/PayEngineSDK.framework/Headers/UIControl+CustomControl.h +0 -33
  156. package/ios/PayEngineSDK.xcframework/ios-arm64_x86_64-simulator/PayEngineSDK.framework/Headers/UIViewController+TouchControl.h +0 -27
@@ -10,82 +10,143 @@ import PayEngineSDK
10
10
 
11
11
  @objc(RNPayEngineNative)
12
12
  class RNPayEngineNative: NSObject {
13
- static var instance: PayEngine?
13
+ static var instance: PayEngine?
14
+
15
+ static var applePayInstance: PEApplePay?
16
+
17
+
18
+ private var resultFromJS: [String: Any]?
19
+ private var semaphore: DispatchSemaphore?
20
+ private var accessTokenProvider: (() throws -> PEAccessTokenRepresentable)?
21
+
22
+ @objc(setConfig:baseURL:)
23
+ func setConfig(_ publicKey: String, baseURL: String?) {
24
+ let config = PEConfig(publicKey: publicKey, baseURL: baseURL)
25
+ RNPayEngineNative.instance = PayEngine(config: config)
14
26
 
15
- static var applePayInstance: PEApplePay?
16
-
17
- @objc(setConfig:baseURL:)
18
- func setConfig(_ publicKey: String, baseURL: String?) {
19
- let config = PEConfig(publicKey: publicKey, baseURL: baseURL)
20
- RNPayEngineNative.instance = PayEngine(config: config)
21
-
22
- debugPrint("PayEngine Plugin setConfig successfully. Current native SDK version: \(PayEngine.getCurrentVersionString() ?? "")")
27
+ debugPrint("PayEngine Plugin setConfig successfully. Current native SDK version: \(PayEngine.getCurrentVersionString() ?? "")")
28
+ }
29
+
30
+ func getInstance() throws -> PayEngine {
31
+ guard let instance = RNPayEngineNative.instance else {
32
+ throw RNPEError.common("Configuration is not set")
23
33
  }
24
34
 
25
- func getInstance() throws -> PayEngine {
26
- guard let instance = RNPayEngineNative.instance else {
27
- throw RNPEError.common("Configuration is not set")
35
+ return instance
36
+ }
37
+
38
+ @objc(createFraudMonitorSession:resolver:rejecter:)
39
+ func createFraudMonitorSession(merchantId: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
40
+ DispatchQueue.main.async {
41
+ do {
42
+ let payengine = try self.getInstance()
43
+ payengine.createFraudMonitorSession(merchantId) { fraudResult in
44
+ switch fraudResult {
45
+ case .success(let sessionId):
46
+ return resolve(sessionId)
47
+ case .failure(let error):
48
+ return reject("error", "Unable to obtain session ID", error)
49
+ }
28
50
  }
29
-
30
- return instance
51
+ } catch {
52
+ return reject("error", error.localizedDescription, error)
53
+ }
31
54
  }
32
-
33
- @objc(createFraudMonitorSession:resolver:rejecter:)
34
- func createFraudMonitorSession(merchantId: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
35
- DispatchQueue.main.async {
36
- do {
37
- let payengine = try self.getInstance()
38
- payengine.createFraudMonitorSession(merchantId) { fraudResult in
39
- switch fraudResult {
40
- case .success(let sessionId):
41
- return resolve(sessionId)
42
- case .failure(let error):
43
- return reject("error", "Unable to obtain session ID", error)
44
- }
45
- }
46
- } catch {
47
- return reject("error", error.localizedDescription, error)
48
- }
55
+ }
56
+
57
+ @objc(getBrowserInfo:rejecter:)
58
+ func getBrowserInfo(resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
59
+ DispatchQueue.main.async {
60
+ do {
61
+ // get current root view from react native
62
+ if let rootView = UIApplication.shared.keyWindow?.rootViewController?.view {
63
+ let payengine = try self.getInstance()
64
+ payengine.getBrowserInfo(view: rootView) { browserInfo in
65
+ return resolve(browserInfo)
66
+ }
67
+ } else {
68
+ return reject("error", "Unable to find current root view", nil)
49
69
  }
70
+ } catch {
71
+ return reject("error", error.localizedDescription, error)
72
+ }
50
73
  }
51
-
52
- @objc(getBrowserInfo:rejecter:)
53
- func getBrowserInfo(resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
54
- DispatchQueue.main.async {
55
- do {
56
- // get current root view from react native
57
- if let rootView = UIApplication.shared.keyWindow?.rootViewController?.view {
58
- let payengine = try self.getInstance()
59
- payengine.getBrowserInfo(view: rootView) { browserInfo in
60
- return resolve(browserInfo)
61
- }
62
- } else {
63
- return reject("error", "Unable to find current root view", nil)
64
- }
65
- } catch {
66
- return reject("error", error.localizedDescription, error)
67
- }
74
+ }
75
+
76
+ @objc(isApplePaySupported:resolver:rejecter:)
77
+ func isApplePaySupported(merchantId: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
78
+ do {
79
+ let payengine = try self.getInstance()
80
+ payengine.setupApplePay(merchantId: merchantId) { result in
81
+ switch result {
82
+ case .success(let applepay):
83
+ RNPayEngineNative.applePayInstance = applepay
84
+ return resolve(true)
85
+ case .failure(let error):
86
+ return reject("error", error.localizedDescription, error)
68
87
  }
88
+ }
89
+ } catch {
90
+ return reject("error", error.localizedDescription, error)
91
+ }
92
+ }
93
+
94
+
95
+
96
+ @objc(configureFetchAccessTokenCallback:rejecter:)
97
+ func configureFetchAccessTokenCallback(resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
98
+ resolve(nil)
99
+ accessTokenProvider = { [weak self] in
100
+ guard let self = self else {
101
+ throw NSError(domain: "com.payengine.error", code: 500, userInfo: [NSLocalizedDescriptionKey: "Instance deallocated"])
102
+ }
103
+
104
+ return try self.fetchAccessTokenFromReact()
69
105
  }
70
106
 
71
- @objc(isApplePaySupported:resolver:rejecter:)
72
- func isApplePaySupported(merchantId: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
73
- do {
74
- let payengine = try self.getInstance()
75
- payengine.setupApplePay(merchantId: merchantId) { result in
76
- switch result {
77
- case .success(let applepay):
78
- RNPayEngineNative.applePayInstance = applepay
79
- return resolve(true)
80
- case .failure(let error):
81
- return reject("error", error.localizedDescription, error)
82
- }
83
- }
84
- } catch {
85
- return reject("error", error.localizedDescription, error)
86
- }
107
+ PayEngine.setFetchAccessTokenCallback(accessTokenProvider!)
108
+ }
109
+
110
+ @objc(provideFetchAccessTokenResult:resolver:rejecter:)
111
+ func provideFetchAccessTokenResult(_ value: [String: Any]?, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
112
+ // Called from JS when value is ready
113
+ resolve(nil)
114
+ resultFromJS = value
115
+ semaphore?.signal()
116
+ }
117
+
118
+ private func fetchAccessTokenFromReact() throws -> PEAccessTokenRepresentable {
119
+ // Step 1: Send event
120
+ semaphore = DispatchSemaphore(value: 0)
121
+ RNPEEventEmitter.emitter.sendEvent(withName: RNPEEvents.EVENT_FETCH_ACCESS_TOKEN, body: nil)
122
+
123
+ // Step 2: Wait for JS to respond (up to 5 sec)
124
+ _ = semaphore?.wait(timeout: .now() + 5)
125
+
126
+ // Step 3: Use the result or fallback
127
+ if let accessToken = resultFromJS?["accessToken"] as? String,
128
+ let expiresIn = resultFromJS?["expiresIn"] as? Int64 {
129
+ return AccessToken(accessToken: accessToken, expiresIn: expiresIn)
87
130
  }
131
+
132
+ throw NSError(domain: "com.payengine.error", code: 500, userInfo: [NSLocalizedDescriptionKey: "nil values encountered"])
133
+ }
134
+
135
+ @objc(logout:resolver:rejecter:)
136
+ func logout(_ merchantId: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
137
+ PayEngine.logout(merchantId: merchantId)
138
+ resolve(nil)
139
+ }
88
140
  }
89
141
 
90
142
 
143
+ // Helper class to conform to the protocol
144
+ private class AccessToken: PEAccessTokenRepresentable {
145
+ let accessToken: String
146
+ let expiresIn: Int64
91
147
 
148
+ init(accessToken: String, expiresIn: Int64) {
149
+ self.accessToken = accessToken
150
+ self.expiresIn = expiresIn
151
+ }
152
+ }
@@ -12,4 +12,5 @@ class RNPEEvents {
12
12
  static let EVENT_BANK_ACCOUNT_RESPOND = "onBankAccountRespond"
13
13
  static let EVENT_CARD_RESPOND = "onCardRespond"
14
14
  static let EVENT_READY = "onReady"
15
+ static let EVENT_FETCH_ACCESS_TOKEN = "fetchAccessToken"
15
16
  }
@@ -14,6 +14,12 @@ RCT_EXTERN_METHOD(getBrowserInfo:(RCTPromiseResolveBlock)resolve rejecter:(RCTPr
14
14
 
15
15
  RCT_EXTERN_METHOD(isApplePaySupported:(NSString *)merchantId resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
16
16
 
17
+ RCT_EXTERN_METHOD(configureFetchAccessTokenCallback:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
18
+
19
+ RCT_EXTERN_METHOD(provideFetchAccessTokenResult:(NSDictionary *)value resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
20
+
21
+ RCT_EXTERN_METHOD(logout:(NSString *)merchantId resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
22
+
17
23
  + (BOOL)requiresMainQueueSetup
18
24
  {
19
25
  return NO;
@@ -11,7 +11,7 @@ var _reactNative = require("react-native");
11
11
 
12
12
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
13
 
14
- const PayEngine = () => {
14
+ const PayEngine = _props => {
15
15
  return /*#__PURE__*/_react.default.createElement(_reactNative.Text, null, "Obsolete. Please check out the package readme");
16
16
  };
17
17
 
@@ -1 +1 @@
1
- {"version":3,"names":["PayEngine"],"sources":["PayEngine.tsx"],"sourcesContent":["import React from 'react';\nimport { Text } from 'react-native';\n\nconst PayEngine = () => {\n return <Text>Obsolete. Please check out the package readme</Text>;\n};\n\nexport default PayEngine;\n"],"mappings":";;;;;;;AAAA;;AACA;;;;AAEA,MAAMA,SAAS,GAAG,MAAM;EACtB,oBAAO,6BAAC,iBAAD,wDAAP;AACD,CAFD;;eAIeA,S"}
1
+ {"version":3,"names":["PayEngine","_props"],"sources":["PayEngine.tsx"],"sourcesContent":["import React from 'react';\nimport { Text } from 'react-native';\n\nconst PayEngine = (_props: any) => {\n return <Text>Obsolete. Please check out the package readme</Text>;\n};\n\nexport default PayEngine;\n"],"mappings":";;;;;;;AAAA;;AACA;;;;AAEA,MAAMA,SAAS,GAAIC,MAAD,IAAiB;EACjC,oBAAO,6BAAC,iBAAD,wDAAP;AACD,CAFD;;eAIeD,S"}
@@ -21,6 +21,130 @@ const COMPONENT_NAME = 'RNPEApplePayButton';
21
21
  const RNPEApplePayButton = (0, _reactNative.requireNativeComponent)(COMPONENT_NAME); // @ts-ignore
22
22
 
23
23
  const RNPEApplePayButtonManager = _reactNative.UIManager[COMPONENT_NAME];
24
+
25
+ /**
26
+ * A React component for initiating an Apple Pay transaction.
27
+ *
28
+ * This button wraps the Apple Pay experience, including presenting the Apple Pay sheet,
29
+ * handling user interactions, processing the payment, and managing callbacks such as
30
+ * payment success, failure, and contact/method selection.
31
+ *
32
+ * It exposes imperative methods via `ref` to allow control over the Apple Pay sheet,
33
+ * such as updating summary items or shipping options in response to user input.
34
+ *
35
+ * ## Example Usage:
36
+ *
37
+ * ```tsx
38
+ * const paymentRequest = {
39
+ * merchantId: "merchant.com.example",
40
+ * countryCode: "US",
41
+ * currencyCode: "USD",
42
+ * paymentAmount: 10.00,
43
+ * paymentSummaryItems: [
44
+ * { label: "Test Item", amount: "10.00" }
45
+ * ],
46
+ * requiredShippingContactFields: ["name", "postalAddress"]
47
+ * };
48
+ *
49
+ * <PEApplePayButton
50
+ * paymentRequest={paymentRequest}
51
+ *
52
+ * // Triggered when payment fails
53
+ * onPaymentFailed={(error) => console.error("Payment failed:", error)}
54
+ *
55
+ * // Triggered when Apple Pay sheet is dismissed by the user
56
+ * onPaymentSheetDismissed={() => console.log("Payment sheet dismissed")}
57
+ *
58
+ * // Triggered when a valid token is generated after successful Apple Pay authorization
59
+ * onTokenDidReturn={(token, metadata, billingContact, shippingContact) => {
60
+ * console.log('Apple Pay token:', token, metadata, billingContact, shippingContact);
61
+ * // TODO: Send token to your server for processing
62
+ * purchaseWithToken(token);
63
+ * }}
64
+ *
65
+ * // Triggered when user selects or updates their shipping contact info
66
+ * onShippingContactSelected={(event) => {
67
+ * console.log('onShippingContactSelected', event.nativeEvent);
68
+ *
69
+ * if (!event.nativeEvent.contact.postalCode) {
70
+ * // Invalid postal code — update Apple Pay sheet with an error
71
+ * buttonRef?.current?.updatePaymentSheet([], [], [{
72
+ * errorType: PEApplePaySheetErrorType.InvalidShippingAddress,
73
+ * field: PEApplePayInvalidShippingField.PostalCode,
74
+ * message: 'Please update postal code to continue'
75
+ * }]);
76
+ * } else {
77
+ * // Provide updated shipping methods if contact is valid
78
+ * buttonRef?.current?.updatePaymentSheet([], [
79
+ * {
80
+ * identifier: 'new-shipping1',
81
+ * label: 'Updated shipping 1',
82
+ * amount: 3.99
83
+ * },
84
+ * {
85
+ * identifier: 'new-shipping2',
86
+ * label: 'Updated shipping 2',
87
+ * amount: 5.99
88
+ * }
89
+ * ], []);
90
+ * }
91
+ * }}
92
+ *
93
+ * // Triggered when user selects a shipping method
94
+ * onShippingMethodSelected={(event) => {
95
+ * console.log('onShippingMethodSelected', event.nativeEvent);
96
+ *
97
+ * const shippingFee = event.nativeEvent.shippingMethod.amount;
98
+ * const items = [
99
+ * {
100
+ * label: 'Product price',
101
+ * amount: paymentRequest.paymentAmount
102
+ * },
103
+ * ...(shippingFee > 0 ? [{
104
+ * label: 'Shipping Fee',
105
+ * amount: shippingFee
106
+ * }] : []),
107
+ * {
108
+ * label: 'Total',
109
+ * amount: paymentRequest.paymentAmount + shippingFee
110
+ * }
111
+ * ];
112
+ *
113
+ * buttonRef?.current?.updatePaymentSheet(items, [], []);
114
+ * }}
115
+ *
116
+ * // Triggered when user selects a payment method (e.g., credit, debit)
117
+ * onPaymentMethodSelected={(event) => {
118
+ * console.log('onPaymentMethodSelected', event.nativeEvent);
119
+ *
120
+ * const isCredit = event.nativeEvent.paymentMethod.type === PEApplePayPaymentMethodType.credit;
121
+ * const items = [
122
+ * {
123
+ * label: 'Product price',
124
+ * amount: paymentRequest.paymentAmount
125
+ * },
126
+ * ...(isCredit ? [{
127
+ * label: 'Credit discount',
128
+ * amount: 10
129
+ * }] : []),
130
+ * {
131
+ * label: 'Total',
132
+ * amount: paymentRequest.paymentAmount - (isCredit ? 1.00 : 0.00)
133
+ * }
134
+ * ];
135
+ *
136
+ * buttonRef?.current?.updatePaymentSheet(items, [], []);
137
+ * }}
138
+ *
139
+ * ref={applePayRef}
140
+ * />
141
+ * ```
142
+ *
143
+ * @param props - The props for configuring the Apple Pay button behavior.
144
+ * @param ref - A ref to access Apple Pay sheet update methods imperatively.
145
+ *
146
+ * @category Apple Pay
147
+ */
24
148
  const PEApplePayButton = /*#__PURE__*/React.forwardRef((props, ref) => {
25
149
  const buttonRef = React.useRef();
26
150
  React.useImperativeHandle(ref, () => ({
@@ -1 +1 @@
1
- {"version":3,"names":["RNPEEventEmitter","NativeModules","peEventEmitter","NativeEventEmitter","COMPONENT_NAME","RNPEApplePayButton","requireNativeComponent","RNPEApplePayButtonManager","UIManager","PEApplePayButton","React","forwardRef","props","ref","buttonRef","useRef","useImperativeHandle","updatePaymentSheet","summaryItems","shippingMethods","errors","Promise","resolve","reject","listener","addListener","args","remove","error","Error","callNativeMethod","useEffect","console","log","useCallback","methodName","params","viewId","findNodeHandle","current","commandId","Commands","toString","Platform","OS","Number","dispatchViewManagerCommand","pmError","event","onPaymentFailed","nativeEvent","pmTokenDidReturn","onTokenDidReturn","token","metadata","metadataString","billingContact","billingContactString","shippingContact","shippingContactString","JSON","parse","undefined","pmSheetDidDismiss","onPaymentSheetDismissed","height","width","style","stringify","paymentRequest","platformOptions","onPaymentMethodSelected","onShippingContactSelected","onShippingMethodSelected"],"sources":["PEApplePayButton.tsx"],"sourcesContent":["import * as React from 'react';\nimport {\n findNodeHandle,\n NativeEventEmitter,\n NativeModules,\n Platform,\n requireNativeComponent,\n Text,\n UIManager,\n ViewProps,\n} from 'react-native';\nimport type { PEPaymentRequest, PESummaryItem } from '../PEPaymentRequest';\nimport type {\n PEApplePayContact,\n PEApplePayPaymentMethod,\n PEApplePaySheetError,\n PEApplePayShippingMethod,\n} from './PEApplePayInterfaces';\n\nconst { RNPEEventEmitter } = NativeModules;\n\nconst peEventEmitter = new NativeEventEmitter(RNPEEventEmitter);\n\nconst COMPONENT_NAME = 'RNPEApplePayButton';\nconst RNPEApplePayButton =\n requireNativeComponent<NativePEApplePayViewProps>(COMPONENT_NAME);\n\n// @ts-ignore\nconst RNPEApplePayButtonManager = UIManager[COMPONENT_NAME];\n\ntype NativePEApplePayEvent = {\n nativeEvent: {\n error?: string;\n token?: string;\n metadata?: any;\n billingContact?: string;\n shippingContact?: string;\n paymentMethod?: string;\n contact?: string;\n shippingMethod?: string;\n };\n};\n\ninterface NativePEApplePayViewProps extends ViewProps {\n paymentRequest: string;\n onPmSheetDidDismiss: (event: NativePEApplePayEvent) => void;\n onPmTokenDidReturn: (event: NativePEApplePayEvent) => void;\n onPmError: (event: NativePEApplePayEvent) => void;\n onPaymentMethodSelected?: (event: {\n nativeEvent: {\n paymentMethod: PEApplePayPaymentMethod;\n };\n }) => void;\n onShippingContactSelected?: (event: {\n nativeEvent: {\n contact: PEApplePayContact;\n };\n }) => void;\n onShippingMethodSelected?: (event: {\n nativeEvent: {\n shippingMethod: PEApplePayShippingMethod;\n };\n }) => void;\n}\n\nexport interface PEApplePayButtonProps extends ViewProps {\n paymentRequest: PEPaymentRequest;\n onTokenDidReturn?: (\n token: string,\n metadata?: any,\n billingContact?: PEApplePayContact,\n shippingContact?: PEApplePayContact\n ) => void;\n onPaymentSheetDismissed?: () => void;\n onPaymentFailed?: (error: Error) => void;\n /**\n * This callback is triggered whenever the payment method changes in the Apple Pay sheet.\n * You MUST update the Apple Pay sheet in your callback using the updatePaymentSheet function,\n * otherwise the Apple Pay sheet will hang and the payment flow will automatically cancel.\n */\n onPaymentMethodSelected?: (event: {\n nativeEvent: {\n paymentMethod: PEApplePayPaymentMethod;\n };\n }) => void;\n /**\n * This callback is triggered whenever the user selects a shipping method in the Apple Pay sheet.\n * You MUST update the Apple Pay sheet in your callback using the updatePaymentSheet function,\n * otherwise the Apple Pay sheet will hang and the payment flow will automatically cancel.\n */\n onShippingContactSelected?: (event: {\n nativeEvent: {\n contact: PEApplePayContact;\n };\n }) => void;\n /**\n * This callback is triggered whenever the user selects a shipping contact in the Apple Pay sheet.\n * You MUST update the Apple Pay sheet in your callback using the updatePaymentSheet function,\n * otherwise the Apple Pay sheet will hang and the payment flow will automatically cancel.\n */\n onShippingMethodSelected?: (event: {\n nativeEvent: {\n shippingMethod: PEApplePayShippingMethod;\n };\n }) => void;\n}\n\nexport interface PEApplePayButtonMethods {\n /**\n * This method must be called after either onPaymentMethodSelected, onShippingContactSelected or\n * onShippingMethodSelected callbacks are triggered.\n * `shippingMethods` and `errors` are only applicable for onShippingContactSelected callback\n */\n updatePaymentSheet: (\n summaryItems: PESummaryItem[],\n shippingMethods: PEApplePayShippingMethod[],\n errors: PEApplePaySheetError[]\n ) => Promise<boolean>;\n}\n\nexport const PEApplePayButton = React.forwardRef<\n PEApplePayButtonMethods,\n PEApplePayButtonProps\n>((props, ref) => {\n const buttonRef = React.useRef<any>();\n\n React.useImperativeHandle(ref, () => ({\n updatePaymentSheet: async (\n summaryItems: PESummaryItem[],\n shippingMethods: PEApplePayShippingMethod[],\n errors: PEApplePaySheetError[]\n ): Promise<boolean> => {\n return new Promise((resolve, reject) => {\n const listener = peEventEmitter.addListener(\n 'onUpdatePaymentSheetResult',\n (args) => {\n listener.remove();\n\n const { error } = args;\n if (error) {\n reject(new Error(error));\n } else {\n resolve(true);\n }\n }\n );\n callNativeMethod('updatePaymentSheet', [\n summaryItems,\n shippingMethods,\n errors,\n ]);\n });\n },\n }));\n\n React.useEffect(() => {\n const listener = peEventEmitter.addListener(\n 'onUpdatePaymentSheetResult',\n (args) => {\n console.log('Received event onUpdatePaymentSheetResult', args);\n }\n );\n return () => {\n listener.remove();\n };\n }, []);\n\n const callNativeMethod = React.useCallback(\n (methodName: string, params: any[] = []) => {\n const viewId = findNodeHandle(buttonRef.current);\n let commandId = RNPEApplePayButtonManager.Commands[methodName].toString();\n if (Platform.OS === 'ios') {\n commandId = Number(commandId);\n }\n UIManager.dispatchViewManagerCommand(viewId, commandId, params);\n },\n [buttonRef.current]\n );\n\n const pmError = (event: NativePEApplePayEvent) => {\n if (props.onPaymentFailed) {\n props.onPaymentFailed(new Error(event.nativeEvent.error));\n }\n };\n\n const pmTokenDidReturn = (event: NativePEApplePayEvent) => {\n if (props.onTokenDidReturn) {\n const {\n token,\n metadata: metadataString,\n billingContact: billingContactString,\n shippingContact: shippingContactString,\n } = event.nativeEvent;\n console.log(\n 'ON token',\n token,\n metadataString,\n billingContactString,\n shippingContactString\n );\n const metadata = metadataString ? JSON.parse(metadataString) : null;\n const billingContact = billingContactString\n ? (JSON.parse(billingContactString) as PEApplePayContact)\n : null;\n const shippingContact = shippingContactString\n ? (JSON.parse(shippingContactString) as PEApplePayContact)\n : null;\n\n props.onTokenDidReturn(\n token!,\n metadata,\n billingContact ?? undefined,\n shippingContact ?? undefined\n );\n }\n };\n\n const pmSheetDidDismiss = () => {\n if (props.onPaymentSheetDismissed) {\n props.onPaymentSheetDismissed();\n }\n };\n\n if (Platform.OS !== 'ios') {\n return <Text>Apple Pay is not supported on this platform</Text>;\n }\n\n return (\n <RNPEApplePayButton\n ref={buttonRef}\n style={{ height: 32, width: '100%', ...(props.style as object) }}\n paymentRequest={JSON.stringify({\n ...props.paymentRequest,\n ...props.paymentRequest.platformOptions,\n })}\n onPmError={pmError}\n onPmTokenDidReturn={pmTokenDidReturn}\n onPmSheetDidDismiss={pmSheetDidDismiss}\n onPaymentMethodSelected={props.onPaymentMethodSelected}\n onShippingContactSelected={props.onShippingContactSelected}\n onShippingMethodSelected={props.onShippingMethodSelected}\n />\n );\n});\n"],"mappings":";;;;;;;AAAA;;AACA;;;;;;AAkBA,MAAM;EAAEA;AAAF,IAAuBC,0BAA7B;AAEA,MAAMC,cAAc,GAAG,IAAIC,+BAAJ,CAAuBH,gBAAvB,CAAvB;AAEA,MAAMI,cAAc,GAAG,oBAAvB;AACA,MAAMC,kBAAkB,GACtB,IAAAC,mCAAA,EAAkDF,cAAlD,CADF,C,CAGA;;AACA,MAAMG,yBAAyB,GAAGC,sBAAA,CAAUJ,cAAV,CAAlC;AA4FO,MAAMK,gBAAgB,gBAAGC,KAAK,CAACC,UAAN,CAG9B,CAACC,K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,CAACoD,uBAAV,EAAmC;MACjCpD,KAAK,CAACoD,uBAAN;IACD;EACF,CAJD;;EAMA,IAAIrB,qBAAA,CAASC,EAAT,KAAgB,KAApB,EAA2B;IACzB,oBAAO,oBAAC,iBAAD,sDAAP;EACD;;EAED,oBACE,oBAAC,kBAAD;IACE,GAAG,EAAE9B,SADP;IAEE,KAAK,EAAE;MAAEmD,MAAM,EAAE,EAAV;MAAcC,KAAK,EAAE,MAArB;MAA6B,GAAItD,KAAK,CAACuD;IAAvC,CAFT;IAGE,cAAc,EAAEP,IAAI,CAACQ,SAAL,CAAe,EAC7B,GAAGxD,KAAK,CAACyD,cADoB;MAE7B,GAAGzD,KAAK,CAACyD,cAAN,CAAqBC;IAFK,CAAf,CAHlB;IAOE,SAAS,EAAEvB,OAPb;IAQE,kBAAkB,EAAEI,gBARtB;IASE,mBAAmB,EAAEY,iBATvB;IAUE,uBAAuB,EAAEnD,KAAK,CAAC2D,uBAVjC;IAWE,yBAAyB,EAAE3D,KAAK,CAAC4D,yBAXnC;IAYE,wBAAwB,EAAE5D,KAAK,CAAC6D;EAZlC,EADF;AAgBD,CA3H+B,CAAzB"}
1
+ {"version":3,"names":["RNPEEventEmitter","NativeModules","peEventEmitter","NativeEventEmitter","COMPONENT_NAME","RNPEApplePayButton","requireNativeComponent","RNPEApplePayButtonManager","UIManager","PEApplePayButton","React","forwardRef","props","ref","buttonRef","useRef","useImperativeHandle","updatePaymentSheet","summaryItems","shippingMethods","errors","Promise","resolve","reject","listener","addListener","args","remove","error","Error","callNativeMethod","useEffect","console","log","useCallback","methodName","params","viewId","findNodeHandle","current","commandId","Commands","toString","Platform","OS","Number","dispatchViewManagerCommand","pmError","event","onPaymentFailed","nativeEvent","pmTokenDidReturn","onTokenDidReturn","token","metadata","metadataString","billingContact","billingContactString","shippingContact","shippingContactString","JSON","parse","undefined","pmSheetDidDismiss","onPaymentSheetDismissed","height","width","style","stringify","paymentRequest","platformOptions","onPaymentMethodSelected","onShippingContactSelected","onShippingMethodSelected"],"sources":["PEApplePayButton.tsx"],"sourcesContent":["import * as React from 'react';\nimport {\n findNodeHandle,\n NativeEventEmitter,\n NativeModules,\n Platform,\n requireNativeComponent,\n Text,\n UIManager,\n ViewProps,\n} from 'react-native';\nimport type { PEPaymentRequest, PESummaryItem } from '../PEPaymentRequest';\nimport type {\n PEApplePayContact,\n PEApplePayPaymentMethod,\n PEApplePaySheetError,\n PEApplePayShippingMethod,\n} from './PEApplePayInterfaces';\n\nconst { RNPEEventEmitter } = NativeModules;\n\nconst peEventEmitter = new NativeEventEmitter(RNPEEventEmitter);\n\nconst COMPONENT_NAME = 'RNPEApplePayButton';\nconst RNPEApplePayButton =\n requireNativeComponent<NativePEApplePayViewProps>(COMPONENT_NAME);\n\n// @ts-ignore\nconst RNPEApplePayButtonManager = UIManager[COMPONENT_NAME];\n\ntype NativePEApplePayEvent = {\n nativeEvent: {\n error?: string;\n token?: string;\n metadata?: any;\n billingContact?: string;\n shippingContact?: string;\n paymentMethod?: string;\n contact?: string;\n shippingMethod?: string;\n };\n};\n\ninterface NativePEApplePayViewProps extends ViewProps {\n paymentRequest: string;\n onPmSheetDidDismiss: (event: NativePEApplePayEvent) => void;\n onPmTokenDidReturn: (event: NativePEApplePayEvent) => void;\n onPmError: (event: NativePEApplePayEvent) => void;\n onPaymentMethodSelected?: (event: {\n nativeEvent: {\n paymentMethod: PEApplePayPaymentMethod;\n };\n }) => void;\n onShippingContactSelected?: (event: {\n nativeEvent: {\n contact: PEApplePayContact;\n };\n }) => void;\n onShippingMethodSelected?: (event: {\n nativeEvent: {\n shippingMethod: PEApplePayShippingMethod;\n };\n }) => void;\n}\n\n/**\n * Props for the Apple Pay button component.\n *\n * This interface defines the properties you can pass to the Apple Pay button,\n * including the payment request and various event callbacks triggered throughout\n * the Apple Pay flow.\n *\n * @category Apple Pay\n */\nexport interface PEApplePayButtonProps extends ViewProps {\n /**\n * The payment request containing transaction details such as the total amount,\n * currency, supported networks, and required contact fields.\n */\n paymentRequest: PEPaymentRequest;\n\n /**\n * Callback triggered when the Apple Pay token is successfully generated.\n *\n * @param token - A string representing the Apple Pay payment token.\n * @param metadata - Optional metadata related to the transaction.\n * @param billingContact - The billing contact information (if available).\n * @param shippingContact - The shipping contact information (if available).\n *\n * Example:\n * ```ts\n * onTokenDidReturn: (token, metadata, billing, shipping) => {\n * console.log('Token:', token);\n * console.log('Billing contact:', billing?.givenName);\n * console.log('Shipping contact:', shipping?.givenName);\n * }\n * ```\n */\n onTokenDidReturn?: (\n token: string,\n metadata?: any,\n billingContact?: PEApplePayContact,\n shippingContact?: PEApplePayContact\n ) => void;\n\n /**\n * Callback triggered when the Apple Pay sheet is dismissed,\n * either by completing the payment or canceling it.\n */\n onPaymentSheetDismissed?: () => void;\n\n /**\n * Callback triggered when the Apple Pay process fails.\n *\n * @param error - The error that occurred during the payment flow.\n */\n onPaymentFailed?: (error: Error) => void;\n\n /**\n * Callback triggered when the user selects or changes the payment method\n * within the Apple Pay sheet.\n *\n * You MUST call `updatePaymentSheet` in response to this callback to update\n * the Apple Pay sheet. Failing to do so will cause the sheet to hang\n * and the transaction will automatically cancel.\n */\n onPaymentMethodSelected?: (event: {\n nativeEvent: {\n paymentMethod: PEApplePayPaymentMethod;\n };\n }) => void;\n\n /**\n * Callback triggered when the user selects a shipping contact\n * (e.g., their shipping address) within the Apple Pay sheet.\n *\n * You MUST call `updatePaymentSheet` in response to this callback to update\n * shipping methods, summary items, or errors. Failure to do so will hang the\n * sheet and cancel the transaction automatically.\n */\n onShippingContactSelected?: (event: {\n nativeEvent: {\n contact: PEApplePayContact;\n };\n }) => void;\n\n /**\n * Callback triggered when the user selects a shipping method (e.g., standard or express)\n * in the Apple Pay sheet.\n *\n * You MUST call `updatePaymentSheet` in response to this callback to reflect\n * any changes in pricing or available options. If you don't, the Apple Pay sheet\n * will hang and the payment will be canceled.\n */\n onShippingMethodSelected?: (event: {\n nativeEvent: {\n shippingMethod: PEApplePayShippingMethod;\n };\n }) => void;\n}\n\n\n/**\n * Exposes imperative methods for controlling the Apple Pay payment sheet.\n *\n * This interface is typically used via a `ref` to programmatically update\n * the state of the Apple Pay sheet after certain user interactions.\n *\n * Specifically, the `updatePaymentSheet` method should be called in response to\n * any of the following events:\n * - `onPaymentMethodSelected`\n * - `onShippingContactSelected`\n * - `onShippingMethodSelected`\n *\n * @category Apple Pay\n */\nexport interface PEApplePayButtonMethods {\n /**\n * Updates the Apple Pay payment sheet with new summary items, shipping methods, and validation errors.\n *\n * This method should be called in response to user selections made on the Apple Pay sheet,\n * such as selecting a new payment method, shipping contact, or shipping method.\n *\n * ### Parameters:\n * - `summaryItems`: The updated list of items summarizing the total payment amount (e.g., subtotal, tax, total).\n * - `shippingMethods`: A list of available shipping methods based on the selected shipping contact.\n * - Only applicable when the `onShippingContactSelected` callback is triggered.\n * - `errors`: A list of validation errors (e.g., invalid address or unsupported shipping region).\n * - Also only applicable for `onShippingContactSelected`.\n *\n * ### Returns:\n * - A `Promise<boolean>` indicating whether the update was successful.\n *\n * ### Example:\n * ```ts\n * await ref.current?.updatePaymentSheet(\n * updatedSummaryItems,\n * availableShippingMethods,\n * validationErrors\n * );\n * ```\n */\n updatePaymentSheet: (\n summaryItems: PESummaryItem[],\n shippingMethods: PEApplePayShippingMethod[],\n errors: PEApplePaySheetError[]\n ) => Promise<boolean>;\n}\n\n\n/**\n * A React component for initiating an Apple Pay transaction.\n *\n * This button wraps the Apple Pay experience, including presenting the Apple Pay sheet,\n * handling user interactions, processing the payment, and managing callbacks such as\n * payment success, failure, and contact/method selection.\n *\n * It exposes imperative methods via `ref` to allow control over the Apple Pay sheet,\n * such as updating summary items or shipping options in response to user input.\n *\n * ## Example Usage:\n *\n * ```tsx\n * const paymentRequest = {\n * merchantId: \"merchant.com.example\",\n * countryCode: \"US\",\n * currencyCode: \"USD\",\n * paymentAmount: 10.00,\n * paymentSummaryItems: [\n * { label: \"Test Item\", amount: \"10.00\" }\n * ],\n * requiredShippingContactFields: [\"name\", \"postalAddress\"]\n * };\n *\n * <PEApplePayButton\n * paymentRequest={paymentRequest}\n *\n * // Triggered when payment fails\n * onPaymentFailed={(error) => console.error(\"Payment failed:\", error)}\n *\n * // Triggered when Apple Pay sheet is dismissed by the user\n * onPaymentSheetDismissed={() => console.log(\"Payment sheet dismissed\")}\n *\n * // Triggered when a valid token is generated after successful Apple Pay authorization\n * onTokenDidReturn={(token, metadata, billingContact, shippingContact) => {\n * console.log('Apple Pay token:', token, metadata, billingContact, shippingContact);\n * // TODO: Send token to your server for processing\n * purchaseWithToken(token);\n * }}\n *\n * // Triggered when user selects or updates their shipping contact info\n * onShippingContactSelected={(event) => {\n * console.log('onShippingContactSelected', event.nativeEvent);\n *\n * if (!event.nativeEvent.contact.postalCode) {\n * // Invalid postal code — update Apple Pay sheet with an error\n * buttonRef?.current?.updatePaymentSheet([], [], [{\n * errorType: PEApplePaySheetErrorType.InvalidShippingAddress,\n * field: PEApplePayInvalidShippingField.PostalCode,\n * message: 'Please update postal code to continue'\n * }]);\n * } else {\n * // Provide updated shipping methods if contact is valid\n * buttonRef?.current?.updatePaymentSheet([], [\n * {\n * identifier: 'new-shipping1',\n * label: 'Updated shipping 1',\n * amount: 3.99\n * },\n * {\n * identifier: 'new-shipping2',\n * label: 'Updated shipping 2',\n * amount: 5.99\n * }\n * ], []);\n * }\n * }}\n *\n * // Triggered when user selects a shipping method\n * onShippingMethodSelected={(event) => {\n * console.log('onShippingMethodSelected', event.nativeEvent);\n *\n * const shippingFee = event.nativeEvent.shippingMethod.amount;\n * const items = [\n * {\n * label: 'Product price',\n * amount: paymentRequest.paymentAmount\n * },\n * ...(shippingFee > 0 ? [{\n * label: 'Shipping Fee',\n * amount: shippingFee\n * }] : []),\n * {\n * label: 'Total',\n * amount: paymentRequest.paymentAmount + shippingFee\n * }\n * ];\n *\n * buttonRef?.current?.updatePaymentSheet(items, [], []);\n * }}\n *\n * // Triggered when user selects a payment method (e.g., credit, debit)\n * onPaymentMethodSelected={(event) => {\n * console.log('onPaymentMethodSelected', event.nativeEvent);\n *\n * const isCredit = event.nativeEvent.paymentMethod.type === PEApplePayPaymentMethodType.credit;\n * const items = [\n * {\n * label: 'Product price',\n * amount: paymentRequest.paymentAmount\n * },\n * ...(isCredit ? [{\n * label: 'Credit discount',\n * amount: 10\n * }] : []),\n * {\n * label: 'Total',\n * amount: paymentRequest.paymentAmount - (isCredit ? 1.00 : 0.00)\n * }\n * ];\n *\n * buttonRef?.current?.updatePaymentSheet(items, [], []);\n * }}\n *\n * ref={applePayRef}\n * />\n * ```\n *\n * @param props - The props for configuring the Apple Pay button behavior.\n * @param ref - A ref to access Apple Pay sheet update methods imperatively.\n *\n * @category Apple Pay\n */\nexport const PEApplePayButton = React.forwardRef<\n PEApplePayButtonMethods,\n PEApplePayButtonProps\n>((props, ref) => {\n const buttonRef = React.useRef<any>();\n\n React.useImperativeHandle(ref, () => ({\n updatePaymentSheet: async (\n summaryItems: PESummaryItem[],\n shippingMethods: PEApplePayShippingMethod[],\n errors: PEApplePaySheetError[]\n ): Promise<boolean> => {\n return new Promise((resolve, reject) => {\n const listener = peEventEmitter.addListener(\n 'onUpdatePaymentSheetResult',\n (args) => {\n listener.remove();\n\n const { error } = args;\n if (error) {\n reject(new Error(error));\n } else {\n resolve(true);\n }\n }\n );\n callNativeMethod('updatePaymentSheet', [\n summaryItems,\n shippingMethods,\n errors,\n ]);\n });\n },\n }));\n\n React.useEffect(() => {\n const listener = peEventEmitter.addListener(\n 'onUpdatePaymentSheetResult',\n (args) => {\n console.log('Received event onUpdatePaymentSheetResult', args);\n }\n );\n return () => {\n listener.remove();\n };\n }, []);\n\n const callNativeMethod = React.useCallback(\n (methodName: string, params: any[] = []) => {\n const viewId = findNodeHandle(buttonRef.current);\n let commandId = RNPEApplePayButtonManager.Commands[methodName].toString();\n if (Platform.OS === 'ios') {\n commandId = Number(commandId);\n }\n UIManager.dispatchViewManagerCommand(viewId, commandId, params);\n },\n [buttonRef.current]\n );\n\n const pmError = (event: NativePEApplePayEvent) => {\n if (props.onPaymentFailed) {\n props.onPaymentFailed(new Error(event.nativeEvent.error));\n }\n };\n\n const pmTokenDidReturn = (event: NativePEApplePayEvent) => {\n if (props.onTokenDidReturn) {\n const {\n token,\n metadata: metadataString,\n billingContact: billingContactString,\n shippingContact: shippingContactString,\n } = event.nativeEvent;\n console.log(\n 'ON token',\n token,\n metadataString,\n billingContactString,\n shippingContactString\n );\n const metadata = metadataString ? JSON.parse(metadataString) : null;\n const billingContact = billingContactString\n ? (JSON.parse(billingContactString) as PEApplePayContact)\n : null;\n const shippingContact = shippingContactString\n ? (JSON.parse(shippingContactString) as PEApplePayContact)\n : null;\n\n props.onTokenDidReturn(\n token!,\n metadata,\n billingContact ?? undefined,\n shippingContact ?? undefined\n );\n }\n };\n\n const pmSheetDidDismiss = () => {\n if (props.onPaymentSheetDismissed) {\n props.onPaymentSheetDismissed();\n }\n };\n\n if (Platform.OS !== 'ios') {\n return <Text>Apple Pay is not supported on this platform</Text>;\n }\n\n return (\n <RNPEApplePayButton\n ref={buttonRef}\n style={{ height: 32, width: '100%', ...(props.style as object) }}\n paymentRequest={JSON.stringify({\n ...props.paymentRequest,\n ...props.paymentRequest.platformOptions,\n })}\n onPmError={pmError}\n onPmTokenDidReturn={pmTokenDidReturn}\n onPmSheetDidDismiss={pmSheetDidDismiss}\n onPaymentMethodSelected={props.onPaymentMethodSelected}\n onShippingContactSelected={props.onShippingContactSelected}\n onShippingMethodSelected={props.onShippingMethodSelected}\n />\n );\n});\n"],"mappings":";;;;;;;AAAA;;AACA;;;;;;AAkBA,MAAM;EAAEA;AAAF,IAAuBC,0BAA7B;AAEA,MAAMC,cAAc,GAAG,IAAIC,+BAAJ,CAAuBH,gBAAvB,CAAvB;AAEA,MAAMI,cAAc,GAAG,oBAAvB;AACA,MAAMC,kBAAkB,GACtB,IAAAC,mCAAA,EAAkDF,cAAlD,CADF,C,CAGA;;AACA,MAAMG,yBAAyB,GAAGC,sBAAA,CAAUJ,cAAV,CAAlC;;AAsLA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMK,gBAAgB,gBAAGC,KAAK,CAACC,UAAN,CAG9B,CAACC,KAAD,EAAQC,GAAR,KAAgB;EAChB,MAAMC,SAAS,GAAGJ,KAAK,CAACK,MAAN,EAAlB;EAEAL,KAAK,CAACM,mBAAN,CAA0BH,GAA1B,EAA+B,OAAO;IACpCI,kBAAkB,EAAE,OAClBC,YADkB,EAElBC,eAFkB,EAGlBC,MAHkB,KAIG;MACrB,OAAO,IAAIC,OAAJ,CAAY,CAACC,OAAD,EAAUC,MAAV,KAAqB;QACtC,MAAMC,QAAQ,GAAGtB,cAAc,CAACuB,WAAf,CACf,4BADe,EAEdC,IAAD,IAAU;UACRF,QAAQ,CAACG,MAAT;UAEA,MAAM;YAAEC;UAAF,IAAYF,IAAlB;;UACA,IAAIE,KAAJ,EAAW;YACTL,MAAM,CAAC,IAAIM,KAAJ,CAAUD,KAAV,CAAD,CAAN;UACD,CAFD,MAEO;YACLN,OAAO,CAAC,IAAD,CAAP;UACD;QACF,CAXc,CAAjB;QAaAQ,gBAA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AC2D,uBAVjC;IAWE,yBAAyB,EAAE3D,KAAK,CAAC4D,yBAXnC;IAYE,wBAAwB,EAAE5D,KAAK,CAAC6D;EAZlC,EADF;AAgBD,CA3H+B,CAAzB"}
@@ -4,7 +4,69 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.PEApplePaySheetErrorType = exports.PEApplePayPaymentMethodType = exports.PEApplePayInvalidShippingField = void 0;
7
+
8
+ /**
9
+ * A model representing a contact associated with Apple Pay.
10
+ *
11
+ * This interface defines the contact details that can be associated with an Apple Pay transaction,
12
+ * including personal and address information such as the contact's name, address, email, and phone number.
13
+ * The fields are optional, meaning not all fields need to be provided when creating an instance.
14
+ *
15
+ * ## Example Usage:
16
+ * ```ts
17
+ * const contact: PEApplePayContact = {
18
+ * givenName: 'John',
19
+ * familyName: 'Doe',
20
+ * addressLines: ['123 Main St', 'Suite 400'],
21
+ * locality: 'Anytown',
22
+ * administrativeArea: 'CA',
23
+ * postalCode: '12345',
24
+ * country: 'USA',
25
+ * countryCode: 'US',
26
+ * subAdministrativeArea: 'SubArea',
27
+ * subLocality: 'Locality',
28
+ * emailAddress: 'john.doe@example.com',
29
+ * phoneNumber: '+1234567890',
30
+ * };
31
+ * ```
32
+ *
33
+ * @category Apple Pay
34
+ */
35
+
36
+ /**
37
+ * A model representing the selected Apple Pay payment method.
38
+ *
39
+ * This interface provides details about the payment method chosen by the user
40
+ * during an Apple Pay transaction. It includes the method's display name,
41
+ * payment network (e.g., Visa, MasterCard), and the type of payment method.
42
+ *
43
+ * ## Example Usage:
44
+ * ```ts
45
+ * const paymentMethod: PEApplePayPaymentMethod = {
46
+ * displayName: 'Visa 1234',
47
+ * network: 'Visa',
48
+ * type: 'credit', // or 'debit', depending on your enum or string literal type
49
+ * };
50
+ * ```
51
+ *
52
+ * @category Apple Pay
53
+ */
54
+
55
+ /**
56
+ * Enum representing the different types of payment methods supported by Apple Pay.
57
+ * Each value corresponds to a specific payment method category.
58
+ *
59
+ * @category Apple Pay
60
+ */
7
61
  let PEApplePayPaymentMethodType;
62
+ /**
63
+ * Represents a shipping method available during Apple Pay checkout.
64
+ *
65
+ * Includes label, amount, and identifier.
66
+ *
67
+ * @category Apple Pay
68
+ */
69
+
8
70
  exports.PEApplePayPaymentMethodType = PEApplePayPaymentMethodType;
9
71
 
10
72
  (function (PEApplePayPaymentMethodType) {
@@ -16,7 +78,23 @@ exports.PEApplePayPaymentMethodType = PEApplePayPaymentMethodType;
16
78
  PEApplePayPaymentMethodType[PEApplePayPaymentMethodType["eMoney"] = 5] = "eMoney";
17
79
  })(PEApplePayPaymentMethodType || (exports.PEApplePayPaymentMethodType = PEApplePayPaymentMethodType = {}));
18
80
 
81
+ /**
82
+ * Enum representing the types of errors that can occur during the Apple Pay
83
+ * sheet process. These errors typically relate to issues with the shipping
84
+ * address provided by the user.
85
+ *
86
+ * @category Apple Pay
87
+ */
19
88
  let PEApplePaySheetErrorType;
89
+ /**
90
+ *
91
+ * Enum representing the fields of shipping address that may be invalid
92
+ * during Apple Pay transactions. These values can be used to identify
93
+ * which part of the shipping address is incorrect or missing.
94
+ *
95
+ * @category Apple Pay
96
+ */
97
+
20
98
  exports.PEApplePaySheetErrorType = PEApplePaySheetErrorType;
21
99
 
22
100
  (function (PEApplePaySheetErrorType) {
@@ -1 +1 @@
1
- {"version":3,"names":["PEApplePayPaymentMethodType","PEApplePaySheetErrorType","PEApplePayInvalidShippingField"],"sources":["PEApplePayInterfaces.ts"],"sourcesContent":["export interface PEApplePayContact {\n givenName?: string;\n familyName?: string;\n addressLines?: string[];\n locality?: string;\n administrativeArea?: string;\n postalCode?: string;\n country?: string;\n countryCode?: string;\n subAdministrativeArea?: string;\n subLocality?: string;\n emailAddress?: string;\n phoneNumber?: string;\n}\n\nexport interface PEApplePayPaymentMethod {\n displayName?: string;\n network?: string;\n type: PEApplePayPaymentMethodType;\n}\n\nexport enum PEApplePayPaymentMethodType {\n unknown = 0,\n debit = 1,\n credit = 2,\n prepaid = 3,\n store = 4,\n eMoney = 5\n}\n\nexport interface PEApplePayShippingMethod {\n identifier: string;\n amount: number;\n label: string;\n}\n\nexport type PEApplePaySheetError =\n | {\n errorType: PEApplePaySheetErrorType.InvalidShippingAddress;\n field: PEApplePayInvalidShippingField;\n message?: string;\n }\n | {\n errorType:\n | PEApplePaySheetErrorType.UnserviceableShippingAddress\n message?: string;\n };\n\nexport enum PEApplePaySheetErrorType {\n InvalidShippingAddress = 'InvalidShippingAddress',\n UnserviceableShippingAddress = 'UnserviceableShippingAddress',\n}\n\nexport enum PEApplePayInvalidShippingField {\n Street = 'street',\n City = 'city',\n SubAdministrativeArea = 'subAdministrativeArea',\n State = 'state',\n PostalCode = 'postalCode',\n Country = 'country',\n CountryCode = 'countryCode',\n SubLocality = 'subLocality',\n}\n"],"mappings":";;;;;;IAqBYA,2B;;;WAAAA,2B;EAAAA,2B,CAAAA,2B;EAAAA,2B,CAAAA,2B;EAAAA,2B,CAAAA,2B;EAAAA,2B,CAAAA,2B;EAAAA,2B,CAAAA,2B;EAAAA,2B,CAAAA,2B;GAAAA,2B,2CAAAA,2B;;IA2BAC,wB;;;WAAAA,wB;EAAAA,wB;EAAAA,wB;GAAAA,wB,wCAAAA,wB;;IAKAC,8B;;;WAAAA,8B;EAAAA,8B;EAAAA,8B;EAAAA,8B;EAAAA,8B;EAAAA,8B;EAAAA,8B;EAAAA,8B;EAAAA,8B;GAAAA,8B,8CAAAA,8B"}
1
+ {"version":3,"names":["PEApplePayPaymentMethodType","PEApplePaySheetErrorType","PEApplePayInvalidShippingField"],"sources":["PEApplePayInterfaces.ts"],"sourcesContent":["/**\n * A model representing a contact associated with Apple Pay.\n *\n * This interface defines the contact details that can be associated with an Apple Pay transaction,\n * including personal and address information such as the contact's name, address, email, and phone number.\n * The fields are optional, meaning not all fields need to be provided when creating an instance.\n *\n * ## Example Usage:\n * ```ts\n * const contact: PEApplePayContact = {\n * givenName: 'John',\n * familyName: 'Doe',\n * addressLines: ['123 Main St', 'Suite 400'],\n * locality: 'Anytown',\n * administrativeArea: 'CA',\n * postalCode: '12345',\n * country: 'USA',\n * countryCode: 'US',\n * subAdministrativeArea: 'SubArea',\n * subLocality: 'Locality',\n * emailAddress: 'john.doe@example.com',\n * phoneNumber: '+1234567890',\n * };\n * ```\n *\n * @category Apple Pay\n */\nexport interface PEApplePayContact {\n /**\n * The given (first) name of the contact.\n * \n * Example: \"John\"\n */\n givenName?: string;\n\n /**\n * The family (last) name of the contact.\n * \n * Example: \"Doe\"\n */\n familyName?: string;\n\n /**\n * The contact's address lines, typically representing street addresses.\n * \n * Example: [\"123 Main St\", \"Suite 400\"]\n */\n addressLines?: string[];\n\n /**\n * The city or locality of the contact's address.\n * \n * Example: \"Anytown\"\n */\n locality?: string;\n\n /**\n * The state, province, or administrative area of the contact's address.\n * \n * Example: \"CA\"\n */\n administrativeArea?: string;\n\n /**\n * The postal code (ZIP code) of the contact's address.\n * \n * Example: \"12345\"\n */\n postalCode?: string;\n\n /**\n * The full country name of the contact's address.\n * \n * Example: \"USA\"\n */\n country?: string;\n\n /**\n * The ISO country code (e.g., \"US\" for the United States).\n * \n * Example: \"US\"\n */\n countryCode?: string;\n\n /**\n * A more specific administrative area within the main administrative area.\n * \n * Example: \"SubArea\"\n */\n subAdministrativeArea?: string;\n\n /**\n * A more specific locality within the main locality.\n * \n * Example: \"Locality\"\n */\n subLocality?: string;\n\n /**\n * The contact's email address.\n * \n * Example: \"john.doe@example.com\"\n */\n emailAddress?: string;\n\n /**\n * The contact's phone number.\n * \n * Example: \"+1234567890\"\n */\n phoneNumber?: string;\n}\n\n\n/**\n * A model representing the selected Apple Pay payment method.\n *\n * This interface provides details about the payment method chosen by the user\n * during an Apple Pay transaction. It includes the method's display name,\n * payment network (e.g., Visa, MasterCard), and the type of payment method.\n *\n * ## Example Usage:\n * ```ts\n * const paymentMethod: PEApplePayPaymentMethod = {\n * displayName: 'Visa 1234',\n * network: 'Visa',\n * type: 'credit', // or 'debit', depending on your enum or string literal type\n * };\n * ```\n *\n * @category Apple Pay\n */\nexport interface PEApplePayPaymentMethod {\n /**\n * A user-facing description of the payment method.\n * \n * This typically includes the card type and last few digits, e.g., \"Visa 1234\".\n */\n displayName?: string;\n\n /**\n * The network associated with the payment method.\n * \n * Common examples include \"Visa\", \"MasterCard\", \"Amex\", etc.\n */\n network?: string;\n\n /**\n * The type of payment method.\n * \n * This is a required field indicating whether the method is a credit card, debit card, etc.\n */\n type: PEApplePayPaymentMethodType;\n}\n\n\n/**\n * Enum representing the different types of payment methods supported by Apple Pay.\n * Each value corresponds to a specific payment method category.\n * \n * @category Apple Pay\n */\nexport enum PEApplePayPaymentMethodType {\n /** Unknown payment method type. */\n unknown = 0,\n\n /** Debit card payment method. */\n debit = 1,\n\n /** Credit card payment method. */\n credit = 2,\n\n /** Prepaid card payment method. */\n prepaid = 3,\n\n /** Store card payment method. */\n store = 4,\n\n /** Electronic money (e-money) payment method. */\n eMoney = 5\n}\n\n\n/**\n * Represents a shipping method available during Apple Pay checkout.\n *\n * Includes label, amount, and identifier.\n *\n * @category Apple Pay\n */\nexport interface PEApplePayShippingMethod {\n /** Unique identifier for the shipping method. */\n identifier: string;\n\n /** Cost associated with this shipping method. */\n amount: number;\n\n /** Display label (e.g., \"Express Delivery\"). */\n label: string;\n}\n\n/**\n * Type representing the possible errors that can occur during the Apple Pay\n * sheet process. This includes issues related to invalid or unserviceable\n * shipping addresses.\n * \n * * @category Apple Pay\n */\nexport type PEApplePaySheetError =\n | {\n /** The error occurs due to an invalid shipping address. */\n errorType: PEApplePaySheetErrorType.InvalidShippingAddress;\n\n /** The specific field in the shipping address that caused the error. */\n field: PEApplePayInvalidShippingField;\n\n /** An optional message providing more details about the error. */\n message?: string;\n }\n | {\n /** The error occurs due to an unserviceable shipping address. */\n errorType: PEApplePaySheetErrorType.UnserviceableShippingAddress;\n\n /** An optional message providing more details about the error. */\n message?: string;\n };\n\n/**\n * Enum representing the types of errors that can occur during the Apple Pay \n * sheet process. These errors typically relate to issues with the shipping \n * address provided by the user.\n * \n * @category Apple Pay\n */\nexport enum PEApplePaySheetErrorType {\n /** The shipping address provided is invalid. */\n InvalidShippingAddress = 'InvalidShippingAddress',\n\n /** The shipping address provided is unserviceable (e.g., the address cannot be delivered to). */\n UnserviceableShippingAddress = 'UnserviceableShippingAddress',\n}\n\n/**\n * \n * Enum representing the fields of shipping address that may be invalid\n * during Apple Pay transactions. These values can be used to identify \n * which part of the shipping address is incorrect or missing.\n * \n * @category Apple Pay\n */\nexport enum PEApplePayInvalidShippingField {\n /** The street address is invalid or missing. */\n Street = 'street',\n\n /** The city is invalid or missing. */\n City = 'city',\n\n /** The sub-administrative area (e.g., district) is invalid or missing. */\n SubAdministrativeArea = 'subAdministrativeArea',\n\n /** The state or province is invalid or missing. */\n State = 'state',\n\n /** The postal code is invalid or missing. */\n PostalCode = 'postalCode',\n\n /** The country is invalid or missing. */\n Country = 'country',\n\n /** The country code is invalid or missing. */\n CountryCode = 'countryCode',\n\n /** The sub-locality (e.g., neighborhood) is invalid or missing. */\n SubLocality = 'subLocality',\n}\n\n"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAwFA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAyBA;AACA;AACA;AACA;AACA;AACA;IACYA,2B;AAqBZ;AACA;AACA;AACA;AACA;AACA;AACA;;;;WA3BYA,2B;EAAAA,2B,CAAAA,2B;EAAAA,2B,CAAAA,2B;EAAAA,2B,CAAAA,2B;EAAAA,2B,CAAAA,2B;EAAAA,2B,CAAAA,2B;EAAAA,2B,CAAAA,2B;GAAAA,2B,2CAAAA,2B;;AAiEZ;AACA;AACA;AACA;AACA;AACA;AACA;IACYC,wB;AAQZ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;WAfYA,wB;EAAAA,wB;EAAAA,wB;GAAAA,wB,wCAAAA,wB;;IAgBAC,8B;;;WAAAA,8B;EAAAA,8B;EAAAA,8B;EAAAA,8B;EAAAA,8B;EAAAA,8B;EAAAA,8B;EAAAA,8B;EAAAA,8B;GAAAA,8B,8CAAAA,8B"}
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["PEGooglePayAddress.ts"],"sourcesContent":["export interface PEGooglePayAddress {\n address1?: string;\n address2?: string;\n address3?: string;\n administrativeArea?: string;\n countryCode?: string;\n locality?: string;\n name?: string;\n phoneNumber?: string;\n postalCode?: string;\n}"],"mappings":""}
1
+ {"version":3,"names":[],"sources":["PEGooglePayAddress.ts"],"sourcesContent":["/**\n * Represents a Google Pay address containing structured user information.\n *\n * This model holds address details returned from Google Pay, including\n * name, street address lines, locality, country code, phone number, and postal code.\n *\n * ## Example Usage:\n * ```ts\n * const address: PEGooglePayAddress = {\n * address1: \"1600 Amphitheatre Parkway\",\n * administrativeArea: \"CA\",\n * countryCode: \"US\",\n * locality: \"Mountain View\",\n * name: \"John Doe\",\n * phoneNumber: \"+1 123-456-7890\",\n * postalCode: \"94043\",\n * };\n * ```\n *\n * @category Google Pay\n */\nexport interface PEGooglePayAddress {\n /** The first line of the street address (e.g., \"123 Main St\"). */\n address1?: string;\n\n /** The second line of the street address (e.g., apartment, suite, or unit number). */\n address2?: string;\n\n /** The third line of the street address (if applicable). */\n address3?: string;\n\n /** The state, province, or region of the address. */\n administrativeArea?: string;\n\n /** The two-letter country code in ISO 3166-1 alpha-2 format (e.g., \"US\", \"CA\"). */\n countryCode?: string;\n\n /** The city or town of the address. */\n locality?: string;\n\n /** The full name of the recipient. */\n name?: string;\n\n /** The phone number associated with the address. */\n phoneNumber?: string;\n\n /** The ZIP or postal code. */\n postalCode?: string;\n}\n"],"mappings":""}
@@ -18,6 +18,59 @@ const {
18
18
  } = _reactNative.NativeModules;
19
19
  const RNPEGooglePayButton = (0, _reactNative.requireNativeComponent)('RNPEGooglePayButton');
20
20
  const peEventEmitter = new _reactNative.NativeEventEmitter(RNPEEventEmitter);
21
+ /**
22
+ * Props for rendering the Google Pay payment button.
23
+ *
24
+ * This interface defines the configuration and callback handlers
25
+ * used when initiating a Google Pay transaction.
26
+ *
27
+ * @category Google Pay
28
+ */
29
+
30
+ /**
31
+ * A React Native component for rendering a Google Pay button.
32
+ *
33
+ * This button allows users to initiate a Google Pay transaction using the
34
+ * provided `paymentRequest`. The component communicates with native code
35
+ * and emits events through a shared event emitter (`peEventEmitter`) to
36
+ * notify the JavaScript layer about the payment result.
37
+ *
38
+ * ## Example Usage:
39
+ * ```tsx
40
+ * const paymentRequest = {
41
+ * merchantId: 'your-merchant-id',
42
+ * paymentAmount: 10.00,
43
+ * paymentItems: [
44
+ * { label: 'Test Item', amount: 10.00 }
45
+ * ],
46
+ * platformOptions: {
47
+ * billingAddressRequired: true,
48
+ * shippingAddressRequired: true,
49
+ * },
50
+ * };
51
+ *
52
+ * <PEGooglePayButton
53
+ * paymentRequest={paymentRequest}
54
+ * onPaymentFailed={(error) => {
55
+ * console.log("Payment failed", error);
56
+ * }}
57
+ * onPaymentSheetDismissed={() => {
58
+ * console.log("Payment sheet dismissed");
59
+ * }}
60
+ * onTokenDidReturn={(token, metadata, billingAddress, shippingAddress) => {
61
+ * console.log("Payment successful", token, metadata, billingAddress, shippingAddress);
62
+ * }}
63
+ * />
64
+ * ```
65
+ *
66
+ * ## Platform Support:
67
+ * - **Android only**: On iOS, this component renders a fallback message.
68
+ *
69
+ * @param props - See {@link PEGooglePayButtonProps}
70
+ * @returns A Google Pay button on Android or a fallback message on iOS.
71
+ *
72
+ * @category Google Pay
73
+ */
21
74
  const PEGooglePayButton = /*#__PURE__*/React.forwardRef((props, ref) => {
22
75
  React.useImperativeHandle(ref, () => ({}));
23
76
  React.useEffect(() => {