@funnelfox/billing 0.13.1 → 0.13.2
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/dist/chunk-index.cjs.js +209 -30
- package/dist/chunk-index.es.js +209 -30
- package/dist/funnelfox-billing.js +209 -30
- package/dist/funnelfox-billing.min.js +1 -1
- package/package.json +2 -2
- package/src/types.d.ts +42 -16
|
@@ -565,7 +565,7 @@
|
|
|
565
565
|
/**
|
|
566
566
|
* @fileoverview Constants for Funnefox SDK
|
|
567
567
|
*/
|
|
568
|
-
const SDK_VERSION = '0.13.
|
|
568
|
+
const SDK_VERSION = '0.13.2';
|
|
569
569
|
const DEFAULTS = {
|
|
570
570
|
BASE_URL: 'https://billing.funnelfox.com',
|
|
571
571
|
REGION: 'default',
|
|
@@ -1381,11 +1381,13 @@
|
|
|
1381
1381
|
}
|
|
1382
1382
|
}
|
|
1383
1383
|
/**
|
|
1384
|
-
* Sends the request exactly once: no retry and no client timeout
|
|
1384
|
+
* Sends the request exactly once: no retry and, without `timeoutMs`, no client timeout
|
|
1385
|
+
* (FFB-704, decision 9).
|
|
1385
1386
|
* Same URL, headers and error classes as `request()`. Used only by `silentPurchase`'s
|
|
1386
|
-
* `handle3DS` mode for `one_click` and `resume_payment`, which must not be POSTed twice
|
|
1387
|
+
* `handle3DS` mode for `one_click` and `resume_payment`, which must not be POSTed twice;
|
|
1388
|
+
* `one_click` is re-sent by the caller only with the same idempotency key.
|
|
1387
1389
|
*/
|
|
1388
|
-
async requestOnce(endpoint, options = {}) {
|
|
1390
|
+
async requestOnce(endpoint, options = {}, timeoutMs) {
|
|
1389
1391
|
const url = `${this.baseUrl}/${this.orgId}${endpoint}`;
|
|
1390
1392
|
const requestOptions = {
|
|
1391
1393
|
method: 'GET',
|
|
@@ -1397,7 +1399,10 @@
|
|
|
1397
1399
|
...options,
|
|
1398
1400
|
};
|
|
1399
1401
|
try {
|
|
1400
|
-
|
|
1402
|
+
const request = this._makeRequest(url, requestOptions);
|
|
1403
|
+
return await (timeoutMs
|
|
1404
|
+
? withTimeout(request, timeoutMs, 'Request timed out')
|
|
1405
|
+
: request);
|
|
1401
1406
|
}
|
|
1402
1407
|
catch (error) {
|
|
1403
1408
|
if (error instanceof APIError) {
|
|
@@ -1603,11 +1608,11 @@
|
|
|
1603
1608
|
}));
|
|
1604
1609
|
}
|
|
1605
1610
|
/** `one_click`, POSTed exactly once (see `requestOnce`). */
|
|
1606
|
-
async oneClickOnce(payload) {
|
|
1611
|
+
async oneClickOnce(payload, timeoutMs) {
|
|
1607
1612
|
return (await this.requestOnce(API_ENDPOINTS.ONE_CLICK, {
|
|
1608
1613
|
method: 'POST',
|
|
1609
1614
|
body: JSON.stringify(payload),
|
|
1610
|
-
}));
|
|
1615
|
+
}, timeoutMs));
|
|
1611
1616
|
}
|
|
1612
1617
|
/** `resume_payment`, POSTed exactly once (see `requestOnce`). */
|
|
1613
1618
|
async resumePaymentOnce(params) {
|
|
@@ -2160,6 +2165,9 @@
|
|
|
2160
2165
|
this.counter = 0;
|
|
2161
2166
|
this.cachedSessionResponse = null;
|
|
2162
2167
|
this.taxRecalcSeq = 0;
|
|
2168
|
+
// WebKit allows one ApplePaySession per page: a second tap while the sheet is
|
|
2169
|
+
// still opening throws InvalidAccessError, but Primer asks to start first.
|
|
2170
|
+
this.isApplePaySheetOpen = false;
|
|
2163
2171
|
this.cardSessionFieldConfig = {};
|
|
2164
2172
|
this.isTelemetryEnabled = false;
|
|
2165
2173
|
this.telemetryCleanup = null;
|
|
@@ -2326,6 +2334,7 @@
|
|
|
2326
2334
|
primerHandler.handleFailure(error?.message || 'Payment processing failed');
|
|
2327
2335
|
}
|
|
2328
2336
|
finally {
|
|
2337
|
+
this.isApplePaySheetOpen = false;
|
|
2329
2338
|
this.onLoaderChangeWithRace(false);
|
|
2330
2339
|
this._setState('ready');
|
|
2331
2340
|
}
|
|
@@ -2351,6 +2360,7 @@
|
|
|
2351
2360
|
primerHandler.handleFailure(error?.message || 'Payment processing failed');
|
|
2352
2361
|
}
|
|
2353
2362
|
finally {
|
|
2363
|
+
this.isApplePaySheetOpen = false;
|
|
2354
2364
|
this.emit(EVENTS.PURCHASE_COMPLETED);
|
|
2355
2365
|
this.onLoaderChangeWithRace(false);
|
|
2356
2366
|
this._setState('ready');
|
|
@@ -2679,6 +2689,7 @@
|
|
|
2679
2689
|
onTokenizeSuccess: this.handleTokenizeSuccess,
|
|
2680
2690
|
onResumeSuccess: this.handleResumeSuccess,
|
|
2681
2691
|
onResumeError: error => {
|
|
2692
|
+
this.isApplePaySheetOpen = false;
|
|
2682
2693
|
if (error.stack?.includes('PROCESSOR_3DS') &&
|
|
2683
2694
|
error.code === 'RESUME_ERROR' &&
|
|
2684
2695
|
error.message?.includes('fetch resume key')) {
|
|
@@ -2688,15 +2699,23 @@
|
|
|
2688
2699
|
this.emit(EVENTS.PURCHASE_FAILURE, error);
|
|
2689
2700
|
},
|
|
2690
2701
|
onCheckoutFail: error => {
|
|
2702
|
+
this.isApplePaySheetOpen = false;
|
|
2691
2703
|
this.emit(EVENTS.PURCHASE_FAILURE, error);
|
|
2692
2704
|
},
|
|
2693
2705
|
onTokenizeError: error => {
|
|
2706
|
+
this.isApplePaySheetOpen = false;
|
|
2694
2707
|
this.emit(EVENTS.PURCHASE_FAILURE, error);
|
|
2695
2708
|
},
|
|
2696
2709
|
onTokenizeStart: () => {
|
|
2697
2710
|
wasPaymentProcessedStarted = true;
|
|
2698
2711
|
},
|
|
2699
2712
|
onTokenizeShouldStart: data => {
|
|
2713
|
+
if (data.paymentMethodType === exports.PaymentMethod.APPLE_PAY) {
|
|
2714
|
+
if (this.isApplePaySheetOpen) {
|
|
2715
|
+
return false;
|
|
2716
|
+
}
|
|
2717
|
+
this.isApplePaySheetOpen = true;
|
|
2718
|
+
}
|
|
2700
2719
|
this.activePaymentMethodType = data.paymentMethodType;
|
|
2701
2720
|
this.emit(EVENTS.ERROR, undefined);
|
|
2702
2721
|
this.emit(EVENTS.START_PURCHASE, data.paymentMethodType);
|
|
@@ -2708,6 +2727,7 @@
|
|
|
2708
2727
|
this.emit(EVENTS.ERROR, undefined);
|
|
2709
2728
|
break;
|
|
2710
2729
|
case 'PAYMENT_METHOD_UNSELECTED':
|
|
2730
|
+
this.isApplePaySheetOpen = false;
|
|
2711
2731
|
if (!wasPaymentProcessedStarted) {
|
|
2712
2732
|
this.emit(EVENTS.PURCHASE_CANCELLED);
|
|
2713
2733
|
}
|
|
@@ -2987,11 +3007,23 @@
|
|
|
2987
3007
|
* checkout, tokenize a vaulted instrument through the vault manager as a stand-in, and in
|
|
2988
3008
|
* `onTokenizeSuccess` continue with the one-click `action_required_token` instead. Primer then
|
|
2989
3009
|
* shows its 3DS overlay; `onResumeSuccess` yields the resume token for `resume_payment`.
|
|
3010
|
+
*
|
|
3011
|
+
* With processor 3DS (`PROCESSOR_3DS`) Primer frames the processor's hosted 3DS page and cannot
|
|
3012
|
+
* tell a frictionless check from a challenge, and nothing reaches the page from the cross-origin
|
|
3013
|
+
* frame (FFB-758 spike). A frictionless check finishes within ~5 s, so the overlay stays
|
|
3014
|
+
* invisible for `THREE_DS_OVERLAY_REVEAL_DELAY_MS` and only then counts as a shown challenge.
|
|
2990
3015
|
*/
|
|
2991
3016
|
/** Primer client-token intents that carry a 3DS step. */
|
|
2992
3017
|
const PRIMER_3DS_INTENTS = ['3DS_AUTHENTICATION', 'PROCESSOR_3DS'];
|
|
2993
3018
|
/** Default `threeDSTimeoutMs`. */
|
|
2994
3019
|
const DEFAULT_THREE_DS_TIMEOUT_MS = 600000;
|
|
3020
|
+
/**
|
|
3021
|
+
* How long Primer's 3DS overlay stays invisible. Frictionless checks on billing-dev took
|
|
3022
|
+
* 4.2-5.0 s from overlay to resume; a real challenge is shown this much later.
|
|
3023
|
+
*/
|
|
3024
|
+
const THREE_DS_OVERLAY_REVEAL_DELAY_MS = 6000;
|
|
3025
|
+
/** Primer's 3DS overlay (Primer Web SDK 2.57.3, verified in the FFB-758 spike). */
|
|
3026
|
+
const PRIMER_OVERLAY_SELECTOR = '#primer-overlay';
|
|
2995
3027
|
/** Close button of Primer's 3DS overlay (Primer Web SDK 2.57.3, verified in the spike). */
|
|
2996
3028
|
const PRIMER_OVERLAY_CLOSE_SELECTOR = '[data-testid="OverlayContent.closeButton"]';
|
|
2997
3029
|
/** Decodes the `intent` of a Primer client token (a JWT); `null` if it is not one. */
|
|
@@ -3035,6 +3067,26 @@
|
|
|
3035
3067
|
const button = document.querySelector(PRIMER_OVERLAY_CLOSE_SELECTOR);
|
|
3036
3068
|
button?.click();
|
|
3037
3069
|
}
|
|
3070
|
+
/** Hides Primer's overlay until the returned function is called. */
|
|
3071
|
+
function hidePrimerOverlay() {
|
|
3072
|
+
if (typeof document === 'undefined') {
|
|
3073
|
+
return () => { };
|
|
3074
|
+
}
|
|
3075
|
+
const style = document.createElement('style');
|
|
3076
|
+
style.textContent = `${PRIMER_OVERLAY_SELECTOR}{opacity:0!important;pointer-events:none!important}`;
|
|
3077
|
+
document.head.appendChild(style);
|
|
3078
|
+
return () => style.remove();
|
|
3079
|
+
}
|
|
3080
|
+
/**
|
|
3081
|
+
* A Primer update that renames the overlay would leave it visible during the hidden phase, while
|
|
3082
|
+
* `threeDSChallenged` stays false for a check that finishes in that time.
|
|
3083
|
+
*/
|
|
3084
|
+
function warnIfOverlayNotFound() {
|
|
3085
|
+
if (typeof document !== 'undefined' &&
|
|
3086
|
+
!document.querySelector(PRIMER_OVERLAY_SELECTOR)) {
|
|
3087
|
+
console.warn(`[FunnelfoxSDK] Primer 3DS overlay ${PRIMER_OVERLAY_SELECTOR} not found`);
|
|
3088
|
+
}
|
|
3089
|
+
}
|
|
3038
3090
|
function toPrimerError(message, error) {
|
|
3039
3091
|
return error instanceof PrimerError ? error : new PrimerError(message, error);
|
|
3040
3092
|
}
|
|
@@ -3065,6 +3117,9 @@
|
|
|
3065
3117
|
return new Promise(resolve => {
|
|
3066
3118
|
let settled = false;
|
|
3067
3119
|
let tokenized = false;
|
|
3120
|
+
let revealed = false;
|
|
3121
|
+
let revealTimer = null;
|
|
3122
|
+
let showOverlay = () => { };
|
|
3068
3123
|
// True only while create_client_session is in flight.
|
|
3069
3124
|
let sessionInFlight = false;
|
|
3070
3125
|
let timer = null;
|
|
@@ -3078,12 +3133,17 @@
|
|
|
3078
3133
|
clearTimeout(timer);
|
|
3079
3134
|
timer = null;
|
|
3080
3135
|
}
|
|
3136
|
+
if (revealTimer) {
|
|
3137
|
+
clearTimeout(revealTimer);
|
|
3138
|
+
revealTimer = null;
|
|
3139
|
+
}
|
|
3140
|
+
showOverlay();
|
|
3081
3141
|
headless = null;
|
|
3082
3142
|
resolve(result);
|
|
3083
3143
|
};
|
|
3084
|
-
|
|
3144
|
+
const onTimeout = () => {
|
|
3085
3145
|
timer = null;
|
|
3086
|
-
if (
|
|
3146
|
+
if (revealed) {
|
|
3087
3147
|
// The challenge was shown and the customer did not finish it.
|
|
3088
3148
|
settle({ kind: 'abandoned' });
|
|
3089
3149
|
// Close Primer's overlay; the close error it raises is ignored (already settled).
|
|
@@ -3099,17 +3159,37 @@
|
|
|
3099
3159
|
});
|
|
3100
3160
|
return;
|
|
3101
3161
|
}
|
|
3162
|
+
if (tokenized) {
|
|
3163
|
+
// The overlay is about to be shown: the reveal restarts the timer.
|
|
3164
|
+
return;
|
|
3165
|
+
}
|
|
3102
3166
|
settle({
|
|
3103
3167
|
kind: 'error',
|
|
3104
3168
|
error: new PrimerError('Timed out before the 3DS challenge was shown (threeDSTimeoutMs)'),
|
|
3105
3169
|
});
|
|
3106
|
-
}
|
|
3170
|
+
};
|
|
3171
|
+
timer = setTimeout(onTimeout, timeoutMs);
|
|
3107
3172
|
const onTokenizeSuccess = (_data, handler) => {
|
|
3108
|
-
|
|
3173
|
+
// A repeated tokenization would start a second reveal timer, so the challenge
|
|
3174
|
+
// (and the caller's onThreeDSStart) would be reported twice: refuse it.
|
|
3175
|
+
if (settled || tokenized) {
|
|
3109
3176
|
callSafely(() => handler.handleFailure());
|
|
3110
3177
|
return;
|
|
3111
3178
|
}
|
|
3112
3179
|
tokenized = true;
|
|
3180
|
+
showOverlay = hidePrimerOverlay();
|
|
3181
|
+
revealTimer = setTimeout(() => {
|
|
3182
|
+
revealTimer = null;
|
|
3183
|
+
revealed = true;
|
|
3184
|
+
showOverlay();
|
|
3185
|
+
warnIfOverlayNotFound();
|
|
3186
|
+
callSafely(params.onChallengeShown);
|
|
3187
|
+
// The whole timeout belongs to the challenge the customer can see.
|
|
3188
|
+
if (timer) {
|
|
3189
|
+
clearTimeout(timer);
|
|
3190
|
+
}
|
|
3191
|
+
timer = setTimeout(onTimeout, timeoutMs);
|
|
3192
|
+
}, params.revealDelayMs);
|
|
3113
3193
|
// Ignore the stand-in vaulted token: run the one-click 3DS action instead.
|
|
3114
3194
|
handler.continueWithNewClientToken(actionToken);
|
|
3115
3195
|
};
|
|
@@ -3123,6 +3203,10 @@
|
|
|
3123
3203
|
clearTimeout(timer);
|
|
3124
3204
|
timer = null;
|
|
3125
3205
|
}
|
|
3206
|
+
if (revealTimer) {
|
|
3207
|
+
clearTimeout(revealTimer);
|
|
3208
|
+
revealTimer = null;
|
|
3209
|
+
}
|
|
3126
3210
|
let response;
|
|
3127
3211
|
try {
|
|
3128
3212
|
response = await apiClient.resumePaymentOnce({
|
|
@@ -3376,7 +3460,80 @@
|
|
|
3376
3460
|
}
|
|
3377
3461
|
const ONE_CLICK_IN_PROGRESS = 'one_click_in_progress';
|
|
3378
3462
|
const DOUBLE_PURCHASE = 'double_purchase';
|
|
3463
|
+
const IDEMPOTENCY_KEY_IN_PROGRESS = 'idempotency_key_in_progress';
|
|
3464
|
+
const ONE_CLICK_RETRY_DELAYS_MS = [1000, 2000, 4000];
|
|
3465
|
+
/** Longer than the backend's wait for the user's lock (~12.6 s). */
|
|
3466
|
+
const ONE_CLICK_TIMEOUT_MS = 25000;
|
|
3379
3467
|
const oneClickInFlight = new Set();
|
|
3468
|
+
/** A random UUID v4, or `null` when the browser has no crypto (then one_click is not retried). */
|
|
3469
|
+
function createIdempotencyKey() {
|
|
3470
|
+
const cryptoApi = typeof crypto === 'undefined' ? undefined : crypto;
|
|
3471
|
+
if (typeof cryptoApi?.randomUUID === 'function') {
|
|
3472
|
+
return cryptoApi.randomUUID();
|
|
3473
|
+
}
|
|
3474
|
+
if (typeof cryptoApi?.getRandomValues !== 'function') {
|
|
3475
|
+
return null;
|
|
3476
|
+
}
|
|
3477
|
+
const bytes = cryptoApi.getRandomValues(new Uint8Array(16));
|
|
3478
|
+
bytes[6] = (bytes[6] & 0x0f) | 0x40;
|
|
3479
|
+
bytes[8] = (bytes[8] & 0x3f) | 0x80;
|
|
3480
|
+
const hex = Array.from(bytes, byte => byte.toString(16).padStart(2, '0'));
|
|
3481
|
+
return [
|
|
3482
|
+
hex.slice(0, 4).join(''),
|
|
3483
|
+
hex.slice(4, 6).join(''),
|
|
3484
|
+
hex.slice(6, 8).join(''),
|
|
3485
|
+
hex.slice(8, 10).join(''),
|
|
3486
|
+
hex.slice(10, 16).join(''),
|
|
3487
|
+
].join('-');
|
|
3488
|
+
}
|
|
3489
|
+
/**
|
|
3490
|
+
* Failures after which the backend may or may not have processed the request. Retrying them
|
|
3491
|
+
* with the same idempotency key is safe: the backend never charges a key twice (FFB-757).
|
|
3492
|
+
* A 2xx APIError means the body could not be parsed.
|
|
3493
|
+
*/
|
|
3494
|
+
function isRetryableOneClickError(error) {
|
|
3495
|
+
if (error instanceof NetworkError) {
|
|
3496
|
+
return true;
|
|
3497
|
+
}
|
|
3498
|
+
if (!(error instanceof APIError) || error.statusCode === null) {
|
|
3499
|
+
return false;
|
|
3500
|
+
}
|
|
3501
|
+
if (error.statusCode >= 500) {
|
|
3502
|
+
return true;
|
|
3503
|
+
}
|
|
3504
|
+
if (error.statusCode >= 200 && error.statusCode < 300) {
|
|
3505
|
+
return true;
|
|
3506
|
+
}
|
|
3507
|
+
return (error.statusCode === 400 && error.errorCode === IDEMPOTENCY_KEY_IN_PROGRESS);
|
|
3508
|
+
}
|
|
3509
|
+
function isEmptyResponse(response) {
|
|
3510
|
+
return !response || typeof response !== 'object' || !('status' in response);
|
|
3511
|
+
}
|
|
3512
|
+
/** `one_click`, retried with the same idempotency key; sent once when there is no key. */
|
|
3513
|
+
async function postOneClick(apiClient, payload) {
|
|
3514
|
+
if (!payload.idempotency_key) {
|
|
3515
|
+
return apiClient.oneClickOnce(payload);
|
|
3516
|
+
}
|
|
3517
|
+
for (const delay of ONE_CLICK_RETRY_DELAYS_MS) {
|
|
3518
|
+
try {
|
|
3519
|
+
const response = await apiClient.oneClickOnce(payload, ONE_CLICK_TIMEOUT_MS);
|
|
3520
|
+
if (!isEmptyResponse(response)) {
|
|
3521
|
+
return response;
|
|
3522
|
+
}
|
|
3523
|
+
}
|
|
3524
|
+
catch (error) {
|
|
3525
|
+
if (!isRetryableOneClickError(error)) {
|
|
3526
|
+
throw error;
|
|
3527
|
+
}
|
|
3528
|
+
}
|
|
3529
|
+
await sleep(delay);
|
|
3530
|
+
}
|
|
3531
|
+
const response = await apiClient.oneClickOnce(payload, ONE_CLICK_TIMEOUT_MS);
|
|
3532
|
+
if (isEmptyResponse(response)) {
|
|
3533
|
+
throw new NetworkError('one_click returned an empty response');
|
|
3534
|
+
}
|
|
3535
|
+
return response;
|
|
3536
|
+
}
|
|
3380
3537
|
function declineFields(data) {
|
|
3381
3538
|
return {
|
|
3382
3539
|
failedMessageForUser: data.failed_message_for_user ?? null,
|
|
@@ -3465,7 +3622,7 @@
|
|
|
3465
3622
|
}
|
|
3466
3623
|
}
|
|
3467
3624
|
/** Maps a `resume_payment` response after a challenge (rows 5, 6, 6b, 6c, 7, 8). */
|
|
3468
|
-
function mapResumeResponse(response, orderId, threeDSAuthDeclineCodes = THREE_DS_AUTH_DECLINE_CODES) {
|
|
3625
|
+
function mapResumeResponse(response, orderId, threeDSChallenged, threeDSAuthDeclineCodes = THREE_DS_AUTH_DECLINE_CODES) {
|
|
3469
3626
|
const data = response?.data;
|
|
3470
3627
|
if (response?.status !== 'success' || !data) {
|
|
3471
3628
|
return {
|
|
@@ -3473,7 +3630,7 @@
|
|
|
3473
3630
|
result: {
|
|
3474
3631
|
outcome: 'error',
|
|
3475
3632
|
orderId,
|
|
3476
|
-
threeDSChallenged
|
|
3633
|
+
threeDSChallenged,
|
|
3477
3634
|
error: envelopeError(response, 'Resume payment failed'),
|
|
3478
3635
|
failedRequest: 'resume_payment',
|
|
3479
3636
|
},
|
|
@@ -3486,7 +3643,7 @@
|
|
|
3486
3643
|
result: {
|
|
3487
3644
|
outcome: 'error',
|
|
3488
3645
|
orderId,
|
|
3489
|
-
threeDSChallenged
|
|
3646
|
+
threeDSChallenged,
|
|
3490
3647
|
error: new FunnefoxSDKError('resume_payment returned another action token; chained 3DS is not supported', 'one_click_chained_action'),
|
|
3491
3648
|
},
|
|
3492
3649
|
};
|
|
@@ -3495,22 +3652,24 @@
|
|
|
3495
3652
|
case 'succeeded':
|
|
3496
3653
|
return {
|
|
3497
3654
|
threeDS: 'passed',
|
|
3498
|
-
result: { outcome: 'succeeded', orderId, threeDSChallenged
|
|
3655
|
+
result: { outcome: 'succeeded', orderId, threeDSChallenged },
|
|
3499
3656
|
};
|
|
3500
3657
|
case 'processing':
|
|
3501
3658
|
return {
|
|
3502
3659
|
threeDS: 'passed',
|
|
3503
|
-
result: { outcome: 'processing', orderId, threeDSChallenged
|
|
3660
|
+
result: { outcome: 'processing', orderId, threeDSChallenged },
|
|
3504
3661
|
};
|
|
3505
3662
|
case 'failed': {
|
|
3506
|
-
|
|
3507
|
-
|
|
3663
|
+
// Without a shown challenge the customer saw no 3DS step: a decline is a plain decline.
|
|
3664
|
+
const authFailed = threeDSChallenged &&
|
|
3665
|
+
(threeDSAuthDeclineCodes === null ||
|
|
3666
|
+
threeDSAuthDeclineCodes.includes(data.decline_code ?? ''));
|
|
3508
3667
|
return {
|
|
3509
3668
|
threeDS: authFailed ? 'failed' : 'passed',
|
|
3510
3669
|
result: {
|
|
3511
3670
|
outcome: authFailed ? '3ds_failed' : 'declined',
|
|
3512
3671
|
orderId,
|
|
3513
|
-
threeDSChallenged
|
|
3672
|
+
threeDSChallenged,
|
|
3514
3673
|
...declineFields(data),
|
|
3515
3674
|
},
|
|
3516
3675
|
};
|
|
@@ -3521,7 +3680,7 @@
|
|
|
3521
3680
|
result: {
|
|
3522
3681
|
outcome: 'error',
|
|
3523
3682
|
orderId,
|
|
3524
|
-
threeDSChallenged
|
|
3683
|
+
threeDSChallenged,
|
|
3525
3684
|
error: new APIError(data.checkout_status === 'cancelled'
|
|
3526
3685
|
? 'Payment was cancelled'
|
|
3527
3686
|
: `Unhandled checkout status: ${data.checkout_status}`, null, { response }),
|
|
@@ -3529,30 +3688,30 @@
|
|
|
3529
3688
|
};
|
|
3530
3689
|
}
|
|
3531
3690
|
}
|
|
3532
|
-
function mapThreeDSRun(run, orderId) {
|
|
3691
|
+
function mapThreeDSRun(run, orderId, threeDSChallenged) {
|
|
3533
3692
|
switch (run.kind) {
|
|
3534
3693
|
case 'resumed':
|
|
3535
|
-
return mapResumeResponse(run.response, orderId);
|
|
3694
|
+
return mapResumeResponse(run.response, orderId, threeDSChallenged);
|
|
3536
3695
|
case 'failed':
|
|
3537
3696
|
return {
|
|
3538
3697
|
threeDS: 'failed',
|
|
3539
3698
|
result: {
|
|
3540
3699
|
outcome: '3ds_failed',
|
|
3541
3700
|
orderId,
|
|
3542
|
-
threeDSChallenged
|
|
3701
|
+
threeDSChallenged,
|
|
3543
3702
|
error: run.error,
|
|
3544
3703
|
},
|
|
3545
3704
|
};
|
|
3546
3705
|
case 'abandoned':
|
|
3547
3706
|
return {
|
|
3548
3707
|
threeDS: 'abandoned',
|
|
3549
|
-
result: { outcome: '3ds_abandoned', orderId, threeDSChallenged
|
|
3708
|
+
result: { outcome: '3ds_abandoned', orderId, threeDSChallenged },
|
|
3550
3709
|
};
|
|
3551
3710
|
default: {
|
|
3552
3711
|
const result = {
|
|
3553
3712
|
outcome: 'error',
|
|
3554
3713
|
orderId,
|
|
3555
|
-
threeDSChallenged
|
|
3714
|
+
threeDSChallenged,
|
|
3556
3715
|
error: run.error,
|
|
3557
3716
|
};
|
|
3558
3717
|
if (run.failedRequest) {
|
|
@@ -3615,9 +3774,14 @@
|
|
|
3615
3774
|
timeout: DEFAULTS.REQUEST_TIMEOUT,
|
|
3616
3775
|
retryAttempts: DEFAULTS.RETRY_ATTEMPTS,
|
|
3617
3776
|
});
|
|
3777
|
+
const payload = buildOneClickRequest(options);
|
|
3778
|
+
const idempotencyKey = createIdempotencyKey();
|
|
3779
|
+
if (idempotencyKey) {
|
|
3780
|
+
payload.idempotency_key = idempotencyKey;
|
|
3781
|
+
}
|
|
3618
3782
|
let response;
|
|
3619
3783
|
try {
|
|
3620
|
-
response = await apiClient
|
|
3784
|
+
response = await postOneClick(apiClient, payload);
|
|
3621
3785
|
}
|
|
3622
3786
|
catch (error) {
|
|
3623
3787
|
if (error instanceof APIError &&
|
|
@@ -3628,6 +3792,16 @@
|
|
|
3628
3792
|
threeDSChallenged: false,
|
|
3629
3793
|
};
|
|
3630
3794
|
}
|
|
3795
|
+
if (idempotencyKey && isRetryableOneClickError(error)) {
|
|
3796
|
+
// The charge may have gone through: the caller must not start a new payment.
|
|
3797
|
+
return {
|
|
3798
|
+
outcome: 'processing',
|
|
3799
|
+
orderId: null,
|
|
3800
|
+
threeDSChallenged: false,
|
|
3801
|
+
error: error,
|
|
3802
|
+
failedRequest: 'one_click',
|
|
3803
|
+
};
|
|
3804
|
+
}
|
|
3631
3805
|
return {
|
|
3632
3806
|
outcome: 'error',
|
|
3633
3807
|
orderId: null,
|
|
@@ -3641,15 +3815,15 @@
|
|
|
3641
3815
|
return step.result;
|
|
3642
3816
|
}
|
|
3643
3817
|
const { orderId, actionToken } = step;
|
|
3818
|
+
let challenged = false;
|
|
3644
3819
|
let ended = false;
|
|
3645
3820
|
const end = (result) => {
|
|
3646
|
-
if (ended) {
|
|
3821
|
+
if (!challenged || ended) {
|
|
3647
3822
|
return;
|
|
3648
3823
|
}
|
|
3649
3824
|
ended = true;
|
|
3650
3825
|
callHook('onThreeDSEnd', options.onThreeDSEnd, { result });
|
|
3651
3826
|
};
|
|
3652
|
-
callHook('onThreeDSStart', options.onThreeDSStart, { orderId });
|
|
3653
3827
|
try {
|
|
3654
3828
|
const run = await runOneClickThreeDS({
|
|
3655
3829
|
apiClient,
|
|
@@ -3659,8 +3833,13 @@
|
|
|
3659
3833
|
orderId,
|
|
3660
3834
|
actionToken,
|
|
3661
3835
|
timeoutMs: options.threeDSTimeoutMs ?? DEFAULT_THREE_DS_TIMEOUT_MS,
|
|
3836
|
+
revealDelayMs: THREE_DS_OVERLAY_REVEAL_DELAY_MS,
|
|
3837
|
+
onChallengeShown: () => {
|
|
3838
|
+
challenged = true;
|
|
3839
|
+
callHook('onThreeDSStart', options.onThreeDSStart, { orderId });
|
|
3840
|
+
},
|
|
3662
3841
|
});
|
|
3663
|
-
const mapped = mapThreeDSRun(run, orderId);
|
|
3842
|
+
const mapped = mapThreeDSRun(run, orderId, challenged);
|
|
3664
3843
|
end(mapped.threeDS);
|
|
3665
3844
|
return mapped.result;
|
|
3666
3845
|
}
|
|
@@ -3669,7 +3848,7 @@
|
|
|
3669
3848
|
return {
|
|
3670
3849
|
outcome: 'error',
|
|
3671
3850
|
orderId,
|
|
3672
|
-
threeDSChallenged:
|
|
3851
|
+
threeDSChallenged: challenged,
|
|
3673
3852
|
error: error instanceof Error
|
|
3674
3853
|
? error
|
|
3675
3854
|
: new FunnefoxSDKError('One-click 3DS step failed', undefined, error),
|