Skip to main content

Payment Status

We have an existing webhook system that sends notifications for each paid or canceled payment. However, in some cases, these requests may fail due to network issues or invalid endpoint URLs.

In these cases, you can use the getPaymentStatus action which will return you the status of the payment.

Requirements

In order to get the status of the payment, you will need:

  • Your API Token: abcd... which can be found in your dashboard here.
  • The action: getPaymentStatus
  • The paymentID : 0123456789
warning

It's crucial to keep your API Token confidential. Therefore, it's advised to make the API request server-side to prevent parameter tampering and token leaks.

The HTTPS Request

Make a GET request to https://api.swaycoin.io, including the required parameters.

You can test it within your browser!
https://api.swaycoin.io?token=YOUR_API_TOKEN&action=getPaymentStatus&paymentID=0123456789

Using Code

const YOUR_API_TOKEN = 'YOUR_API_TOKEN';
const paymentID = '0123456789';
const endpoint = `https://api.swaycoin.io?token=${YOUR_API_TOKEN}&action=getPaymentStatus&paymentID=${paymentID}`;

fetch(endpoint)
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json();
})
.then(data => console.log(data))
.catch(error => console.error('Error:', error));

The HTTPS Response

Upon successful execution, you should receive a JSON response similar to:

// Response indicating a successful request
{
"request_status": "success",
"message": "The payment is completed.",
"payment_status": "1" // The payment is completed. Please see below all possilble payment_status codes
}

Upon failed execution, you should receive a JSON response similar to:

// Response indicating a failed request
{
"request_status": "error",
"message": "No paymentID found for that token."
}

Possible payment_status codes

payment_statusStatusDescription
1PaidThe user has sent the required amount, and the transaction has been confirmed by the blockchain.
2PendingThe user is asked to transfer the necessary amount to the address. The transaction has not yet taken place on the blockchain.
0FailedThe payment has been canceled by the user.