{"id":3387,"date":"2021-03-08T21:27:16","date_gmt":"2021-03-08T21:27:16","guid":{"rendered":"https:\/\/documents.openpay.mx\/?p=3387"},"modified":"2022-05-23T16:37:49","modified_gmt":"2022-05-23T16:37:49","slug":"suscriptions","status":"publish","type":"post","link":"https:\/\/documents-mx-dev.opdevhm.com\/en\/docs\/suscriptions.html","title":{"rendered":"Subscriptions"},"content":{"rendered":"
<?<\/span>\n$openpay<\/span> =<\/span> Openpay<\/span>::<\/span>getInstance<\/span>(<\/span>'mzdtln0bmtms6o3kck8f'<\/span>,<\/span> 'sk_e568c42a6c384b7ab02cd47d2e407cab'<\/span>);<\/span>\n\n$planDataRequest<\/span> =<\/span> array<\/span><\/strong>(<\/span>\n 'amount'<\/span> =><\/span> 150.00<\/span>,<\/span>\n 'status_after_retry'<\/span> =><\/span> 'cancelled'<\/span>,<\/span>\n 'retry_times'<\/span> =><\/span> 2<\/span>,<\/span>\n 'name'<\/span> =><\/span> 'Plan Curso Verano'<\/span>,<\/span>\n 'repeat_unit'<\/span> =><\/span> 'month'<\/span>,<\/span>\n 'trial_days'<\/span> =><\/span> '30'<\/span>,<\/span>\n 'repeat_every'<\/span> =><\/span> '1'<\/span>,<\/span>\n 'currency'<\/span> =><\/span> 'MXN'<\/span>);<\/span>\n\n$plan<\/span> =<\/span> $openpay<\/span>-><\/span>plans<\/span>-><\/span>add<\/span>(<\/span>$planDataRequest<\/span>);<\/span>\n?><\/span><\/code><\/pre>\n<\/figure>\n<\/div>\nYou can have as many plans as you want. For example you can have a Gold, Platinum and Bronze plan for different levels of service.<\/blockquote>\nIf the request is successful we will have a response that contains the id<\/code> of the plan\n\nResponse:<\/strong>\n\n {<\/span>\n \"name\"<\/span>:<\/span>\"Servicio de TV\"<\/span>,<\/span>\n \"status\"<\/span>:<\/span>\"active\"<\/span>,<\/span>\n \"amount\"<\/span>:<\/span>99.99<\/span>,<\/span>\n \"currency\"<\/span>:<\/span>\"MXN\"<\/span>,<\/span>\n \"id\"<\/span>:<\/span>\"psjubnktzpofhakixfkp\"<\/span>,<\/span>\n \"creation_date\"<\/span>:<\/span>\"2014-02-14T13:47:55-06:00\"<\/span>,<\/span>\n \"repeat_every\"<\/span>:<\/span>1<\/span>,<\/span>\n \"repeat_unit\"<\/span>:<\/span>\"month\"<\/span>,<\/span>\n \"retry_times\"<\/span>:<\/span>2<\/span>,<\/span>\n \"status_after_retry\"<\/span>:<\/span>\"cancelled\"<\/span>,<\/span>\n \"trial_days\"<\/span>:<\/span>30<\/span>\n }<\/span>\n <\/code><\/pre>\n<\/figure>\nFor more information about the plan parameters go to \"Add Plan\"<\/em><\/span><\/p>\nOption 2.- Creation from the dashboard<\/strong>\n\nYou can also create plans from the dashboard in Planes -> Agregar:\n\n
<\/center>\nCard tokenization<\/h2>\nTo tokenize a customer card using the library Openpay.js<\/a>.\n\nPrimero agregamos al head<\/code> and Openpay.js<\/a> files to the head:\n\n<<\/span>script<\/span> type<\/span>=<\/span>\"text\/javascript\"<\/span> src<\/span>=<\/span>\"https:\/\/ajax.googleapis.com\/ajax\/libs\/jquery\/1.11.0\/jquery.min.js\"<\/span>><\/<\/span><\/span>script<\/span>><\/span>\n<<\/span>script<\/span> type<\/span>=<\/span>\"text\/javascript\"<\/span> src<\/span>=<\/span>\"https:\/\/js.openpay.mx\/openpay.v1.min.js\"<\/span>><\/<\/span><\/span>script<\/span>><\/span><\/code><\/pre>\n<\/figure>\nNow let\u2019s set the merchant-id<\/code> and thepublic-key<\/code>):\n\n<<\/span>script <\/span>type<\/span>=<\/span>\"text\/javascript\"<\/span>><\/span>\n $<\/span>(<\/span>document<\/span>).<\/span>ready<\/span>(<\/span>function<\/span><\/strong>()<\/span> {<\/span>\n OpenPay<\/span>.<\/span>setId<\/span>(<\/span>'mzdtln0bmtms6o3kck8f'<\/span>);<\/span>\n OpenPay<\/span>.<\/span>setApiKey<\/span>(<\/span>'pk_f0660ad5a39f4912872e24a7a660370c'<\/span>);<\/span>\n OpenPay<\/span>.<\/span>setSandboxMode<\/span>(<\/span>true<\/span><\/strong>);<\/span>\n });<\/span>\n<\/<\/span><\/span>script<\/span>><\/span><\/code><\/pre>\n<\/figure>\nCard token creation<\/h2>\nOnce you have installed and you set up the library, you\u2019ll need to call the OpenPay.token.create () method in order to create a token.\n\nOpenPay<\/span>.<\/span>token<\/span>.<\/span>create<\/span>(<\/span>CREATE_PARAMETERS_OBJECT<\/span>,<\/span> SUCCESS_CALLBACK<\/span>,<\/span> ERROR_CALLBACK<\/span>);<\/span><\/code><\/pre>\n<\/figure>\nThe parameters for this method are:\n\n \t- Parameter
CREATE_PARAMETERS_OBJECT<\/code> is a Javascript object containing the card information.<\/li>\n \t- Parameter
SUCCESS_CALLBACK<\/code> defines the function to be called if the operation was successful.<\/li>\n \t- Parameter
ERROR_CALLBACK<\/code> defines the function to be called if the operation failed.<\/li>\n<\/ul>\nExample of creating a token:\n\nOpenPay<\/span>.<\/span>token<\/span>.<\/span>create<\/span>({<\/span>\n \"card_number\"<\/span>:<\/span>\"4111111111111111\"<\/span>,<\/span>\n \"holder_name\"<\/span>:<\/span>\"Juan Perez Ramirez\"<\/span>,<\/span>\n \"expiration_year\"<\/span>:<\/span>\"20\"<\/span>,<\/span>\n \"expiration_month\"<\/span>:<\/span>\"12\"<\/span>