ArgusDocs
English Türkçe

Server-to-server card payments

On this page

Take a card payment when the card form posts to your server and your server sends the card to the API.

Your server sends the card with your secret key, in the same call that creates and confirms the payment. Your checkout page does not call the API, and you do not tokenize the card first.

  1. The customer submits the card form to your server.
  2. Your server calls POST /v1/payment_intents with the card and confirm: true.
  3. If the status is succeeded, you are done. If it is requires_action, send the customer to the bank. The customer comes back to your return_url, and you read the payment with GET.

When your request arrives, we take the card number and security code out of it and put them in secure card storage. Nothing else reads the request first. From then on, only a masked reference to the card is used.

When to use it

Use server-to-server card payments when:

If you do not want card numbers on your server, use browser tokenization instead. Card payments compares the two. Once the card is collected, 3D Secure, installments, capture, refunds and webhooks work the same way in both.

Before you start

Create and confirm the payment

Send the card in payment_method_data.card, with type: "card" and confirm: true. Take the amount from your own order, never from the form the customer submitted.

{
  "amount": 12500,
  "currency": "try",
  "confirm": true,
  "payment_method_data": {
    "type": "card",
    "card": {
      "number": "4109090000000011",
      "exp_month": 12,
      "exp_year": 2030,
      "cvc": "123",
      "holder_name": "AYSE YILMAZ"
    },
    "billing_details": {
      "name": "Ayşe Yılmaz",
      "email": "ayse.yilmaz@example.com",
      "address": {"line1": "Caferağa Mah. Moda Cad. No:12", "city": "Kadıköy", "state": "İstanbul", "postal_code": "34710", "country": "TR"}
    }
  },
  "payment_method_options": {"card": {"three_d_secure": "required"}},
  "client_details": {
    "ip": "198.51.100.23",
    "user_agent": "Mozilla/5.0 (Linux; Android 14) AppleWebKit/537.36 Chrome/126.0 Mobile Safari/537.36",
    "accept_language": "tr-TR,tr;q=0.9,en;q=0.8",
    "device_id": "chk_7f3a9c2e51b04d68"
  },
  "return_url": "https://modakitabevi.com.tr/odeme/sonuc",
  "description": "Sipariş SIP-2026-10423",
  "metadata": {"order_id": "SIP-2026-10423"}
}
curl -X POST https://api.pf.organizer.tr/v1/payment_intents \
  -H "Authorization: Bearer sk_sandbox_YOUR_KEY" \
  -H "Idempotency-Key: order-SIP-2026-10423-attempt-1" \
  -H "Content-Type: application/json" \
  -d @payment.json

three_d_secure: required forces the 3D Secure redirect, so you can test it. Leave the option out to let us decide for each payment. It defaults to automatic. See payments without 3D Secure.

The request body must be JSON (Content-Type: application/json). We refuse a form-encoded or multipart body with 415 unsupported_media_type before we read anything in it. This way a card is never taken from a form post by accident. The card fields are:

Field Rule
number A string of 13 to 19 digits, without spaces or dashes, that passes the Luhn check.
exp_month An integer from 1 to 12.
exp_year A four-digit integer (2030), at most 20 years ahead. A card is valid through the end of its expiry month.
cvc Optional: a string of 3 or 4 digits. Send it when the customer is present. We keep it until the payment is authorized, for 15 minutes at most, and then delete it.
holder_name Optional, up to 128 characters.

Every card payment also needs payment_method_data.billing_details with name, address.line1, address.city and address.country. Without them, you get 400 billing_details_required. In the sandbox, a missing field only adds a warning to the request log. See customers and billing.

return_url is an http or https address of up to 2048 characters. Send it with every payment. When 3D Secure is required and return_url is missing, you get 400 parameter_missing with param return_url, and nothing is charged.

We accept raw card fields in three places only:

We refuse a card number anywhere else before anything is stored. In the URL, it gives 400 card_data_in_url. In another field, such as metadata or description, it gives 400 card_data_in_unexpected_field.

A card object without a number, for example a hand-made {token, last4, …}, is refused with 400 card_details_required. The BIN, brand, last four digits and issuer always come from the card storage, never from your request.

Tell us who your customer is

In this integration, every request comes from your server. Your server's IP address says nothing about the cardholder. Fraud screening, our risk controls and the bank need the cardholder's address and device. Send them in client_details, with the create call or the confirm call:

Field What to send
ip The customer's IP address as it reached your server: one IPv4 or IPv6 address, without a port. Behind a load balancer or CDN, take the client address your edge reports, not the address of the proxy.
user_agent The User-Agent header of the customer's browser, unchanged. Up to 512 characters.
accept_language The Accept-Language header of the customer's browser, unchanged. Up to 128 characters.
browser_language The language of the customer's browser or app as one language tag, such as tr-TR (navigator.language), up to 35 characters. We pass it to the bank with the 3D Secure request, so the bank's page uses your customer's language. Use the redirect_to_url you get back as it is: it belongs to the bank, and we never add a language to it. Without browser_language, we use the first language of accept_language.
device_id Your own stable id for the device or checkout session, for example a first-party cookie value or an app installation id. Letters, digits and _ - . :, up to 128 characters. Never derive it from the card.

All five fields are optional. Send what you have, on every payment. The rules:

The response when 3D Secure is needed

