{"id":3542,"date":"2021-03-10T18:07:52","date_gmt":"2021-03-10T18:07:52","guid":{"rendered":"https:\/\/documents.openpay.mx\/?p=3542"},"modified":"2021-03-10T19:30:16","modified_gmt":"2021-03-10T19:30:16","slug":"ruby","status":"publish","type":"post","link":"https:\/\/documents-mx-dev.opdevhm.com\/en\/docs\/ruby.html","title":{"rendered":"API Reference | Ruby"},"content":{"rendered":"
The Openpay API is designed on REST<\/a>, therefore you\u2019ll find that URLs are oriented to resources and that HTTP response codes are used to indicate errors in the API.<\/p> All the API responses are in JSON<\/a>format, including the errors.<\/p> In the case to use the existents Openpay API clients (Java<\/a>, Php<\/a>, C#<\/a>, Python<\/a>, Ruby<\/a>, NodeJS<\/a>), the responses are specifically of type defined in the clients and their respective languajes.<\/p> Available resourcers<\/p><\/blockquote> a) By Merchant<\/p><\/blockquote> b) By Customer<\/p><\/blockquote> The Openpay REST API has a test environment (sandbox) and a production environment. For integrating your system with Openpay, use the credentials that were generated when you signed up. Once you are ready to move to production environment and your request is approved, new credentials will be generated for accessing the production environment.<\/p> The following URIs are the basis of the endpoints for the supported environments:<\/p> A complete endpoint consists of the base URI of the environment, the identifier of the Merchant and the resource.<\/p> For example, if we want to create a new customer, the endpoint would be:<\/p> In order to create a complete request is necessary to send the right HTTP headers and the information in JSON format.<\/p> Authentication example<\/p><\/blockquote> Production<\/p><\/blockquote> To make requests to the Openpay API, is necessary to send the API Key on all your calls to our servers. You can get the key from the dashboard<\/a>.<\/p> There are 2 types of API keys:<\/p> For API authentication you must use the basic access authentication<\/a>, where the API key is the username. The password is not required and it should be left blank for purposes of simplicity<\/p> Openpay returns JSON objects in the service responses.<\/p> Object example<\/p><\/blockquote>API Endpoints<\/h2>
\/v1\/{MERCHANT_ID}\/...\n\n\/fees\n\/fees\/{FEE_ID}\n\/charges\n\/charges\/{TRANSACTION_ID}\n\/payouts\n\/payouts\/{TRANSACTION_ID}\n\/cards\n\/cards\/{CARD_ID}\n\/customers\n\/customers\/{CUSTOMER_ID}\n\/plans\n\/plans\/{PLAN_ID}\n\u200b\/tokens\n\/tokens\/{TOKEN_ID}\n<\/code><\/pre>\/v1\/{MERCHANT_ID}\/customers\/{CUSTOMER_ID}\/...\n\n\/cards\n\/cards\/{CARD_ID}\n\/bankaccounts\n\/bankaccounts\/{BANKACCOUNT_ID}\n\/charges\n\/charges\/{TRANSACTION_ID}\n\/payouts\n\/payouts\/{TRANSACTION_ID}\n\/transfers\n\/transfers\/{TRANSACTION_ID}\n\/subscriptions\n\/subscriptions\/{SUBSCRIPTION_ID}\n<\/code><\/pre>Production:<\/code><\/li>https:\/\/api.openpay.mx<\/code><\/li><\/ul>POST https:\/\/sandbox-api.openpay.mx\/v1\/mzdtln0bmtms6o3kck8f\/customers<\/code><\/p>Authentication<\/h2>
#Sandbox\nopenpay=OpenpayApi.new(\"moiep6umtcnanql3jrxp\",\"sk_3433941e467c4875b178ce26348b0fac\")\n\n#Produccion\nopenpay=OpenpayApi.new(\"moiep6umtcnanql3jrxp\",\"sk_3433941e467c4875b178ce26348b0fac\", true)\n\n\n#Definir timeout para los request's\n#Este cliente maneja un timeout por defecto de 90 seg., para configurar el timeout usado para crear los request a los servicios de Openpay, es necesario definir expl\u00edcitamente el tipo de ambiente, seguido del nuevo valor del timeout para el request:\n\n#Sintaxis:\n# openpay_prod=OpenpayApi.new(merchant_id,private_key,isProduction,timeout)\n#Example:\n# openpay_prod=OpenpayApi.new(merchant_id,private_key,false,30)\n<\/code><\/pre>#Solo es necesario pasar como tercer argumento un \"true\" cuando se crea el objeto OpenpayApi\n<\/code><\/pre>Errors<\/h2>
Error Object<\/h2>
{\n \"category\" : \"request\",\n \"description\" : \"The customer with id 'm4hqp35pswl02mmc567' does not exist\",\n \"http_code\" : 404,\n \"error_code\" : 1005,\n \"request_id\" : \"1981cdb8-19cb-4bad-8256-e95d58bc035c\",\n \"fraud_rules\": [\n \"Billing <> BIN Country for VISA\/MC\"\n ]\n}\n<\/code><\/pre>#Para el caso de Ruby, toda operaci\u00f3n puede regresar cualquiera de las siguientes excepciones:\n\n# => OpenpayException: Para errores genericos, como acceso a recursos invalidos, etc.\n# => OpenpayConnectionException: Para errores relacionados con problemas en la conexi\u00f3n al servidor.\n# => OpenpayTransactionException: Para errores relacionados durante la ejecuci\u00f3n de las operaciones.\n<\/code><\/pre>