Step 3: Create the formToken
Objective
- Generate a formToken.
The formToken
is a key generated by the gateway. It defines the payment context (amount, currency, order number, buyer contact details, etc.).
The formToken
is the result of the response of the call to the Charge/CreatePayment REST Web Service. It is valid for 15 minutes.
I. Request for a simple payment
Example: .
- amount : 9.90 €.
- order: "myOrderId-999999",
- buyer's email: "sample@example.com ".
/en/rest/V4.0/api/kb/authentication.html
https://github.com/lyra/rest-php-examples/blob/master/www/minimalEmbeddedForm.php#L9-L44
https://api.lyra.com/api-payment/V4/Charge/CreatePayment
{ "amount": 990, "currency": "EUR", "orderId": "myOrderId-999999", "customer": { "email": "sample@example.com" } }
{ "amount": 1500, "currency": "PEN", "orderId": "myOrderId-999999", "more": "parameters", "customer": { "email": "sample@example.com" } }
{ "amount": 20000, "currency": "ARS", "orderId": "myOrderId-999999", "more": "parameters", "customer": { "email": "sample@example.com" } }
{ "amount": 100000, "currency": "COP", "orderId": "myOrderId-999999", "more": "parameters", "customer": { "email": "sample@example.com" } }
{ "amount": 2500, "currency": "BRL", "orderId": "myOrderId-999999", "more": "parameters", "customer": { "email": "sample@example.com" } }
II. Response for a simple payment
{ "status": "SUCCESS", "_type": "V4/WebService/Response", "webService": "Charge/CreatePayment", "applicationProvider": "PAYZEN", "version": "V4", "applicationVersion": "4.1.0", "answer": { "formToken": "DEMO-TOKEN-TO-BE-REPLACED", "_type": "V4/Charge/PaymentForm" } }
III. Other use cases
- Select payment methods
- Offering payment method registration.
- Increasing the chances of frictionless in 3DS2
- Transmitting custom data
Other examples are available on this page: Usage cases.
IV. Using the Playground
Use the Charge/CreatePayment Playground to see all available fields.
Click the "Test me" button, create your request and execute the REST call in order to generate the formToken.
V. Simplified PHP example
In the sample
folder, the file for this step is formToken.php.
For more details, Example file: formToken.php