The call returns 200 with the payment. When the bank wants the cardholder to authenticate, status is requires_action and next_action says where to send the customer:

{
  "id": "pi_01J9ZQ4V8K2M3N5P7R9T1W3Y5A",
  "object": "payment_intent",
  "amount": 12500,
  "amount_charged": 12500,
  "surcharge": 0,
  "amount_capturable": 0,
  "amount_received": 0,
  "captured_minor": 0,
  "refunded_minor": 0,
  "amount_refundable": 0,
  "currency": "try",
  "status": "requires_action",
  "capture_method": "automatic",
  "installments": 1,
  "three_d_secure": {"requested": "required", "effective": "required"},
  "payment_method": null,
  "payment_method_type": "card",
  "card": {
    "brand": "visa",
    "bin": "410909",
    "last4": "0011",
    "masked": "410909******0011",
    "fingerprint": "5f1d7c0f9b2a4e6d8c3b1a0f7e9d2c4b",
    "exp_month": 12,
    "exp_year": 2030,
    "card_type": "credit",
    "domestic": true
  },
  "next_action": {
    "type": "redirect_to_url",
    "redirect_to_url": {
      "url": "https://pay.example.com/3ds/pi_01J9ZQ4V8K2M3N5P7R9T1W3Y5A",
      "return_url": "https://modakitabevi.com.tr/odeme/sonuc"
    }
  },
  "last_payment_error": null,
  "fraud_status": "none",
  "cancellation_reason": null,
  "auth_expires_at": null,
  "customer": null,
  "customer_details": null,
  "receipt_email": null,
  "billing_details": {
    "name": "Ayşe Yılmaz",
    "email": "ayse.yilmaz@example.com",
    "address": {"line1": "Caferağa Mah. Moda Cad. No:12", "city": "Kadıköy", "state": "İstanbul", "postal_code": "34710", "country": "TR"}
  },
  "shipping": null,
  "description": "Sipariş SIP-2026-10423",
  "return_url": "https://modakitabevi.com.tr/odeme/sonuc",
  "metadata": {"order_id": "SIP-2026-10423"},
  "latest_attempt": "att_01J9ZQ4V8K2M3N5P7R9T1W3Y5C",
  "source": "api",
  "created": 1795167000,
  "livemode": false,
  "client_details": {
    "ip": "198.51.100.23",
    "user_agent": "Mozilla/5.0 (Linux; Android 14) AppleWebKit/537.36 Chrome/126.0 Mobile Safari/537.36",
    "accept_language": "tr-TR,tr;q=0.9,en;q=0.8",
    "device_id": "chk_7f3a9c2e51b04d68"
  }
}

The response never contains the card number or the security code. card holds the masked reference. Use brand, last4 and card_type for the order confirmation, and fingerprint to recognize the same card across payments. The examples leave out the fees and settlement objects. The API reference shows them.

Without 3D Secure, the same call already ends in succeeded, or in requires_capture for a pre-authorization, and next_action is null. This happens with three_d_secure: none on an account that allows it, or with automatic when we do not ask for authentication. If your account or the amount is not enabled for none, you get 400 non_secure_not_allowed. Send automatic instead.

Create first, confirm later

Only the request that pays with the card may carry it. To create the payment before the customer has entered the card, leave out confirm and payment_method_data. Then send the card to the confirm call:

{
  "payment_method_data": {
    "type": "card",
    "card": {
      "number": "4109090000000011",
      "exp_month": 12,
      "exp_year": 2030,
      "cvc": "123",
      "holder_name": "AYSE YILMAZ"
    },
    "billing_details": {
      "name": "Ayşe Yılmaz",
      "address": {"line1": "Caferağa Mah. Moda Cad. No:12", "city": "Kadıköy", "country": "TR"}
    }
  },
  "client_details": {"ip": "198.51.100.23", "device_id": "chk_7f3a9c2e51b04d68"},
  "return_url": "https://modakitabevi.com.tr/odeme/sonuc"
}
curl -X POST https://api.pf.organizer.tr/v1/payment_intents/pi_01J9ZQ4V8K2M3N5P7R9T1W3Y5A/confirm \
  -H "Authorization: Bearer sk_sandbox_YOUR_KEY" \
  -H "Idempotency-Key: order-SIP-2026-10423-attempt-1" \
  -H "Content-Type: application/json" \
  -d @confirm.json

A create call that carries a card without confirm: true is refused with 400 card_without_confirm (param confirm). The card is not stored first, so no card or security code waits for a confirmation that may never come.

You may name a saved card, payment_method: "pm_…", on create without confirm. Nothing is held for it.

The confirm call also retries a declined payment. The payment's status is then requires_payment_method, and the new card replaces the old one.

Two calls instead of one

You can also tokenize the card from your server with POST /v1/payment_methods and your secret key. Then pay with the returned pm_… id, as in browser tokenization. Do this when you need a pm_… id before you pay, for example to preview installments for the card. For a plain payment, the single call above is simpler.

3D Secure: redirect and return

When status is requires_action, your server does three things before it answers the customer's browser:

  1. Store the payment's id with your order, for example pi_01J9… for order SIP-2026-10423. The return page needs it.
  2. Redirect the browser to next_action.redirect_to_url.url with HTTP 303. If next_action.type is html_form, return next_action.html_form.html as the page instead, with content type text/html. That page posts the customer to the bank.
  3. Do not touch the card again. We handle the bank page, the challenge and the result.

