The following guide explains the required steps in order to receive payments using Alipay through the Openpay API.
Flow
Steps:
The customer requests to pay through Alipay
The merchant starts a new Alipay transaction using the Openpay API
The merchant redirects the customer to the URL returned by Openpay
The customer pays using his Alipay account
The transaction is completed in Openpay
The merchant is notified of a completed payment
The customer is redirected back to the merchant website, and the merchant verifies the transaction status
The merchant receives a notification from Openpay as an alternate confirmation method
The merchant must implement steps 1 through 3 to start the transaction, and step 6 to receive the completed payment notification.
Starting a transaction (Steps 1 through 3)
In order to start an Alipay transaction you must specify the transaction method as alipay. Additionaly, you must specify the URL to where the customer will be redirected to once the payment process is completed.
<?php $openpay=Openpay::getInstance('mzdtln0bmtms6o3kck8f','sk_e568c42a6c384b7ab02cd47d2e407cab');$chargeData=array('method'=>'alipay','amount'=>100.00, 'description'=>'Cargo mediante Alipay','redirect_url'=>'https://www.example.com/myUrl');$charge=$openpay->charges->create($chargeData);?>
If the process is successful, Openpay will return a response with an URL to which your customer must be redirected to in order to complete their payment through Alipay. Response:
{"id":"trxxqosgmdsvt3hocoun","authorization":null,"operation_type":"in","method":"alipay","transaction_type":"charge","status":"charge_pending","conciliated":false,"creation_date":"2018-06-20T10:45:20-05:00","operation_date":"2018-06-20T10:45:20-05:00","description":"Cargo mediante Alipay","error_message":null,"order_id":null,"due_date":"2018-06-21T10:45:20-05:00","payment_method":{"type":"redirect","url":"https://sandbox-api.openpay.mx/v1/mzdtln0bmtms6o3kck8f/charges/trxxqosgmdsvt3hocoun/redirect/"},"amount":100,"currency":"MXN","fee":{"amount":5.4,"tax":0.86,"currency":"MXN"}}
Alipay payment (Steps 4 and 5)
Once the user arrives in the Alipay website, they can use the Alipay App to scan the given QR Code:
Or, alternatively, the customer can login into their Alipay account and complete payment in the browser:
Payment confirmation (Step 6)
Once the transaction has been paid, Openpay will set the transaction status to completed. The customer will be redirected back to the merchant website and a notification will be sent to the merchant's configured webhooks.
Redirect confirmation (6a)
Una vez que el usuario haya completado su pago en Alipay, será redirigido a la URL que fue indicada al momento de crear el cargo, con el parámetro id agregado indicando la transacción que se ha completado. Ejemplo:
The merchant must then use this ID to retrieve the transaction status using the Openpay API, and confirm that the transaction statusis completed. Note: If the transaction status is not yet completed, the transaction is still pending payment and could still be completed at a later date.
{"id":"trxxqosgmdsvt3hocoun","authorization":"2018062121001003210200378650","operation_type":"in","method":"alipay","transaction_type":"charge","status":"completed","conciliated":false,"creation_date":"2018-06-20T10:45:20-05:00","operation_date":"2018-06-20T11:31:25-05:00","description":"Cargo mediante Alipay","error_message":null,"order_id":null,"due_date":"2018-06-21T10:45:20-05:00","payment_method":{"type":"redirect","url":"https://sandbox-api.openpay.mx/v1/mzdtln0bmtms6o3kck8f/charges/trxxqosgmdsvt3hocoun/redirect/"},"amount":100,"currency":"MXN","fee":{"amount":5.4,"tax":0.86,"currency":"MXN"}}
Payment notification (6b)
Existe la posibilidad de que el usuario no sea redirigido a la página final del comercio, por ejemplo, en casos en los que el usuario cierre su ventana después del pago o si la comunicación falla durante la redirección. Para manejar estos casos, adicionalmente a la URL de respuesta, se recomienda que el comercio reciba las notificaciones de pago de Openpay, mediante las cuales será notificado cuando una transacción de Alipay haya sido completada. Note:The webhook notification may be sent before or after the customer is redirected back to your webpage.Notification example:
{"type":"charge.succeeded","event_date":"2018-06-20T11:31:24-05:00","transaction":{"id":"trxxqosgmdsvt3hocoun","authorization":"2018062121001003210200378650","operation_type":"in","method":"alipay","transaction_type":"charge","status":"completed","conciliated":false,"creation_date":"2018-06-20T10:45:20-05:00", "operation_date":"2018-06-20T11:31:24-05:00","description":"Cargo mediante Alipay","error_message":null,"order_id":null,"due_date":"2018-06-21T10:45:20-05:00","payment_method":{"type":"redirect","url":"https://sandbox-api.openpay.mx/v1/mzdtln0bmtms6o3kck8f/charges/trxxqosgmdsvt3hocoun/redirect/"},"amount":100,"currency":"MXN","fee":{"amount":5.4,"tax":0.86,"currency":"MXN"}}}