<?php$openpay=Openpay::getInstance('mzdtln0bmtms6o3kck8f','sk_e568c42a6c384b7ab02cd47d2e407cab');$customer=array('name'=>'Mario','last_name'=>'Benedetti Farrugia','phone_number'=>'1111111111','email'=>'mario_benedetti@miempresa.mx');$chargeRequest=array("method":"card",'amount'=>111,'description'=>'Cargo desde terminal virtual de 111','customer'=>$customer,'send_email'=>false,'confirm'=>false,'redirect_url'=>'http://www.openpay.mx/index.html');$charge=$openpay->charges->create($chargeRequest);?>
OpenpayAPIapi=newOpenpayAPI("https://sandbox-api.openpay.mx","sk_e568c42a6c384b7ab02cd47d2e407cab","mzdtln0bmtms6o3kck8f");Customercustomer=newCustomer();customer.setName("Mario");customer.setLastName("Benedetti Farrugia");customer.setPhoneNumber("1111111111");customer.setEmail("mario_benedetti@miempresa.mx");BigDecimalamount=newBigDecimal("111");Stringdescription="Cargo desde terminal virtual de 111";StringredirectUrl="http://www.openpay.mx/index.html";booleansendEmail=false;booleanconfirm=false;CreateCardChargeParamschargeParams=newCreateCardChargeParams().amount(amount).description(description).customer(customer).sendEmail(sendEmail).confirm(confirm).redirectUrl(redirectUrl);Chargecharge=api.charges().create(chargeParams);
OpenpayAPIapi=newOpenpayAPI("sk_e568c42a6c384b7ab02cd47d2e407cab","mzdtln0bmtms6o3kck8f");ChargeRequestrequest=newChargeRequest();Customercustomer=newCustomer();customer.Name="Mario";customer.LastName="Benedetti Farrugia";customer.PhoneNumber="1111111111";customer.Email="mario_benedetti@miempresa.mx";request.Method="card";request.Amount=newDecimal(111.00);request.Description="Cargo desde terminal virtual de 111";request.OrderId="oid-00051";request.Confirm=false;request.SendEmail=false;request.RedirectUrl="http://www.openpay.mx/index.html";request.Customer=customer;Chargecharge=api.ChargeService.Create(request);
varchargeRequest={'method':'card','amount':111,'description':'Cargo desde terminal virtual de 111','customer':{'name':'Mario','last_name':'Benedetti Farrugia','phone_number':'1111111111','email':'mario_benedetti@miempresa.mx'},'send_email':false,'confirm':false,'redirect_url':'http://www.openpay.mx/index.html')}openpay.charges.create(chargeRequest,function(error,charge){// ...});
@openpay=OpenpayApi.new("mzdtln0bmtms6o3kck8f","sk_e568c42a6c384b7ab02cd47d2e407cab")@charges=@openpay.create(:charges)customer_hash={"name"=>"Mario","last_name"=>"Benedetti Farrugia","phone_number"=>"1111111111","email"=>"mario_benedetti@miempresa.mx"}request_hash={"method"=>"card","amount"=>100.00,"description"=>"Cargo inicial a mi merchant","order_id"=>"oid-00051","customer"=>customer_hash,"send_email"=>false,"confirm"=>false,"redirect_url"=>"http://www.openpay.mx/index.html"}response_hash=@charges.create(request_hash.to_hash)
Redirect to the Openpay form
If the call is correct then a response will be returned with a transaction object. in the pending state represented in the language used.
Response:
{"id":"trq7yrthx5vc4gtjdkwg","authorization":null,"method":"card","operation_type":"in","transaction_type":"charge","status":"charge_pending","conciliated":false,"creation_date":"2016-09-09T18:52:02-05:00","operation_date":"2016-09-09T18:52:02-05:00","description":"Cargo desde terminal virtual de 111","error_message":null,"amount":111,"currency":"MXN","payment_method":{"type":"redirect","url":"https://sandbox-api.openpay.mx/v1/mexzhpxok3houd5lbvz1/charges/trq7yrthx5vc4gtjdkwg/card_capture"},"customer":{"name":"Mario","last_name":"Benedetti Farrugia","email":"mario_benedetti@miempresa.mx","phone_number":"1111111111","creation_date":"2016-09-09T18:52:02-05:00","clabe":null,"external_id":null}}
Redirect the user to the url contained in the url attribute that is inside the payment_method object.
Fill payment data
That the user fill in the requested information and click on Make payment
Click on Continue
If the payment was successful the user clicked on Continue
This redirects to the url that was provided when creating the charge (in the case of the Openpay page example), terminating the payment flow.
Notes:
You can simulate different results using the test cards
Implement Notifications to know the status of payments in real time