When the customer has authenticated, or failed to, we complete the payment. We then redirect the browser with a GET to your return_url and add two parameters. They follow ?, or & if your URL already has a query string, which we keep as it is. A #fragment in your return_url stays at the end, after the two parameters, so they still reach your server:

https://modakitabevi.com.tr/odeme/sonuc
  ?payment_intent=pi_01J9ZQ4V…
  &argus_signature=t%3D1795167042%2C…

The address is one line. It is broken here to fit the page, and the values are shortened.

On your return page:

  1. Verify the signature, as described below. A redirect without a valid signature did not come from us: answer 400 and do nothing else.
  2. Read the payment id and look up the order you stored for it.
  3. Read the payment from the API with your secret key (GET /v1/payment_intents/{id}) and decide from its status. The signature tells you that we made the redirect and which payment it is about. It never tells you how the payment ended, so never decide from the redirect alone.
  4. Check that metadata.order_id, or the mapping you stored, matches the order. Check that amount and currency are what you expect.

To carry a reference of your own through the redirect, put it in the return_url you send, for example https://modakitabevi.com.tr/odeme/sonuc?order=SIP-2026-10423. The query string comes back unchanged, before the two parameters. Use it only as a hint for finding the order. The proof is the payment you read and its metadata.

Verify the redirect

We sign the redirect with your return signing secret (rtsec_…). This secret is separate from your API keys and from the signing secret of any webhook endpoint. You manage it like a webhook secret. A secret key can roll it and read its state. A restricted key needs the webhook_endpoints write scope to roll it and the read scope to read its state.

curl -X POST https://api.pf.organizer.tr/v1/return_signing_secret/roll \
  -H "Authorization: Bearer sk_sandbox_YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{"expires_in_seconds": 3600}'
{
  "object": "return_signing_secret",
  "secret": "rtsec_Zk3vX9p2QmT7aB1cD4eF6gH8jK0LmN5oPqRsTuVwXyZ",
  "rolled_at": 1795167000,
  "previous_secret_expires_at": 1795170600
}

The secret is shown only in this response. Store it with your other secrets. Your first roll is how you get the secret. If you send an Idempotency-Key and repeat the call, the replay has secret: null. Roll again.

A later roll replaces it, and redirects are signed with the new secret at once. With expires_in_seconds (at most 7 days, default 0), redirects also carry a signature made with the previous secret for that time. This lets you deploy the new secret without turning away a customer who is on the way back.

GET /v1/return_signing_secret shows when the secret was rolled. It never shows the secret.

You verify the redirect as you verify webhook signatures. The signed payload is the payment id:

  1. Split argus_signature at the commas into t and one or more v1 values.
  2. Compute the HMAC-SHA256 of <t>.<payment_intent> with your secret as the key, and hex-encode it. Use the whole secret, rtsec_ included. An example payload is 1795167042.pi_01J9ZQ4V8K2M3N5P7R9T1W3Y5A.
  3. Accept the redirect if the result equals one of the v1 values and t is at most 5 minutes old. Compare in constant time.

The complete samples do this in PHP and Node.js.

The return is a top-level GET navigation from another site. The browser does not send a session cookie with SameSite=Strict on it. Use Lax, or find the order from the payment id as above.

status on return Meaning and next step
succeeded Paid. Deliver the order once. The webhook may arrive too.
requires_capture Authorized (capture_method: manual). Capture it when you ship.
processing The bank has not answered yet. Show "Payment received, confirming" and wait for the webhook.
requires_payment_method Authentication failed or the card was declined. last_payment_error has the reason. Offer another card.
requires_action The customer came back without finishing 3D Secure. We cancel an unfinished challenge after a time limit, 15 minutes by default. The payment then becomes canceled.
canceled Canceled, for example after an abandoned challenge. Create a new payment.

After a successful payment, the payment you read looks like this, without fees and settlement:

{
  "id": "pi_01J9ZQ4V8K2M3N5P7R9T1W3Y5A",
  "object": "payment_intent",
  "amount": 12500,
  "amount_charged": 12500,
  "surcharge": 0,
  "amount_capturable": 0,
  "amount_received": 12500,
  "captured_minor": 12500,
  "refunded_minor": 0,
  "amount_refundable": 12500,
  "currency": "try",
  "status": "succeeded",
  "capture_method": "automatic",
  "installments": 1,
  "three_d_secure": {"requested": "required", "effective": "required"},
  "payment_method": null,
  "payment_method_type": "card",
  "card": {
    "brand": "visa",
    "bin": "410909",
    "last4": "0011",
    "masked": "410909******0011",
    "fingerprint": "5f1d7c0f9b2a4e6d8c3b1a0f7e9d2c4b",
    "exp_month": 12,
    "exp_year": 2030,
    "card_type": "credit",
    "domestic": true
  },
  "next_action": null,
  "last_payment_error": null,
  "fraud_status": "none",
  "cancellation_reason": null,
  "auth_expires_at": null,
  "customer": null,
  "customer_details": null,
  "receipt_email": null,
  "billing_details": {
    "name": "Ayşe Yılmaz",
    "email": "ayse.yilmaz@example.com",
    "address": {"line1": "Caferağa Mah. Moda Cad. No:12", "city": "Kadıköy", "state": "İstanbul", "postal_code": "34710", "country": "TR"}
  },
  "shipping": null,
  "description": "Sipariş SIP-2026-10423",
  "return_url": "https://modakitabevi.com.tr/odeme/sonuc",
  "metadata": {"order_id": "SIP-2026-10423"},
  "latest_attempt": "att_01J9ZQ4V8K2M3N5P7R9T1W3Y5C",
  "source": "api",
  "created": 1795167000,
  "livemode": false
}

