Creating Payments
When a customer completes checkout in WordPress and selects the Coinsnap payment method, the plugin creates a Coinsnap invoice and redirects the customer to the hosted payment page.
What the plugin does
- Customer clicks Place Order in WooCommerce checkout
- WooCommerce calls the plugin's
process_payment()method - Plugin calls the Coinsnap API to create an invoice
- Plugin redirects the customer to
invoice.checkoutLink
The API call
From AbstractGateway::createInvoice() in the plugin source:
$client = new Invoice($this->apiHelper->url, $this->apiHelper->apiKey);
$invoice = $client->createInvoice(
$this->apiHelper->storeId, // Store ID from coinsnap_store_id option
strtoupper($order->get_currency()),
PreciseNumber::parseFloat((float) $order->get_total(), 2),
(string) $order->get_id(), // orderId
$order->get_billing_email(), // buyerEmail
$order->get_billing_first_name() . ' ' . $order->get_billing_last_name(), // buyerName
$this->get_return_url($order), // redirectUrl (WC thank-you page)
$metadata, // includes taxIncluded, orderNumber, coinsnapDiscount
$redirectAutomatically, // from coinsnap_autoredirect option (default: true)
$walletMessage
);
// Store invoice ID and checkout link against the order
$order->update_meta_data('Coinsnap_id', $invoice->getData()['id']);
$order->update_meta_data('Coinsnap_redirect', $invoice->getData()['checkoutLink']);
$order->save();
// Redirect customer to Coinsnap payment page
return [
'result' => 'success',
'redirect' => $invoice->getData()['checkoutLink'],
];
Required parameters
| Parameter | Value | Source |
|---|---|---|
amount | Order total | $order->get_total() |
currency | Store currency | get_woocommerce_currency() |
orderId | WooCommerce order ID | $order->get_id() |
buyerEmail | Customer email | $order->get_billing_email() |
redirectUrl | WooCommerce thank-you page | $this->get_return_url($order) |
Invoice ID storage
The plugin stores two meta values on the WooCommerce order after invoice creation:
| Meta key | Value |
|---|---|
Coinsnap_id | The Coinsnap invoice ID — used to match incoming webhook events |
Coinsnap_redirect | The checkoutLink URL — used if the customer needs to be redirected again |
Coinsnap_transactionurl | Link to the invoice in the Coinsnap dashboard |
The webhook handler looks up orders by Coinsnap_id:
$orders = wc_get_orders([
'meta_key' => 'Coinsnap_id',
'meta_value' => $postData->invoiceId,
]);
Order status after invoice creation
The order stays in its existing status (usually pending) until Coinsnap sends a webhook. Status transitions:
| Webhook event | WooCommerce status (default) |
|---|---|
New | pending — no change |
Processing | on-hold — full payment received, waiting for settlement |
Settled | completed — payment confirmed |
Expired | cancelled — no payment received |
All mappings are configurable per-store in WooCommerce → Settings → Coinsnap → Order States.
Custom integration (without a plugin)
If you need to create payments programmatically in a custom WordPress plugin or theme:
<?php
function coinsnap_create_invoice(WC_Order $order): array {
$api_key = get_option('coinsnap_api_key');
$store_id = get_option('coinsnap_store_id');
$response = wp_remote_post(
"https://app.coinsnap.io/api/v1/stores/{$store_id}/invoices",
[
'headers' => [
'x-api-key' => $api_key,
'Content-Type' => 'application/json',
],
'body' => json_encode([
'amount' => $order->get_total(),
'currency' => get_woocommerce_currency(),
'orderId' => (string) $order->get_id(),
'buyerEmail' => $order->get_billing_email(),
'redirectUrl' => wc_get_checkout_url(),
]),
]
);
if (is_wp_error($response)) {
throw new RuntimeException('Coinsnap API error: ' . $response->get_error_message());
}
return json_decode(wp_remote_retrieve_body($response), true);
}