Generate a payment link
First, make sure that you have set up TezosPayments as described in the Set Up chapter.
Create a payment in tez tokensβ
To create a payment, you need to call the createPayment
method of the TezosPayments
class passing PaymentCreateParameters
:
- TypeScript
- JavaScript
const payment = await tezospayments.createPayment({
amount: '10'
});
// Your customers can use this link to make the payment
console.log(payment.url);
const payment = await tezospayments.createPayment({
amount: '10'
});
// Your customers can use this link to make the payment
console.log(payment.url);
Where '10'
is an amount of tez tokens. The amount should be represented by a string.
Create a payment in FA tokensβ
To create a payment, you need to call the createPayment
method of the TezosPayments
class passing PaymentCreateParameters
with a FA-token metadata:
- TypeScript
- JavaScript
const payment = await tezospayments.createPayment({
amount: '50.17',
asset: {
address: 'KT1K9gCRgaLRFKTErYt1wVxA3Frb9FjasjTV',
decimals: 18,
id: null
}
});
// Your customers can use this link to make the payment
console.log(payment.url);
const payment = await tezospayments.createPayment({
amount: '50.17',
asset: {
address: 'KT1K9gCRgaLRFKTErYt1wVxA3Frb9FjasjTV',
decimals: 18,
id: null
}
});
// Your customers can use this link to make the payment
console.log(payment.url);
You need to pass the FA-token metadata to the asset
object:
address: string
. An address of the token contract;decimals: number
. A number of decimals;id: number | null
. If it is a FA 1.2 token, passnull
.
'50.17'
is an amount of target tokens. The amount should be represented by a string.
Create a payment with a client dataβ
If you want to pass some data to the payment form, you need to set the data
field of PaymentCreateParameters
:
- TypeScript
- JavaScript
const payment = await tezospayments.createPayment({
amount: '100',
data: {
item: 'Watch',
count: 3
}
});
// Your customers can use this link to make the payment
console.log(payment.url);
const payment = await tezospayments.createPayment({
amount: '100',
data: {
item: 'Watch',
count: 3
}
});
// Your customers can use this link to make the payment
console.log(payment.url);
The type of the data
field should be any object that can be serialized as JSON.
info
The data will only be displayed in the payment form and wonβt be stored in the blockchain.
Create a payment with the custom IDβ
By default, the TezosPayments package generates a payment ID automatically. But if you want to use the custom ID, you need to pass this ID with PaymentCreateParameters
:
- TypeScript
- JavaScript
const payment = await tezospayments.createPayment({
amount: '11',
id: 'customId'
});
// Your customers can use this link to make the payment
console.log(payment.url);
const payment = await tezospayments.createPayment({
amount: '11',
id: 'customId'
});
// Your customers can use this link to make the payment
console.log(payment.url);
info
Payment ID - it's a unique identifier that helps you match the completed operation (payment) with your customer's order, purchase, and so forth.