Webhooks are the source of truth

The customer may close the tab at the bank, lose the connection or never come back. Register a webhook endpoint and rely on its events for the outcome:

Verify the signature of every delivery. Handle the return page and the webhook with the same idempotent routine, keyed by the payment id. Whichever arrives first marks the order paid, and the second finds nothing left to do. Use the event's sequence to ignore an older event that arrives late.

Installments

Installments (taksit) work as described in installments, with one difference: the preview never takes a card number. It takes the first 6 to 8 digits of the card (the BIN) or a pm_… id. Cut the BIN from what the customer typed into your card form and send only those digits. A bin that is not 6 to 8 digits is refused with 400. A full card number there is refused as card data in the wrong field (card_data_in_unexpected_field). We do not echo or log it.

Your checkout page can send the BIN to the preview with your publishable key while the customer types. Your server can also call it with the secret key:

{
  "bin": "435508",
  "amount": 100000,
  "currency": "try"
}
curl -X POST https://api.pf.organizer.tr/v1/installment_plans/preview \
  -H "Authorization: Bearer sk_sandbox_YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{"bin": "435508", "amount": 100000, "currency": "try"}'

Show the plans. Then send the chosen count with the payment in payment_method_options.card.installments.count, from 1 to 36. Keep amount as your price. We add any installment surcharge the customer pays.

{
  "amount": 100000,
  "currency": "try",
  "confirm": true,
  "payment_method_data": {
    "type": "card",
    "card": {
      "number": "4355080000000013",
      "exp_month": 12,
      "exp_year": 2030,
      "cvc": "123",
      "holder_name": "AYSE YILMAZ"
    },
    "billing_details": {
      "name": "Ayşe Yılmaz",
      "address": {"line1": "Caferağa Mah. Moda Cad. No:12", "city": "Kadıköy", "country": "TR"}
    }
  },
  "payment_method_options": {"card": {"installments": {"count": 3}}},
  "return_url": "https://modakitabevi.com.tr/odeme/sonuc",
  "metadata": {"order_id": "SIP-2026-10432"}
}

The payment then shows installments: 3, amount: 100000, surcharge and amount_charged, the total charged to the card. A count the card cannot use with your account is refused with 402 installments_not_available, and nothing is charged. Offer a count from the latest preview.

Pre-authorization: manual capture and cancel

Add "capture_method": "manual" to the create request. The card is authorized and 3D Secure works as above. The payment then ends in requires_capture with auth_expires_at, instead of succeeded. You do not need the card again to capture. When you ship, call POST /v1/payment_intents/{id}/capture for the full amount or a part of it. To release the authorization, call POST /v1/payment_intents/{id}/cancel.

We cancel an authorization that is still open at auth_expires_at. Pre-authorization, capture and cancel has the details, errors and webhooks.

Save the card for later

To charge the same customer again without asking for the card, create the customer once (see customers). Then add customer and setup_future_usage: true to the first payment. Do this only with the cardholder's consent.

{
  "amount": 12500,
  "currency": "try",
  "confirm": true,
  "customer": "cus_01J9ZQ9D3F5H7K9M2P4R6T8W1Y",
  "setup_future_usage": true,
  "billing_details_from_customer": true,
  "payment_method_data": {
    "type": "card",
    "card": {
      "number": "4109090000000011",
      "exp_month": 12,
      "exp_year": 2030,
      "cvc": "123",
      "holder_name": "AYSE YILMAZ"
    }
  },
  "return_url": "https://modakitabevi.com.tr/odeme/sonuc",
  "metadata": {"order_id": "SIP-2026-10423"}
}

setup_future_usage needs customer, because a card is saved to a customer and never to your account as a whole. Without customer, the request is refused with 400 parameter_missing (param customer) and nothing is created.

Once the payment is authorized (succeeded or requires_capture), we save the card in secure storage. The new pm_… id goes into the payment's payment_method field. A payment that asked for this also has setup_future_usage_status:

setup_future_usage_status Meaning
pending The payment is not authorized yet, for example because it waits for 3D Secure. Nothing was saved.
saved The card is saved. payment_method is its pm_… id.
failed The payment went through, but the card could not be saved. payment_method is null. Ask for the card again next time.

A failed save never fails the payment. So do not assume that a paid payment saved its card. Read setup_future_usage_status after the payment is authorized: in the response of the call, or on the return page after 3D Secure.

{
  "amount": 8900,
  "currency": "try",
  "confirm": true,
  "customer": "cus_01J9ZQ9D3F5H7K9M2P4R6T8W1Y",
  "payment_method": "pm_01J9ZQA2B4C6D8E1F3G5H7J9K2",
  "billing_details_from_customer": true,
  "return_url": "https://modakitabevi.com.tr/odeme/sonuc",
  "metadata": {"order_id": "SIP-2026-10466"}
}

3D Secure, installments and manual capture apply to a saved card as to a new one. Keep the return_url and the redirect handling.

