PHP code example of invoq / invoq-php
1. Go to this page and download the library: Download invoq/invoq-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/ */
invoq / invoq-php example snippets
use Invoq\Invoq;
$invoq = new Invoq(getenv('INVOQ_SECRET_KEY'));
$invoq = new Invoq(getenv('INVOQ_SECRET_KEY'), [
'apiOrigin' => 'http://localhost:8787',
'timeoutMs' => 10_000,
]);
$invoice = $invoq->invoices->create([
'amount' => '129',
'description' => 'SaaS boilerplate',
'reference_id' => 'order_1234',
'return_url' => 'https://merchant.test/thanks',
]);
$invoice = $invoq->invoices->get('inv_123');
$paidInvoice = $invoq->invoices->createTestPayment($invoice['id'], [
'amount' => $invoice['amount'],
'reference_id' => 'test_payment_001',
]);
use function Invoq\isInvoicePaid;
use function Invoq\isInvoicePaymentReversed;
use function Invoq\verifyWebhook;
$rawBody = file_get_contents('php://input');
$event = verifyWebhook(
$rawBody === false ? '' : $rawBody,
['invoq-signature' => $_SERVER['HTTP_INVOQ_SIGNATURE'] ?? null],
getenv('INVOQ_WEBHOOK_SECRET'),
);
if (isInvoicePaid($event)) {
$orderId = $event['data']['invoice']['reference_id'];
if ($orderId === null) {
throw new RuntimeException('Missing invoice reference_id for fulfillment.');
}
fulfillOrder($orderId);
} elseif (isInvoicePaymentReversed($event)) {
holdOrder($event['data']['invoice']['reference_id']);
}
http_response_code(200);
use Invoq\InvoqApiError;
use Invoq\InvoqError;
try {
$invoq->invoices->create(['amount' => '0.001']);
} catch (InvoqApiError $error) {
error_log((string) $error->status);
error_log((string) $error->getApiCode());
error_log(json_encode($error->fields));
error_log(json_encode($error->meta));
} catch (InvoqError $error) {
throw $error;
}
bash
composer text
missing_signature
invalid_signature_header
timestamp_outside_tolerance
signature_mismatch
invalid_payload