@tapayadot/accept-react-native 1.3.3 → 1.14.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.
- package/README.md +196 -363
- package/android/build.gradle +23 -34
- package/android/src/main/java/com/tapaya/acceptsdkreactnative/AcceptSdkReactNativeModule.kt +191 -673
- package/android/src/main/java/com/tapaya/acceptsdkreactnative/Errors.kt +81 -0
- package/android/src/main/java/com/tapaya/acceptsdkreactnative/Parsing.kt +166 -0
- package/android/src/main/java/com/tapaya/acceptsdkreactnative/Serialization.kt +216 -0
- package/app.json +2 -2
- package/app.plugin.js +1 -1
- package/build/Accept.d.ts +255 -0
- package/build/Accept.d.ts.map +1 -0
- package/build/Accept.js +387 -0
- package/build/Accept.js.map +1 -0
- package/build/Accept.types.d.ts +352 -0
- package/build/Accept.types.d.ts.map +1 -0
- package/build/Accept.types.js +9 -0
- package/build/Accept.types.js.map +1 -0
- package/build/AcceptError.d.ts +53 -0
- package/build/AcceptError.d.ts.map +1 -0
- package/build/AcceptError.js +107 -0
- package/build/AcceptError.js.map +1 -0
- package/build/AcceptSdkReactNativeModule.d.ts +67 -26
- package/build/AcceptSdkReactNativeModule.d.ts.map +1 -1
- package/build/AcceptSdkReactNativeModule.js +53 -3
- package/build/AcceptSdkReactNativeModule.js.map +1 -1
- package/build/index.d.ts +7 -237
- package/build/index.d.ts.map +1 -1
- package/build/index.js +7 -254
- package/build/index.js.map +1 -1
- package/build/utils.d.ts.map +1 -1
- package/build/utils.js +2 -2
- package/build/utils.js.map +1 -1
- package/expo-module.config.json +1 -6
- package/package.json +8 -12
- package/plugin/withAcceptSdk.js +45 -0
- package/build/AcceptSdkReactNative.types.d.ts +0 -259
- package/build/AcceptSdkReactNative.types.d.ts.map +0 -1
- package/build/AcceptSdkReactNative.types.js +0 -2
- package/build/AcceptSdkReactNative.types.js.map +0 -1
- package/ios/.xcode.env +0 -11
- package/ios/AcceptSdkReactNative.podspec +0 -33
- package/ios/AcceptSdkReactNativeAppDelegate.swift +0 -13
- package/ios/AcceptSdkReactNativeModule.swift +0 -749
- package/ios/Podfile +0 -63
- package/ios/Podfile.properties.json +0 -4
- package/ios/acceptsdkreactnative.xcodeproj/project.pbxproj +0 -540
- package/ios/acceptsdkreactnative.xcodeproj/xcshareddata/xcschemes/acceptsdkreactnative.xcscheme +0 -88
- package/plugin/withCustomRepoModule.js +0 -96
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
import type { AcceptDisplay, AcceptLogEntry, AcceptLogLevel, AcceptSubscription, AcceptTheme, ActivateTerminalResult, InitializeOptions, MerchantConfig, MerchantInformation, MinimumAmount, OnboardingStatus, PayResult, PaymentEvent, PaymentOptions, PaymentRequest, PaymentState, PaymentStatus, PaymentSubscription, PluginStatus, PluginUpdateInfo, RefundReason, SdkState } from "./Accept.types";
|
|
2
|
+
/**
|
|
3
|
+
* Entry point to the Accept SDK. Mirrors the `Accept` object in the Accept SDK for Android, so the
|
|
4
|
+
* Android reference documentation applies unchanged.
|
|
5
|
+
*
|
|
6
|
+
* ```ts
|
|
7
|
+
* import Accept from '@tapayadot/accept-react-native';
|
|
8
|
+
*
|
|
9
|
+
* Accept.initialize({ isProduction: false });
|
|
10
|
+
* await Accept.auth.authenticate(merchantToken);
|
|
11
|
+
*
|
|
12
|
+
* if (!Accept.plugin.isInstalled()) await Accept.plugin.install();
|
|
13
|
+
* await Accept.plugin.activateTerminal();
|
|
14
|
+
*
|
|
15
|
+
* const result = await Accept.payments.payAsync({ amount: 1000, currency: 'USD' });
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare const Accept: {
|
|
19
|
+
auth: {
|
|
20
|
+
/**
|
|
21
|
+
* Authenticates the SDK for the merchant identified by `merchantToken`. Must succeed before
|
|
22
|
+
* {@link merchant} or {@link payments} can be used.
|
|
23
|
+
*
|
|
24
|
+
* @throws AcceptError `NotInitialized`, `NoInternetConnection`, `Unknown`.
|
|
25
|
+
*/
|
|
26
|
+
authenticate(merchantToken: string): Promise<void>;
|
|
27
|
+
};
|
|
28
|
+
sdk: {
|
|
29
|
+
/** The version of the Accept SDK for Android bundled in this build. Safe before `initialize`. */
|
|
30
|
+
readonly version: string;
|
|
31
|
+
/**
|
|
32
|
+
* Whether the SDK was initialized against production.
|
|
33
|
+
*
|
|
34
|
+
* @throws AcceptError `NotInitialized`.
|
|
35
|
+
*/
|
|
36
|
+
readonly isProduction: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* This device's stable identifier, assigned on the first successful
|
|
39
|
+
* {@link auth.authenticate} and retained until the app is uninstalled.
|
|
40
|
+
*
|
|
41
|
+
* @returns the device id, or `null` before the first authentication.
|
|
42
|
+
* @throws AcceptError `NotInitialized`, `Unknown`.
|
|
43
|
+
*/
|
|
44
|
+
deviceId(): Promise<string | null>;
|
|
45
|
+
/**
|
|
46
|
+
* The minimum payable amount per supported currency.
|
|
47
|
+
*
|
|
48
|
+
* @throws AcceptError `NotInitialized`, `NoInternetConnection`, `Unknown`.
|
|
49
|
+
*/
|
|
50
|
+
minimumAmounts(): Promise<MinimumAmount[]>;
|
|
51
|
+
};
|
|
52
|
+
merchant: {
|
|
53
|
+
/**
|
|
54
|
+
* The merchant's business profile, or `null` if onboarding hasn't been submitted yet.
|
|
55
|
+
*
|
|
56
|
+
* @throws AcceptError `NotAuthenticated`, `NoInternetConnection`, `Unknown`.
|
|
57
|
+
*/
|
|
58
|
+
info(): Promise<MerchantInformation | null>;
|
|
59
|
+
/**
|
|
60
|
+
* The merchant's payment configuration.
|
|
61
|
+
*
|
|
62
|
+
* @throws AcceptError `NotAuthenticated`, `NoInternetConnection`, `Unknown`.
|
|
63
|
+
*/
|
|
64
|
+
config(): Promise<MerchantConfig>;
|
|
65
|
+
/**
|
|
66
|
+
* Whether the merchant is ready to accept payments, or what is blocking it.
|
|
67
|
+
*
|
|
68
|
+
* @throws AcceptError `NotAuthenticated`, `NoInternetConnection`, `Unknown`.
|
|
69
|
+
*/
|
|
70
|
+
onboardingStatus(): Promise<OnboardingStatus>;
|
|
71
|
+
/**
|
|
72
|
+
* The currency codes the merchant accepts. Shorthand for `config().availableCurrencies`.
|
|
73
|
+
*
|
|
74
|
+
* @throws AcceptError `NotAuthenticated`, `NoInternetConnection`, `Unknown`.
|
|
75
|
+
*/
|
|
76
|
+
availableCurrencies(): Promise<string[]>;
|
|
77
|
+
};
|
|
78
|
+
payments: {
|
|
79
|
+
/**
|
|
80
|
+
* Sets the defaults applied to payments that don't override them on {@link pay}.
|
|
81
|
+
*
|
|
82
|
+
* Only the keys present are changed, so one option can be set without disturbing the others.
|
|
83
|
+
* `display` is also what the terminal warm-up fired by {@link auth.authenticate} follows — set it
|
|
84
|
+
* before authenticating to keep the warm-up off the merchant's screen.
|
|
85
|
+
*/
|
|
86
|
+
setOptions(options: PaymentOptions): void;
|
|
87
|
+
/**
|
|
88
|
+
* Launches the plugin's payment flow and streams its lifecycle to `listener`.
|
|
89
|
+
*
|
|
90
|
+
* Never throws: a failure to create the payment arrives as a `creationFailed` event carrying an
|
|
91
|
+
* {@link AcceptError}. The stream ends after `result` or `creationFailed`, at which point the
|
|
92
|
+
* subscription removes itself.
|
|
93
|
+
*
|
|
94
|
+
* ```ts
|
|
95
|
+
* Accept.payments.pay({ amount: 1000, currency: 'USD' }, (event) => {
|
|
96
|
+
* if (event.type === 'result' && event.payResult.type === 'success') {
|
|
97
|
+
* console.log(event.payResult.paymentToken);
|
|
98
|
+
* }
|
|
99
|
+
* });
|
|
100
|
+
* ```
|
|
101
|
+
*
|
|
102
|
+
* @returns a handle that stops delivering events; see {@link PaymentSubscription.remove}.
|
|
103
|
+
*/
|
|
104
|
+
pay(request: PaymentRequest, listener: (event: PaymentEvent) => void): PaymentSubscription;
|
|
105
|
+
/**
|
|
106
|
+
* {@link pay} reduced to its outcome, for callers that don't render the intermediate states.
|
|
107
|
+
*
|
|
108
|
+
* @returns the terminal {@link PayResult}.
|
|
109
|
+
* @throws AcceptError whatever the payment would have reported as `creationFailed` — including
|
|
110
|
+
* `PaymentInProgress`, `NotAuthenticated`, `PluginNotReadyForPayments`, `AmountBelowMinimum`,
|
|
111
|
+
* and `LocationPermissionRequired`.
|
|
112
|
+
*/
|
|
113
|
+
payAsync(request: PaymentRequest): Promise<PayResult>;
|
|
114
|
+
/**
|
|
115
|
+
* The current status of the payment identified by `paymentToken`.
|
|
116
|
+
*
|
|
117
|
+
* @throws AcceptError `NotAuthenticated`, `SessionExpired`, `PaymentNotFound`,
|
|
118
|
+
* `NoInternetConnection`, `Unknown`.
|
|
119
|
+
*/
|
|
120
|
+
status(paymentToken: string): Promise<PaymentStatus>;
|
|
121
|
+
/**
|
|
122
|
+
* Cancels the payment identified by `paymentToken`.
|
|
123
|
+
*
|
|
124
|
+
* @returns the resulting {@link PaymentState}.
|
|
125
|
+
* @throws AcceptError `NotAuthenticated`, `SessionExpired`, `PaymentNotFound`,
|
|
126
|
+
* `NoInternetConnection`, `Unknown`.
|
|
127
|
+
*/
|
|
128
|
+
cancel(paymentToken: string): Promise<PaymentState>;
|
|
129
|
+
/**
|
|
130
|
+
* Refunds the payment identified by `paymentToken`.
|
|
131
|
+
*
|
|
132
|
+
* @returns the resulting {@link PaymentState}.
|
|
133
|
+
* @throws AcceptError `NotAuthenticated`, `SessionExpired`, `PaymentNotFound`,
|
|
134
|
+
* `NoInternetConnection`, `Unknown`.
|
|
135
|
+
*/
|
|
136
|
+
refund(paymentToken: string, reason: RefundReason): Promise<PaymentState>;
|
|
137
|
+
};
|
|
138
|
+
plugin: {
|
|
139
|
+
/**
|
|
140
|
+
* Whether the plugin app is installed on this device.
|
|
141
|
+
*
|
|
142
|
+
* @throws AcceptError `NotInitialized`, `Unknown`.
|
|
143
|
+
*/
|
|
144
|
+
isInstalled(): boolean;
|
|
145
|
+
/**
|
|
146
|
+
* Opens the plugin's store listing so the merchant can install it. Uses the organization's
|
|
147
|
+
* branded listing when one is configured and the SDK is authenticated.
|
|
148
|
+
*
|
|
149
|
+
* @throws AcceptError `NotInitialized`, `Unknown`.
|
|
150
|
+
*/
|
|
151
|
+
install(): Promise<void>;
|
|
152
|
+
/**
|
|
153
|
+
* Runs the plugin's terminal activation flow and resolves when it finishes. Activation is
|
|
154
|
+
* required before the device can take card payments.
|
|
155
|
+
*
|
|
156
|
+
* @throws AcceptError `ActivationInProgress`, `NotAuthenticated`, `PluginUnavailable`,
|
|
157
|
+
* `NoInternetConnection`, `NoTidsAvailableForMerchant`, `MerchantOnboardingIncomplete`,
|
|
158
|
+
* `Unknown`.
|
|
159
|
+
*/
|
|
160
|
+
activateTerminal(): Promise<ActivateTerminalResult>;
|
|
161
|
+
/**
|
|
162
|
+
* The plugin's current installed/authenticated/ready state.
|
|
163
|
+
*
|
|
164
|
+
* @throws AcceptError `NotInitialized`, `PluginUnavailable`, `PluginTimeout`, `Unknown`.
|
|
165
|
+
*/
|
|
166
|
+
status(): Promise<PluginStatus>;
|
|
167
|
+
/**
|
|
168
|
+
* Whether a newer plugin build is available on Google Play. Call {@link install} to send the
|
|
169
|
+
* merchant to its listing.
|
|
170
|
+
*
|
|
171
|
+
* @throws AcceptError `NotInitialized`, `PluginUnavailable`, `PluginTimeout`, `Unknown`.
|
|
172
|
+
*/
|
|
173
|
+
updateInfo(): Promise<PluginUpdateInfo>;
|
|
174
|
+
/**
|
|
175
|
+
* Logs the merchant out of the plugin app.
|
|
176
|
+
*
|
|
177
|
+
* @throws AcceptError `NotInitialized`, `PluginUnavailable`, `PluginTimeout`, `Unknown`.
|
|
178
|
+
*/
|
|
179
|
+
logout(): Promise<void>;
|
|
180
|
+
};
|
|
181
|
+
displays: {
|
|
182
|
+
/** Every display the device currently reports, primary first. */
|
|
183
|
+
all(): AcceptDisplay[];
|
|
184
|
+
/**
|
|
185
|
+
* The customer-facing panel of a dual-sided device, or `null` on single-screen devices. This is
|
|
186
|
+
* what `{ type: 'customerFacing' }` targets.
|
|
187
|
+
*/
|
|
188
|
+
customerFacing(): AcceptDisplay | null;
|
|
189
|
+
/** Whether a customer-facing display is available right now. */
|
|
190
|
+
readonly isDualScreen: boolean;
|
|
191
|
+
};
|
|
192
|
+
/**
|
|
193
|
+
* Initializes the SDK against sandbox or production. Must be called before any other surface is
|
|
194
|
+
* used — typically once, at app startup.
|
|
195
|
+
*
|
|
196
|
+
* Safe to call more than once; each call resets which environment subsequent requests target.
|
|
197
|
+
*/
|
|
198
|
+
initialize(options?: InitializeOptions): void;
|
|
199
|
+
/** The SDK's current lifecycle state. */
|
|
200
|
+
readonly state: SdkState;
|
|
201
|
+
/**
|
|
202
|
+
* Subscribes to {@link state} transitions. The listener fires with the current state on
|
|
203
|
+
* subscription, then on every change.
|
|
204
|
+
*/
|
|
205
|
+
addStateListener(listener: (state: SdkState) => void): AcceptSubscription;
|
|
206
|
+
/**
|
|
207
|
+
* Clears all locally persisted SDK state — auth token, device id, cached config, and theme — and
|
|
208
|
+
* resets {@link state} to `idle`. Call this on merchant logout.
|
|
209
|
+
*
|
|
210
|
+
* @throws AcceptError `Unknown`.
|
|
211
|
+
*/
|
|
212
|
+
clear(): Promise<void>;
|
|
213
|
+
/**
|
|
214
|
+
* Enables or disables diagnostic logging. Shorthand for {@link setLogLevel}: `true` maps to
|
|
215
|
+
* `'DEBUG'`, `false` to `'NONE'`.
|
|
216
|
+
*/
|
|
217
|
+
setDebugLoggingEnabled(enabled: boolean): void;
|
|
218
|
+
/**
|
|
219
|
+
* Sets the verbosity of diagnostic logging. Defaults to `'DEBUG'` against sandbox and `'NONE'`
|
|
220
|
+
* against production; call after {@link initialize} to override.
|
|
221
|
+
*/
|
|
222
|
+
setLogLevel(level: AcceptLogLevel): void;
|
|
223
|
+
/**
|
|
224
|
+
* Routes SDK logs into `listener` instead of Logcat, for forwarding into your own logging stack.
|
|
225
|
+
* Pass `null` to restore the default Logcat sink.
|
|
226
|
+
*/
|
|
227
|
+
setLogger(listener: ((entry: AcceptLogEntry) => void) | null): void;
|
|
228
|
+
/**
|
|
229
|
+
* Sets the branding applied to the plugin's activation, status, and payment screens.
|
|
230
|
+
*
|
|
231
|
+
* Session-wide, not per payment: it persists until changed or cleared with `null`. Pushed to the
|
|
232
|
+
* plugin opportunistically the next time it is bound or launched, so there is no confirmation
|
|
233
|
+
* that it was applied — the plugin may not be installed or running yet.
|
|
234
|
+
*/
|
|
235
|
+
setTheme(theme: AcceptTheme | null): void;
|
|
236
|
+
/**
|
|
237
|
+
* The theme currently set via {@link setTheme}, or `null`. Reflects local SDK state only, not
|
|
238
|
+
* whether the plugin applied it.
|
|
239
|
+
*/
|
|
240
|
+
getTheme(): AcceptTheme | null;
|
|
241
|
+
/**
|
|
242
|
+
* Stores `base64` image data in SDK-private storage and returns a `content://` URL the plugin can
|
|
243
|
+
* read — for a logo the host app holds locally rather than at a stable URL. Use the result
|
|
244
|
+
* anywhere an {@link AcceptTheme} image field takes a URL.
|
|
245
|
+
*
|
|
246
|
+
* `assetToBase64` from `@tapayadot/accept-react-native/utils` turns a `require('./logo.png')`
|
|
247
|
+
* into the expected string.
|
|
248
|
+
*
|
|
249
|
+
* @param fileExtension the extension to store the data under, without a leading dot. Tells the
|
|
250
|
+
* plugin how to decode it; defaults to `'png'`.
|
|
251
|
+
* @throws AcceptError `NotInitialized`.
|
|
252
|
+
*/
|
|
253
|
+
createLocalThemeImageUri(base64: string, fileExtension?: string): string;
|
|
254
|
+
};
|
|
255
|
+
//# sourceMappingURL=Accept.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Accept.d.ts","sourceRoot":"","sources":["../src/Accept.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EACb,cAAc,EACd,cAAc,EACd,kBAAkB,EAClB,WAAW,EACX,sBAAsB,EACtB,iBAAiB,EACjB,cAAc,EACd,mBAAmB,EACnB,aAAa,EACb,gBAAgB,EAChB,SAAS,EACT,YAAY,EACZ,cAAc,EACd,cAAc,EACd,YAAY,EACZ,aAAa,EACb,mBAAmB,EACnB,YAAY,EACZ,gBAAgB,EAChB,YAAY,EACZ,QAAQ,EACT,MAAM,gBAAgB,CAAC;AAsTxB;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,MAAM;;QAnTjB;;;;;WAKG;oCACyB,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;;;QASlD,iGAAiG;0BAClF,MAAM;QAIrB;;;;WAIG;+BACiB,OAAO;QAI3B;;;;;;WAMG;oBACS,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;QAIlC;;;;WAIG;0BACe,OAAO,CAAC,aAAa,EAAE,CAAC;;;QAS1C;;;;WAIG;gBACK,OAAO,CAAC,mBAAmB,GAAG,IAAI,CAAC;QAI3C;;;;WAIG;kBACO,OAAO,CAAC,cAAc,CAAC;QAIjC;;;;WAIG;4BACiB,OAAO,CAAC,gBAAgB,CAAC;QAI7C;;;;WAIG;+BACoB,OAAO,CAAC,MAAM,EAAE,CAAC;;;QASxC;;;;;;WAMG;4BACiB,cAAc,GAAG,IAAI;QAIzC;;;;;;;;;;;;;;;;WAgBG;qBAEQ,cAAc,YACb,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,GACtC,mBAAmB;QAqBtB;;;;;;;WAOG;0BACe,cAAc,GAAG,OAAO,CAAC,SAAS,CAAC;QAUrD;;;;;WAKG;6BACkB,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;QAIpD;;;;;;WAMG;6BACkB,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;QAInD;;;;;;WAMG;6BACkB,MAAM,UAAU,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC;;;QASzE;;;;WAIG;uBACY,OAAO;QAItB;;;;;WAKG;mBACQ,OAAO,CAAC,IAAI,CAAC;QAIxB;;;;;;;WAOG;4BACiB,OAAO,CAAC,sBAAsB,CAAC;QAInD;;;;WAIG;kBACO,OAAO,CAAC,YAAY,CAAC;QAI/B;;;;;WAKG;sBACW,OAAO,CAAC,gBAAgB,CAAC;QAIvC;;;;WAIG;kBACO,OAAO,CAAC,IAAI,CAAC;;;QAYvB,iEAAiE;eAC1D,aAAa,EAAE;QAItB;;;WAGG;0BACe,aAAa,GAAG,IAAI;QAItC,gEAAgE;+BAC5C,OAAO;;IAgC3B;;;;;OAKG;yBACiB,iBAAiB,GAAQ,IAAI;IAIjD,yCAAyC;oBAC5B,QAAQ;IAIrB;;;OAGG;+BACwB,CAAC,KAAK,EAAE,QAAQ,KAAK,IAAI,GAAG,kBAAkB;IAIzE;;;;;OAKG;aACM,OAAO,CAAC,IAAI,CAAC;IAItB;;;OAGG;oCAC6B,OAAO,GAAG,IAAI;IAI9C;;;OAGG;uBACgB,cAAc,GAAG,IAAI;IAIxC;;;OAGG;wBACiB,CAAC,CAAC,KAAK,EAAE,cAAc,KAAK,IAAI,CAAC,GAAG,IAAI,GAAG,IAAI;IAMnE;;;;;;OAMG;oBACa,WAAW,GAAG,IAAI,GAAG,IAAI;IAIzC;;;OAGG;gBACS,WAAW,GAAG,IAAI;IAI9B;;;;;;;;;;;OAWG;qCAEO,MAAM,kBACC,MAAM,GACpB,MAAM;CAKV,CAAC"}
|
package/build/Accept.js
ADDED
|
@@ -0,0 +1,387 @@
|
|
|
1
|
+
import { mapErrors, mapErrorsSync, toAcceptError } from "./AcceptError";
|
|
2
|
+
import Native from "./AcceptSdkReactNativeModule";
|
|
3
|
+
/**
|
|
4
|
+
* Correlates a `pay()` call with its events. Monotonic within a JavaScript context, which is all
|
|
5
|
+
* that is needed: the native side only ever routes an event back to the caller that started it.
|
|
6
|
+
*/
|
|
7
|
+
let nextRequestId = 0;
|
|
8
|
+
const newRequestId = () => `pay-${++nextRequestId}`;
|
|
9
|
+
/** A payment event that ends the stream. */
|
|
10
|
+
const isTerminal = (event) => event.type === "result" || event.type === "creationFailed";
|
|
11
|
+
/**
|
|
12
|
+
* Authentication surface. Mirrors `Accept.auth`.
|
|
13
|
+
*/
|
|
14
|
+
const auth = {
|
|
15
|
+
/**
|
|
16
|
+
* Authenticates the SDK for the merchant identified by `merchantToken`. Must succeed before
|
|
17
|
+
* {@link merchant} or {@link payments} can be used.
|
|
18
|
+
*
|
|
19
|
+
* @throws AcceptError `NotInitialized`, `NoInternetConnection`, `Unknown`.
|
|
20
|
+
*/
|
|
21
|
+
authenticate(merchantToken) {
|
|
22
|
+
return mapErrors(() => Native.authenticate(merchantToken));
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* SDK-level configuration and diagnostics. Mirrors `Accept.sdk`.
|
|
27
|
+
*/
|
|
28
|
+
const sdk = {
|
|
29
|
+
/** The version of the Accept SDK for Android bundled in this build. Safe before `initialize`. */
|
|
30
|
+
get version() {
|
|
31
|
+
return Native.getSdkVersion();
|
|
32
|
+
},
|
|
33
|
+
/**
|
|
34
|
+
* Whether the SDK was initialized against production.
|
|
35
|
+
*
|
|
36
|
+
* @throws AcceptError `NotInitialized`.
|
|
37
|
+
*/
|
|
38
|
+
get isProduction() {
|
|
39
|
+
return mapErrorsSync(() => Native.isProduction());
|
|
40
|
+
},
|
|
41
|
+
/**
|
|
42
|
+
* This device's stable identifier, assigned on the first successful
|
|
43
|
+
* {@link auth.authenticate} and retained until the app is uninstalled.
|
|
44
|
+
*
|
|
45
|
+
* @returns the device id, or `null` before the first authentication.
|
|
46
|
+
* @throws AcceptError `NotInitialized`, `Unknown`.
|
|
47
|
+
*/
|
|
48
|
+
deviceId() {
|
|
49
|
+
return mapErrors(() => Native.getDeviceId());
|
|
50
|
+
},
|
|
51
|
+
/**
|
|
52
|
+
* The minimum payable amount per supported currency.
|
|
53
|
+
*
|
|
54
|
+
* @throws AcceptError `NotInitialized`, `NoInternetConnection`, `Unknown`.
|
|
55
|
+
*/
|
|
56
|
+
minimumAmounts() {
|
|
57
|
+
return mapErrors(() => Native.getMinimumAmounts());
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Merchant profile and onboarding. Mirrors `Accept.merchant`. Requires {@link auth.authenticate}.
|
|
62
|
+
*/
|
|
63
|
+
const merchant = {
|
|
64
|
+
/**
|
|
65
|
+
* The merchant's business profile, or `null` if onboarding hasn't been submitted yet.
|
|
66
|
+
*
|
|
67
|
+
* @throws AcceptError `NotAuthenticated`, `NoInternetConnection`, `Unknown`.
|
|
68
|
+
*/
|
|
69
|
+
info() {
|
|
70
|
+
return mapErrors(() => Native.getMerchantInfo());
|
|
71
|
+
},
|
|
72
|
+
/**
|
|
73
|
+
* The merchant's payment configuration.
|
|
74
|
+
*
|
|
75
|
+
* @throws AcceptError `NotAuthenticated`, `NoInternetConnection`, `Unknown`.
|
|
76
|
+
*/
|
|
77
|
+
config() {
|
|
78
|
+
return mapErrors(() => Native.getMerchantConfig());
|
|
79
|
+
},
|
|
80
|
+
/**
|
|
81
|
+
* Whether the merchant is ready to accept payments, or what is blocking it.
|
|
82
|
+
*
|
|
83
|
+
* @throws AcceptError `NotAuthenticated`, `NoInternetConnection`, `Unknown`.
|
|
84
|
+
*/
|
|
85
|
+
onboardingStatus() {
|
|
86
|
+
return mapErrors(() => Native.getOnboardingStatus());
|
|
87
|
+
},
|
|
88
|
+
/**
|
|
89
|
+
* The currency codes the merchant accepts. Shorthand for `config().availableCurrencies`.
|
|
90
|
+
*
|
|
91
|
+
* @throws AcceptError `NotAuthenticated`, `NoInternetConnection`, `Unknown`.
|
|
92
|
+
*/
|
|
93
|
+
availableCurrencies() {
|
|
94
|
+
return mapErrors(() => Native.getAvailableCurrencies());
|
|
95
|
+
},
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* Payments. Mirrors `Accept.payments`. Requires {@link auth.authenticate}.
|
|
99
|
+
*/
|
|
100
|
+
const payments = {
|
|
101
|
+
/**
|
|
102
|
+
* Sets the defaults applied to payments that don't override them on {@link pay}.
|
|
103
|
+
*
|
|
104
|
+
* Only the keys present are changed, so one option can be set without disturbing the others.
|
|
105
|
+
* `display` is also what the terminal warm-up fired by {@link auth.authenticate} follows — set it
|
|
106
|
+
* before authenticating to keep the warm-up off the merchant's screen.
|
|
107
|
+
*/
|
|
108
|
+
setOptions(options) {
|
|
109
|
+
Native.setPaymentOptions(options);
|
|
110
|
+
},
|
|
111
|
+
/**
|
|
112
|
+
* Launches the plugin's payment flow and streams its lifecycle to `listener`.
|
|
113
|
+
*
|
|
114
|
+
* Never throws: a failure to create the payment arrives as a `creationFailed` event carrying an
|
|
115
|
+
* {@link AcceptError}. The stream ends after `result` or `creationFailed`, at which point the
|
|
116
|
+
* subscription removes itself.
|
|
117
|
+
*
|
|
118
|
+
* ```ts
|
|
119
|
+
* Accept.payments.pay({ amount: 1000, currency: 'USD' }, (event) => {
|
|
120
|
+
* if (event.type === 'result' && event.payResult.type === 'success') {
|
|
121
|
+
* console.log(event.payResult.paymentToken);
|
|
122
|
+
* }
|
|
123
|
+
* });
|
|
124
|
+
* ```
|
|
125
|
+
*
|
|
126
|
+
* @returns a handle that stops delivering events; see {@link PaymentSubscription.remove}.
|
|
127
|
+
*/
|
|
128
|
+
pay(request, listener) {
|
|
129
|
+
const requestId = newRequestId();
|
|
130
|
+
let removed = false;
|
|
131
|
+
const subscription = Native.addListener("onPaymentEvent", (payload) => {
|
|
132
|
+
if (payload.requestId !== requestId)
|
|
133
|
+
return;
|
|
134
|
+
if (isTerminal(payload.event))
|
|
135
|
+
remove();
|
|
136
|
+
listener(payload.event);
|
|
137
|
+
});
|
|
138
|
+
const remove = () => {
|
|
139
|
+
if (removed)
|
|
140
|
+
return;
|
|
141
|
+
removed = true;
|
|
142
|
+
subscription.remove();
|
|
143
|
+
Native.stopPaymentEvents(requestId);
|
|
144
|
+
};
|
|
145
|
+
Native.startPayment(requestId, request);
|
|
146
|
+
return { remove };
|
|
147
|
+
},
|
|
148
|
+
/**
|
|
149
|
+
* {@link pay} reduced to its outcome, for callers that don't render the intermediate states.
|
|
150
|
+
*
|
|
151
|
+
* @returns the terminal {@link PayResult}.
|
|
152
|
+
* @throws AcceptError whatever the payment would have reported as `creationFailed` — including
|
|
153
|
+
* `PaymentInProgress`, `NotAuthenticated`, `PluginNotReadyForPayments`, `AmountBelowMinimum`,
|
|
154
|
+
* and `LocationPermissionRequired`.
|
|
155
|
+
*/
|
|
156
|
+
payAsync(request) {
|
|
157
|
+
return new Promise((resolve, reject) => {
|
|
158
|
+
payments.pay(request, (event) => {
|
|
159
|
+
if (event.type === "result")
|
|
160
|
+
resolve(event.payResult);
|
|
161
|
+
else if (event.type === "creationFailed")
|
|
162
|
+
reject(toAcceptError(event.error));
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
},
|
|
166
|
+
/**
|
|
167
|
+
* The current status of the payment identified by `paymentToken`.
|
|
168
|
+
*
|
|
169
|
+
* @throws AcceptError `NotAuthenticated`, `SessionExpired`, `PaymentNotFound`,
|
|
170
|
+
* `NoInternetConnection`, `Unknown`.
|
|
171
|
+
*/
|
|
172
|
+
status(paymentToken) {
|
|
173
|
+
return mapErrors(() => Native.getPaymentStatus(paymentToken));
|
|
174
|
+
},
|
|
175
|
+
/**
|
|
176
|
+
* Cancels the payment identified by `paymentToken`.
|
|
177
|
+
*
|
|
178
|
+
* @returns the resulting {@link PaymentState}.
|
|
179
|
+
* @throws AcceptError `NotAuthenticated`, `SessionExpired`, `PaymentNotFound`,
|
|
180
|
+
* `NoInternetConnection`, `Unknown`.
|
|
181
|
+
*/
|
|
182
|
+
cancel(paymentToken) {
|
|
183
|
+
return mapErrors(() => Native.cancelPayment(paymentToken));
|
|
184
|
+
},
|
|
185
|
+
/**
|
|
186
|
+
* Refunds the payment identified by `paymentToken`.
|
|
187
|
+
*
|
|
188
|
+
* @returns the resulting {@link PaymentState}.
|
|
189
|
+
* @throws AcceptError `NotAuthenticated`, `SessionExpired`, `PaymentNotFound`,
|
|
190
|
+
* `NoInternetConnection`, `Unknown`.
|
|
191
|
+
*/
|
|
192
|
+
refund(paymentToken, reason) {
|
|
193
|
+
return mapErrors(() => Native.refundPayment(paymentToken, reason));
|
|
194
|
+
},
|
|
195
|
+
};
|
|
196
|
+
/**
|
|
197
|
+
* The Accept plugin app — the companion that drives the physical terminal. Mirrors `Accept.plugin`.
|
|
198
|
+
*/
|
|
199
|
+
const plugin = {
|
|
200
|
+
/**
|
|
201
|
+
* Whether the plugin app is installed on this device.
|
|
202
|
+
*
|
|
203
|
+
* @throws AcceptError `NotInitialized`, `Unknown`.
|
|
204
|
+
*/
|
|
205
|
+
isInstalled() {
|
|
206
|
+
return mapErrorsSync(() => Native.isPluginInstalled());
|
|
207
|
+
},
|
|
208
|
+
/**
|
|
209
|
+
* Opens the plugin's store listing so the merchant can install it. Uses the organization's
|
|
210
|
+
* branded listing when one is configured and the SDK is authenticated.
|
|
211
|
+
*
|
|
212
|
+
* @throws AcceptError `NotInitialized`, `Unknown`.
|
|
213
|
+
*/
|
|
214
|
+
install() {
|
|
215
|
+
return mapErrors(() => Native.installPlugin());
|
|
216
|
+
},
|
|
217
|
+
/**
|
|
218
|
+
* Runs the plugin's terminal activation flow and resolves when it finishes. Activation is
|
|
219
|
+
* required before the device can take card payments.
|
|
220
|
+
*
|
|
221
|
+
* @throws AcceptError `ActivationInProgress`, `NotAuthenticated`, `PluginUnavailable`,
|
|
222
|
+
* `NoInternetConnection`, `NoTidsAvailableForMerchant`, `MerchantOnboardingIncomplete`,
|
|
223
|
+
* `Unknown`.
|
|
224
|
+
*/
|
|
225
|
+
activateTerminal() {
|
|
226
|
+
return mapErrors(() => Native.activateTerminal());
|
|
227
|
+
},
|
|
228
|
+
/**
|
|
229
|
+
* The plugin's current installed/authenticated/ready state.
|
|
230
|
+
*
|
|
231
|
+
* @throws AcceptError `NotInitialized`, `PluginUnavailable`, `PluginTimeout`, `Unknown`.
|
|
232
|
+
*/
|
|
233
|
+
status() {
|
|
234
|
+
return mapErrors(() => Native.getPluginStatus());
|
|
235
|
+
},
|
|
236
|
+
/**
|
|
237
|
+
* Whether a newer plugin build is available on Google Play. Call {@link install} to send the
|
|
238
|
+
* merchant to its listing.
|
|
239
|
+
*
|
|
240
|
+
* @throws AcceptError `NotInitialized`, `PluginUnavailable`, `PluginTimeout`, `Unknown`.
|
|
241
|
+
*/
|
|
242
|
+
updateInfo() {
|
|
243
|
+
return mapErrors(() => Native.getPluginUpdateInfo());
|
|
244
|
+
},
|
|
245
|
+
/**
|
|
246
|
+
* Logs the merchant out of the plugin app.
|
|
247
|
+
*
|
|
248
|
+
* @throws AcceptError `NotInitialized`, `PluginUnavailable`, `PluginTimeout`, `Unknown`.
|
|
249
|
+
*/
|
|
250
|
+
logout() {
|
|
251
|
+
return mapErrors(() => Native.logoutPlugin());
|
|
252
|
+
},
|
|
253
|
+
};
|
|
254
|
+
/**
|
|
255
|
+
* Screen topology, for dual-sided POS hardware. Mirrors `Accept.displays`.
|
|
256
|
+
*
|
|
257
|
+
* Every member reads the platform live, so a display hot-plugged or powered off between calls is
|
|
258
|
+
* reflected immediately. None of them throw.
|
|
259
|
+
*/
|
|
260
|
+
const displays = {
|
|
261
|
+
/** Every display the device currently reports, primary first. */
|
|
262
|
+
all() {
|
|
263
|
+
return Native.getDisplays();
|
|
264
|
+
},
|
|
265
|
+
/**
|
|
266
|
+
* The customer-facing panel of a dual-sided device, or `null` on single-screen devices. This is
|
|
267
|
+
* what `{ type: 'customerFacing' }` targets.
|
|
268
|
+
*/
|
|
269
|
+
customerFacing() {
|
|
270
|
+
return Native.getCustomerFacingDisplay();
|
|
271
|
+
},
|
|
272
|
+
/** Whether a customer-facing display is available right now. */
|
|
273
|
+
get isDualScreen() {
|
|
274
|
+
return Native.isDualScreen();
|
|
275
|
+
},
|
|
276
|
+
};
|
|
277
|
+
/** The listener currently receiving forwarded SDK logs, if any. */
|
|
278
|
+
let logSubscription = null;
|
|
279
|
+
/**
|
|
280
|
+
* Entry point to the Accept SDK. Mirrors the `Accept` object in the Accept SDK for Android, so the
|
|
281
|
+
* Android reference documentation applies unchanged.
|
|
282
|
+
*
|
|
283
|
+
* ```ts
|
|
284
|
+
* import Accept from '@tapayadot/accept-react-native';
|
|
285
|
+
*
|
|
286
|
+
* Accept.initialize({ isProduction: false });
|
|
287
|
+
* await Accept.auth.authenticate(merchantToken);
|
|
288
|
+
*
|
|
289
|
+
* if (!Accept.plugin.isInstalled()) await Accept.plugin.install();
|
|
290
|
+
* await Accept.plugin.activateTerminal();
|
|
291
|
+
*
|
|
292
|
+
* const result = await Accept.payments.payAsync({ amount: 1000, currency: 'USD' });
|
|
293
|
+
* ```
|
|
294
|
+
*/
|
|
295
|
+
export const Accept = {
|
|
296
|
+
auth,
|
|
297
|
+
sdk,
|
|
298
|
+
merchant,
|
|
299
|
+
payments,
|
|
300
|
+
plugin,
|
|
301
|
+
displays,
|
|
302
|
+
/**
|
|
303
|
+
* Initializes the SDK against sandbox or production. Must be called before any other surface is
|
|
304
|
+
* used — typically once, at app startup.
|
|
305
|
+
*
|
|
306
|
+
* Safe to call more than once; each call resets which environment subsequent requests target.
|
|
307
|
+
*/
|
|
308
|
+
initialize(options = {}) {
|
|
309
|
+
Native.initialize(options.isProduction ?? false);
|
|
310
|
+
},
|
|
311
|
+
/** The SDK's current lifecycle state. */
|
|
312
|
+
get state() {
|
|
313
|
+
return Native.getState();
|
|
314
|
+
},
|
|
315
|
+
/**
|
|
316
|
+
* Subscribes to {@link state} transitions. The listener fires with the current state on
|
|
317
|
+
* subscription, then on every change.
|
|
318
|
+
*/
|
|
319
|
+
addStateListener(listener) {
|
|
320
|
+
return Native.addListener("onStateChange", ({ state }) => listener(state));
|
|
321
|
+
},
|
|
322
|
+
/**
|
|
323
|
+
* Clears all locally persisted SDK state — auth token, device id, cached config, and theme — and
|
|
324
|
+
* resets {@link state} to `idle`. Call this on merchant logout.
|
|
325
|
+
*
|
|
326
|
+
* @throws AcceptError `Unknown`.
|
|
327
|
+
*/
|
|
328
|
+
clear() {
|
|
329
|
+
return mapErrors(() => Native.clear());
|
|
330
|
+
},
|
|
331
|
+
/**
|
|
332
|
+
* Enables or disables diagnostic logging. Shorthand for {@link setLogLevel}: `true` maps to
|
|
333
|
+
* `'DEBUG'`, `false` to `'NONE'`.
|
|
334
|
+
*/
|
|
335
|
+
setDebugLoggingEnabled(enabled) {
|
|
336
|
+
Native.setDebugLoggingEnabled(enabled);
|
|
337
|
+
},
|
|
338
|
+
/**
|
|
339
|
+
* Sets the verbosity of diagnostic logging. Defaults to `'DEBUG'` against sandbox and `'NONE'`
|
|
340
|
+
* against production; call after {@link initialize} to override.
|
|
341
|
+
*/
|
|
342
|
+
setLogLevel(level) {
|
|
343
|
+
Native.setLogLevel(level);
|
|
344
|
+
},
|
|
345
|
+
/**
|
|
346
|
+
* Routes SDK logs into `listener` instead of Logcat, for forwarding into your own logging stack.
|
|
347
|
+
* Pass `null` to restore the default Logcat sink.
|
|
348
|
+
*/
|
|
349
|
+
setLogger(listener) {
|
|
350
|
+
logSubscription?.remove();
|
|
351
|
+
logSubscription = listener ? Native.addListener("onLog", listener) : null;
|
|
352
|
+
Native.setLogForwardingEnabled(listener !== null);
|
|
353
|
+
},
|
|
354
|
+
/**
|
|
355
|
+
* Sets the branding applied to the plugin's activation, status, and payment screens.
|
|
356
|
+
*
|
|
357
|
+
* Session-wide, not per payment: it persists until changed or cleared with `null`. Pushed to the
|
|
358
|
+
* plugin opportunistically the next time it is bound or launched, so there is no confirmation
|
|
359
|
+
* that it was applied — the plugin may not be installed or running yet.
|
|
360
|
+
*/
|
|
361
|
+
setTheme(theme) {
|
|
362
|
+
Native.setTheme(theme);
|
|
363
|
+
},
|
|
364
|
+
/**
|
|
365
|
+
* The theme currently set via {@link setTheme}, or `null`. Reflects local SDK state only, not
|
|
366
|
+
* whether the plugin applied it.
|
|
367
|
+
*/
|
|
368
|
+
getTheme() {
|
|
369
|
+
return Native.getTheme();
|
|
370
|
+
},
|
|
371
|
+
/**
|
|
372
|
+
* Stores `base64` image data in SDK-private storage and returns a `content://` URL the plugin can
|
|
373
|
+
* read — for a logo the host app holds locally rather than at a stable URL. Use the result
|
|
374
|
+
* anywhere an {@link AcceptTheme} image field takes a URL.
|
|
375
|
+
*
|
|
376
|
+
* `assetToBase64` from `@tapayadot/accept-react-native/utils` turns a `require('./logo.png')`
|
|
377
|
+
* into the expected string.
|
|
378
|
+
*
|
|
379
|
+
* @param fileExtension the extension to store the data under, without a leading dot. Tells the
|
|
380
|
+
* plugin how to decode it; defaults to `'png'`.
|
|
381
|
+
* @throws AcceptError `NotInitialized`.
|
|
382
|
+
*/
|
|
383
|
+
createLocalThemeImageUri(base64, fileExtension = "png") {
|
|
384
|
+
return mapErrorsSync(() => Native.createLocalThemeImageUri(base64, fileExtension));
|
|
385
|
+
},
|
|
386
|
+
};
|
|
387
|
+
//# sourceMappingURL=Accept.js.map
|