Declines and errors

A failed request returns the error object: type, code, decline_code, param, message and request_id. Branch on type and code, never on message. Three cases matter for card payments.

The card was refused before a payment was created. We check the card when we store it. A number that fails the length or Luhn check, an expired card or a malformed security code gives 402 card_error. Its code and decline_code hold the same value: invalid_card, expired_card or incorrect_cvc. No payment_intent is attached, because nothing was created.

{
  "error": {
    "type": "card_error",
    "code": "invalid_card",
    "decline_code": "invalid_card",
    "param": null,
    "message": "Your card number is invalid.",
    "request_id": "req_01J9ZQ4V8K2M3N5P7R9T1W3Y5F"
  }
}

An invalid expiry date, a holder name over 128 characters or a card field of the wrong type gives 400 invalid_request_error with the code card_invalid_parameters. An expiry date is invalid when exp_month is outside 1 to 12, or exp_year is not a four-digit year or lies more than 20 years ahead.

{
  "error": {
    "type": "invalid_request_error",
    "code": "card_invalid_parameters",
    "decline_code": null,
    "param": null,
    "message": "The card's number, expiration date (exp_month 1-12, four-digit exp_year) or holder name is missing or invalid.",
    "request_id": "req_01J9ZQ4V8K2M3N5P7R9T1W3Y5G"
  }
}

Ask the customer to correct the card details and send the request again. We return these errors before your Idempotency-Key is used, so you may send the corrected card with the same key. The same holds for 400 card_without_confirm and 415 unsupported_media_type: the request was refused before anything was stored.

The bank or fraud screening declined the payment. You get 402 with type: card_error, code: card_declined and a decline_code, or type: fraud_error from fraud screening. The payment exists, so the error carries it as payment_intent. Its status is requires_payment_method, and last_payment_error has the reason:

{
  "error": {
    "type": "card_error",
    "code": "card_declined",
    "decline_code": "insufficient_funds",
    "param": null,
    "message": "The card has insufficient funds.",
    "request_id": "req_01J9ZQ4V8K2M3N5P7R9T1W3Y5H",
    "payment_intent": {
      "id": "pi_01J9ZQ4V8K2M3N5P7R9T1W3Y5A",
      "object": "payment_intent",
      "amount": 12551,
      "currency": "try",
      "status": "requires_payment_method",
      "last_payment_error": {
        "type": "card_error",
        "code": "card_declined",
        "decline_code": "insufficient_funds",
        "message": "The card has insufficient funds."
      },
      "metadata": {"order_id": "SIP-2026-10423"},
      "created": 1795167000,
      "livemode": false
    }
  }
}

Show the customer a short, friendly message and keep the exact reason for your logs. The decline codes say whether another attempt makes sense. For a new attempt, create a new payment, or call POST /v1/payment_intents/{id}/confirm on the same payment with a new card. Use a new Idempotency-Key for it. One exception: after incorrect_cvc, expired_card or invalid_card, you may send the corrected card with the same key. See idempotency and safe retries. 402 no_eligible_terminal and 402 installments_not_available are card refusals with the same error object.

The request was refused or could not be completed. Other 400, 403 and 404 errors say what to fix, and param names the field. Examples are billing_details_required, parameter_missing for return_url, return_url_not_allowed, website_not_registered, ip_not_allowed, product_not_enabled and non_secure_not_allowed. A 503 with card_vault_unavailable, card_tokenization_unavailable or risk_check_unavailable means that a service the call needs was not available, and nothing was done. Retry with the same key after a short pause. If the response has a Retry-After header, wait that many seconds.

Every error has a request_id. We send it in the Request-Id response header too. Quote it to support.

Idempotency and safe retries

Send an Idempotency-Key with every POST. It is a string of 1 to 255 characters; anything else gives 400 idempotency_key_invalid. We run a request at most once per key. For 24 hours, a repeat gets the stored response with Idempotent-Replayed: true. Errors and retries has the general rules. For card payments, note these points:

What is and is not logged

We keep card data out of every log we write:

Protecting your side is up to you:

The request log shows the IP address your request came from, which is your server's, as its source. The cardholder's address, browser and device that you send in client_details are part of the logged request body and of the payment. They never count as the source of the request.

Security and compliance

In this integration, the card number and security code pass through your server. Your server, and every system that can see the request on its way, is therefore in scope for the card data security standard (PCI DSS). These systems include web servers, proxies, load balancers, application logs and memory dumps. What applies to you depends on your volume and your agreement. Confirm your obligations with your bank or a PCI assessor. We do not classify your integration for you.

Browser tokenization moves the card off your server, but not off your checkout page. See the comparison.

Complete samples

Each sample is a checkout handler and a return handler, without a framework. They read the secret key from ARGUS_SECRET_KEY, the return signing secret from ARGUS_RETURN_SIGNING_SECRET and the base URL from ARGUS_API_BASE, for example https://api.pf.organizer.tr/v1.

The samples send an Idempotency-Key and the customer's client_details, and they verify the signature of the return redirect. They build exceptions from the error code and request_id only, so a card never ends up in an exception message or a log.

The order is hard-coded. In your shop, it comes from your database.

PHP

PHP 8.1 or later, with the bundled cURL extension. argus.php is the client, checkout.php receives the card form and return.php is your return_url.

