Charge Wallet
As previously mentioned, customers can charge their wallet during a payment. Voucherly also provides a dedicated flow specifically for recharging the wallet.
This use case is available only if the wallet feature is enabled from the Dashboard.
Wallet Recharge Lifecycle
The process is similar to a regular payment, with minor differences in the parameters passed to the Create Payment API.
-
When the customer wants to charge their wallet, you must create a new payment via the Create Payment API, setting
modetoWallet.- You can specify an amount to charge by including a single
linewith the desired amount and setting the quantity to 1. - If no
lineis passed, Voucherly will prompt the customer to input the amount.
- You can specify an amount to charge by including a single
-
The API response will include the URL of the Voucherly Checkout page to which the customer must be redirected.
-
The customer can complete the recharge using a voucher payment gateway, a non-voucher payment gateway, or a combination of both.
-
After the recharge is completed, if the
callbackUrlfield was provided in the Create Payment API request, a Server-to-Server (S2S) notification will be sent to the specified URL. The customer will then be redirected to the merchant's website URL provided in the request.
Once the customer exits the checkout page, the transaction will already be in the Confirmed state. You do not need to confirm it via API, and wallet recharges cannot be refunded.
Quick Guide
Below is a detailed example of how to integrate the wallet recharge flow from scratch.
1. Create Payment
Refer to the Create Payment API for full functionality and details.
When the customer is ready to recharge their wallet, the merchant's site must make an HTTP call to the Create Payment API.
In the request:
- Set
modetoWallet. - Include customer data or
customerId(if returning). - Provide
redirectOkUrlandredirectKoUrlfor post-checkout redirection.
If you want Voucherly to prompt the customer for the amount they wish to recharge, do not include any lines. Otherwise, populate a single payment line with:
- A quantity of 1.
- The amount to be recharged.
The referenceId is optional and allows the merchant to include a custom identifier (e.g., cart ID or order ID) for reconciliation with their internal system.
It is highly recommended to set up a Server-to-Server (S2S) endpoint that Voucherly can call to notify the merchant of the payment outcome. The URL for this endpoint should be included in the callbackUrl field.
- HTTP
- cURL
POST /v1/payments HTTP/1.1
Host: api-stg.voucherly.it
X-API-Key: sk_test_kXbJtcgYV8hvdKqWS3iWEPZME20zgF6yC4YZp0m9rEbPJGxdf7GZY3nl
Content-Length: 900
{
"referenceId": "eb8f57f8-241b-4142-b7b0-d308d724541a",
"customerId": "cs_XBEKOB7mJLM",
"customerFirstName": "Mario",
"customerLastName": "Rossi",
"customerEmail": "mario.rossi@email.com",
"redirectOkUrl": "https://www.myecommerce.com/success",
"redirectKoUrl": "https://www.myecommerce.com/error",
"callbackUrl": "https://api.myecommerce.com/webhook/payment",
"mode": "Wallet"
}
curl --location 'api-stg.voucherly.it/v1/payments' \
--header 'X-API-Key: sk_test_kXbJtcgYV8hvdKqWS3iWEPZME20zgF6yC4YZp0m9rEbPJGxdf7GZY3nl' \
--data-raw '{
"referenceId": "eb8f57f8-241b-4142-b7b0-d308d724541a",
"customerId": "cs_XBEKOB7mJLM",
"customerFirstName": "Mario",
"customerLastName": "Rossi",
"customerEmail": "mario.rossi@email.com",
"redirectOkUrl": "https://www.myecommerce.com/success",
"redirectKoUrl": "https://www.myecommerce.com/error",
"callbackUrl": "https://api.myecommerce.com/webhook/payment",
"mode": "Wallet"
}'
The Voucherly API returns the newly created Payment object. The key field to focus on is CheckoutUrl, which contains the URL of the Voucherly Checkout system. The merchant's website must redirect the user to this URL to proceed with the payment.
{
"id": "pay_wxNPzBQ4P5o",
"referenceId": "eb8f57f8-241b-4142-b7b0-d308d724541a",
"mode": "Wallet",
"customerId": "cs_XBEKOB7mJLM",
"customerFirstName": "Mario",
"customerLastName": "Rossi",
"customerEmail": "mario.rossi@email.com",
"paymentGateways": [],
"checkoutUrl": "https://checkout-stg.voucherly.it/pay?Id=pay_wxNPzBQ4P5o",
"redirectOkUrl": "https://www.myecommerce.com/success",
"redirectKoUrl": "https://www.myecommerce.com/error",
"callbackUrl": "https://api.myecommerce.com/webhook/payment",
"totalAmount": 476,
"discountAmount": 200,
"finalAmount": 276,
"paidAmount": 0,
"paidVoucherAmount": 0,
"amount": 276,
"hasWallet": true,
"status": "Requested",
"lines": [],
"discounts": []
}
2. Configure a Checkout Callback Page
When the customer completes the wallet recharge on the Voucherly Checkout page, they are redirected to the URLs specified in the Create Payment API request:
- If the payment was completed successfully, the user is redirected to
redirectOkUrl. - In case of an error, the user is redirected to
redirectKoUrl.
The merchant must configure two routes on their site to handle the payment result and accept the query-string parameters sent with the redirect:
- success: Can be
OKif the payment succeeded, otherwiseKO. - status: The payment status.
- paymentId: The payment ID, in the format
pay_XXXXXXXXXXX. - referenceId: The merchant's custom reference ID sent when creating the payment.
- amount: The amount paid, in cents.
- voucherAmount: The amount paid with meal vouchers, in cents.
- walletAmount: The amount paid with the wallet, in cents.
- transactions: The number of transactions.
- customerId: The Voucherly customer identifier, in the format
cs_XXXXXXXXXXX. It must be stored in the merchant's system for future payments. - customerFirstName: The customer's first name.
- customerLastName: The customer's last name.
- customerEmail: The customer's email address.
- tenant: live or sand.
3. Configure a Server-to-Server Endpoint (Optional)
We recommend defining an endpoint that Voucherly will call via S2S to notify the payment result before redirecting to the merchant's site. See here for more details on how to implement an S2S endpoint and its behavior.
As described in the Server-to-Server section, make sure your endpoint responds correctly to S2S notifications. Otherwise, the payment will be cancelled and the amounts refunded.