Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "processout.js",
"version": "1.9.10",
"version": "1.9.11",
"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",
Expand Down
4 changes: 2 additions & 2 deletions src/dynamic-checkout/payment-methods/apm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ module ProcessOut {
)
},
error => {
if (error.code === "customer.canceled") {
if (isCustomerCancellationError(error)) {
this.resetContainerHtml().appendChild(
new DynamicCheckoutPaymentCancelledView(this.processOutInstance, this.paymentConfig)
.element,
Expand Down Expand Up @@ -364,7 +364,7 @@ module ProcessOut {
)
},
error => {
if (error.code === "customer.canceled") {
if (isCustomerCancellationError(error)) {
this.resetContainerHtml().appendChild(
new DynamicCheckoutPaymentCancelledView(
this.processOutInstance,
Expand Down
2 changes: 1 addition & 1 deletion src/dynamic-checkout/payment-methods/card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ module ProcessOut {
}

private handleCardPaymentError(error) {
if (error.code === "customer.canceled") {
if (isCustomerCancellationError(error)) {
this.resetContainerHtml().appendChild(
new DynamicCheckoutPaymentCancelledView(this.processOutInstance, this.paymentConfig)
.element,
Expand Down
4 changes: 2 additions & 2 deletions src/dynamic-checkout/payment-methods/saved-apm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ module ProcessOut {
)
},
error => {
if (error.code === "customer.canceled") {
if (isCustomerCancellationError(error)) {
this.resetContainerHtml().appendChild(
new DynamicCheckoutPaymentCancelledView(
this.processOutInstance,
Expand Down Expand Up @@ -255,7 +255,7 @@ module ProcessOut {
}

private handlePaymentError(error) {
if (error.code === "customer.canceled") {
if (isCustomerCancellationError(error)) {
this.resetContainerHtml().appendChild(
new DynamicCheckoutPaymentCancelledView(this.processOutInstance, this.paymentConfig)
.element,
Expand Down
2 changes: 1 addition & 1 deletion src/dynamic-checkout/payment-methods/saved-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ module ProcessOut {
}

private handlePaymentError(error) {
if (error.code === "customer.canceled") {
if (isCustomerCancellationError(error)) {
this.resetContainerHtml().appendChild(
new DynamicCheckoutPaymentCancelledView(this.processOutInstance, this.paymentConfig)
.element,
Expand Down
1 change: 1 addition & 0 deletions src/dynamic-checkout/references.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
/// <reference path="locales/pt.ts" />
/// <reference path="locales/ta.ts" />
/// <reference path="locales/vi.ts" />
/// <reference path="utils/errors.ts" />
/// <reference path="utils/events.ts" />
/// <reference path="utils/translations.ts" />
/// <reference path="utils/elements.ts" />
Expand Down
11 changes: 11 additions & 0 deletions src/dynamic-checkout/utils/errors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/// <reference path="../references.ts" />

module ProcessOut {
// The SDK raises "customer.canceled" for cancellations it detects itself
// (overlay cancel, tab/window closed), while cancellations that happen on a
// gateway's hosted page come back from the API as "customer.cancelled".
// Both must be treated as a customer cancellation.
export function isCustomerCancellationError(error: { code?: string }): boolean {
return error.code === "customer.canceled" || error.code === "customer.cancelled"
}
}
20 changes: 20 additions & 0 deletions test/dynamic-checkout/errors.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { describe, expect, it } from "vitest"
import { loadNamespaceFile } from "../support/loadNamespace"

const { isCustomerCancellationError } = loadNamespaceFile("src/dynamic-checkout/utils/errors.ts")

describe("isCustomerCancellationError", () => {
it("matches the SDK-internal cancellation code", () => {
expect(isCustomerCancellationError({ code: "customer.canceled" })).toBe(true)
})

it("matches the API cancellation code raised by gateway-hosted pages", () => {
expect(isCustomerCancellationError({ code: "customer.cancelled" })).toBe(true)
})

it("rejects other error codes", () => {
expect(isCustomerCancellationError({ code: "customer.popup-blocked" })).toBe(false)
expect(isCustomerCancellationError({ code: "card.declined" })).toBe(false)
expect(isCustomerCancellationError({})).toBe(false)
})
})
13 changes: 13 additions & 0 deletions test/support/loadNamespace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,16 @@ export function loadApmUtils(navigator: FakeNavigator = {}): Record<string, any>
run(moduleShim, moduleShim.exports, navigator)
return moduleShim.exports
}

/**
* Load a self-contained namespace source file and return its `ProcessOut`
* namespace. Only suitable for files with no dependencies on the rest of
* the bundle or on browser globals.
*/
export function loadNamespaceFile(relativePath: string): Record<string, any> {
const js = compile(relativePath)
const moduleShim = { exports: {} as Record<string, any> }
const run = new Function("module", "exports", `${js}\nmodule.exports = ProcessOut;`)
run(moduleShim, moduleShim.exports)
return moduleShim.exports
}
Loading