<?php
// argus.php: a small client for the payment API.
final class ArgusApiError extends RuntimeException
{
    public function __construct(public readonly int $status, public readonly array $error)
    {
        // Only the code and the request id: never the request body (it holds the card).
        parent::__construct(($error['code'] ?? 'error') . ' (' . ($error['request_id'] ?? '') . ')', $status);
    }
}

final class ArgusNetworkError extends RuntimeException
{
}

function argus_request(string $method, string $path, ?array $body = null, ?string $idempotencyKey = null): array
{
    $base = getenv('ARGUS_API_BASE') ?: 'https://api.pf.organizer.tr/v1';
    $headers = ['Authorization: Bearer ' . getenv('ARGUS_SECRET_KEY'), 'Content-Type: application/json'];
    if ($idempotencyKey !== null) {
        $headers[] = 'Idempotency-Key: ' . $idempotencyKey;
    }
    $ch = curl_init($base . $path);
    curl_setopt_array($ch, [
        CURLOPT_CUSTOMREQUEST => $method,
        CURLOPT_HTTPHEADER => $headers,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_CONNECTTIMEOUT => 10,
        CURLOPT_TIMEOUT => 60,
    ]);
    if ($body !== null) {
        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body));
    }
    $raw = curl_exec($ch);
    if ($raw === false) {
        throw new ArgusNetworkError('Network error: ' . curl_error($ch));
    }
    $status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
    $data = json_decode($raw, true) ?? [];
    if ($status >= 400) {
        throw new ArgusApiError($status, $data['error'] ?? []);
    }
    return $data;
}

// True when argus_signature was made by us for this payment, at most $tolerance seconds ago.
function argus_verify_return(string $paymentId, string $signature, int $tolerance = 300): bool
{
    $secret = getenv('ARGUS_RETURN_SIGNING_SECRET');
    $timestamp = null;
    $candidates = [];
    foreach (explode(',', $signature) as $part) {
        [$name, $value] = array_pad(explode('=', $part, 2), 2, '');
        if ($name === 't') {
            $timestamp = $value;
        } elseif ($name === 'v1') {
            $candidates[] = $value;
        }
    }
    if (!$secret || $timestamp === null || !ctype_digit($timestamp) || abs(time() - (int) $timestamp) > $tolerance) {
        return false;
    }
    $expected = hash_hmac('sha256', $timestamp . '.' . $paymentId, $secret);
    foreach ($candidates as $candidate) {
        if (hash_equals($expected, $candidate)) {
            return true;
        }
    }
    return false;
}
<?php
// checkout.php: the customer's card form posts here.
require __DIR__ . '/argus.php';

// The order comes from your own database, never from the form.
$order = ['id' => 'SIP-2026-10423', 'amount' => 12500, 'attempt' => 1];

try {
    $payment = argus_request('POST', '/payment_intents', [
        'amount' => $order['amount'],
        'currency' => 'try',
        'confirm' => true,
        'payment_method_data' => [
            'type' => 'card',
            'card' => [
                'number' => preg_replace('/\D+/', '', $_POST['card_number'] ?? ''),
                'exp_month' => (int) ($_POST['exp_month'] ?? 0),
                'exp_year' => (int) ($_POST['exp_year'] ?? 0),
                'cvc' => $_POST['cvc'] ?? '',
                'holder_name' => $_POST['holder_name'] ?? '',
            ],
            'billing_details' => [
                'name' => $_POST['holder_name'] ?? '',
                'email' => $_POST['email'] ?? '',
                // Use the address your checkout form collected.
                'address' => ['line1' => 'Caferağa Mah. Moda Cad. No:12', 'city' => 'Kadıköy', 'country' => 'TR'],
            ],
        ],
        'payment_method_options' => ['card' => ['three_d_secure' => 'required']],
        // Your customer's own client. REMOTE_ADDR is right only without a proxy in front of PHP:
        // behind a load balancer or CDN use the client address your edge reports.
        'client_details' => [
            'ip' => $_SERVER['REMOTE_ADDR'] ?? null,
            'user_agent' => substr($_SERVER['HTTP_USER_AGENT'] ?? '', 0, 512) ?: null,
            'accept_language' => substr($_SERVER['HTTP_ACCEPT_LANGUAGE'] ?? '', 0, 128) ?: null,
        ],
        'return_url' => 'https://modakitabevi.com.tr/odeme/sonuc',
        'metadata' => ['order_id' => $order['id']],
    ], 'order-' . $order['id'] . '-attempt-' . $order['attempt']);
} catch (ArgusApiError $e) {
    // Never log $_POST or the request body. The code and request id are enough.
    error_log('payment refused: ' . $e->getMessage());
    if (($e->error['type'] ?? '') === 'card_error') {
        exit('Your card was not accepted. Please check the details or try another card.');
    }
    exit('The payment could not be started. Please try again later.');
} catch (ArgusNetworkError $e) {
    // The outcome is unknown. Do not retry with a new key: look the order up first.
    error_log('payment outcome unknown for order ' . $order['id']);
    exit('We could not confirm your payment. Please do not pay again; we will check it.');
}

// Remember which payment belongs to the order before the customer leaves.
// save_payment_for_order($order['id'], $payment['id']);

if ($payment['status'] === 'requires_action') {
    $action = $payment['next_action'];
    if ($action['type'] === 'redirect_to_url') {
        header('Location: ' . $action['redirect_to_url']['url'], true, 303);
    } else {
        echo $action['html_form']['html'];
    }
    exit;
}

