E-commerce checkout
Sell a shop order through a payment link with items, a buyer and VAT per rate, and learn safely that it was paid.
A shop can sell an order through a payment link: the link carries the items, the buyer and the order reference, the buyer pays on a Payrudder page, and the invoice comes out with the right lines and VAT per rate. This guide makes one order and shows how the shop learns that it was paid. It builds on Let a customer pay.
Before you start
export BASE=https://api.payrudder.com
export PAYRUDDER_API_KEY=prk_test_...
api() { curl -sS -H "Authorization: Bearer $PAYRUDDER_API_KEY" -H "Content-Type: application/json" "$@"; }Steps
Set the return addresses
Set the two return addresses once, in the console, in the Billing profile (https only): checkout_success_url and checkout_cancel_url. Saving them sets both environments, sandbox and live.
Make the link
api -X POST $BASE/v1/payment-links -H "Idempotency-Key: order-1001" -d '{
"kind": "adhoc",
"currency": "TRY",
"order_ref": "ORD-1001",
"customer_email": "ayse@example.com",
"items": [
{ "ref": "sku-shirt", "name": "Shirt", "quantity": 2, "unit_amount_minor": 10100, "vat_rate_bps": 2000, "physical": true },
{ "ref": "sku-ebook", "name": "E-book", "quantity": 1, "unit_amount_minor": 120000, "vat_rate_bps": 100 }
],
"buyer": {
"name": "Ayşe Yılmaz",
"tax_id": "",
"billing_address": { "line1": "Moda Cad. 1", "city": "İstanbul", "postal_code": "34710", "country": "TR" }
},
"shipping_address": { "line1": "Moda Cad. 1", "city": "İstanbul", "postal_code": "34710", "country": "TR" }
}'What each part means is in The order, field by field below.
Send the buyer to the page
Send the buyer to the url of the answer.
After a payment ends, the payment page shows a link back, with ?link=<link id>&order=<order_ref> added:
- to the success address after a paid payment,
- to the cancel address after a failed one that can no longer be paid. While the buyer can still try again, the page shows only the pay buttons.
Confirm the payment
Do not mark the order paid because the buyer arrived there. Anyone can open that address.
Confirm the payment one of two ways:
- the webhook
payment_link.paid(andinvoice.paid), which carryorder_refandlink_idso you can find the order (Webhooks), or GET /v1/payment-links/{id}with thelinkof the address:statusispaidwhen it is.
The event looks like this:
{ "type": "payment_link.paid", "data": { "link_id": "...", "order_ref": "ORD-1001", "invoice_id": "...", "currency": "TRY", "total_minor": "140200", "paid_count": 1 } }An event can arrive more than once. Handle it by link_id and order_ref, and answer 2xx once the order is safe.
The order, field by field
unit_amount_minor is what the buyer pays for one, in minor units, and vat_rate_bps is the rate in basis points (2000 is 20 %).
amount_minor may be left out, or sent equal to the sum of quantity * unit_amount_minor. Any other value is 400 billing.link.items_total_mismatch.
A rate of 0 is not supported yet (billing.link.zero_vat_unsupported).
The invoice has one line per item, stored without VAT, and one TAX line per rate, so the lines add up to what the buyer paid. A coupon lowers the VAT in proportion.
Payrudder issues the e-invoice only when an e-invoice integrator is connected (Tax and e-invoices).
The buyer is who the invoice is made out to. With items, these are required (billing.link.buyer_required):
name, at most 200 characters,billing_address:line1,cityand a two-lettercountry; every field at most 200 characters.
A link with items also needs customer_external_id or customer_email (billing.link.customer_required).
tax_id is a 10-digit tax number for a company, an 11-digit citizen number, or empty for a consumer without one. A buyer in Turkey without one is invoiced as 11111111111, even when the customer record has a tax id.
An item ref is at most 100 characters.
The customer is customer_external_id if you send it (made when missing), else the one customer of yours with that customer_email, else a new one.
Two customers with the same e-mail is 409 billing.link.customer_email_ambiguous: send customer_external_id, and keep the one the answer returns.
A customer found by e-mail alone is not offered their saved card on the payment page: an e-mail does not prove who is paying.
Required when an item is physical, with the same fields as the billing address (billing.link.shipping_required).
It goes to the payment provider, is never returned by the API, and is deleted when the link is paid, expires or is revoked.
A link with items is single-use, so the same order cannot be paid twice.
order_ref is your order number. It is shown on the invoice and sent back in the events and the return URL.
Things to know
- The link back is shown for an order that has an
order_ref, once it is paid, or failed and no longer payable. With no return address set, the page shows none. - In the sandbox the page, the return addresses and the events are the real ones and the payment goes to the simulator (Test mode).
- With iyzico the items are sent as the basket and
<invoice id>:<order_ref>as the basket id (iyzico).