ā Declined card
Customer attempts to pay with a card the test gateway rejects. We expect payment.failed, the link to stay open (so the customer can retry with a different card), and the customer to remain on the hosted page.
What to do
- Click Run scenario.
- On the hosted page, enter any non-test card number, e.g.
4242 4242 4242 4242, any future expiry, any CVV. - Click Pay. The hosted page shows a decline error and re-enables the form for retry.
payment.failedwebhook arrives ā see the envelope on Event log; it includes alast_payment_errorwith NMI's reason code.- The link stays in
openstatus ā the customer can retry with another card.
The code (creating the payment is identical)
The decline isn't triggered by anything in your API request ā it happens on the hosted page when the customer types a card that the test gateway rejects. Your code only sees the result via the webhook.
// Node.js
const r = await fetch('https://app.sknpay.com/api/v1/payments', {
method: 'POST',
headers: {
Authorization: 'Bearer ' + process.env.SKNPAY_API_KEY,
'Content-Type': 'application/json',
'Idempotency-Key': 'order-' + Date.now(),
},
body: JSON.stringify({
amount: 750, // minor units ā 7.50 USD
currency: 'USD',
description: 'Decline test',
customer_email: 'test@example.com',
success_url: 'https://yoursite.com/thanks',
cancel_url: 'https://yoursite.com/cart',
}),
})
const payment = await r.json()
res.redirect(303, payment.url) // ā customer pays on hosted page
<?php
$ch = curl_init('https://app.sknpay.com/api/v1/payments');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . getenv('SKNPAY_API_KEY'),
'Content-Type: application/json',
'Idempotency-Key: order-' . time(),
],
CURLOPT_POSTFIELDS => json_encode([
'amount' => 750,
'currency' => 'USD',
'description' => 'Decline test',
'customer_email' => 'test@example.com',
'success_url' => 'https://yoursite.com/thanks',
'cancel_url' => 'https://yoursite.com/cart',
]),
]);
$payment = json_decode(curl_exec($ch), true);
header('Location: ' . $payment['url'], true, 303);
# Python (Flask + requests)
r = requests.post(
'https://app.sknpay.com/api/v1/payments',
headers={
'Authorization': f'Bearer {os.environ["SKNPAY_API_KEY"]}',
'Content-Type': 'application/json',
'Idempotency-Key': f'order-{int(time.time())}',
},
json={
'amount': 750,
'currency': 'USD',
'description': 'Decline test',
'customer_email': 'test@example.com',
'success_url': 'https://yoursite.com/thanks',
'cancel_url': 'https://yoursite.com/cart',
},
)
return redirect(r.json()['url'], code=303)
curl -X POST https://app.sknpay.com/api/v1/payments \
-H "Authorization: Bearer $SKNPAY_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: order-$(date +%s)" \
-d '{
"amount": 750,
"currency": "USD",
"description": "Decline test",
"customer_email": "test@example.com",
"success_url": "https://yoursite.com/thanks",
"cancel_url": "https://yoursite.com/cart"
}'