echo $payment['status'] === 'succeeded' ? 'Thank you, your payment was received.' : 'Payment status: ' . $payment['status'];
<?php
// return.php: the customer lands here after 3D Secure
// (GET /pay/return?payment_intent=pi_...&argus_signature=t%3D...%2Cv1%3D...).
require __DIR__ . '/argus.php';

$id = $_GET['payment_intent'] ?? '';
if (!preg_match('/^pi_[A-Za-z0-9]+$/', $id) || !argus_verify_return($id, $_GET['argus_signature'] ?? '')) {
    // Not a redirect we made for this payment.
    http_response_code(400);
    exit('Unknown payment.');
}

// Fetch the payment with the secret key. The signature says where the redirect comes from,
// never how the payment ended.
$payment = argus_request('GET', '/payment_intents/' . rawurlencode($id));

// The payment must belong to the order stored for it.
$expectedOrder = 'SIP-2026-10423'; // find_order_by_payment_id($id)
if (($payment['metadata']['order_id'] ?? null) !== $expectedOrder || $payment['amount'] !== 12500 || $payment['currency'] !== 'try') {
    http_response_code(400);
    exit('Unknown payment.');
}

switch ($payment['status']) {
    case 'succeeded':
        echo 'Thank you, your payment was received.'; // mark_order_paid() once; the webhook may also do it
        break;
    case 'requires_capture':
        echo 'Your payment is authorized.';
        break;
    case 'processing':
        echo 'Payment received, confirming with the bank. We will email you.';
        break;
    case 'requires_payment_method':
        echo 'The payment was not completed: ' . ($payment['last_payment_error']['decline_code'] ?? 'declined') . '. Please try another card.';
        break;
    default:
        echo 'Payment status: ' . $payment['status'];
}

Node.js

Node.js 18 or later, with the built-in fetch and no packages. Both handlers are in one file. Adapt the two route functions to your web framework.

// server.mjs: node server.mjs
import { createServer } from 'node:http';
import { createHmac, timingSafeEqual } from 'node:crypto';

const BASE = process.env.ARGUS_API_BASE ?? 'https://api.pf.organizer.tr/v1';
const KEY = process.env.ARGUS_SECRET_KEY;
const RETURN_SECRET = process.env.ARGUS_RETURN_SIGNING_SECRET;

// True when argus_signature was made by us for this payment, at most toleranceSeconds ago.
function verifyReturn(paymentId, signature, toleranceSeconds = 300) {
  let timestamp = null;
  const candidates = [];
  for (const part of String(signature).split(',')) {
    const at = part.indexOf('=');
    const name = part.slice(0, at);
    const value = part.slice(at + 1);
    if (name === 't') timestamp = value;
    else if (name === 'v1') candidates.push(value);
  }
  if (!RETURN_SECRET || !/^\d+$/.test(timestamp ?? '') || Math.abs(Date.now() / 1000 - Number(timestamp)) > toleranceSeconds) return false;
  const expected = Buffer.from(createHmac('sha256', RETURN_SECRET).update(`${timestamp}.${paymentId}`).digest('hex'));
  return candidates.some((c) => c.length === expected.length && timingSafeEqual(Buffer.from(c), expected));
}

class ArgusApiError extends Error {
  constructor(status, error) {
    // Only the code and the request id: never the request body (it holds the card).
    super(`${error?.code ?? 'error'} (${error?.request_id ?? ''})`);
    this.status = status;
    this.error = error ?? {};
  }
}

async function argus(method, path, body, idempotencyKey) {
  const headers = { Authorization: `Bearer ${KEY}`, 'Content-Type': 'application/json' };
  if (idempotencyKey) headers['Idempotency-Key'] = idempotencyKey;
  const res = await fetch(BASE + path, {
    method,
    headers,
    body: body ? JSON.stringify(body) : undefined,
    signal: AbortSignal.timeout(60_000),
  });
  const data = await res.json().catch(() => ({}));
  if (!res.ok) throw new ArgusApiError(res.status, data.error);
  return data;
}

async function readForm(req) {
  let raw = '';
  for await (const chunk of req) raw += chunk;
  return new URLSearchParams(raw);
}

