Cancel Payment

Cancel a pending payment link to invalidate it before the customer completes payment.

DELETE/api/v1/payments/:id

When to Use

Use this endpoint when you need to invalidate a payment link:

  • Customer cancels their order
  • Cart amount changes (cancel old, create new)
  • You want to invalidate an old payment link

Note: This only works for pending or processing payments. You cannot cancel a payment that has already been completed.

Response

json
{
"success": true,
"data": {
"id": "550e8400-e29b-41d4-a716-446655440000",
"status": "cancelled",
"message": "Payment cancelled successfully"
}
}

cURL Example

bash
curl -X DELETE https://pay.ultrapay.cc/api/v1/payments/550e8400-e29b-41d4-a716-446655440000 \
-H "X-Public-Key: upp_your_public_key" \
-H "X-Secret-Key: ups_your_secret_key"

Handling Cart Changes

If a customer modifies their cart after a payment link has been created, you should cancel the old payment and create a new one with the updated amount:

javascript
// Cancel old payment
await fetch(`https://pay.ultrapay.cc/api/v1/payments/${oldTransactionId}`, {
method: 'DELETE',
headers: {
'X-Public-Key': 'upp_your_public_key',
'X-Secret-Key': 'ups_your_secret_key',
},
});
// Create new payment with updated amount
const response = await fetch('https://pay.ultrapay.cc/api/v1/payments/create', {
method: 'POST',
headers: {
'X-Public-Key': 'upp_your_public_key',
'X-Secret-Key': 'ups_your_secret_key',
'Content-Type': 'application/json',
},
body: JSON.stringify({
amount: newAmount,
currency: 'usd',
successUrl: 'https://yoursite.com/thank-you',
cancelUrl: 'https://yoursite.com/checkout',
}),
});
const { data } = await response.json();
window.location.href = data.paymentUrl;
navigate select