PayRequest API
FinancePublic API Docs for PayRequest
PayRequest provides an easy-to-use API that allows developers to create and manage payments in their applications. By using the PayRequest API, you can quickly and securely set up payment flows, enable customers to make payments within your application, and more. In this blog post, we will dive into the different endpoints and provide examples in JavaScript.
Authorization
To use the PayRequest API, you must first create an account on the website and authenticate yourself. You will receive an API key that you will use in your requests to authenticate your account.
Base URL
The base URL for the PayRequest API is "https://api.payrequest.io/v1/". All endpoints we will discuss in this blog post will be appended to this base URL.
Endpoints
Create Payment Request
To create a payment request, you can use the "POST /payment-request" endpoint. Below is an example in JavaScript:
const response = await fetch(
`https://api.payrequest.io/v1/payment-request`,
{
method: 'POST',
headers: {
Accept: 'application/json',
Authorization: `Bearer ${YOUR_API_KEY}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
amount: 10.5,
currency: 'USD',
note: 'This is a payment request',
description: 'Payment for groceries',
redirectUrl: 'https://example.com/payment-successful'
})
}
);
const data = await response.json();
console.log(data);
Retrieve Payment Request
To retrieve a payment request, you can use the "GET /payment-request/{id}" endpoint. Replace {id} with the ID of the payment request you want to retrieve. Below is an example in JavaScript:
const id = 'PR_PYl8D3pJ';
const response = await fetch(
`https://api.payrequest.io/v1/payment-request/${id}`,
{
method: 'GET',
headers: {
Accept: 'application/json',
Authorization: `Bearer ${YOUR_API_KEY}`,
}
}
);
const data = await response.json();
console.log(data);
Create Payment
To create a payment, you can use the "POST /payment" endpoint. Below is an example in JavaScript:
const response = await fetch(
`https://api.payrequest.io/v1/payment`,
{
method: 'POST',
headers: {
Accept: 'application/json',
Authorization: `Bearer ${YOUR_API_KEY}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
amount: 10.5,
currency: 'USD',
paymentRequestId: 'PR_PYl8D3pJ',
note: 'This is a payment'
})
}
);
const data = await response.json();
console.log(data);
Retrieve Payment
To retrieve a payment, you can use the "GET /payment/{id}" endpoint. Replace {id} with the ID of the payment you want to retrieve. Below is an example in JavaScript:
const id = 'PM_Ty35ouoP';
const response = await fetch(
`https://api.payrequest.io/v1/payment/${id}`,
{
method: 'GET',
headers: {
Accept: 'application/json',
Authorization: `Bearer ${YOUR_API_KEY}`,
}
}
);
const data = await response.json();
console.log(data);
Conclusion
The PayRequest API provides an easy-to-use interface for creating and managing payments in your applications. We hope this blog post has been useful in demonstrating how to use the different endpoints of the API in JavaScript. If you have any questions or feedback, please feel free to let us know.