Accept crypto payments in PHP with one file and two endpoints
Accept crypto payments in PHP with one helper file: create the invoice on your server, open the checkout, ship on a verified webhook. No framework or Composer.
This page shows the shape of a PHP integration and the mistakes that break it. The full runnable example is in the docs: plain PHP example, and the helper's reference is intents-php.
<?php
// "Pay with crypto" + Place order: create the invoice for this order.
require __DIR__ . '/intents.php';
require __DIR__ . '/orders.php';
$input = json_decode(file_get_contents('php://input'), true);
$order = load_orders()[$input['orderId'] ?? ''] ?? null;
header('Content-Type: application/json');
if ($order === null) { http_response_code(404); exit('{"error":"unknown order"}'); }
// The amount comes from your records; `reference` makes a repeat return the same invoice.
$intents = new \IntentsFi\Intents(getenv('INTENTS_SECRET_KEY'));
$invoice = $intents->createInvoice(['amount' => $order['amount'], 'reference' => $order['id']]);
echo json_encode(['invoiceId' => $invoice['id'], 'clientSecret' => $invoice['clientSecret']]);
To accept crypto payments in PHP, create an invoice on your server with your secret key, open the hosted checkout or the pop-up with it, and mark the order paid only from a verified webhook. With Intents Checkout that is one helper file, intents.php, and two endpoints. Customers pay in any token; you receive stablecoins at your own address.
Our takeCopy intents.php, write checkout.php and webhook.php, and test the whole loop with an ik_test_ key before you touch anything else. A framework adds routing, not steps.
Code
<?php
// "Pay with crypto" + Place order: create the invoice for this order.
require __DIR__ . '/intents.php';
require __DIR__ . '/orders.php';
$input = json_decode(file_get_contents('php://input'), true);
$order = load_orders()[$input['orderId'] ?? ''] ?? null;
header('Content-Type: application/json');
if ($order === null) { http_response_code(404); exit('{"error":"unknown order"}'); }
// The amount comes from your records; `reference` makes a repeat return the same invoice.
$intents = new \IntentsFi\Intents(getenv('INTENTS_SECRET_KEY'));
$invoice = $intents->createInvoice(['amount' => $order['amount'], 'reference' => $order['id']]);
echo json_encode(['invoiceId' => $invoice['id'], 'clientSecret' => $invoice['clientSecret']]);
<?php
// The only place an order is marked paid: a verified invoice.paid webhook.
require __DIR__ . '/intents.php';
require __DIR__ . '/orders.php';
try {
$event = \IntentsFi\Intents::verifyWebhook(
file_get_contents('php://input'), // the raw body
$_SERVER, // reads HTTP_X_INTENTS_SIGNATURE
(string) getenv('INTENTS_WEBHOOK_SECRET')
);
} catch (\IntentsFi\WebhookSignatureError $e) {
http_response_code(400);
exit('bad signature');
}
// "Send test event" samples were never paid: acknowledge them, ship nothing.
if ($event['type'] === 'invoice.paid' && !\IntentsFi\Intents::isTestEvent($event)) {
mark_paid((string) $event['data']['reference']); // idempotent: events can arrive twice
}
http_response_code(204);
<script src="https://pay.intents.fi/v1/checkout.js"></script>
<button id="place" type="button">Place order</button>
<script>
document.getElementById("place").addEventListener("click", async () => {
const res = await fetch("/checkout.php", {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify({ orderId: "order_1001" }),
});
const { invoiceId, clientSecret } = await res.json();
// onPaid only updates this page; the order ships from the webhook.
IntentsCheckout.open({ invoiceId, clientSecret, onPaid: () => location.assign("/?paid=1") });
});
</script>
# A test key while you build: dashboard.intents.fi → API keys → Test mode
INTENTS_SECRET_KEY=ik_test_...
# The whsec_… shown once when you add the webhook endpoint
INTENTS_WEBHOOK_SECRET=whsec_...
The whole integration, in three files
Accepting crypto payments in PHP needs the same three pieces as any server-side checkout, and none of them is crypto code. You never build a transaction, watch a chain or hold a private key.
| File | What it does | Runs where |
|---|---|---|
checkout.php |
Looks up the order, calls createInvoice(), returns the invoice to the page or redirects to it |
Your server |
index.html (or your template) |
Shows Pay with crypto beside your other methods and opens the checkout | The customer’s browser |
webhook.php |
Verifies the signature and marks the order paid | Your server, called by ours |
The customer pays in what they hold, such as USDT on Tron, SOL or ETH. The exact amount you invoiced, less the fee, arrives at your own address in the stablecoin and network you chose. The helper, intents.php, is one file with no dependencies beyond the curl and json extensions, so it drops into a 15-year-old shop as easily as a new Laravel app. Its full reference is on the intents-php docs page, and the runnable version of the code above is the plain PHP example.
Hosted page or pop-up
Both use the same webhook.php. The only difference is what checkout.php returns and how much front-end code you write.
Redirect or pop-up: what changes in your PHP
| Compared on | Hosted page (redirect) | Pop-up (checkout.js) |
|---|---|---|
| PHP you write | checkout.php redirects to $invoice['url'] Better | checkout.php returns id and clientSecret as JSON |
| Front-end code | None: a form post Better | One script tag and a click handler |
| Customer leaves your site | Yes, to pay.intents.fi and back | No Better |
| What reaches the browser | Only the checkout URL | The invoice id and its clientSecret |
| Safety elements (amount, network warning, QR, countdown, refund address) | Built in | Built in |
| webhook.php | Same file | Same file |
The redirect is the shortest path for a classic PHP shop: a form posts to checkout.php, it creates the invoice and sends a Location: header to $invoice['url']. Pass successUrl in createInvoice() so the customer comes back to your thank-you page. The pop-up keeps the customer on your page; it needs one script tag and the click handler shown in index.html. If you want Pay with crypto to look like a native row beside Card and PayPal, load option.css and copy the markup from the payment option docs.
The webhook, line by line
webhook.php is the only file allowed to ship an order, so it is the one to get right.
- Read the raw body with
file_get_contents('php://input').$_POSTis empty for a JSON body, and decoding then re-encoding changes the bytes the signature covers. - Verify.
verifyWebhook()readsHTTP_X_INTENTS_SIGNATUREfrom$_SERVER, recomputes an HMAC-SHA256 over"<timestamp>.<body>"with yourwhsec_secret, and compares in constant time. It throwsWebhookSignatureErrorwith a reason code, such asmissing_signature,timestamp_out_of_toleranceorsignature_mismatch, which tells you whether the header, the clock or the secret is wrong. - Skip test samples.
isTestEvent()is true for deliveries from Send test event in the dashboard. - Act on the invoice, not the delivery.
$event['data']is the full invoice, asgetInvoice()returns it. Events can repeat and arrive out of order, so key the update onreferenceand make it idempotent. - Answer 2xx fast. Return 204 and push slow work, such as emails, to a queue or cron. A slow or failed answer is retried.
Behind nginx or a load balancer, check that the X-Intents-Signature header reaches PHP untouched, and that nothing rewrites the body. Verify and test webhooks covers retries, Resend and how to test a receiver locally through a tunnel.
In a framework
The helper is plain PHP, so frameworks change only where the two endpoints live.
| Plain PHP | Laravel | Symfony | |
|---|---|---|---|
| Create invoice | checkout.php |
A controller action on POST /checkout/crypto |
A controller on POST /checkout/crypto |
| Raw webhook body | file_get_contents('php://input') |
$request->getContent() |
$request->getContent() |
| Headers to verify | $_SERVER |
$request->server->all() |
$request->server->all() |
| CSRF | Not used | Exclude the webhook route | Not applied to a plain controller |
| Secrets | getenv() |
config() from .env |
%env()% parameters |
| Slow work | Cron | A queued job | Messenger |
For a store platform written in PHP there is usually a module already. The WooCommerce plugin and the WHMCS module are built on the same helper, so read their pages before writing your own.
Before you go live
0 of 8 done
Errors and retries
createInvoice() throws \IntentsFi\ApiError when the API refuses a request. Its ->errorCode carries the API’s code and ->status the HTTP status, so you can tell a bad key from a bad amount.
| Code | Usually means | What to do |
|---|---|---|
UNAUTHORIZED |
The key is wrong, revoked or missing | Check INTENTS_SECRET_KEY for the environment |
INVALID_REQUEST |
A missing reference or an amount that is not a USD string |
Send '42.00', not 42 or '$42' |
LIVE_MODE_LOCKED |
A live key before the account has a verified email and a payout wallet | Finish the dashboard’s go-live checklist |
| Timeout or 5xx | A network problem | Retry with the same reference: you get the same invoice, never a second one |
The same reference always returns the same invoice, which is what makes a retry safe. A customer who double-clicks Place order sees one invoice, not two. Every error code has its own page under the errors reference.
What it costs and where the money goes
Each settled payment costs 0.4%, with no fixed fee and no setup, monthly or payout fee. The customer’s network and routing costs are inside the amount they are quoted, so you receive the invoice amount less 0.4%, and nothing when a customer pays in your own settlement asset on its chain. Money goes from the customer’s payment straight to your settlement address; Intents never holds it, and that address can only be changed from a dashboard session with a fresh code.
Compare it with card processing on crypto vs credit card fees, see the full price on pricing, or, if you would rather write against plain HTTP, start from the crypto checkout API.
Questions
Short answers. The docs go deeper.
How do I accept crypto payments in PHP?
Create an invoice on your server with your secret key and the order's amount, send the customer to the invoice's hosted checkout or open it in a pop-up, and mark the order paid only when a verified invoice.paid webhook arrives. With Intents Checkout the helper is one file, intents.php, and the integration is two endpoints: one that creates the invoice and one that receives the webhook.
Is there a PHP library for crypto payments?
Yes. intents-php is a single file with createInvoice, getInvoice and verifyWebhook. It needs PHP 7.4 or later and the curl extension for API calls, and it has no framework dependency. The WooCommerce, WHMCS and PrestaShop plugins check webhook signatures with the same code.
How do I verify a crypto payment webhook in PHP?
Read the raw body with file_get_contents('php://input') and pass it, the request headers and your webhook secret to verifyWebhook. It checks the X-Intents-Signature header, an HMAC-SHA256 over the timestamp and the body, and rejects deliveries more than 300 seconds old. On a bad signature it throws, and you answer 400.
Can I use it with Laravel or Symfony?
Yes. The helper is plain PHP, so it works inside any framework. In Laravel, read the raw body with $request->getContent() and exclude the webhook route from CSRF protection; in Symfony use $request->getContent(). Keep the key in your framework's environment config.
Do I need a crypto wallet or a node to test?
No. With an ik_test_ key the checkout shows a Complete the test payment button instead of a deposit address. It walks the invoice to paid and sends a real signed webhook to your endpoint, and no money moves. You add a payout wallet only when you take the account live.
Which currencies do customers pay in, and what do I receive?
Customers pay in any of 3,000+ assets on the networks the checkout supports, from a connected wallet or by sending to a deposit address. You receive the exact invoice amount, less the fee, in the stablecoin and network you chose, such as USDC on Base or USDT on Tron, at your own address.
What does it cost?
0.4% of each settled payment, with no fixed fee and no setup, monthly or payout fee. There is nothing to pay while you build in test mode.