Tokenize (encrypt and store) the card information

Sensitive card information must be tokenized from the front end of your website for security reasons.

Step 1

Add conekta.js to your site.

  • Note: jQuery is not not required to use conekta.js and is used in this tutorial for practicality.
  • Our frontend library conekta.js only tokenizes the cards.

If you are building an app, please tokenize card information using one of our SDKs: Android, iOS o Xamarin.

Conekta.js Response Objects

  • Token object: the object we return when the card is tokenized with success.
  • Error object: the object we return when something goes wrong.

Step 1.1

Add your tokenization script.

Definitions

  • Conekta.setPublicKey() adds your public key to allow the card tokenization.
  • conektaSuccessResponseHandler returns the token object when the call is successful.
  • conektaErrorResponseHandler returns the error object when the call goes wrong.
  • Conekta.Token.create() sends the info to our server.

Tokens can only be used once and unused tokens will expire in one hour.

Step 1.2

Add the card form to your site.

Conekta.js collects card info using the data-attributes of your form but if you prefer, you can capture card information yourself. See conekta.js for more details.

Create a customer and generate a payment

Step 2

Initialize your Conekta client by adding your private key and API version

If you don't already have your private key, you can get it here.

Step 2.1

Create a customer and add payment information

When you create a customer with the information of your client and with the previously generated ConektaJS token, you will be able to retry charges and make recurrent charges, as long as you have your customer's consent.

A customer can have many payment_sources but only one can be the default.

Change the default payment method of your customer

The example shows the minimum set of attributes required, if you want to know more about the customer object, review our REST API.

Step 2.2

Charge an order

Creating an ordergenerates a charge to your client. If you do not want to charge immediately, you can generate an order without a charge. Once you are ready to charge your customer simply update the order and add the charges array information.

It is important that all information sent to Conekta be correct as it will be used by our antifraud system to approve payments. Incorrect information will decrease decision accuracy and lead to lower acceptance rates and/or higher chargeback rates.

The fields shown in the example are the minimum set of attributes required. If you want to improve the speed of your transaction you will need to know more about the order object, to do this review our REST API.

Step 2.3

Process the response

You will receive a JSON object with a lot of information, you can choose to show only the fields you deem necessary.

Conekta recommends that you notify your user via email.

That's it! Please remember to exchange your sandbox keys for the production keys.

Sometimes your client's selected payment method will not process the charge, if so, offer your client the option to try with another payment source.

Try with another card

You will need the payment_source_id in order to process the charge with a non-default payment source.

Offline retry

We recommend that you suggest another payment method, such as Oxxo Pay or SPEI, after more than 2 failed card attempts.