1 | import { NativeModules } from 'react-native'
|
2 | import JudoPBBAButton from './components/JudoPBBAButton'
|
3 | import { version as packageVersion } from './package.json'
|
4 |
|
5 | import {
|
6 | JudoConfiguration,
|
7 | JudoResponse,
|
8 | JudoTransactionMode,
|
9 | JudoTransactionType,
|
10 | JudoAuthorization
|
11 | } from './types/JudoTypes'
|
12 |
|
13 | export {
|
14 | JudoTransactionType,
|
15 | JudoTransactionMode,
|
16 | JudoPaymentMethod,
|
17 | JudoCardNetwork,
|
18 | ChallengeRequestIndicator,
|
19 | JudoThreeDSButtonType,
|
20 | ScaExemption
|
21 | } from './types/JudoTypes'
|
22 |
|
23 | export type {
|
24 | JudoAmount,
|
25 | JudoReference,
|
26 | JudoAddress,
|
27 | JudoUIConfiguration,
|
28 | JudoAccountDetails,
|
29 | JudoTheme,
|
30 | JudoResponse,
|
31 | JudoConfiguration,
|
32 | JudoAuthorization,
|
33 | NetworkTimeout,
|
34 | JudoThreeDSButtonCustomization,
|
35 | JudoThreeDSLabelCustomization,
|
36 | JudoThreeDSTextBoxCustomization,
|
37 | JudoThreeDSToolbarCustomization,
|
38 | JudoThreeDSUIConfiguration
|
39 | } from './types/JudoTypes'
|
40 |
|
41 | export {
|
42 | JudoPaymentSummaryItemType,
|
43 | JudoMerchantCapability,
|
44 | JudoContactField,
|
45 | JudoShippingType,
|
46 | JudoReturnedInfo
|
47 | } from './types/JudoApplePayTypes'
|
48 |
|
49 | export type {
|
50 | JudoApplePayConfiguration,
|
51 | JudoPaymentSummaryItem,
|
52 | JudoShippingMethod
|
53 | } from './types/JudoApplePayTypes'
|
54 |
|
55 | export {
|
56 | JudoAddressFormat,
|
57 | JudoGooglePayEnvironment
|
58 | } from './types/JudoGooglePayTypes'
|
59 |
|
60 | export type {
|
61 | JudoGooglePayConfiguration,
|
62 | JudoBillingAddressParameters,
|
63 | JudoShippingAddressParameters
|
64 | } from './types/JudoGooglePayTypes'
|
65 |
|
66 | export type { JudoPBBAConfiguration } from './types/JudoPBBATypes'
|
67 |
|
68 | export { JudoPBBAButton }
|
69 |
|
70 | class JudoPay {
|
71 | //------------------------------------------------------------------
|
72 | // Private properties
|
73 | //------------------------------------------------------------------
|
74 |
|
75 | private readonly authorization: JudoAuthorization
|
76 |
|
77 | //------------------------------------------------------------------
|
78 | // Public properties
|
79 | //------------------------------------------------------------------
|
80 |
|
81 | /**
|
82 | * This property is used to toggle the sandbox environment on and off.
|
83 | * You can use the sandbox environment to test our SDK features.
|
84 | */
|
85 | public isSandboxed = true
|
86 |
|
87 | //------------------------------------------------------------------
|
88 | // Initializers
|
89 | //------------------------------------------------------------------
|
90 |
|
91 | /**
|
92 | * The designated initializer that is used to configure the JudoPay session, based
|
93 | * on a provided object that implements the JudoAuthorization interface.
|
94 | *
|
95 | * @param authorization - can be either a JudoBasicAuthorization (token & secret) or
|
96 | * a JudoSessionAuthorization (token & payment session) instance.
|
97 | */
|
98 | constructor(authorization: JudoAuthorization) {
|
99 | this.authorization = authorization
|
100 | }
|
101 |
|
102 | //------------------------------------------------------------------
|
103 | // SDK Features
|
104 | //------------------------------------------------------------------
|
105 |
|
106 | /**
|
107 | * A method used to verify if any Pay By Bank App supported banking apps are installed
|
108 | * on the device.
|
109 | *
|
110 | * This can be useful for conditionally rendering the PBBA button only if the bank app
|
111 | * is available (PBBA won't work otherwise).
|
112 | *
|
113 | * @returns an asynchronous boolean value that indicates if any PBBA apps are installed.
|
114 | */
|
115 | public isBankingAppAvailable(): Promise<boolean> {
|
116 | return NativeModules.RNJudo.isBankingAppAvailable()
|
117 | }
|
118 |
|
119 | /**
|
120 | * A method used to verify if ApplePay is supported for given configuration object
|
121 | *
|
122 | * This needs to be invoked before invoking ApplePay transactions.
|
123 | *
|
124 | * @returns an asynchronous boolean value that indicates if ApplePay is available.
|
125 | */
|
126 | public isApplePayAvailableWithConfiguration(
|
127 | configuration: JudoConfiguration
|
128 | ): Promise<boolean> {
|
129 | const params = this.generateJudoParameters(configuration)
|
130 | return NativeModules.RNJudo.isApplePayAvailableWithConfiguration(params)
|
131 | }
|
132 |
|
133 | /**
|
134 | * A method for invoking the Judo UI for card transactions.
|
135 | * Supported operations - payments, pre-auths, register card, save card, check card.
|
136 | *
|
137 | * @param type - a JudoTransactionType value that defines the transaction type.
|
138 | * @param configuration - a JudoConfiguration object that is used to configure/customize the payment flow.
|
139 | *
|
140 | * @returns an asynchronous JudoResponse object, containing the transaction results.
|
141 | */
|
142 | public async invokeTransaction(
|
143 | type: JudoTransactionType,
|
144 | configuration: JudoConfiguration
|
145 | ): Promise<JudoResponse> {
|
146 | const params = {
|
147 | ...this.generateTransactionTypeParameters(type, configuration),
|
148 | packageVersion
|
149 | }
|
150 | return NativeModules.RNJudo.invokeTransaction(params)
|
151 | }
|
152 |
|
153 | public async fetchTransactionDetails(
|
154 | receiptId: string
|
155 | ): Promise<JudoResponse> {
|
156 | const params = {
|
157 | authorization: this.generateAuthorizationParameters(),
|
158 | sandboxed: this.isSandboxed,
|
159 | receiptId,
|
160 | packageVersion
|
161 | }
|
162 |
|
163 | return NativeModules.RNJudo.fetchTransactionDetails(params)
|
164 | }
|
165 |
|
166 | /**
|
167 | * A method for completing a payment/pre-auth transaction using a saved card token.
|
168 | *
|
169 | * @param mode - a JudoTransactionMode value that defines if the transaction is either a payment or pre-auth.
|
170 | * @param configuration - a JudoConfiguration object that is used to configure/customize the payment flow.
|
171 | * @param cardToken - the saved card token string.
|
172 | * @param securityCode - the saved card token security code.
|
173 | * @param cardholderName - the saved card token cardholder name.
|
174 | * @param cardScheme - the saved card token scheme name.
|
175 | *
|
176 | * @returns an asynchronous JudoResponse object, containing the transaction results.
|
177 | */
|
178 | public async performTokenTransaction(
|
179 | mode: JudoTransactionMode,
|
180 | configuration: JudoConfiguration,
|
181 | cardToken: string,
|
182 | securityCode: string | undefined | null,
|
183 | cardholderName: string | undefined | null,
|
184 | cardScheme: string
|
185 | ): Promise<JudoResponse> {
|
186 | const params = {
|
187 | ...this.generateTransactionModeParameters(mode, configuration),
|
188 | ...{
|
189 | cardToken,
|
190 | securityCode,
|
191 | cardholderName,
|
192 | cardScheme
|
193 | },
|
194 | packageVersion
|
195 | }
|
196 | return NativeModules.RNJudo.performTokenTransaction(params)
|
197 | }
|
198 |
|
199 | /**
|
200 | * A method for invoking Apple Pay transactions.
|
201 | * For this transaction to work, the required JudoApplePayConfiguration parameters must be present as part of
|
202 | * the JudoConfiguration object passed to the method.
|
203 | *
|
204 | * @param mode - a JudoTransactionMode value that defines if the transaction is either a payment or pre-auth.
|
205 | * @param configuration - a JudoConfiguration object that is used to configure/customize the payment flow.
|
206 | *
|
207 | * @returns an asynchronous JudoResponse object, containing the transaction results.
|
208 | */
|
209 | public async invokeApplePay(
|
210 | mode: JudoTransactionMode,
|
211 | configuration: JudoConfiguration
|
212 | ): Promise<JudoResponse> {
|
213 | const params = {
|
214 | ...this.generateTransactionModeParameters(mode, configuration),
|
215 | packageVersion
|
216 | }
|
217 | return NativeModules.RNJudo.invokeApplePay(params)
|
218 | }
|
219 |
|
220 | /**
|
221 | * A method for invoking Google Pay transactions.
|
222 | * For this transaction to work, the required JudoGooglePayConfiguration parameters must be present as part of
|
223 | * the JudoConfiguration object passed to the method.
|
224 | *
|
225 | * @param mode - a JudoTransactionMode value that defines if the transaction is either a payment or pre-auth.
|
226 | * @param configuration - a JudoConfiguration object that is used to configure/customize the payment flow.
|
227 | *
|
228 | * @returns an asynchronous JudoResponse object, containing the transaction results.
|
229 | */
|
230 | public async invokeGooglePay(
|
231 | mode: JudoTransactionMode,
|
232 | configuration: JudoConfiguration
|
233 | ): Promise<JudoResponse> {
|
234 | const params = {
|
235 | ...this.generateTransactionModeParameters(mode, configuration),
|
236 | packageVersion
|
237 | }
|
238 | return NativeModules.RNJudo.invokeGooglePay(params)
|
239 | }
|
240 |
|
241 | /**
|
242 | * A method for invoking Pay By Bank App transactions.
|
243 | *
|
244 | * @param configuration - a JudoConfiguration object that is used to configure/customize the payment flow.
|
245 | *
|
246 | * @returns an asynchronous JudoResponse object, containing the transaction results.
|
247 | */
|
248 | public async invokePayByBankApp(
|
249 | configuration: JudoConfiguration
|
250 | ): Promise<JudoResponse> {
|
251 | const params = {
|
252 | ...this.generateJudoParameters(configuration),
|
253 | packageVersion
|
254 | }
|
255 | return NativeModules.RNJudo.invokePayByBankApp(params)
|
256 | }
|
257 |
|
258 | /**
|
259 | * A method for invoking the Judo wallet, allowing users to pay with their preferred payment method.
|
260 | * (Cards, Apple Pay/Google Pay, iDEAL, Pay By Bank App)
|
261 | *
|
262 | * @param mode - a JudoTransactionMode value that defines if the transaction is either a payment or pre-auth.
|
263 | * @param configuration - a JudoConfiguration object that is used to configure/customize the payment flow.
|
264 | *
|
265 | * @returns an asynchronous JudoResponse object, containing the transaction results.
|
266 | */
|
267 | public async invokePaymentMethodScreen(
|
268 | mode: JudoTransactionMode,
|
269 | configuration: JudoConfiguration
|
270 | ): Promise<JudoResponse> {
|
271 | const params = {
|
272 | ...this.generateTransactionModeParameters(mode, configuration),
|
273 | packageVersion
|
274 | }
|
275 | return NativeModules.RNJudo.invokePaymentMethodScreen(params)
|
276 | }
|
277 |
|
278 | //------------------------------------------------------------------
|
279 | // Private helper methods
|
280 | //------------------------------------------------------------------
|
281 |
|
282 | private readonly generateJudoParameters = (
|
283 | configuration: JudoConfiguration
|
284 | ): Record<string, any> => {
|
285 | return {
|
286 | authorization: this.generateAuthorizationParameters(),
|
287 | sandboxed: this.isSandboxed,
|
288 | configuration: configuration
|
289 | }
|
290 | }
|
291 |
|
292 | private readonly generateTransactionTypeParameters = (
|
293 | type: JudoTransactionType,
|
294 | configuration: JudoConfiguration
|
295 | ): Record<string, any> => {
|
296 | return {
|
297 | authorization: this.generateAuthorizationParameters(),
|
298 | sandboxed: this.isSandboxed,
|
299 | transactionType: type,
|
300 | configuration: configuration
|
301 | }
|
302 | }
|
303 |
|
304 | private readonly generateTransactionModeParameters = (
|
305 | mode: JudoTransactionMode,
|
306 | configuration: JudoConfiguration
|
307 | ): Record<string, any> => {
|
308 | return {
|
309 | authorization: this.generateAuthorizationParameters(),
|
310 | sandboxed: this.isSandboxed,
|
311 | transactionMode: mode,
|
312 | configuration: configuration
|
313 | }
|
314 | }
|
315 |
|
316 | private readonly generateAuthorizationParameters = (): Record<
|
317 | string,
|
318 | any
|
319 | > => {
|
320 | if (this.authorization.secret) {
|
321 | return {
|
322 | token: this.authorization.token,
|
323 | secret: this.authorization.secret
|
324 | }
|
325 | }
|
326 |
|
327 | return {
|
328 | token: this.authorization.token,
|
329 | paymentSession: this.authorization.paymentSession
|
330 | }
|
331 | }
|
332 | }
|
333 |
|
334 | export default JudoPay
|