\n\t\t\t\t\t\t\t
Openpay has a special model for commercial partners, which allows the partner to create transactions on behalf of a merchant, without having the merchant share their Openpay access keys. Under this model, the merchant can decide when to restrict or allow a commercial partner in Openpay.<\/p>
In order for a commercial partner to integrate to the Openpay platform, it is essential to understand the following topics:<\/p>
Charging a card <\/a><\/li>Openpay API <\/a><\/li>OAuth 2 Standard <\/a><\/li>OAuth 2 Clients <\/a><\/li>Rest\/HTTPS Services <\/a><\/li><\/ol>To integrate a commercial parter into the platform, you need to go through the following steps<\/strong><\/p>Registering the commercial partner.<\/li> Integrating the OAuth 2.0 protocol in the partner's application.<\/li> Consuming the Openpay API services using the partner's credentials.<\/li><\/ol>1. Registering the commercial partner.<\/h2> As the first step, it is necessary to register the commercial partner in the Openpay platform. This process consists of submitting a registration form with information similar to the one required for the merchants. After filling and submitting this form, Openpay staff will validate the information, and if the information is correct a confirmation will be sent to your email, along with your partner identification codes.<\/p>
To enter the registration form for testing click here <\/a><\/p>Once the testing registration form is submitted, the partner account will be automatically activated and an email with the required information for OAuth 2.0 integration will be sent.<\/p>
The email sent to the partner will contain \"client_id\" and \"client_secret\" codes, which will identify the partner in the Openpay platform.<\/p>
Note:<\/strong><\/span> After you successfully test your integration with the testing environment, you can register in production by clicking here <\/a><\/em><\/span><\/p>2. Integrating the OAuth 2.0 protocol in the partner's application.<\/h2> The OAuth flow used by Openpay for the Partner model allows a Merchant to authorize securely a commercial partner to create transactions in Openpay on their behalf, using the partner's own keys.<\/p>
The partner must implement the OAuth 2.0 standard in their web application in order to integrate their web application with Openpay. The following diagrams shows the two flows allowed by the Openpay model:<\/p>
Flow 1<\/strong> : When the Merchant already has an Openpay account, the following interactions take place between the Merchant, the Partner, and Openpay.<\/p> <\/p>
Flow 2<\/strong>: The following diagram shows the interaction between the Merchant, the Partner, and Openpay when the merchant sill hasn't registered in Openpay.<\/p> <\/p>
In both flows there are three different endpoints that should be consumed: One to request the Merchant's authorization, another to retrieve an access token, and a third one to retrieve the Merchant information.<\/p>
OAuth Endpoints<\/strong><\/p>https:\/\/sandbox-dashboard.openpay.mx\/oauth\/authorize<\/code>: Allows the Merchant to grant permissions to the partner to create charges on behalf of the merchant.<\/li>https:\/\/sandbox-dashboard.openpay.mx\/oauth\/token<\/code>: Allows the Partner to obtain an access token.<\/li>https:\/\/sandbox-dashboard.openpay.mx\/oauth\/merchant<\/code>: Allows the Partner to retrieve the Merchant information in order to create transactions on their behalf.<\/li><\/ul>Note:<\/strong><\/span> In order to use the production environment endpoints, you need to replace \"sandbox-dashboard.openpay.mx\" with \"dashboard.openpay.mx\" in all paths.<\/em><\/span><\/p>The interactions between the three entities during the OAuth flow can be summarized in 5 steps as follows:<\/p>
1. Requesting access to the Merchant's account<\/h3> The \u201cClient\" (Partner) must send an HTTP request to the \u201cService provider\" (Openpay), requesting access to the Merchant's account. The service provider validates that the request is valid, and the \u201cUser\" (Merchant) is redirected to a page hosted by the service provider, in which the Merchant can grant the requested authorizations in order for the Partner to create transactions on his behalf.<\/p>
The Partner must provide a button so the Merchant can activate the feature to allow the Partner to process payments with Openpay. This button should call the Authorization URI.<\/p>
<\/p>
The URI to call is explained next.<\/p>
HTTP Request specification:<\/strong><\/p>It must be a GET request to the authorization URI<\/li> The content type must be \u201ctext\/html\", \"application\/xhtml+xml\", or \"application\/xml\u201d<\/li><\/ul>Syntax:<\/strong><\/p> https:\/\/\/oauth\/authorize?\n client_id<\/span>=<\/span>\n &<\/span>redirect_uri<\/span>=<\/span>\n &<\/span>response_type<\/span>=<\/span>code\n &<\/span>scope<\/span>=<\/span><\/code><\/pre><\/figure>Example:<\/strong><\/p> https:\/\/sandbox-dashboard.openpay.mx\/oauth\/authorize?\n client_id<\/span>=<\/span>ppk_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n &<\/span>redirect_uri<\/span>=<\/span>https%3a%2f%2flocalhost%3a8443%2fsitepartner%2fregisterok\n &<\/span>response_type<\/span>=<\/span>code\n &<\/span>scope<\/span>=<\/span>read+write<\/code><\/pre><\/figure>Where:<\/strong><\/p>client_id:<\/strong> Unique Partner identifier, sent by email to the Partner after completing their registration and being verified by Openpay staff.<\/li>redirect_uri:<\/strong> URI to which the merchant will be redirected after they approve the Partner. This URL must match the URI given in the registration form, otherwise the approval will fail. Don't forget to URL encode this parameter in your request.<\/li>response_type:<\/strong> Fixed value \u201ccode\u201d. This indicates that an authorization code is expected to be returned after the merchant authorizes the Partner.<\/li>scope:<\/strong> Fixed value \u201cread+write\u201d. Indicates the permissions that the Partner will have once they have access to the Merchant's information to create charges.<\/li><\/ul>Note:<\/strong><\/span><\/em><\/p>The possible OAUth errors are described in the section \u201cerrores OAuth\u201d<\/a><\/span><\/em><\/li><\/ul>In order to call the production environment URI, you need to replace \"sandbox-dashboard.openpay.mx\" with \"dashboard.openpay.mx\"<\/span><\/em><\/li><\/ul>2. Authenticating the Merchant on the Openpay platform<\/h3> The Merchant will have the possibility of creating a new account or using an existing one in Openpay. Either an explicit or implict authorization is required from the Merchant, for the Partner to be able to create charges on their behalf. Both cases are described next.<\/p>
The merchant creates a new account in Openpay<\/strong>El comercio al dar clic en el bot\u00f3n que provee el integrador desde su aplicativo, ser\u00e1 enviado a una p\u00e1gina dentro de la plataforma Openpay. El comercio selecciona “Nueva cuenta”, completa el formulario de registro y lo env\u00eda a Openpay.Openpay validar\u00e1 la informaci\u00f3n solicitada en el formulario, en caso de ser correctos estos datos personal de Openpay enviar\u00e1 un correo electr\u00f3nico de confirmaci\u00f3n. El correo recibido tendr\u00e1 un bot\u00f3n para definir una contrase\u00f1a y poder ingresar al portal WEB que provee Openpay para cualquier comercio.<\/li><\/ol>Note:<\/strong><\/em><\/span><\/p>When a new Merchant account is created this way, the Partner will have an implicit authorization to charge on behalf of the Merchant.<\/em><\/span><\/li><\/ul>The Merchant uses an existing account in Openpay<\/strong>El comercio al dar clic en el bot\u00f3n que provee el integrador desde su aplicativo, ser\u00e1 enviado a una p\u00e1gina dentro de la plataforma Openpay. El comercio selecciona “Usar cuenta” e inicia sesi\u00f3n en Openpay.Como parte de la seguridad que provee este esquema de integraci\u00f3n, al comercio se le mostrar\u00e1 una p\u00e1gina de autorizaci\u00f3n para que expl\u00edcitamente conceda al Integrador los permisos necesarios para que pueda realizar operaciones en su nombre.En caso de que el comercio no permita el acceso a su cuenta, el proveedor de servicios har\u00e1 un redirect a la URI del Integrador, enviando como par\u00e1metros de respuesta en la URI:error:<\/strong> access_denied<\/li>error_description:<\/strong> User+denied+access<\/li><\/ul><\/li><\/ol>Note:<\/strong><\/em><\/span><\/p>In the sandbox environment new merchants are automatically validated and receive a confirmation email immediately.<\/em><\/span><\/li><\/ul>When an existing account is used, the Partner must be granted authorization explicitly.<\/em><\/span><\/li><\/ul>3. Receiving the authorization code<\/h3> Once the service provider (Openpay) receives the request to grant authorization to the Partner, an authorization code will be generated, which will be sent to the Partner as a parameter in the redirect URI they provided.<\/p>
The URI to which the Merchant is redirected is formed as follows:<\/strong><\/p>Syntax:<\/strong><\/p> https:\/\/?code=<\/code><\/code><\/code><\/pre><\/figure>Example:<\/strong><\/p> https:\/\/www.sitepartner.mx\/PartnerTest\/home?\n code<\/span>=<\/span>769FkXdN7rAicf1l2dLUEeBLs53pgM<\/code><\/pre><\/figure>Where:<\/strong><\/p>redirect_uri:<\/strong> URI to which the merchant will be redirected to once he approves the Partner.<\/li>code:<\/strong> Authorization code used by the Partner to obtain the access tokens.<\/li><\/ul>Note:<\/strong><\/span> The authorization code returned to the Partner by Openpay must be stored, since this will be used to request future access tokens.<\/em><\/span><\/p>4. Requesting access tokens<\/h3> Once the Partner has an authorization code, they must use it in a HTTP request in order to retrieve an access token from the service provider.<\/p>
The URI used to retrieve the access token is explained next.<\/p>
HTTP Request specification:<\/strong><\/p>It must be a GET request to the token URI<\/li><\/ul>Syntax:<\/strong><\/p>https:\/\/\/oauth\/token\n ?code=<\/span>\n &<\/span>client_id<\/span>=<\/span>\n &<\/span>client_secret<\/span>=<\/span>\n &<\/span>grant_type<\/span>=<\/span>authorization_code\n &<\/span>redirect_uri<\/span>=<\/span><\/code><\/code><\/pre><\/code><\/code><\/pre><\/figure>Example:<\/strong><\/p> https:\/\/sandbox-dashboard.openpay.mx\/oauth\/token?\n code<\/span>=<\/span>769FkXdN7rAicf1l2dLUEeBLs53pgM\n &<\/span>client_id<\/span>=<\/span>ppk_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n &<\/span>client_secret<\/span>=<\/span>psk_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n &<\/span>grant_type<\/span>=<\/span>authorization_code\n &<\/span>redirect_uri<\/span>=<\/span>http%3A%2F%2Fwww.sitepartner.mx%2FPartnerTest%2Fhome<\/code><\/pre><\/figure>Where:<\/strong><\/p>code:<\/strong> Authorization code used by the Partner to obtain the access tokens.<\/li>client_id:<\/strong> Unique identifier for the Partner, which was sent to their email after their registration and validation.<\/li>client_secret:<\/strong> Secret key of the Partner, which was sent to their email after their registration and validation.<\/li>grant_type:<\/strong> Fixed value \u201cauthorization_code\u201d. Indicates the kind of request being made.<\/li>redirect_uri:<\/strong> URI to which the merchant will be redirected after they approve the Partner. This URL must match the URI given in the registration form, otherwise the approval will fail. Don't forget to URL encode this parameter in your request.<\/li><\/ul> The following is the response that the service provider will return to the Partner:<\/p>
HTTP Response specification:<\/strong><\/p>Returned Content Type:<\/strong> \u201capplication\/json\u201d<\/li>Response code:<\/strong> 200.<\/li><\/ul>Syntax:<\/strong><\/p>{\n \"access_token\":\"<<\/span>access_token<\/span>><\/span>\",\n \"token_type\":\"<<\/span>token_type<\/span>><\/span>\",\n \"refresh_token\":\"<<\/span>refresh_token<\/span>><\/span>\",\n \"expires_in\":<<\/span>expires_in<\/span>><\/span>,\n \"scope\":\"<<\/span>scope<\/span>><\/span>\"\n}<\/code><\/pre><\/figure>Example:<\/strong><\/p>