Prerequisites
You need a WordPress + WooCommerce installation, a Paychainly account with an API key, and a webhook endpoint accessible from the internet (use ngrok for local development).
Plugin Structure
woocommerce-paychainly/
├── woocommerce-paychainly.php # Main plugin file
├── includes/
│ ├── class-paychainly-gateway.php
│ └── class-webhook-handler.phpRegistering the Gateway
add_filter('woocommerce_payment_gateways', function($gateways) {
$gateways[] = 'WC_Paychainly_Gateway';
return $gateways;
});Processing the Payment
When a customer clicks "Place Order", your gateway calls Paychainly to create a deposit session and redirects the customer to a payment page showing the USDT deposit address and a countdown timer:
public function process_payment($order_id) {
$order = wc_get_order($order_id);
$amount = $order->get_total();
$response = wp_remote_post('https://paychainly.com/api/v1/addresses/start-session', [
'headers' => ['x-api-key' => $this->api_key, 'Content-Type' => 'application/json'],
'body' => json_encode(['userId' => (string)$order_id, 'amount' => $amount]),
]);
$data = json_decode(wp_remote_retrieve_body($response), true);
$order->update_meta_data('_paychainly_address', $data['address']);
$order->save();
return ['result' => 'success', 'redirect' => $this->get_return_url($order)];
}Handling the Webhook
Register a WooCommerce API endpoint to receive the deposit_detected webhook. Verify the signature, then mark the order as paid:
$order->payment_complete($payload['txHash']);
$order->add_order_note('Paychainly: payment confirmed — ' . $payload['txHash']);Testing
Enable sandbox mode in Paychainly, use the POST /api/sandbox/credit endpoint to simulate a deposit, and verify your webhook handler marks the order paid correctly.