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
405 changes: 405 additions & 0 deletions examples/dynamic-checkout-init/index.html

Large diffs are not rendered by default.

44 changes: 42 additions & 2 deletions examples/dynamic-checkout/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@
</form>
</section>

<section class="example-section">
<h2>Code Example</h2>
<pre id="code-preview" class="code-preview"></pre>
</section>

<section class="example-section">
<h2>Dispatched Events</h2>
<ol id="dynamic-checkout-event-log" class="event-log"></ol>
Expand Down Expand Up @@ -190,6 +195,7 @@ <h2>Dispatched Events</h2>

try {
const client = new ProcessOut.ProcessOut(formValues.projectId)

const dynamicCheckout = client.setupDynamicCheckout(
{
invoiceId: formValues.invoiceId,
Expand All @@ -201,9 +207,9 @@ <h2>Dispatched Events</h2>
hideSavedPaymentMethods: formValues.hideSavedPaymentMethods,
showStatusMessage: formValues.showStatusMessage,
payButtonText: formValues.payButtonText,
additionalData: formValues.additionalData.value,
cvcLabel: formValues.cvcLabel,
cvcPlaceholder: formValues.cvcPlaceholder,
additionalData: formValues.additionalData.value,
},
{
payButtonColor: formValues.payButtonColor,
Expand All @@ -212,12 +218,46 @@ <h2>Dispatched Events</h2>
)

dynamicCheckout.mount("#dynamic-cko-container")

updateCodePreview(formValues)
} catch (error) {
showFormError(error && error.message ? error.message : String(error))
dynamicCheckoutContainer.innerHTML = ""
dynamicCheckoutContainer.textContent = ""
}
}

function updateCodePreview(formValues) {
const config = {
invoiceId: formValues.invoiceId,
clientSecret: formValues.clientSecret,
locale: formValues.locale,
capturePayments: formValues.capturePayments,
allowFallbackToSale: formValues.allowFallbackToSale,
enforceSavePaymentMethod: formValues.enforceSavePaymentMethod,
hideSavedPaymentMethods: formValues.hideSavedPaymentMethods,
showStatusMessage: formValues.showStatusMessage,
payButtonText: formValues.payButtonText,
cvcLabel: formValues.cvcLabel,
cvcPlaceholder: formValues.cvcPlaceholder,
additionalData: formValues.additionalData.value,
}

const theme = {
payButtonColor: formValues.payButtonColor,
payButtonTextColor: formValues.payButtonTextColor,
}

const code =
'const client = new ProcessOut.ProcessOut("' + formValues.projectId + '")\n\n' +
"const checkout = client.setupDynamicCheckout(\n" +
" " + JSON.stringify(config, null, 2).replace(/\n/g, "\n ") + ",\n" +
" " + JSON.stringify(theme, null, 2).replace(/\n/g, "\n ") + ",\n" +
Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The generated code preview includes an extra trailing comma after the theme argument (...,\n)), which makes the displayed snippet invalid JavaScript for some environments. Drop the comma after the second argument so the preview matches a runnable setupDynamicCheckout(config, theme) call.

Suggested change
" " + JSON.stringify(theme, null, 2).replace(/\n/g, "\n ") + ",\n" +
" " + JSON.stringify(theme, null, 2).replace(/\n/g, "\n ") + "\n" +

Copilot uses AI. Check for mistakes.
")\n\n" +
'checkout.mount("#dynamic-cko-container")'

document.getElementById("code-preview").textContent = code
}

