Create a charge
Capture funds from a customer's card or saved payment method directly from your server with POST /v1/charges.
Send a POST /v1/charges request from your server to authorize and capture a
payment immediately. Use this server-to-server flow when you charge a saved
payment method (pm_…), a card token (tok_card_…), or raw card details under
full PCI DSS compliance (SAQ-D).
Requirements
Before you start, make sure you have:
- Your API credentials. The examples use the sandbox (
https://api.sandbox.pay.com/v1) with ansk-pay-com-sandbox-key. - A unique
idempotency-keyheader for eachPOSTrequest. - PCI DSS SAQ-D compliance if you send raw card numbers in
source_data.card.
Process a charge
Follow these steps to create a charge, inspect its status, and handle 3D Secure authentication when required.
- 1
Send the charge request
Call
POST /v1/chargeswithamount(in minor units, so8000equals $80.00 USD),currency, and a payment source:source: A saved payment method ID (pm_…) or a card token (tok_card_…).source_data: Raw card details, an alternative payment method, or an encrypted Apple Pay or Google Pay payload.
POST https://api.sandbox.pay.com/v1/charges{ "amount": 8000, "currency": "usd", "source_data": { "type": "card", "card": { "number": "4242424242424242", "expiry_month": "12", "expiry_year": "2028", "cvv": "123", "name": "John Smith" } }, "payment_method_options": { "card": { "duplicate_card_check": false } } }The
paidboolean indicates whether funds have settled to your bank account, not whether the charge was approved. A newly approved charge returnsstatus: "succeeded"withpaid: false. Always checkstatusto confirm approval. - 2
Check the payment status
Inspect the
statusfield in the201response:succeeded: The charge was approved and the funds are captured. Settlement to your bank account happens later (seepaid).pending: The charge is waiting for confirmation, as with asynchronous methods such as SEPA or ACH.requires_authentication: The customer must complete a 3D Secure challenge or a bank login before the funds can be captured. This happens when regulations such as PSD2 require it, when you enforce 3D Secure for fraud prevention, or when an alternative payment method needs a bank login. Complete the next step.requires_confirmation: Authentication is complete. Confirm the charge to finish it.succeeded_partially: The charge was approved for less than the requested amount. See Handle partial approvals.requires_partial_approval_action: The charge was partially approved and server-to-server partial approval is on. Confirm or cancel the partial amount, as Handle partial approvals describes.awaiting_final_confirmation: The payment method approved the charge, but its final confirmation is still pending. Wait for the final status before you fulfill the order.
A declined charge (
failed) and a charge a risk rule blocked (blocked) both return HTTP400witherror.type: "payment_method_error",error.code: "card_declined", and adecline_code. The charge is still created, so you can retrieve it to see its status. See Decline codes. - 3
Handle customer authentication (when required)
If
statusisrequires_authentication, callPOST /v1/sessions/authentication/linkedwith the charge ID inresource. Setconfirmbased on whether Pay.com completes the charge automatically after the challenge:Pay.com authorizes the charge automatically after the customer completes the challenge and sends a
charge.succeededorcharge.failedwebhook. No additional API call is needed.POST https://api.sandbox.pay.com/v1/sessions/authentication/linked{ "resource": "chrg_686511994907394048", "confirm": true, "return_url": "https://your-site.com/payment/complete" }Redirect the customer to
url. Pay.com finishes authorization after the challenge and sends the result in a webhook.
Listen for webhooks
Confirm payment outcomes on your backend through webhooks rather than relying only on synchronous responses. Subscribe to:
charge.succeeded: Funds are captured. Fulfill the order.charge.failed: The charge was declined or couldn't complete.
Verify the Pay-Signature header on every incoming event before acting on it.
See Verify webhook signatures
and Webhook events.
Next steps
Related payment guides:
- Universal checkout: Embed a hosted Pay.com.js checkout form (SAQ-A).
- Create a charge with 3DS: Pass browser metadata and enforce 3D Secure for PSD2 or fraud prevention.
- Hold and capture: Authorize funds first and capture later.
- Refund a charge: Return full or partial funds on a settled charge.
- Wallets: Process Apple Pay and Google Pay tokens server-to-server.