NAV
  • Widget payments
  • 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.

    ParameterTypeDescription
    merchantIdstringMerchant identification
    invoiceInvoice details
    descriptionstringPayments description (max 255)
    orderNostringOrder number in the merchant system (max 50)
    expiresstringInvoice expiration date (ISO 8601 format, for example 2022-12-01T00:00:00Z)
    urlstringPayment link received via API
    amountAmount
    valuenumberAmount to pay
    currencystringCurrency code (for example TND)
    paymentMethodstringPayment method
    customerCustomer data
    emailstringe-mail
    phonestringphone
    receiptReceipt details
    clientClient details
    emailstringClient e-mail
    phonestringClient telephone
    namestringCompany name (max 150)
    innstringCompany TIN
    itemsItems list (max 110)
    namestringName (max 255)
    quantitynumberQuantity (for example 5.425)
    pricenumberPrice (for example 10.50)
    excisenumberExcise (for example 10.50)
    product
    codestringProduct code (base64 format)
    countrystringCountry origin code (for example ru)
    declarationstringTax declaration number (max 32)
    vatTypestringVAT type
    paymentSubjectstringPayment subject
    paymentMethodstringPayment method
    agentTypestringAgent type
    supplierSupplier details
    namestringSupplier name (max 150)
    innstringSupplier TIN
    phonestringSupplier telephone
    paymentFormPayment form data
    themestringTheme (light theme light or dark theme dark)
    primaryColorstringBrand color (hex format, for example #a5227d)
    productCardProduct / service card
    titlestringProduct / service title (max 80)
    descriptionstringProduct / service description (max 250)
    imageUrlstringProduct image URL
    fieldsAdditional fields (max 30)
    typestringField type (for example input, select, checkbox)
    namestringUnique internal field name (max 150)
    labelstringField name to display (max 30)
    hintstringField hint (field type only input, max 40)
    requiredbooleanMandatory field (only for field types input and select)
    selectOptionsOptions to select (field type only select)
    labelstringOption name (max 30)
    valuestringOption value (max 30)
    additionalAmountnumberAdditional amount (for example 10.50)
    additionalAmountnumberAdditional amount (field type only checkbox, for example 10.50)
    onSuccessfunctionCallback function on success payment
    onFailfunctionCallback 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"
        }
    });