curl
# Step 2: find a variant id (products are created in the dashboard)
curl https://api.paywio.com/v1/products \
-H "Authorization: Bearer sk_test_..."
# Step 3: create a checkout and send your buyer to its "url"
curl https://api.paywio.com/v1/checkouts \
-H "Authorization: Bearer sk_test_..." \
-H "Idempotency-Key: order-1001" \
-H "Content-Type: application/json" \
-d '{
"variant_id": "var_01j9z8k3m4n5p6q7r8s9t0v1w2",
"customer_email": "[email protected]",
"metadata": {"order_ref": "1001"}
}'
PHP
<?php
$key = getenv('PAYWIO_SECRET_KEY'); // sk_test_...
function paywio(string $key, string $method, string $path,
?array $body = null, array $extra = []): array
{
$ch = curl_init('https://api.paywio.com/v1'.$path);
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => $method,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => array_merge([
'Authorization: Bearer '.$key,
'Content-Type: application/json',
], $extra),
]);
if ($body !== null) {
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body));
}
return json_decode((string) curl_exec($ch), true) ?: [];
}
// Step 2: find a variant id of an approved product
$variantId = null;
foreach (paywio($key, 'GET', '/products')['data'] ?? [] as $product) {
if ($product['status'] === 'approved') {
$variantId = $product['variants'][0]['id'];
break;
}
}
// Step 3: create a checkout and send your buyer to its "url"
$checkout = paywio($key, 'POST', '/checkouts', [
'variant_id' => $variantId,
'customer_email' => '[email protected]',
'metadata' => ['order_ref' => '1001'],
], ['Idempotency-Key: order-1001']);
header('Location: '.$checkout['url']);
Node.js
// quickstart.mjs (Node 18+, no dependencies)
const KEY = process.env.PAYWIO_SECRET_KEY; // sk_test_...
async function paywio(method, path, body, headers = {}) {
const res = await fetch(`https://api.paywio.com/v1${path}`, {
method,
headers: {
Authorization: `Bearer ${KEY}`,
'Content-Type': 'application/json',
...headers,
},
body: body && JSON.stringify(body),
});
const json = await res.json();
if (!res.ok) {
const { code, message, request_id } = json.error;
throw new Error(`${code}: ${message} (${request_id})`);
}
return json;
}
// Step 2: find a variant id of an approved product
const products = await paywio('GET', '/products');
const product = products.data.find((p) => p.status === 'approved');
const variant = product?.variants[0];
// Step 3: create a checkout and send your buyer to its "url"
const checkout = await paywio(
'POST',
'/checkouts',
{
variant_id: variant.id,
customer_email: '[email protected]',
metadata: { order_ref: '1001' },
},
{ 'Idempotency-Key': 'order-1001' },
);
console.log(checkout.url);
Response · 201 Created
{
"object": "checkout",
"id": "chk_01j9z8k3m4n5p6q7r8s9t0v1w2",
"url": "https://pay.paywio.com/c/chk_01j9z8k3m4n5p6q7r8s9t0v1w2",
"status": "open",
"livemode": false,
"variant_id": "var_01j9z8k3m4n5p6q7r8s9t0v1w2",
"metadata": {"order_ref": "1001"},
"created": 1730000000,
"expires_at": 1730086400
}