Payment Window
The Payment Window lets you display a settlement window directly on your site using Paysera's JavaScript library, so customers can pay without being redirected away.
The Payment Window functionality is available only for card payments. Test payments are not available through the iframe you must use the standard redirect flow for testing.
Implementation Steps​
Step 1: Create a button​
Create a button that will open the payment window and give it a unique id (for example payNow):
<button id="payNow" type="button">Payment Demo</button>
Step 2: Generate parameters​
Generate the data and sign parameters using either the WebToPay library or the Custom Integration specification.
The following additional parameters apply to the Payment Window:
| Parameter | Length | Required | Description |
|---|---|---|---|
frame | 1 | Yes | Activates the use of the frame (0 - no, 1 - yes). |
payment | 20 | Yes | The payment method. The value must be card for card payments. |
amount | 11 | Yes | Amount in cents the client has to pay. |
currency | 3 | Yes | Payment currency (e.g. USD, EUR, etc.) you want the client to pay in. If the selected currency cannot be accepted by a specific payment method, the system will convert it automatically to the acceptable currency, according to the currency rate of the day. payamount and paycurrency answers will be sent to your website. |
p_email | 255 | Yes | Paysera will inform the payer about the payment status at this address. |
test | 1 | Yes | Must be 0, as test payments are not available using the iframe. |
card_type | 6 | No | Card type (credit, debit). Allows you to accept only certain types of cards. |
card_brand | 12 | No | Card brand (visa, maestro, visaelectron, mastercard). Allows you to accept only certain brands of cards. |
Step 3: Handle the payment window from JavaScript​
Create the methods responsible for sending the data after the button is clicked, displaying errors, and handling the success flow:
<script>
var checkoutApp = new PayseraCheckout.App();
checkoutApp.on(PayseraCheckout.AppEvent.SUCCESS, function () {
// happens after successful payment, when window is closed
});
checkoutApp.on(PayseraCheckout.AppEvent.ERROR, function (message) {
// happens after unsuccessful payment when window is closed or when the buyer closes the window.
switch (message.code) {
case PayseraCheckout.ErrorCode.USER_CLOSED:
// buyer closed window
break;
case PayseraCheckout.ErrorCode.CARD_INITIAL_RESULT_FAILED:
// failed to get payment configuration
break;
case PayseraCheckout.ErrorCode.CARD_AUTHORIZATION_FAILED:
// failed to authorize card
break;
case PayseraCheckout.ErrorCode.CARD_RESULT_FAILED:
// wrong payment status after card authorization/3D secure
break;
case PayseraCheckout.ErrorCode.CARD_SIGNATURE_FAILED:
// failed to perform 3D secure step
break;
}
});
// Button click event
var payButton = document.getElementById('payNow');
payButton.addEventListener('click', function () {
checkoutApp.pay({
data: '', // generated data
sign: '' // generated sign
});
});
</script>
Error Codes​
The ERROR event provides a message.code matching one of the following constants on PayseraCheckout.ErrorCode:
| Code | Description |
|---|---|
USER_CLOSED | The buyer closed the payment window. |
CARD_INITIAL_RESULT_FAILED | Failed to get payment configuration. |
CARD_AUTHORIZATION_FAILED | Failed to authorize the card. |
CARD_RESULT_FAILED | Wrong payment status after card authorization / 3D Secure. |
CARD_SIGNATURE_FAILED | Failed to perform the 3D Secure step. |
Security Considerations​
- Generate
dataandsignserver-side - never expose your project password to the client. - Verify payment status via the callback - don't rely solely on the frontend
SUCCESSevent; always confirm payment server-side using the callback.
Related Documentation​
- Custom Integration - generate
dataandsignfrom the specification - Integration with a Library - generate
dataandsignusing libwebtopay - Request Parameters - full parameter reference
- Processing Callback - handle payment notifications