{"id":3447,"date":"2021-03-09T20:34:12","date_gmt":"2021-03-09T20:34:12","guid":{"rendered":"https:\/\/documents.openpay.mx\/?p=3447"},"modified":"2022-05-23T16:47:38","modified_gmt":"2022-05-23T16:47:38","slug":"alipay","status":"publish","type":"post","link":"https:\/\/documents-mx-dev.opdevhm.com\/en\/docs\/alipay.html","title":{"rendered":"Alipay Integration"},"content":{"rendered":"
\n\t\t\t\t\t\t
\n\t\t\t\t\t\t
\n\t\t\t\t\t
\n\t\t\t
\n\t\t\t\t\t\t
\n\t\t\t\t
\n\t\t\t\t\t\t\tThe following guide explains the required steps in order to receive payments using Alipay through the Openpay API.\n

Flow<\/h3>\n
\"Flujo<\/center>Steps:\n
    \n \t
  1. The customer requests to pay through Alipay<\/li>\n \t
  2. The merchant starts a new Alipay transaction using the Openpay API<\/li>\n \t
  3. The merchant redirects the customer to the URL returned by Openpay<\/li>\n \t
  4. The customer pays using his Alipay account<\/li>\n \t
  5. The transaction is completed in Openpay<\/li>\n \t
  6. The merchant is notified of a completed payment\n
      \n \t
    1. The customer is redirected back to the merchant website, and the merchant verifies the transaction status<\/li>\n \t
    2. The merchant receives a notification from Openpay as an alternate confirmation method<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n
      The merchant must implement steps 1 through 3 to start the transaction, and step 6 to receive the completed payment notification.\n

      Starting a transaction (Steps 1 through 3)<\/h2>\nIn 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.\n
      \n
      \n
      <?php <\/span>\n    $openpay<\/span> =<\/span> Openpay<\/span>::<\/span>getInstance<\/span>(<\/span>'mzdtln0bmtms6o3kck8f'<\/span>,<\/span> 'sk_e568c42a6c384b7ab02cd47d2e407cab'<\/span>);<\/span>\n    $chargeData<\/span> =<\/span> array<\/span><\/strong>(<\/span>\n        'method'<\/span> =><\/span> 'alipay'<\/span>,<\/span>\n        'amount'<\/span> =><\/span> 100.00<\/span>,<\/span>\n         'description'<\/span> =><\/span> 'Cargo mediante Alipay'<\/span>,<\/span>\n        'redirect_url'<\/span> =><\/span> 'https:\/\/www.example.com\/myUrl'<\/span>\n    );<\/span>\n    $charge<\/span> =<\/span> $openpay<\/span>-><\/span>charges<\/span>-><\/span>create<\/span>(<\/span>$chargeData<\/span>);<\/span> ?><\/span><\/code><\/pre>\n<\/figure>\n<\/div>\nIf 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.\n\nResponse:<\/strong>\n
      \n
      {<\/span>\n  \"id\"<\/span>:<\/span> \"trxxqosgmdsvt3hocoun\"<\/span>,<\/span>\n  \"authorization\"<\/span>:<\/span> null<\/span><\/strong>,<\/span>\n  \"operation_type\"<\/span>:<\/span> \"in\"<\/span>,<\/span>\n  \"method\"<\/span>:<\/span> \"alipay\"<\/span>,<\/span>\n  \"transaction_type\"<\/span>:<\/span> \"charge\"<\/span>,<\/span>\n  \"status\"<\/span>:<\/span> \"charge_pending\"<\/span>,<\/span>\n  \"conciliated\"<\/span>:<\/span> false<\/span><\/strong>,<\/span>\n  \"creation_date\"<\/span>:<\/span> \"2018-06-20T10:45:20-05:00\"<\/span>,<\/span>\n  \"operation_date\"<\/span>:<\/span> \"2018-06-20T10:45:20-05:00\"<\/span>,<\/span>\n  \"description\"<\/span>:<\/span> \"Cargo mediante Alipay\"<\/span>,<\/span>\n  \"error_message\"<\/span>:<\/span> null<\/span><\/strong>,<\/span>\n  \"order_id\"<\/span>:<\/span> null<\/span><\/strong>,<\/span>\n  \"due_date\"<\/span>:<\/span> \"2018-06-21T10:45:20-05:00\"<\/span>,<\/span>\n  \"payment_method\"<\/span>:<\/span> {<\/span>\n    \"type\"<\/span>:<\/span> \"redirect\"<\/span>,<\/span>\n    \"url\"<\/span>:<\/span> \"https:\/\/sandbox-api.openpay.mx\/v1\/mzdtln0bmtms6o3kck8f\/charges\/trxxqosgmdsvt3hocoun\/redirect\/\"<\/span>\n  },<\/span>\n  \"amount\"<\/span>:<\/span> 100<\/span>,<\/span>\n  \"currency\"<\/span>:<\/span> \"MXN\"<\/span>,<\/span>\n  \"fee\"<\/span>:<\/span> {<\/span>\n    \"amount\"<\/span>:<\/span> 5.4<\/span>,<\/span>\n    \"tax\"<\/span>:<\/span> 0.86<\/span>,<\/span>\n    \"currency\"<\/span>:<\/span> \"MXN\"<\/span>\n  }<\/span>\n}<\/span><\/code><\/pre>\n<\/figure>\n

      Alipay payment (Steps 4 and 5)<\/h2>\nOnce the user arrives in the Alipay website, they can use the Alipay App to scan the given QR Code:\n\n
      \"Pago<\/center>Or, alternatively, the customer can login into their Alipay account and complete payment in the browser:\n\n
      \"Pago<\/center>\n

      Payment confirmation (Step 6)<\/h2>\nOnce 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.\n

      Redirect confirmation (6a)<\/h3>\nUna vez que el usuario haya completado su pago en Alipay, ser\u00e1 redirigido a la URL que fue indicada al momento de crear el cargo, con el par\u00e1metro id agregado indicando la transacci\u00f3n que se ha completado.\n\nEjemplo:\n
      https:\/\/www.example.com\/myUrl?id=trxxqosgmdsvt3hocoun\n<\/code><\/pre>\nThe merchant must then use this ID to retrieve the transaction status using the Openpay API, and confirm that the transaction status<\/code> <\/span>is completed<\/code><\/span>.\n\n\nNote:<\/span><\/strong> If the transaction status is not yet completed<\/code>, the transaction is still pending payment and could still be completed at a later date.<\/span><\/em>\n
      \n
      \n
      <?php <\/span> $openpay<\/span> =<\/span> Openpay<\/span>::<\/span>getInstance<\/span>(<\/span>'mzdtln0bmtms6o3kck8f'<\/span>,<\/span> 'sk_e568c42a6c384b7ab02cd47d2e407cab'<\/span>);<\/span>\n$charge<\/span> =<\/span> $openpay<\/span>-><\/span>charges<\/span>-><\/span>get<\/span>(<\/span>'trxxqosgmdsvt3hocoun'<\/span>);<\/span>\n?><\/span><\/code><\/pre>\n<\/figure>\n<\/div>\nResponse:<\/strong>\n
      \n
      {<\/span>\n  \"id\"<\/span>:<\/span> \"trxxqosgmdsvt3hocoun\"<\/span>,<\/span>\n  \"authorization\"<\/span>:<\/span> \"2018062121001003210200378650\"<\/span>,<\/span>\n  \"operation_type\"<\/span>:<\/span> \"in\"<\/span>,<\/span>\n  \"method\"<\/span>:<\/span> \"alipay\"<\/span>,<\/span>\n  \"transaction_type\"<\/span>:<\/span> \"charge\"<\/span>,<\/span>\n  \"status\"<\/span>:<\/span> \"completed\"<\/span>,<\/span>\n  \"conciliated\"<\/span>:<\/span> false<\/span><\/strong>,<\/span>\n  \"creation_date\"<\/span>:<\/span> \"2018-06-20T10:45:20-05:00\"<\/span>,<\/span>\n  \"operation_date\"<\/span>:<\/span> \"2018-06-20T11:31:25-05:00\"<\/span>,<\/span>\n  \"description\"<\/span>:<\/span> \"Cargo mediante Alipay\"<\/span>,<\/span>\n  \"error_message\"<\/span>:<\/span> null<\/span><\/strong>,<\/span>\n  \"order_id\"<\/span>:<\/span> null<\/span><\/strong>,<\/span>\n  \"due_date\"<\/span>:<\/span> \"2018-06-21T10:45:20-05:00\"<\/span>,<\/span>\n  \"payment_method\"<\/span>:<\/span> {<\/span>\n    \"type\"<\/span>:<\/span> \"redirect\"<\/span>,<\/span>\n    \"url\"<\/span>:<\/span> \"https:\/\/sandbox-api.openpay.mx\/v1\/mzdtln0bmtms6o3kck8f\/charges\/trxxqosgmdsvt3hocoun\/redirect\/\"<\/span>\n  },<\/span>\n  \"amount\"<\/span>:<\/span> 100<\/span>,<\/span>\n  \"currency\"<\/span>:<\/span> \"MXN\"<\/span>,<\/span>\n  \"fee\"<\/span>:<\/span> {<\/span>\n    \"amount\"<\/span>:<\/span> 5.4<\/span>,<\/span>\n    \"tax\"<\/span>:<\/span> 0.86<\/span>,<\/span>\n    \"currency\"<\/span>:<\/span> \"MXN\"<\/span>\n  }<\/span>\n}<\/span><\/code><\/pre>\n<\/figure>\n

      Payment notification (6b)<\/h3>\nExiste la posibilidad de que el usuario no sea redirigido a la p\u00e1gina final del comercio, por ejemplo, en casos en los que el usuario cierre su ventana despu\u00e9s del pago o si la comunicaci\u00f3n falla durante la redirecci\u00f3n.\n\nPara 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\u00e1 notificado cuando una transacci\u00f3n de Alipay haya sido completada.\n\nNote:<\/strong> <\/span>The webhook notification may be sent before or after the customer is redirected back to your webpage.<\/em><\/span>\n\nNotification example:<\/strong>\n
      \n
      {<\/span>\n  \"type\"<\/span>:<\/span> \"charge.succeeded\"<\/span>,<\/span>\n  \"event_date\"<\/span>:<\/span> \"2018-06-20T11:31:24-05:00\"<\/span>,<\/span>\n  \"transaction\"<\/span>:<\/span> {<\/span>\n    \"id\"<\/span>:<\/span> \"trxxqosgmdsvt3hocoun\"<\/span>,<\/span>\n    \"authorization\"<\/span>:<\/span> \"2018062121001003210200378650\"<\/span>,<\/span>\n    \"operation_type\"<\/span>:<\/span> \"in\"<\/span>,<\/span>\n    \"method\"<\/span>:<\/span> \"alipay\"<\/span>,<\/span>\n    \"transaction_type\"<\/span>:<\/span> \"charge\"<\/span>,<\/span>\n    \"status\"<\/span>:<\/span> \"completed\"<\/span>,<\/span>\n    \"conciliated\"<\/span>:<\/span> false<\/span><\/strong>,<\/span>\n    \"creation_date\"<\/span>:<\/span> \"2018-06-20T10:45:20-05:00\"<\/span>,<\/span>\n    \"operation_date\"<\/span>:<\/span> \"2018-06-20T11:31:24-05:00\"<\/span>,<\/span>\n    \"description\"<\/span>:<\/span> \"Cargo mediante Alipay\"<\/span>,<\/span>\n    \"error_message\"<\/span>:<\/span> null<\/span><\/strong>,<\/span>\n    \"order_id\"<\/span>:<\/span> null<\/span><\/strong>,<\/span>\n    \"due_date\"<\/span>:<\/span> \"2018-06-21T10:45:20-05:00\"<\/span>,<\/span>\n    \"payment_method\"<\/span>:<\/span> {<\/span>\n      \"type\"<\/span>:<\/span> \"redirect\"<\/span>,<\/span>\n      \"url\"<\/span>:<\/span> \"https:\/\/sandbox-api.openpay.mx\/v1\/mzdtln0bmtms6o3kck8f\/charges\/trxxqosgmdsvt3hocoun\/redirect\/\"<\/span>\n    },<\/span>\n    \"amount\"<\/span>:<\/span> 100<\/span>,<\/span>\n    \"currency\"<\/span>:<\/span> \"MXN\"<\/span>,<\/span>\n    \"fee\"<\/span>:<\/span> {<\/span>\n      \"amount\"<\/span>:<\/span> 5.4<\/span>,<\/span>\n      \"tax\"<\/span>:<\/span> 0.86<\/span>,<\/span>\n      \"currency\"<\/span>:<\/span> \"MXN\"<\/span>\n    }<\/span>\n  }<\/span>\n}<\/span><\/code><\/pre>\n<\/figure>\nFor more details regarding notifications, please check the notifications section<\/a>\n

      Sandbox testing<\/h2>\nIn order to test the payment in Alipay in the Sandbox environment, you can use the following Alipay credentials:\n