Update token using webform

Update token using webform

To consider

To use the card tokenization form, the following aspects should be considered:
  1. The form is available at:
    1. Sandbox: http://sandbox-tokenizeform.greenpay.me/
    2. Producción: https://tokenizeform.greenpay.me/
  2. Get a session and token of a valid tokenization order (A session and token is valid within 30 minutes from the creation of the order) and include de callback param. In order to create session, token and include callback, you can check this article Create a tokenization order.
  3. The card tokenization form is only available for web apps.


Step to update card data

1. Redirect to the tokenization form

After receiving the tokenization order response (session and token), redirect to the tokenization form from the merchant site, this way:
  1. Generate the session and token in sandbox or live according to the environment.
  2. Get the card token to update, stored in database.
  3. Create de url, this way:
    1. Sandbox: http://sandbox-tokenizeform.greenpay.me/{{session}}?{{card_token}}
    2. Production: https://tokenizeform.greenpay.me/{{session}?{{card_token}}
The following is a javascript example to redirect.



const express = require("express");
const app = express();
const tokenToUpdate = "5eb37ba3-f439-4401-8d5e-4d9302c2ccc9"
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
extended: true
}));
app.get("/order", async function (req, res)
{
try {
const security = await postOrder(order);
res.redirect(`https://sandbox-tokenizeform.greenpay.me/${{security.session}}?${{tokenToUpdate}}`)
} catch (err) {
res.send(err);
}
})


When the redirection is done, the following form have to appear with the card data associate to the token.




2. Capture form response

Once the user has completed the form fields and the data is processed, the form is going to redirect to callback URL with the answer in base64 format, this way: callbackURL/base64Response.



In the callback URL destination a function must exist to capture the base64 response and decode it. The following is a javascript example to capture the response.


app.get("/callback/:data", async function (req, res) {
try {
//get the response in base64
const data = req.params.data;

//decode the response in base64
var responsejson = Buffer.from(data, 'base64').toString();
console.log(responsejson);
res.send(JSON.parse(responsejson));
} catch (err) {
res.send(err);
}
});


The following is a response example decoded.


  1. {
  2.     "status": 201,
  3.     "requestId": 1,
  4.     "result": {
  5.         "token": "fb3d1a7b-9cb1-45b7-b49d-b2a3efd98371",
  6.         "last_digits": "7777",
  7.         "bin": "477777"
  8.     },
  9.     "expiration_date": "2109",
  10.     "brand": "Visa",
  11.     "nickname": "Visa",
  12.     "errors": [],
  13.     "callback": "http://localhost:3000/callback",
  14.     "_signature": "5005b0d596e607825ea4385d....f60c35bbbd9dcd44431100"
  15. }

3. Charge a card token

In order to charge a card token check this article.


    • Related Articles

    • Update card token

      To consider To invoke the payments api, the following aspects should be considered: Use the service on the endpoints: Sandbox: https://sandbox-checkout.greenpay.me/tokenize/update Production: https://checkout.greenpay.me/tokenize/update Get ...
    • Update amount

      For this service, the following endpoint must be consumed:  https://sandbox-merchant.greenpay.me/subscriptions/update Step by step to update a subscritpion amount in our API 1. Create a JSON object  JSON structure example {   "subscriptionId": "id ...
    • Update payment method

      For this service, the following endpoint must be consumed:  https://sandbox-merchant.greenpay.me/subscriptions/update/card_token Step by step to update a payment method in our API: 1. Create the JSON object to be sent JSON structure example {   ...
    • Webform payment process

      To consider To use the card payment form, the following aspects should be considered: The form is available at: Sandbox: https://sandbox-checkoutform.greenpay.me/ Producción: https://checkout-form.greenpay.me/ Get a session and token of a valid ...
    • Delete card token

      To consider To use this service, the following aspect should be considered: Use the service on the endpoints: Sandbox: https://sandbox-merchant.greenpay.me/deleteToken Production: https://merchant.greenpay.me/deleteToken Tokens registered in Greenpay ...