function getFormValues() {
const projectId = document.getElementById("project-id").value.trim()
const invoiceId = document.getElementById("invoice-id").value.trim()
Expand Down
15 changes: 15 additions & 0 deletions examples/dynamic-checkout/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,21 @@ pre {
padding: 10px;
}

.code-preview {
background: #1e293b;
color: #e2e8f0;
border-radius: 12px;
padding: 16px;
margin: 0;
overflow-x: auto;
white-space: pre;
font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
font-size: 12px;
line-height: 1.6;
max-height: 480px;
overflow-y: auto;
}

#dynamic-cko-container {
width: 100%;
max-width: 420px;
Expand Down
3 changes: 3 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ <h1>ProcessOut.js Development Environment</h1>
<li>
<a href="examples/dynamic-checkout/index.html">Dynamic Checkout</a>
</li>
<li>
<a href="examples/dynamic-checkout-init/index.html">Dynamic Checkout (initDynamicCheckout)</a>
</li>
<li>
<a href="examples/native-apm/index.html">Native APM</a>
</li>
Expand Down
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.8.5",
"version": "1.8.6",
"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
19 changes: 12 additions & 7 deletions src/dynamic-checkout/clients/apple-pay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

module ProcessOut {
export class ApplePayClient {
private static readonly METHOD_KEY = "applepay"

processOutInstance: ProcessOut
paymentConfig: DynamicCheckoutPaymentConfig

Expand All @@ -16,6 +18,7 @@ module ProcessOut {
getViewContainer: () => HTMLElement,
) {
const applePayScript = document.createElement("script")

applePayScript.src = applePaySdkUrl
applePayScript.onload = () => {
buttonContainer.innerHTML = `<apple-pay-button buttonstyle="white-outline" type="plain" locale="en-US"></apple-pay-button>`
Expand Down Expand Up @@ -139,21 +142,23 @@ module ProcessOut {
invoiceData: Invoice,
getViewContainer: () => HTMLElement,
) {
const methodOptions = this.paymentConfig.getOptionsForMethod(ApplePayClient.METHOD_KEY)

this.processOutInstance.makeCardPayment(
invoiceData.id,
cardToken,
{
authorize_only: !this.paymentConfig.capturePayments,
allow_fallback_to_sale: this.paymentConfig.allowFallbackToSale,
authorize_only: !methodOptions.capturePayments,
allow_fallback_to_sale: !!methodOptions.allowFallbackToSale,
},
invoiceId => {
if (this.paymentConfig.showStatusMessage) {
if (methodOptions.showStatusMessage) {
getViewContainer().appendChild(
new DynamicCheckoutPaymentSuccessView(this.processOutInstance, this.paymentConfig)
.element,
)
} else if (
!this.paymentConfig.showStatusMessage &&
!methodOptions.showStatusMessage &&
!this.paymentConfig.invoiceDetails.return_url
) {
getViewContainer().appendChild(
Expand All @@ -169,13 +174,13 @@ module ProcessOut {
})
},
error => {
if (this.paymentConfig.showStatusMessage) {
if (methodOptions.showStatusMessage) {
getViewContainer().appendChild(
new DynamicCheckoutPaymentErrorView(this.processOutInstance, this.paymentConfig)
.element,
)
} else if (
!this.paymentConfig.showStatusMessage &&
!methodOptions.showStatusMessage &&
!this.paymentConfig.invoiceDetails.return_url
) {
getViewContainer().appendChild(
Expand All @@ -194,7 +199,7 @@ module ProcessOut {
},
undefined,
invoiceId => {
if (this.paymentConfig.showStatusMessage) {
if (methodOptions.showStatusMessage) {
getViewContainer().appendChild(
new DynamicCheckoutPaymentPendingView(this.processOutInstance, this.paymentConfig)
.element,
Expand Down
24 changes: 11 additions & 13 deletions src/dynamic-checkout/clients/google-pay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ module ProcessOut {
}
}
export class GooglePayClient {
private static readonly METHOD_KEY = "googlepay"

googleClient: any
processOutInstance: ProcessOut
paymentConfig: DynamicCheckoutPaymentConfig
Expand Down Expand Up @@ -120,6 +122,8 @@ module ProcessOut {
}

private makePayment(invoiceData: Invoice, getViewContainer: () => HTMLElement) {
const methodOptions = this.paymentConfig.getOptionsForMethod(GooglePayClient.METHOD_KEY)

this.googleClient
.loadPaymentData(this.paymentRequest)
.then(paymentData => {
Expand All @@ -136,21 +140,18 @@ module ProcessOut {
invoiceData.id,
token,
{
authorize_only: !this.paymentConfig.capturePayments,
allow_fallback_to_sale: this.paymentConfig.allowFallbackToSale,
authorize_only: !methodOptions.capturePayments,
allow_fallback_to_sale: !!methodOptions.allowFallbackToSale,
},
invoiceId => {
if (this.paymentConfig.showStatusMessage) {
if (methodOptions.showStatusMessage) {
getViewContainer().appendChild(
new DynamicCheckoutPaymentSuccessView(
this.processOutInstance,
this.paymentConfig,
).element,
)
} else if (
!this.paymentConfig.showStatusMessage &&
!this.paymentConfig.invoiceDetails.return_url
) {
} else if (!methodOptions.showStatusMessage && !this.paymentConfig.invoiceDetails.return_url) {
getViewContainer().appendChild(
new DynamicCheckoutPaymentInfoView(
this.processOutInstance,
Expand All @@ -166,17 +167,14 @@ module ProcessOut {
})
},
error => {
if (this.paymentConfig.showStatusMessage) {
if (methodOptions.showStatusMessage) {
getViewContainer().appendChild(
new DynamicCheckoutPaymentErrorView(
this.processOutInstance,
this.paymentConfig,
).element,
)
} else if (
!this.paymentConfig.showStatusMessage &&
!this.paymentConfig.invoiceDetails.return_url
) {
} else if (!methodOptions.showStatusMessage && !this.paymentConfig.invoiceDetails.return_url) {
getViewContainer().appendChild(
new DynamicCheckoutPaymentInfoView(
this.processOutInstance,
Expand All @@ -195,7 +193,7 @@ module ProcessOut {
},
undefined,
invoiceId => {
if (this.paymentConfig.showStatusMessage) {
if (methodOptions.showStatusMessage) {
getViewContainer().appendChild(
new DynamicCheckoutPaymentPendingView(this.processOutInstance, this.paymentConfig).element,
)
Expand Down
Loading
Loading