{"templateId":"markdown","sharedDataIds":{"sidebar":"sidebar-guides/sidebars.yaml"},"props":{"metadata":{"markdoc":{"tagList":["liveExample","cards","card"]},"type":"markdown"},"seo":{"title":"Card payments","description":"Shift4 Payment Platform REST API."},"dynamicMarkdocComponents":[],"compilationErrors":[],"ast":{"$$mdtype":"Tag","name":"article","attributes":{},"children":[{"$$mdtype":"Tag","name":"Heading","attributes":{"level":1,"id":"card-payments","__idx":0},"children":["Card payments"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["A card payment with Payment components is: mount the card field components, let the customer type their card, and call ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["checkout.continue()"]}," from your own pay button. The result comes back through ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/guides/core-concepts/checkout/payment-components/events-and-errors"},"children":["events"]},"."]},{"$$mdtype":"Tag","name":"LiveExample","attributes":{"to":"/examples/payment-components","title":"Card payment"},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["This flow in a sandbox checkout form, from mounting the fields to confirming the payment."]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"full-example","__idx":1},"children":["Full example"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"html","header":{"controls":{"copy":{}}},"source":"<script src=\"https://js.shift4.com/v1/shift4.js\"></script>\n\n<div id=\"number\"></div>\n<div id=\"expiry\"></div>\n<div id=\"cvc\"></div>\n<input id=\"cardholder\" type=\"text\" placeholder=\"Cardholder name\" />\n<button id=\"pay\">Pay</button>\n\n<div id=\"result\"></div>\n<div id=\"error\"></div>\n\n<script>\n  (async function () {\n    var shift4 = Shift4('pk_sandbox_XXXXXXXXXXXXXXXXXXXX');\n\n    var checkout = await shift4.createCheckout('{{clientSecret}}');\n\n    // Mount individual card fields\n    checkout.createComponent('number').mount('#number');\n    checkout.createComponent('expiry').mount('#expiry');\n    checkout.createComponent('cvc').mount('#cvc');\n\n    // Or use a single combined card field:\n    // checkout.createComponent('card').mount('#card');\n\n    checkout.addEventListener('checkout_session.succeeded', function () {\n      document.getElementById('result').textContent = 'Payment successful';\n    });\n    checkout.addEventListener('payment.failed', function (event) {\n      document.getElementById('error').textContent = event.error.message;\n    });\n\n    document.getElementById('pay').addEventListener('click', function () {\n      checkout.continue({\n        email: 'customer@example.com',\n        billing: { name: document.getElementById('cardholder').value }\n      });\n    });\n  })();\n</script>\n","lang":"html"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Note that the cardholder name input is a plain element of your own page — only the card number, expiry, and CVC are Shift4-hosted."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"continue-parameters","__idx":2},"children":["continue() parameters"]},{"$$mdtype":"Tag","name":"div","attributes":{"className":"md-table-wrapper"},"children":[{"$$mdtype":"Tag","name":"table","attributes":{"className":"md"},"children":[{"$$mdtype":"Tag","name":"thead","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"th","attributes":{"width":"260px","data-label":"Parameter"},"children":["Parameter "]},{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"Type"},"children":["Type"]},{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"Description"},"children":["Description"]}]}]},{"$$mdtype":"Tag","name":"tbody","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["email"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["string"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Customer email. Optional if provided by a wallet response."]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["billing"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["object"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Billing address sent to the payment processor."]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["billing.name"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["string"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Cardholder name, used for tokenization."]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["billing.address.line1"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["string"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Billing street address."]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["billing.address.zip"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["string"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Billing postal / ZIP code."]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["billing.address.city"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["string"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Billing city."]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["billing.address.country"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["string"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Billing country (two-letter ISO code)."]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["shipping"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["object"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Shipping address, same structure as ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["billing"]},"."]}]}]}]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"billing-and-shipping-addresses","__idx":3},"children":["Billing and shipping addresses"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["If the Checkout Session was created with ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["collectBillingAddress: true"]}," or ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["collectShippingAddress: true"]},", a card payment must supply the corresponding ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["billing"]}," / ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["shipping"]}," object in ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["continue()"]}," — collect the values with your own form fields and pass them along. Wallet payments don't need this: shift4.js fetches the addresses from Apple Pay / Google Pay. See ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/guides/core-concepts/checkout/create-a-checkout-session#collect-an-address"},"children":["Collect an address"]},"."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"offer-wallets-alongside-cards","__idx":4},"children":["Offer wallets alongside cards"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Wallet buttons and card fields represent separate payment flows with independent Checkout Sessions — each requires its own ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["createCheckout()"]}," call:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"html","header":{"controls":{"copy":{}}},"source":"<script src=\"https://js.shift4.com/v1/shift4.js\"></script>\n\n<div id=\"apple-pay-button\"></div>\n<div id=\"google-pay-button\"></div>\n<hr />\n<div id=\"number\"></div>\n<div id=\"expiry\"></div>\n<div id=\"cvc\"></div>\n<input id=\"cardholder\" type=\"text\" placeholder=\"Cardholder name\" />\n<button id=\"pay\">Pay by card</button>\n\n<div id=\"result\"></div>\n<div id=\"error\"></div>\n\n<script>\n  (async function () {\n    var shift4 = Shift4('pk_sandbox_XXXXXXXXXXXXXXXXXXXX');\n\n    // One Checkout Session for wallet payments\n    var walletCheckout = await shift4.createCheckout('{{clientSecret}}');\n    walletCheckout.createComponent('apple-pay-button').mount('#apple-pay-button');\n    walletCheckout.createComponent('google-pay-button').mount('#google-pay-button');\n    walletCheckout.addEventListener('checkout_session.succeeded', onSuccess);\n    walletCheckout.addEventListener('payment.failed', onError);\n\n    // Separate Checkout Session for card payment\n    var cardCheckout = await shift4.createCheckout('{{clientSecret}}');\n    cardCheckout.createComponent('number').mount('#number');\n    cardCheckout.createComponent('expiry').mount('#expiry');\n    cardCheckout.createComponent('cvc').mount('#cvc');\n    cardCheckout.addEventListener('checkout_session.succeeded', onSuccess);\n    cardCheckout.addEventListener('payment.failed', onError);\n\n    document.getElementById('pay').addEventListener('click', function () {\n      cardCheckout.continue({\n        email: 'customer@example.com',\n        billing: { name: document.getElementById('cardholder').value }\n      });\n    });\n\n    function onSuccess() {\n      document.getElementById('result').textContent = 'Payment successful';\n    }\n    function onError(event) {\n      document.getElementById('error').textContent = event.error.message;\n    }\n  })();\n</script>\n","lang":"html"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Each ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["{{clientSecret}}"]}," comes from its own ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/guides/core-concepts/checkout/create-a-checkout-session"},"children":["Checkout Session created on your backend"]},"."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"next-steps","__idx":5},"children":["Next steps"]},{"$$mdtype":"Tag","name":"Cards","attributes":{"columns":3,"cardMinWidth":240},"children":[{"$$mdtype":"Tag","name":"Card","attributes":{"title":"Events & error handling","imagePosition":"start","iconPosition":"auto","layout":"vertical","align":"start","variant":"filled","to":"/guides/core-concepts/checkout/payment-components/events-and-errors"},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The event model, the error object, and how to handle interruptions."]}]},{"$$mdtype":"Tag","name":"Card","attributes":{"title":"Confirm the payment","imagePosition":"start","iconPosition":"auto","layout":"vertical","align":"start","variant":"filled","to":"/guides/core-concepts/checkout/confirm-payment"},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Verify the Checkout Session server-side before you fulfil."]}]},{"$$mdtype":"Tag","name":"Card","attributes":{"title":"Test cards","imagePosition":"start","iconPosition":"auto","layout":"vertical","align":"start","variant":"filled","to":"/guides/core-concepts/checkout/testing"},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Sandbox card numbers for success, failure, and 3D Secure scenarios."]}]}]}]},"headings":[{"value":"Card payments","id":"card-payments","depth":1},{"value":"Full example","id":"full-example","depth":2},{"value":"continue() parameters","id":"continue-parameters","depth":2},{"value":"Billing and shipping addresses","id":"billing-and-shipping-addresses","depth":2},{"value":"Offer wallets alongside cards","id":"offer-wallets-alongside-cards","depth":2},{"value":"Next steps","id":"next-steps","depth":2}],"frontmatter":{"title":"Card payments","description":"Collect a card payment with Payment components — mount the card components, submit with continue(), pass billing and shipping, and combine cards with wallet buttons.","markdown":{"lastUpdatedBlock":{"hide":true}},"seo":{"title":"Card payments"}},"lastModified":"2026-10-29T08:06:54.000Z","pagePropGetterError":{"message":"","name":""}},"slug":"/guides/core-concepts/checkout/payment-components/card-payments","userData":{"isAuthenticated":false,"teams":["anonymous"]},"isPublic":true}