{"templateId":"markdown","sharedDataIds":{"sidebar":"sidebar-docs/sidebars.yaml"},"props":{"metadata":{"markdoc":{"tagList":["tabs","tab","site-link"]},"type":"markdown"},"seo":{"title":"Charging Cards","meta":[{"name":"robots","content":"noindex, nofollow"},{"name":"pingdom","content":"sh3MDv8mJpWhCWSTdGtN"}]},"dynamicMarkdocComponents":[],"compilationErrors":[],"ast":{"$$mdtype":"Tag","name":"article","attributes":{},"children":[{"$$mdtype":"Tag","name":"Heading","attributes":{"level":1,"id":"charging-cards","__idx":0},"children":["Charging Cards"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Once you have a card token representing your user's card from ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/docs/using-components"},"children":["Components"]}," - the next step is to charge that card for the money. This has to be done on your server by making a simple request to our API."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Note that a card token is a temporary representation of card details - it has to be used within 24 hours after creation. Otherwise, it will expire."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["This example shows how to create a charge from card: ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["cardToken"]}]},{"$$mdtype":"Tag","name":"Tabs","attributes":{"size":"medium"},"children":[{"$$mdtype":"Tag","name":"TabItemFragment","attributes":{"label":"Java","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"java","header":{"controls":{"copy":{}}},"source":"Shift4Gateway shift4 =\n    new Shift4Gateway(\"pr_test_tXHm9qV9qV9bjIRHcQr9PLPa\");\n\nChargeRequest chargeRequest = new ChargeRequest(799, \"USD\")\n    .card(new CardRequest(cardToken));\nCharge charge = shift4.createCharge(chargeRequest);\n","lang":"java"},"children":[]}]},{"$$mdtype":"Tag","name":"TabItemFragment","attributes":{"label":"PHP","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"php","header":{"controls":{"copy":{}}},"source":"$shift4 = new Shift4Gateway('pr_test_tXHm9qV9qV9bjIRHcQr9PLPa');\n\n$chargeRequest = new ChargeRequest();\n$chargeRequest->amount(799)->currency('USD')->card($cardToken);\n\n$charge = $shift4->createCharge($chargeRequest);\n","lang":"php"},"children":[]}]},{"$$mdtype":"Tag","name":"TabItemFragment","attributes":{"label":"C#","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"csharp","header":{"controls":{"copy":{}}},"source":"var gateway = new Shift4Gateway(\"pr_test_tXHm9qV9qV9bjIRHcQr9PLPa\");\n\nvar chargeRequest = new ChargeRequest() { Amount = 799, Currency = \"USD\",\n                    Card = new CardRequest() { Id = token.Id } };\nvar charge = await gateway.CreateCharge(chargeRequest);\n","lang":"csharp"},"children":[]}]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["After successfully creating a charge, you should see it on ",{"$$mdtype":"Tag","name":"SiteLink","attributes":{"href":"/charges"},"children":["charges list"]}," in your dashboard."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["More information about creating charges can be found in ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/docs/api/shift4-gateway/charges/createcharge"},"children":["API references"]},"."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"saving-card-for-later-use","__idx":1},"children":["Saving card for later use"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Card tokens are for one-time use only. Once you create a charge from a token, that token can't be used to do anything else. To avoid asking the user for their card data every time you create a charge, you must create a customer with a card."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["This example shows how to use card token to create a customer with a card and how to create a charge on that customer's card"]},{"$$mdtype":"Tag","name":"Tabs","attributes":{"size":"medium"},"children":[{"$$mdtype":"Tag","name":"TabItemFragment","attributes":{"label":"Java","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"java","header":{"controls":{"copy":{}}},"source":"Shift4Gateway shift4 =\n    new Shift4Gateway(\"pr_test_tXHm9qV9qV9bjIRHcQr9PLPa\");\n\nCustomerRequest customerRequest = new CustomerRequest(\"user@example.com\")\n    .card(new CardRequest(tokenId));\nCustomer customer = shift4.createCustomer(customerRequest);\n\nChargeRequest chargeRequest = new ChargeRequest(799, \"USD\")\n    .customerId(customer.getId());\nCharge charge = shift4.createCharge(chargeRequest);\n","lang":"java"},"children":[]}]},{"$$mdtype":"Tag","name":"TabItemFragment","attributes":{"label":"PHP","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"php","header":{"controls":{"copy":{}}},"source":"$shift4 = new Shift4Gateway('pr_test_tXHm9qV9qV9bjIRHcQr9PLPa');\n\n$customerRequest = new CustomerRequest();\n$customerRequest->email('user@example.com')->card($tokenId);\n$customer = $shift4->createCustomer($customerRequest);\n\n$chargeRequest = new ChargeRequest();\n$chargeRequest->amount(799)->currency('USD')->customerId($customer->getId());\n$charge = $shift4->createCharge($chargeRequest);\n","lang":"php"},"children":[]}]},{"$$mdtype":"Tag","name":"TabItemFragment","attributes":{"label":"C#","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"csharp","header":{"controls":{"copy":{}}},"source":"var gateway = new Shift4Gateway(\"pr_test_tXHm9qV9qV9bjIRHcQr9PLPa\");\n\nvar customerRequest = new CustomerRequest() { Email = \"user@example.com\",\n                      Card = new CardRequest() { Id = token.Id } };\nvar customer = await gateway.CreateCustomer(customerRequest);\n\nvar chargeRequest = new ChargeRequest() { Amount = 799, Currency = \"USD\",\n                          CustomerId = customer.Id };\nvar charge = await gateway.CreateCharge(chargeRequest);\n","lang":"csharp"},"children":[]}]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["More information about creating customers can be found in ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/docs/api/shift4-gateway/customers/createcustomer"},"children":["the API references"]},"."]}]},"headings":[{"value":"Charging Cards","id":"charging-cards","depth":1},{"value":"Saving card for later use","id":"saving-card-for-later-use","depth":2}],"frontmatter":{"title":"Charging Cards","description":"Use a card token from Components to create a charge on your server, and save the card on a customer for later use.","seo":{"title":"Charging Cards"}},"lastModified":"2026-09-11T07:43:43.000Z","pagePropGetterError":{"message":"","name":""}},"slug":"/docs/charging-cards","userData":{"isAuthenticated":false,"teams":["anonymous"]},"isPublic":true}