// 1. Create a payment session on the gateway public function pay(Order $order) { $res = Http::withToken(config('cashpylon.live_key')) ->post('https://api.cashpylon.example/v1/sessions', [ 'amount' => $order->total, // fixed here 'currency' => 'EUR', 'reference' => $order->number, 'return_url' => route('orders.thanks'), ]); // 2. Redirect the shopper to the hosted checkout return redirect($res->json('checkout_url')); } // 3. Confirm by webhook, after checking the signature public function webhook(Request $r) { abort_unless(Cashpylon::verify($r), 403); if ($r->input('event') === 'payment.succeeded') { Order::whereNumber($r->input('reference'))->first() ->markPaid($r->input('payment_id')); } return response()->noContent(); }
Three steps from basket to confirmed payment
What the gateway does between the two calls on the left
Payment record
SUCCEEDEDRun this payment in the sandbox See API keys and webhooksPlugins and SDKs
Authentication
Every request carries a secret key as a bearer token. Each merchant has a pair of test keys and a pair of live keys; the key decides which mode the request runs in. Secret keys belong on the server only.
Authorization: Bearer sk_test_your_secret_key Content-Type: application/json
Sandbox
Test keys talk to the sandbox. No real money moves, and the hosted checkout shows a control for choosing the result, so success, pending and failed can each be rehearsed. This demo runs the same way.
Payment sessions
POST/v1/sessions — create a session and get the address of the hosted checkout. The amount and currency are fixed here and cannot be changed by the shopper.
{
"amount": 129.00,
"currency": "EUR",
"reference": "FH-48213",
"return_url": "https://shop.example/orders/thanks"
}{
"id": "ses_4T7K2QM8",
"checkout_url": "https://pay.cashpylon.example/c/ses_4T7K2QM8",
"status": "open"
}Payments
GET/v1/payments/{id} — read one payment. GET/v1/payments — list payments with the same filters as the dashboard.
{
"id": "pay_2H7VR5TS",
"reference": "FH-48177",
"amount": 75.00,
"currency": "USD",
"method": "ach",
"status": "pending"
}Refunds
POST/v1/refunds — refund a captured payment in full, or pass an amount for a partial refund.
{
"payment_id": "pay_8KQ2M4T7",
"amount": 40.00,
"reason": "Item returned"
}Payment links
POST/v1/payment-links — create a shareable link with a QR code for a fixed amount, one-time or as a subscription. Open a sample link.
Signed webhooks
The gateway posts an event to each of the merchant's endpoints when something changes. Every delivery is signed; check the signature before trusting the body, then answer with a 2xx status.
{
"event": "payment.succeeded",
"payment_id": "pay_8KQ2M4T7",
"reference": "FH-48213",
"amount": 129.00,
"currency": "EUR"
}$payload = file_get_contents('php://input'); $expected = hash_hmac('sha256', $payload, $signingSecret); if (!hash_equals($expected, $signatureFromHeader)) { http_response_code(403); return; }
Events: payment.succeeded payment.pending payment.failed refund.created dispute.opened settlement.paid
Errors
Errors come back as JSON with an HTTP status: 401 for a missing or wrong key, 422 when a field fails validation, 404 for an unknown id. The request log in the merchant dashboard keeps each call with its status and timing.
{
"error": "validation_failed",
"message": "The currency field is required."
}