// POST /checkout: the customer's card form.
async function checkout(req, res) {
  const form = await readForm(req);
  // The order comes from your own database, never from the form.
  const order = { id: 'SIP-2026-10423', amount: 12500, attempt: 1 };
  let payment;
  try {
    payment = await argus('POST', '/payment_intents', {
      amount: order.amount,
      currency: 'try',
      confirm: true,
      payment_method_data: {
        type: 'card',
        card: {
          number: (form.get('card_number') ?? '').replace(/\D+/g, ''),
          exp_month: Number(form.get('exp_month')),
          exp_year: Number(form.get('exp_year')),
          cvc: form.get('cvc') ?? '',
          holder_name: form.get('holder_name') ?? '',
        },
        billing_details: {
          name: form.get('holder_name') ?? '',
          email: form.get('email') ?? '',
          // Use the address your checkout form collected.
          address: { line1: 'Caferağa Mah. Moda Cad. No:12', city: 'Kadıköy', country: 'TR' },
        },
      },
      payment_method_options: { card: { three_d_secure: 'required' } },
      // Your customer's own client. The socket address is right only without a proxy in front of Node:
      // behind a load balancer or CDN use the client address your edge reports.
      client_details: {
        ip: req.socket.remoteAddress?.replace(/^::ffff:/, '') ?? null,
        user_agent: req.headers['user-agent']?.slice(0, 512) ?? null,
        accept_language: req.headers['accept-language']?.slice(0, 128) ?? null,
      },
      return_url: 'https://modakitabevi.com.tr/odeme/sonuc',
      metadata: { order_id: order.id },
    }, `order-${order.id}-attempt-${order.attempt}`);
  } catch (err) {
    // Never log the form or the request body. The code and request id are enough.
    console.error('payment failed:', err.message);
    const cardError = err instanceof ArgusApiError && err.error.type === 'card_error';
    res.writeHead(cardError ? 402 : 502, { 'Content-Type': 'text/plain; charset=utf-8' });
    // A network error leaves the outcome unknown: look the order up before trying again.
    return res.end(cardError ? 'Your card was not accepted. Please check the details or try another card.'
      : 'The payment could not be started. Please try again later.');
  }

  // Remember which payment belongs to the order before the customer leaves.
  // await saveOrderPayment(order.id, payment.id);

  if (payment.status === 'requires_action') {
    const action = payment.next_action;
    if (action.type === 'redirect_to_url') {
      res.writeHead(303, { Location: action.redirect_to_url.url });
      return res.end();
    }
    res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' });
    return res.end(action.html_form.html);
  }
  res.writeHead(200, { 'Content-Type': 'text/plain; charset=utf-8' });
  res.end(payment.status === 'succeeded' ? 'Thank you, your payment was received.' : `Payment status: ${payment.status}`);
}

// GET /pay/return?payment_intent=pi_...&argus_signature=...: the customer lands here after 3D Secure.
async function paymentReturn(url, res) {
  const id = url.searchParams.get('payment_intent') ?? '';
  res.setHeader('Content-Type', 'text/plain; charset=utf-8');
  if (!/^pi_[A-Za-z0-9]+$/.test(id) || !verifyReturn(id, url.searchParams.get('argus_signature') ?? '')) {
    // Not a redirect we made for this payment.
    res.statusCode = 400;
    return res.end('Unknown payment.');
  }
  // Fetch the payment with the secret key. The signature says where the redirect comes from,
  // never how the payment ended.
  const payment = await argus('GET', `/payment_intents/${encodeURIComponent(id)}`);
  // The payment must belong to the order stored for it.
  const expectedOrder = 'SIP-2026-10423'; // await findOrderByPaymentId(id)
  if (payment.metadata?.order_id !== expectedOrder || payment.amount !== 12500 || payment.currency !== 'try') {
    res.statusCode = 400;
    return res.end('Unknown payment.');
  }
  switch (payment.status) {
    case 'succeeded': return res.end('Thank you, your payment was received.'); // mark the order paid once
    case 'requires_capture': return res.end('Your payment is authorized.');
    case 'processing': return res.end('Payment received, confirming with the bank. We will email you.');
    case 'requires_payment_method':
      return res.end(`The payment was not completed: ${payment.last_payment_error?.decline_code ?? 'declined'}. Please try another card.`);
    default: return res.end(`Payment status: ${payment.status}`);
  }
}

createServer(async (req, res) => {
  const url = new URL(req.url, 'http://localhost');
  try {
    if (req.method === 'POST' && url.pathname === '/checkout') return await checkout(req, res);
    if (req.method === 'GET' && url.pathname === '/pay/return') return await paymentReturn(url, res);
    res.writeHead(404).end();
  } catch (err) {
    console.error('error:', err.message);
    res.writeHead(500).end();
  }
}).listen(3000);

Try it in the sandbox

  1. Use a sandbox secret key and the test card 4109090000000011 with the expiry date 12/2030 and the CVC 123. Testing lists cards for declines, 3D Secure failures and installments.
  2. Roll your return signing secret once (POST /v1/return_signing_secret/roll) and give it to your return handler. To run the Node.js sample, set ARGUS_API_BASE, ARGUS_SECRET_KEY and ARGUS_RETURN_SIGNING_SECRET, then start it with node server.mjs.
  3. In the sample, change return_url to an address of your own server, such as http://localhost:3000/pay/return. Post the card form to your checkout handler. The sample builds the idempotency key from order.attempt, so change attempt for every new try. A repeat with the same key gets the stored answer. With three_d_secure: required, the payment returns requires_action. On the simulated bank page, enter 00000. The browser then comes back to your return_url with payment_intent and argus_signature.
  4. Check that the return page accepts the signature and reads succeeded. Check that it refuses the same URL with another payment id, or with one character changed in every v1 value of the signature. After a roll with expires_in_seconds, the signature carries two v1 values and the redirect is accepted when either one is right. Check that the payment_intent.succeeded webhook arrives. Check that the Logs page in the Developers menu shows your requests without warnings and without the card number.
  5. Try a decline with 4109090000000516 (insufficient_funds), then pay again with a new key.
  6. Open the payment in the merchant panel or read it from the API. Check that client_details.ip is your customer's address, not your server's, and that the request log shows no client_ip_not_public warning.

In the API reference

Next: See how the customer goes through the bank in Card payments and 3D Secure, then receive the result with Webhooks.