PHP code example of web3e / crypto-gateway-php

1. Go to this page and download the library: Download web3e/crypto-gateway-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

web3e / crypto-gateway-php example snippets


use Web3e\Gateway\Client;

$client = new Client('gwk_public_id', 'api_secret', 'https://api.web3e.cc');

$invoice = $client->createInvoice([
    'orderId'       => '1001',
    'orderAmount'   => '49.90',
    'orderCurrency' => 'USD',
    'successUrl'    => 'https://shop.example/thank-you',
    'cancelUrl'     => 'https://shop.example/cart',
    'callbackUrl'   => 'https://shop.example/ipn/web3e',
]);

header('Location: ' . $invoice['checkoutUrl']); // redirect the buyer

use Web3e\Gateway\WebhookVerifier;

$raw       = file_get_contents('php://input');
$webhookId = $_SERVER['HTTP_SM_WEBHOOK_ID'] ?? '';
$signature = $_SERVER['HTTP_SM_WEBHOOK_SIGNATURE'] ?? '';

$verifier = new WebhookVerifier('your_webhook_secret');
if (!$verifier->verify($raw, $webhookId, $signature)) {
    http_response_code(401);
    exit;
}
$event   = json_decode($raw, true);
$payment = $event['payment'] ?? [];
// mark $payment['merchantOrderId'] paid when $payment['status'] is credited/overpaid
bash
composer 
bash
php tests/run.php     # zero-dependency; no composer install