Update amount

Update amount

For this service, the following endpoint must be consumed: 

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

  1. {
  2.   "subscriptionId": "id returned when subscription was created",
  3.   "merchantId": "your merchantid",
  4.   "secret": "your secret",
  5.   "user": "Some user name",
  6.   "amount": 100
  7. }
Parameters
  1. subscriptionId: Identifier received in the create subscription response.
  2. secret: secret provided by Greenpay.
  3. merchant: merchant provided by Greenpay.
  4. user: user who will update the subscription.
  5. amount: amount for which the subscription will be updated.
Recommendations

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


2. Send update amount request 


An HTTP POST request must be sent to the change amount endpoint, with the JSON containing the subscription data.

Once the request to update the amount 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 subscription amount update. The following code shows an example of the response received. 


Succesfully response example
  1. {
  2.   "status": "SUCCESS",
  3.   "code": 200,
  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.           "currency": "CRC",
  16.           "optional": {
  17.               "key": "value",
  18.               "key1": "value1"
  19.           },
  20.           "terminal": "deKokoTest-eb29-BNCR-CRC",
  21.           "description": "subscription description",
  22.           "subscription": [
  23.               {
  24.                   "amount": 5500.99,
  25.                   "cadence": {
  26.                       "day": 15,
  27.                       "mode": "EVERY",
  28.                       "unit": "MONTH",
  29.                       "every": 1
  30.                   },
  31.                   "endDate": 1544853600000,
  32.                   "startDate": 1536991200000
  33.               }
  34.           ],
  35.           "initialPayment": {
  36.               "amount": 100,
  37.               "description": "some set up description"
  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 subscriptions endpoint update request. This function also obtains the JSON’s “body” that is received in response. 

Request code example
  1. var unirest = require("unirest");

  2. var req = unirest("POST", "https://sandbox-merchant.greenpay.me/subscriptions/update");

  3. req.headers({
  4.    "Postman-Token": "bc6f3d94-d5b0-4b76-afc8-4e13b08f576f",
  5.    "cache-control": "no-cache",
  6.    "Content-Type": "application/json"
  7. });

  8. req.type("json");
  9. req.send({
  10.    "subscriptionId": "f39a928e9c1f1fa32f30e1de1df35656",
  11.    "secret": "QUY5MzBEMkRDMzVCMDFCRDc2NzEwRjZCQjE3NjhFNkE0NjhEQ0MxRjkxQzkzMjAwNzVDNUVGNkY5RTc0N0M0NzkzNUEyQUZFQjczMEYyODEyRjJEMDc5Q0ExNTk1NTA0NjdCMkNBODg1N0Q4MzY2MjI0NEREMUVGQjk4NTcwMzg=",
  12.    "merchantId": "143b28c9-32ad-4635-8ed8-d6abfb6863a0",
  13.    "user": "User Bot",
  14.    "amount": 5500.99
  15. });

  16. req.end(function (res) {
  17.    if (res.error) throw new Error(res.error);

  18.    console.log(res.body);
  19. });
3. Possible errors 
  1. Merchant doesn't exist
When trying to update a subscription with invalid credentials, the response returned will the following. 

Invalid credentials - response example

  1. {
  2.   "code": 500,
  3.   "status": "FAIL",
  4.   "result": [],
  5.   "errors": [
  6.       ""Merchant doesn't exist"."
  7.   ]
  8. }
    • Subscription not found. Update amount is not possible.

    When trying to update an inactive or pending payment subscription, the response returned will be as the following: 


    Subscription not found response example
    1. {
    2.   "code": 500,
    3.   "status": "FAIL",
    4.   "result": [],
    5.   "errors": [
    6.       "Subscription not found. Impossible to pay manually."
    7.   ]
    8. }

      • Related Articles

      • 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 {   ...
      • 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 token using webform

        To consider To use the card tokenization form, the following aspects should be considered: The form is available at: Sandbox: http://sandbox-tokenizeform.greenpay.me/ Producción: https://tokenizeform.greenpay.me/ Get a session and token of a valid ...
      • Subscription service - General information

        This service allow merchants to subscribe their customers to automatic collections in a set time window. This functionality only allows subscription monthly payments. It will be deducted from the customer’s card every month, while the subscription is ...
      • Get responses on a webhook

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