Create Payment
Creating a payment requires a simple request, containing just API keys as authorisation and the payment parameters.
Create a new payment
POST
https://api.piecard.app/payment
Request Body
amount*
number
The amount of Pi being requested. This includes the transaction fee.
memo*
string
Something to describe the payment to the user.
successURL*
string
The redirect URL for a successful payment.
cancelURL*
string
The redirect URL for a failed payment.
metadata
object
Any set object-key pairs for the developer's use. This will be included in the webhook.
sandbox
boolean
Set to true for testing you payment integration. Default is false.
{
success: true,
id: 'YOUR_PAYMENT_ID'
}
Usage with NPM Package
// Create payment
const paymentData = {
amount: NUMBER, // amount of service
memo: STRING, // memo of the transaction
metadata: STRING // metadata,
};
piecard.createPayment(paymentData)
.then((response) => {
console.log("Create payment : ", response);
})
.catch((err) => {
console.log("Create payment error : ", err);
});
From the POST /payment endpoint, you will receive a payment ID.
To initiate the payment, you must redirect the user to 'https://piecard.app/pay/YOUR_PAYMENT_ID'
Example using Axios
const id = 'YOUR_PAYMENT_ID';
const data = {
amount,
memo,
metadata: {
productId: 'xxx',
// you can use the metadata to store any key-value pair
},
sandbox,
successURL,
cancelURL
}; // set these as appropriate
const response = await axios
.post('https://api.piecard.app/payment', data, {
headers: {
clientid: "YOUR_CLIENT_ID",
clientsecret: "YOUR_CLIENT_SECRET",
accesstoken: "YOUR_ACCESS_TOKEN"
}
});
// create the redirect URL
const url = `pi://piecard.app/pay/${response.data.id}`;
// redirect the client
window.open(url);
Last updated
Was this helpful?