Update payment method

Update payment method

For this service, the following endpoint must be consumed: 

  1. 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

  1. {
  2.   "subscriptionId": "id returned when subscription was created",
  3.   "merchantId": "your merchantid",
  4.   "secret": "your secret",
  5.   "user": "Some user name",
  6.   "token": "New token to add"
  7. }
Parameters description

  1. subscriptionId: subscription id receive in response.
  2. secret: secret provided by Greenpay.
  3. merchant: merchantId provided by Greenpay.
  4. user: user who updated the payment method.
  5. token: new token.
Recommendations

The “user” parameter is to follow up the user who changes the payment method.


2. Send request to update payment method

An HTTP POST request must be sent to the update payment method endpoint, with the JSON containing the subscription data.

Once the request to update the payment method has been sent and successfully made, a JSON object is obtained in response.

When receiving this response, the expected parameter from the JSON object is the “body”, since it contains the result of the payment method update. The following code shows an example of the response received.

  1. {
  2.   "code": 200,
  3.   "status": "SUCCESS",
  4.   "result": {
  5.       "id": "3",
  6.       "merchant_id": "143b28c9-32ad-4635-8ed8-d6abfb6863a0",
  7.       "status": "ACTIVE",
  8.       "user_id": "Aaron",
  9.       "user_type": 1,
  10.       "card_tokens": [
  11.           "bf0bd94a-a4e7-4ef6-96c6-2350f3963f93"
  12.       ],
  13.       "purchase_order": {
  14.           "secret": "QUY5MzBEMkRDMzVCMDFCRDc2NzEwRjZCQjE3NjhFNkE0NjhEQ0MxRjkxQzkzMjAwNzVDNUVGNkY5RTc0N0M0NzkzNUEyQUZFQjczMEYyODEyRjJEMDc5Q0ExNTk1NTA0NjdCMkNBODg1N0Q4MzY2MjI0NEREMUVGQjk4NTcwMzg=",
  15.           "terminal": "deKokoTest-eb29-BNCR-CRC",
  16.           "description": "subscription description",
  17.           "currency": "CRC",
  18.           "initialPayment": {
  19.               "amount": 100,
  20.               "description": "some set up description"
  21.           },
  22.           "subscription": [
  23.               {
  24.                   "startDate": 1536991200000,
  25.                   "endDate": 1544853600000,
  26.                   "amount": 10,
  27.                   "cadence": {
  28.                       "mode": "EVERY",
  29.                       "unit": "MONTH",
  30.                       "every": 1,
  31.                       "day": 15
  32.                   }
  33.               }
  34.           ],
  35.           "optional": {
  36.               "key": "value",
  37.               "key1": "value1"
  38.           }
  39.       },
  40.       "next_payment": null,
  41.       "enabled": true,
  42.       "inserted_at": "2018-12-21T20:55:06.299Z",
  43.       "updated_at": "2018-12-21T22:01:11.341Z",
  44.       "general_info": {
  45.           "user": "UserBot"
  46.       }
  47.   },
  48.   "errors": []
  49. }
Below is a javascript example of the payment method endpoint update request. This function also obtains the JSON’s “body” that is received in response.

  1. var url = "https://sandbox-merchant.greenpay.me/subscriptions/update/card_token"

  2. var data = {
  3.    "subscriptionId": "b69cd5773eac06bf25a702bac02e8079",
  4.    "secret": "QUY5MzBEMkRDMzVCMDFCRDc2NzEwRjZCQjE3NjhFNkE0NjhEQ0MxRjkxQzkzMjAwNzVDNUVGNkY5RTc0N0M0NzkzNUEyQUZFQjczMEYyODEyRjJEMDc5Q0ExNTk1NTA0NjdCMkNBODg1N0Q4MzY2MjI0NEREMUVGQjk4NTcwMzg=",
  5.    "merchantId": "143b28c9-32ad-4635-8ed8-d6abfb6863a0",
  6.    "user": "UserBot",
  7.    "token": "bf0bd94a-a4e7-4ef6-96c6-2350f3963f93"
  8. }

  9. var unirest = require("unirest");

  10. var req = unirest("POST", url);

  11. req.headers({
  12.    "cache-control": "no-cache",
  13.    "Content-Type": "application/json"
  14. });

  15. req.type("json");
  16. req.send(data);

  17. req.end(function (res) {
  18.    if (res.error) throw new Error(res.error);
  19.    console.log(res.body);
  20. });
Possible errors
  • Merchant doesn't exist.

If you try to use the service with incorrect credentials, the returned response will be as the following

  1. {
  2.   "code": 500,
  3.   "status": "FAIL",
  4.   "result": [],
  5.   "errors": [
  6.       ""Merchant doesn't exist"."
  7.   ]
  8. }
2.Subscription don't exist.

If an attempt is made to update an inactive subscription or that is not in any of the states (Active, pending or on hold) the response returned will be as the following.

  1. {
  2.   "code": 500,
  3.   "status": "FAIL",
  4.   "result": [],
  5.   "errors": [
  6.       "Subscription don't exist."
  7.   ]
  8. }




    • Related Articles

    • 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 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 ...
    • Manual payment

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

      To consider A payment order is created to prepare the Greenpay API for a make a payment process. The following aspects have to be consider: Use these endpoints: Sandbox: https://sandbox-merchant.greenpay.me/ Production: https://merchant.greenpay.me/ ...
    • Webhook payment response

      1. Description If the merchant requires receiving the payments responses or card tokenization response in a backend, either to update orders, information or only store the response in the database as a backup, then they have to enable a webhook. A ...