Skip to content

Commit

Permalink
fix(checkout): PI-00 fix pending promise for bluesnapdirect APMs iframe
Browse files Browse the repository at this point in the history
  • Loading branch information
vitalii-koshovyi committed Jul 6, 2023
1 parent f661070 commit 9acdde7
Showing 1 changed file with 12 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { noop } from 'lodash';

import {
CancellablePromise,
InvalidArgumentError,
NotInitializedError,
NotInitializedErrorType,
OrderFinalizationNotRequiredError,
OrderRequestBody,
PaymentArgumentInvalidError,
PaymentInitializeOptions,
PaymentIntegrationSelectors,
PaymentIntegrationService,
PaymentMethodCancelledError,
PaymentStrategy,
Expand Down Expand Up @@ -67,9 +69,15 @@ export default class BlueSnapDirectAPMPaymentStrategy implements PaymentStrategy
if (isBlueSnapDirectRedirectResponseProviderData(providerData)) {
const providerDataQuery = new URLSearchParams(providerData).toString();

await this._mountAPMFrame(
`${error.body.additional_action_required.data.redirect_url}&${providerDataQuery}`,
);
const frameUrl = `${error.body.additional_action_required.data.redirect_url}&${providerDataQuery}`;
const { onLoad, style } = this._initializeOptions;
const frame = createIframe(IFRAME_NAME, frameUrl, style);

const promise = new CancellablePromise<undefined>(new Promise(noop));

onLoad(frame, () => promise.cancel(new PaymentMethodCancelledError()));

return Promise.reject();
}
}

Expand All @@ -85,21 +93,6 @@ export default class BlueSnapDirectAPMPaymentStrategy implements PaymentStrategy
return Promise.resolve();
}

private _mountAPMFrame(url: string): Promise<PaymentIntegrationSelectors> {
return new Promise((_, reject) => {
if (!this._initializeOptions) {
throw new NotInitializedError(NotInitializedErrorType.PaymentNotInitialized);
}

const { onLoad, style } = this._initializeOptions;
const frame = createIframe(IFRAME_NAME, url, style);

onLoad(frame, () => {
reject(new PaymentMethodCancelledError());
});
});
}

private _isBlueSnapDirectRedirectResponse(
response: unknown,
): response is BlueSnapDirectRedirectResponse {
Expand Down

0 comments on commit 9acdde7

Please sign in to comment.