Widget payments
Connection
To embed a payment widget on your site, you need to include a JavaScript code on the payment page.
<script src="https://psp.paymaster.tn/cpay/sdk/payment-widget.js"></script>
To display the widget, you need to call the initialization function, passing the necessary parameters there.
function pay () {
var paymentWidget = new cpay.PaymentWidget();
paymentWidget.init({
merchantId: "cf128151-127b-44ed-bde5-26c531cad20d",
invoice: {
description: "test payment"
},
amount: {
value: 10.50,
currency: "TND"
}
});
}
The initialization function can be called, for example, by pressing the "Pay" button.
<button onclick="pay()">Pay</button>
Description of parameters
In requests, mandatory parameters are highlighted in bold.
Parameter | Type | Description |
merchantId | string | Merchant identification |
invoice | Invoice details | |
description | string | Payments description (max 255) |
orderNo | string | Order number in the merchant system (max 50) |
expires | string | Invoice expiration date (ISO 8601 format, for example 2022-12-01T00:00:00Z ) |
url | string | Payment link received via API |
amount | Amount | |
value | number | Amount to pay |
currency | string | Currency code (for example TND ) |
paymentMethod | string | Payment method |
customer | Customer data | |
string | ||
phone | string | phone |
receipt | Receipt details | |
client | Client details | |
string | Client e-mail | |
phone | string | Client telephone |
name | string | Company name (max 150) |
inn | string | Company TIN |
items | Items list (max 110) | |
name | string | Name (max 255) |
quantity | number | Quantity (for example 5.425 ) |
price | number | Price (for example 10.50 ) |
excise | number | Excise (for example 10.50 ) |
product | ||
code | string | Product code (base64 format) |
country | string | Country origin code (for example ru ) |
declaration | string | Tax declaration number (max 32) |
vatType | string | VAT type |
paymentSubject | string | Payment subject |
paymentMethod | string | Payment method |
agentType | string | Agent type |
supplier | Supplier details | |
name | string | Supplier name (max 150) |
inn | string | Supplier TIN |
phone | string | Supplier telephone |
paymentForm | Payment form data | |
theme | string | Theme (light theme light or dark theme dark ) |
primaryColor | string | Brand color (hex format, for example #a5227d ) |
productCard | Product / service card | |
title | string | Product / service title (max 80) |
description | string | Product / service description (max 250) |
imageUrl | string | Product image URL |
fields | Additional fields (max 30) | |
type | string | Field type (for example input , select , checkbox ) |
name | string | Unique internal field name (max 150) |
label | string | Field name to display (max 30) |
hint | string | Field hint (field type only input , max 40) |
required | boolean | Mandatory field (only for field types input and select ) |
selectOptions | Options to select (field type only select ) | |
label | string | Option name (max 30) |
value | string | Option value (max 30) |
additionalAmount | number | Additional amount (for example 10.50 ) |
additionalAmount | number | Additional amount (field type only checkbox , for example 10.50 ) |
onSuccess | function | Callback function on success payment |
onFail | function | Callback function for fail payment |
Additional fields
For fields with select
and checkbox
types, you can specify an additionalAmount, which will be automatically added to the main amount of the invoice, depending on the choice of the payer.
If you want the payer to specify the amount himself, then amount.value must be set to 0
and add a field with type input
and name amount
. The field must be required.
Also, if you want the payer to choose the amount himself, then amount.value must be set to 0
and add a field with the select
type, in which all selectOptions contain additionalAmount. The field must also be required.
In order for the payer to indicate his e-mail or phone number, you need to add a field with the input
type and the name customerEmail
or customerPhone
respectively. The fields may be optional.
Creating an invoice via API
If you use API to create an invoice and want to use a payment widget, then the resulting payment link must be passed to the initialization function.
var paymentWidget = new cpay.PaymentWidget();
paymentWidget.init({
invoice: {
url: "https://psp.paymaster.tn/cpay/a62beecb68c84778b2424294f635b370"
}
});