From c417d6c8f6d6181fb44aef1a8524d110ba2abc6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Jasi=C5=84ski?= Date: Tue, 24 Feb 2026 15:51:31 +0100 Subject: [PATCH 1/2] feat: use outcome property in api requests --- src/dynamic-checkout/clients/apple-pay.ts | 12 +++++ src/dynamic-checkout/clients/google-pay.ts | 12 +++++ src/dynamic-checkout/dynamic-checkout.ts | 2 +- src/dynamic-checkout/locales/de.ts | 1 + src/dynamic-checkout/locales/en.ts | 1 + src/dynamic-checkout/locales/es.ts | 1 + src/dynamic-checkout/locales/fr.ts | 1 + src/dynamic-checkout/locales/it.ts | 1 + src/dynamic-checkout/locales/ja.ts | 1 + src/dynamic-checkout/locales/ko.ts | 1 + src/dynamic-checkout/locales/pl.ts | 1 + src/dynamic-checkout/locales/pt.ts | 37 +++++++-------- src/dynamic-checkout/payment-methods/apm.ts | 46 +++++++++++++++++-- src/dynamic-checkout/payment-methods/card.ts | 17 +++++-- .../payment-methods/saved-apm.ts | 37 ++++++++++----- .../payment-methods/saved-card.ts | 14 ++++++ src/dynamic-checkout/references.ts | 1 + src/dynamic-checkout/views/payment-methods.ts | 7 ++- src/dynamic-checkout/views/payment-pending.ts | 28 +++++++++++ src/processout/outcome.ts | 21 +++++++++ src/processout/processout.ts | 36 +++++++++++---- src/processout/references.ts | 1 + 22 files changed, 231 insertions(+), 48 deletions(-) create mode 100644 src/dynamic-checkout/views/payment-pending.ts create mode 100644 src/processout/outcome.ts diff --git a/src/dynamic-checkout/clients/apple-pay.ts b/src/dynamic-checkout/clients/apple-pay.ts index 58159970..b22acfa5 100644 --- a/src/dynamic-checkout/clients/apple-pay.ts +++ b/src/dynamic-checkout/clients/apple-pay.ts @@ -167,6 +167,18 @@ module ProcessOut { DynamicCheckoutEventsUtils.dispatchPaymentErrorEvent(error) }, + undefined, + invoiceId => { + if (this.paymentConfig.showStatusMessage) { + getViewContainer().appendChild( + new DynamicCheckoutPaymentPendingView(this.processOutInstance, this.paymentConfig).element, + ) + } + + DynamicCheckoutEventsUtils.dispatchPaymentPendingEvent(invoiceId, { + payment_method_name: "apple_pay", + }) + }, ) } diff --git a/src/dynamic-checkout/clients/google-pay.ts b/src/dynamic-checkout/clients/google-pay.ts index 71e00451..cfcc854a 100644 --- a/src/dynamic-checkout/clients/google-pay.ts +++ b/src/dynamic-checkout/clients/google-pay.ts @@ -175,6 +175,18 @@ module ProcessOut { DynamicCheckoutEventsUtils.dispatchPaymentErrorEvent(error) }, + undefined, + invoiceId => { + if (this.paymentConfig.showStatusMessage) { + getViewContainer().appendChild( + new DynamicCheckoutPaymentPendingView(this.processOutInstance, this.paymentConfig).element, + ) + } + + DynamicCheckoutEventsUtils.dispatchPaymentPendingEvent(invoiceId, { + payment_method_name: "google_pay", + }) + }, ) }, error => { diff --git a/src/dynamic-checkout/dynamic-checkout.ts b/src/dynamic-checkout/dynamic-checkout.ts index 273c9338..4a212c26 100644 --- a/src/dynamic-checkout/dynamic-checkout.ts +++ b/src/dynamic-checkout/dynamic-checkout.ts @@ -77,7 +77,7 @@ module ProcessOut { } private onGetInvoiceSuccess(data: any) { - if (!data.success) { + if (resolveOutcome(data) === OUTCOME.Failed) { this.loadView( new DynamicCheckoutPaymentErrorView(this.processOutInstance, this.paymentConfig).element, ) diff --git a/src/dynamic-checkout/locales/de.ts b/src/dynamic-checkout/locales/de.ts index 5dac6bf7..606d9353 100644 --- a/src/dynamic-checkout/locales/de.ts +++ b/src/dynamic-checkout/locales/de.ts @@ -22,6 +22,7 @@ module ProcessOut { "payment-success-message": "Diese Zahlung wurde abgeschlossen.", "payment-info-message": "Wir verarbeiten Ihre Zahlung. Sie können dieses Fenster jetzt schließen.", + "payment-pending-message": "Ihre Zahlung steht noch aus.", "payment-error-generic-message": "Wir konnten Ihre Zahlung nicht verarbeiten.", "street1-label": "Adresszeile 1", "street2-label": "Adresszeile 2", diff --git a/src/dynamic-checkout/locales/en.ts b/src/dynamic-checkout/locales/en.ts index a9ca100e..826a895e 100644 --- a/src/dynamic-checkout/locales/en.ts +++ b/src/dynamic-checkout/locales/en.ts @@ -21,6 +21,7 @@ module ProcessOut { "select-payment-method-label": "Select payment method", "payment-success-message": "This payment is completed.", "payment-info-message": "We are processing your payment. You can now close this window.", + "payment-pending-message": "Your payment is pending.", "payment-error-generic-message": "We were unable to process your payment.", "street1-label": "Address line 1", "street2-label": "Address line 2", diff --git a/src/dynamic-checkout/locales/es.ts b/src/dynamic-checkout/locales/es.ts index 022f2b75..6970a23f 100644 --- a/src/dynamic-checkout/locales/es.ts +++ b/src/dynamic-checkout/locales/es.ts @@ -21,6 +21,7 @@ module ProcessOut { "select-payment-method-label": "Seleccionar método de pago", "payment-success-message": "Este pago se ha completado.", "payment-info-message": "Estamos procesando su pago. Puede cerrar esta ventana.", + "payment-pending-message": "Su pago está pendiente.", "payment-error-generic-message": "No pudimos procesar su pago.", "street1-label": "Dirección, línea 1", "street2-label": "Dirección, línea 2", diff --git a/src/dynamic-checkout/locales/fr.ts b/src/dynamic-checkout/locales/fr.ts index c303ebd0..dca4bc54 100644 --- a/src/dynamic-checkout/locales/fr.ts +++ b/src/dynamic-checkout/locales/fr.ts @@ -22,6 +22,7 @@ module ProcessOut { "payment-success-message": "Ce paiement a été effectué avec succès.", "payment-info-message": "Nous travaillons sur votre paiement. Vous pouvez maintenant fermer cette fenêtre.", + "payment-pending-message": "Votre paiement est en attente.", "payment-error-generic-message": "Nous n'avons pas pu traiter votre paiement.", "street1-label": "Adresse, ligne 1", "street2-label": "Adresse, ligne 2", diff --git a/src/dynamic-checkout/locales/it.ts b/src/dynamic-checkout/locales/it.ts index 6cc82a9d..5422e717 100644 --- a/src/dynamic-checkout/locales/it.ts +++ b/src/dynamic-checkout/locales/it.ts @@ -22,6 +22,7 @@ module ProcessOut { "payment-success-message": "Il pagamento è stato completato.", "payment-info-message": "Stiamo elaborando il tuo pagamento. Ora puoi chiudere questa finestra.", + "payment-pending-message": "Il tuo pagamento è in sospeso.", "payment-error-generic-message": "Non è stato possibile elaborare il pagamento.", "street1-label": "Indirizzo riga 1", "street2-label": "Indirizzo riga 2", diff --git a/src/dynamic-checkout/locales/ja.ts b/src/dynamic-checkout/locales/ja.ts index 8a13753c..891352bb 100644 --- a/src/dynamic-checkout/locales/ja.ts +++ b/src/dynamic-checkout/locales/ja.ts @@ -22,6 +22,7 @@ module ProcessOut { "payment-success-message": "お支払いが完了しました。", "payment-info-message": "お支払いを処理しています。このウィンドウを閉じていただいて構いません。", + "payment-pending-message": "お支払いは保留中です。", "payment-error-generic-message": "お支払いを処理できませんでした。", "street1-label": "住所1", "street2-label": "住所2", diff --git a/src/dynamic-checkout/locales/ko.ts b/src/dynamic-checkout/locales/ko.ts index 064f220e..b8358117 100644 --- a/src/dynamic-checkout/locales/ko.ts +++ b/src/dynamic-checkout/locales/ko.ts @@ -22,6 +22,7 @@ module ProcessOut { "payment-success-message": "결제가 완료되었습니다.", "payment-info-message": "결제를 처리하고 있습니다. 이 창을 닫으셔도 됩니다.", + "payment-pending-message": "결제가 대기 중입니다.", "payment-error-generic-message": "결제를 처리할 수 없습니다.", "street1-label": "주소 1", "street2-label": "주소 2", diff --git a/src/dynamic-checkout/locales/pl.ts b/src/dynamic-checkout/locales/pl.ts index abfed255..c7d4d2d1 100644 --- a/src/dynamic-checkout/locales/pl.ts +++ b/src/dynamic-checkout/locales/pl.ts @@ -21,6 +21,7 @@ module ProcessOut { "select-payment-method-label": "Wybierz metodę płatności", "payment-success-message": "Płatność została zakończona pomyślnie.", "payment-info-message": "Przetwarzamy Twoją płatność. Możesz teraz zamknąć tę okno.", + "payment-pending-message": "Twoja płatność oczekuje na realizację.", "payment-error-generic-message": "Nie udało nam się przetworzyć Twojej płatności.", "street1-label": "Adres, linia 1", "street2-label": "Adres, linia 2", diff --git a/src/dynamic-checkout/locales/pt.ts b/src/dynamic-checkout/locales/pt.ts index e581918c..33d60fba 100644 --- a/src/dynamic-checkout/locales/pt.ts +++ b/src/dynamic-checkout/locales/pt.ts @@ -1,47 +1,48 @@ module ProcessOut { export const pt = { - "apm-redirect-message": "Você será redirecionado para finalizar o pagamento.", - "save-for-future-label": "Salvar para pagamentos futuros", + "apm-redirect-message": "Será redirecionado para finalizar o pagamento.", + "save-for-future-label": "Guardar para pagamentos futuros", "continue-with-apm-button": "Continuar com", "pay-button-text": "Pagar", "card-details-section-title": "Detalhes do cartão", "cardholder-name-label": "Nome do titular do cartão", - "billing-address-section-title": "Endereço de cobrança", + "billing-address-section-title": "Morada de faturação", "country-label": "País", "select-country-placeholder": "Selecione o país", - "select-state-placeholder": "Selecione o estado", + "select-state-placeholder": "Selecione o distrito", "card-number-error-message": "O número do cartão é inválido", "expiry-date-error-message": "A data de validade é inválida", "cvc-error-message": "O CVC é inválido", "cardholder-name-error-message": "O nome do titular do cartão é inválido", - "payment-error-message": "Algo deu errado. Por favor, tente novamente.", + "payment-error-message": "Algo correu mal. Por favor, tente novamente.", "payment-cancelled-message": "O pagamento foi cancelado.", - "express-checkout-header": "Checkout expresso", + "express-checkout-header": "Pagamento expresso", "other-payment-methods-header": "Outros métodos de pagamento", "select-payment-method-label": "Selecionar método de pagamento", "payment-success-message": "Este pagamento foi concluído.", "payment-info-message": - "Estamos processando seu pagamento. Você pode agora fechar esta janela.", - "payment-error-generic-message": "Não conseguimos processar o seu pagamento.", - "street1-label": "Endereço, linha 1", - "street2-label": "Endereço, linha 2", + "Estamos a processar o seu pagamento. Pode agora fechar esta janela.", + "payment-pending-message": "O seu pagamento está pendente.", + "payment-error-generic-message": "Não foi possível processar o seu pagamento.", + "street1-label": "Morada, linha 1", + "street2-label": "Morada, linha 2", "city-label": "Cidade", "postcode-label": "Código postal", - "state-label": "Estado", - "payments-manager-header": "Gerenciar métodos de pagamento salvos", + "state-label": "Distrito", + "payments-manager-header": "Gerir métodos de pagamento guardados", "payments-manager-close-button": "Fechar", - "no-saved-payment-methods-header": "Nenhum método de pagamento salvo", + "no-saved-payment-methods-header": "Nenhum método de pagamento guardado", "no-saved-payment-methods-message": - "Depois de guardar uma forma de pagamento, ela aparecerá aqui. ", + "Da próxima vez que guardar um método de pagamento, aparecerá aqui.", "card-number-label": "Número do cartão", "expiry-date-label": "Data de validade", "cvc-label": "CVC", "card-not-supported-error-message": "Este cartão não é suportado", "card-label": "Cartão", - "delete-payment-method-label": "Excluir método de pagamento", - "settings-button-label": "Gerenciar métodos de pagamento salvos", - "loading-label": "Carregando", - "processing-payment-label": "Processando pagamento", + "delete-payment-method-label": "Eliminar método de pagamento", + "settings-button-label": "Gerir métodos de pagamento guardados", + "loading-label": "A carregar", + "processing-payment-label": "A processar pagamento", "card-form-label": "Formulário de pagamento com cartão", } } diff --git a/src/dynamic-checkout/payment-methods/apm.ts b/src/dynamic-checkout/payment-methods/apm.ts index feb3e57f..29a71c0e 100644 --- a/src/dynamic-checkout/payment-methods/apm.ts +++ b/src/dynamic-checkout/payment-methods/apm.ts @@ -96,10 +96,6 @@ module ProcessOut { paymentToken => { this.resetContainerHtml().appendChild(new DynamicCheckoutInvoiceLoadingView(this.paymentConfig.locale).element) - DynamicCheckoutEventsUtils.dispatchPaymentPendingEvent(paymentToken, { - payment_method_name: apm.gateway_name, - }) - this.processOutInstance.makeCardPayment( this.paymentConfig.invoiceId, paymentToken, @@ -131,6 +127,15 @@ module ProcessOut { DynamicCheckoutEventsUtils.dispatchPaymentErrorEvent(error) }, requestOptions, + invoiceId => { + this.resetContainerHtml().appendChild( + new DynamicCheckoutPaymentPendingView(this.processOutInstance, this.paymentConfig).element, + ) + + DynamicCheckoutEventsUtils.dispatchPaymentPendingEvent(invoiceId, { + payment_method_name: apm.gateway_name, + }) + }, ) }, error => { @@ -174,6 +179,30 @@ module ProcessOut { `invoices/${this.paymentConfig.invoiceId}/capture`, options, data => { + var outcome = resolveOutcome(data) + + if (outcome === OUTCOME.Failed) { + this.resetContainerHtml().appendChild( + new DynamicCheckoutPaymentErrorView(this.processOutInstance, this.paymentConfig) + .element, + ) + + DynamicCheckoutEventsUtils.dispatchPaymentErrorEvent(data) + return + } + + if (outcome === OUTCOME.Pending) { + this.resetContainerHtml().appendChild( + new DynamicCheckoutPaymentPendingView(this.processOutInstance, this.paymentConfig).element, + ) + + DynamicCheckoutEventsUtils.dispatchPaymentPendingEvent(this.paymentConfig.invoiceId, { + payment_method_name: apm.gateway_name, + }) + + return + } + this.processOutInstance.handleAction( data.customer_action.value, paymentToken => { @@ -228,6 +257,15 @@ module ProcessOut { DynamicCheckoutEventsUtils.dispatchPaymentErrorEvent(error) }, requestOptions, + invoiceId => { + this.resetContainerHtml().appendChild( + new DynamicCheckoutPaymentPendingView(this.processOutInstance, this.paymentConfig).element, + ) + + DynamicCheckoutEventsUtils.dispatchPaymentPendingEvent(invoiceId, { + payment_method_name: apm.gateway_name, + }) + }, ) }, error => { diff --git a/src/dynamic-checkout/payment-methods/card.ts b/src/dynamic-checkout/payment-methods/card.ts index 5e40ced1..17c7c31b 100644 --- a/src/dynamic-checkout/payment-methods/card.ts +++ b/src/dynamic-checkout/payment-methods/card.ts @@ -122,10 +122,6 @@ module ProcessOut { cardPaymentOptions["save_source"] = saveForFutureCheckbox.checked } - DynamicCheckoutEventsUtils.dispatchPaymentPendingEvent(cardToken, { - payment_method_name: "card", - }) - this.procesoutInstance.makeCardPayment( this.paymentConfig.invoiceId, cardToken, @@ -135,6 +131,7 @@ module ProcessOut { { clientSecret: this.paymentConfig.clientSecret, }, + this.handleCardPaymentPending.bind(this), ) } @@ -166,6 +163,18 @@ module ProcessOut { }) } + private handleCardPaymentPending(invoiceId: string) { + if (this.paymentConfig.showStatusMessage) { + this.resetContainerHtml().appendChild( + new DynamicCheckoutPaymentPendingView(this.procesoutInstance, this.paymentConfig).element, + ) + } + + DynamicCheckoutEventsUtils.dispatchPaymentPendingEvent(invoiceId, { + payment_method_name: "card", + }) + } + private handleCardPaymentError(error) { if (this.paymentConfig.showStatusMessage) { this.resetContainerHtml().appendChild( diff --git a/src/dynamic-checkout/payment-methods/saved-apm.ts b/src/dynamic-checkout/payment-methods/saved-apm.ts index 86df63ca..9d031a22 100644 --- a/src/dynamic-checkout/payment-methods/saved-apm.ts +++ b/src/dynamic-checkout/payment-methods/saved-apm.ts @@ -111,10 +111,6 @@ module ProcessOut { return this.processOutInstance.handleAction( apm_customer_token.redirect_url, paymentToken => { - DynamicCheckoutEventsUtils.dispatchPaymentPendingEvent(paymentToken, { - payment_method_name: apm.gateway_name, - }) - this.processOutInstance.makeCardPayment( invoiceId, paymentToken, @@ -158,6 +154,17 @@ module ProcessOut { DynamicCheckoutEventsUtils.dispatchPaymentErrorEvent(error) }, requestOptions, + invoiceId => { + if (this.paymentConfig.showStatusMessage) { + this.resetContainerHtml().appendChild( + new DynamicCheckoutPaymentPendingView(this.processOutInstance, this.paymentConfig).element, + ) + } + + DynamicCheckoutEventsUtils.dispatchPaymentPendingEvent(invoiceId, { + payment_method_name: apm.gateway_name, + }) + }, ) }, error => { @@ -173,13 +180,6 @@ module ProcessOut { ) } - DynamicCheckoutEventsUtils.dispatchPaymentPendingEvent( - this.paymentMethod.apm_customer_token.customer_token_id, - { - payment_method_name: apm.gateway_name, - }, - ) - this.processOutInstance.makeCardPayment( this.paymentConfig.invoiceId, this.paymentMethod.apm_customer_token.customer_token_id, @@ -187,6 +187,7 @@ module ProcessOut { this.handlePaymentSuccess.bind(this), this.handlePaymentError.bind(this), requestOptions, + this.handlePaymentPending.bind(this), ) } @@ -201,6 +202,20 @@ module ProcessOut { }) } + private handlePaymentPending(invoiceId: string) { + if (this.paymentConfig.showStatusMessage) { + this.resetContainerHtml().appendChild( + new DynamicCheckoutPaymentPendingView(this.processOutInstance, this.paymentConfig).element, + ) + } + + DynamicCheckoutEventsUtils.dispatchPaymentPendingEvent(invoiceId, { + payment_method_name: this.paymentMethod.apm + ? this.paymentMethod.apm.gateway_name + : "apm", + }) + } + private handlePaymentError(error) { this.resetContainerHtml().appendChild( new DynamicCheckoutPaymentErrorView(this.processOutInstance, this.paymentConfig).element, diff --git a/src/dynamic-checkout/payment-methods/saved-card.ts b/src/dynamic-checkout/payment-methods/saved-card.ts index f4dd9409..d37c81b7 100644 --- a/src/dynamic-checkout/payment-methods/saved-card.ts +++ b/src/dynamic-checkout/payment-methods/saved-card.ts @@ -100,6 +100,8 @@ module ProcessOut { }, this.handlePaymentSuccess.bind(this), this.handlePaymentError.bind(this), + undefined, + this.handlePaymentPending.bind(this), ) } @@ -124,6 +126,18 @@ module ProcessOut { }) } + private handlePaymentPending(invoiceId: string) { + if (this.paymentConfig.showStatusMessage) { + this.resetContainerHtml().appendChild( + new DynamicCheckoutPaymentPendingView(this.processOutInstance, this.paymentConfig).element, + ) + } + + DynamicCheckoutEventsUtils.dispatchPaymentPendingEvent(invoiceId, { + payment_method_name: "card", + }) + } + private handlePaymentError(error) { if (this.paymentConfig.showStatusMessage) { this.resetContainerHtml().appendChild( diff --git a/src/dynamic-checkout/references.ts b/src/dynamic-checkout/references.ts index 5eeef502..8aeedb18 100644 --- a/src/dynamic-checkout/references.ts +++ b/src/dynamic-checkout/references.ts @@ -6,6 +6,7 @@ /// /// /// +/// /// /// /// diff --git a/src/dynamic-checkout/views/payment-methods.ts b/src/dynamic-checkout/views/payment-methods.ts index 94415398..db423504 100644 --- a/src/dynamic-checkout/views/payment-methods.ts +++ b/src/dynamic-checkout/views/payment-methods.ts @@ -377,7 +377,12 @@ module ProcessOut { "delete", `customers/${customerId}/tokens/${tokenId}`, {}, - () => { + (data) => { + if (resolveOutcome(data) === OUTCOME.Failed) { + DynamicCheckoutEventsUtils.dispatchDeletePaymentMethodErrorEvent(data) + return + } + this.deletePaymentMethodFromDom(tokenId, isCardToken) DynamicCheckoutEventsUtils.dispatchDeletePaymentMethodEvent() }, diff --git a/src/dynamic-checkout/views/payment-pending.ts b/src/dynamic-checkout/views/payment-pending.ts new file mode 100644 index 00000000..0f9ce32e --- /dev/null +++ b/src/dynamic-checkout/views/payment-pending.ts @@ -0,0 +1,28 @@ +/// + +module ProcessOut { + export class DynamicCheckoutPaymentPendingView { + public element: Element + + constructor(processOutInstance: ProcessOut, paymentConfig: DynamicCheckoutPaymentConfig) { + const [element, message] = HTMLElements.createMultipleElements([ + { + tagName: "div", + classNames: ["dco-card-payment-success"], + attributes: { + role: "status", + }, + }, + { + tagName: "p", + classNames: ["dco-card-payment-success-text"], + textContent: Translations.getText("payment-pending-message", paymentConfig.locale), + }, + ]) + + HTMLElements.appendChildren(element, [message]) + + this.element = element + } + } +} diff --git a/src/processout/outcome.ts b/src/processout/outcome.ts new file mode 100644 index 00000000..719c1023 --- /dev/null +++ b/src/processout/outcome.ts @@ -0,0 +1,21 @@ +/// + +module ProcessOut { + export var OUTCOME = { + Success: "success", + Failed: "failed", + Pending: "pending", + } + + export function resolveOutcome(data: any): string { + if ( + data.outcome === OUTCOME.Success || + data.outcome === OUTCOME.Failed || + data.outcome === OUTCOME.Pending + ) { + return data.outcome + } + + return data.success ? OUTCOME.Success : OUTCOME.Failed + } +} diff --git a/src/processout/processout.ts b/src/processout/processout.ts index f522952d..101d7969 100644 --- a/src/processout/processout.ts +++ b/src/processout/processout.ts @@ -633,7 +633,7 @@ module ProcessOut { "cards", data, function (data: any, req: XMLHttpRequest, e: Event): void { - if (!data.success) { + if (resolveOutcome(data) === OUTCOME.Failed) { error(new Exception(data.error_type, data.message)) return } @@ -687,7 +687,7 @@ module ProcessOut { "cards", data, function (data: any, req: XMLHttpRequest, e: Event): void { - if (!data.success) { + if (resolveOutcome(data) === OUTCOME.Failed) { error(new Exception(data.error_type, data.message)) return } @@ -843,7 +843,7 @@ module ProcessOut { cvc: cvc, }, function (data: any, req: XMLHttpRequest, e: Event): void { - if (!data.success) { + if (resolveOutcome(data) === OUTCOME.Failed) { error(new Exception("card.invalid")) return } @@ -949,7 +949,7 @@ module ProcessOut { expand_merchant_accounts: "true", }, function (data: any): void { - if (!data.success) { + if (resolveOutcome(data) === OUTCOME.Failed) { error(new Exception(data.error_type, data.message)) return } @@ -1569,6 +1569,7 @@ module ProcessOut { success: (data: any) => void, error: (err: Exception) => void, apiRequestOptions?: apiRequestOptions, + pending?: (data: any) => void, ): void { this.handleCardActions( "POST", @@ -1579,6 +1580,7 @@ module ProcessOut { success, error, apiRequestOptions, + pending, ) } @@ -1630,7 +1632,7 @@ module ProcessOut { `invoices/${invoiceID}/increment_authorization`, { amount: amount }, function (data: any, req: XMLHttpRequest, e: Event): void { - if (!data.success) { + if (resolveOutcome(data) === OUTCOME.Failed) { error(new Exception("request.validation.error")) return } @@ -1668,7 +1670,7 @@ module ProcessOut { apiEndpoint, {}, function (data: any, req: XMLHttpRequest, e: Event): void { - if (!data.success) { + if (resolveOutcome(data) === OUTCOME.Failed) { error(new Exception("request.validation.error")) return } @@ -1696,7 +1698,7 @@ module ProcessOut { "installment-plans/active", {}, function (data: any, req: XMLHttpRequest, e: Event): void { - if (!data.success) { + if (resolveOutcome(data) === OUTCOME.Failed) { error(new Exception(data.error_type, data.message)) return } @@ -1718,6 +1720,7 @@ module ProcessOut { success: (data: any) => void, error: (err: Exception) => void, apiRequestOptions?: apiRequestOptions, + pending?: (data: any) => void, ): void { // returns this.hppInitialURL only once during the first call from HPP, then returns the endpoint const getEndpoint = (): string => { @@ -1781,11 +1784,25 @@ module ProcessOut { getEndpoint(), payload, function (data: any): void { - if (!data.success) { + var outcome = resolveOutcome(data) + + if (outcome === OUTCOME.Failed) { error(new Exception(data.error_type, data.message)) return } + if (outcome === OUTCOME.Pending) { + // If pending callback is provided, call it with the resourceID + // Otherwise, call the success callback with the resourceID + // This is to ensure backward compatibility with old usage of PO.js + if (pending) { + pending(resourceID) + } else { + success(resourceID) + } + return + } + if (!data.customer_action) { success(resourceID) return @@ -1802,6 +1819,7 @@ module ProcessOut { success, error, apiRequestOptions, + pending, ) }.bind(this) @@ -1828,7 +1846,7 @@ module ProcessOut { success, error, apiRequestOptions, - resourceID, + pending, ) }.bind(this), error, diff --git a/src/processout/references.ts b/src/processout/references.ts index 46853694..be0bec34 100644 --- a/src/processout/references.ts +++ b/src/processout/references.ts @@ -10,6 +10,7 @@ /// /// /// +/// /// /// /// From d7db7ca03d086c90dcc977743f48ce5cacf0f768 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Jasi=C5=84ski?= Date: Tue, 24 Feb 2026 15:51:57 +0100 Subject: [PATCH 2/2] bump version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 0c748a34..ef3b1809 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "processout.js", - "version": "1.7.4", + "version": "1.7.5", "description": "ProcessOut.js is a JavaScript library for ProcessOut's payment processing API.", "scripts": { "build:processout": "tsc -p src/processout && uglifyjs --compress --keep-fnames --ie8 dist/processout.js -o dist/processout.js",