List subscriptions

List subscriptions

For this service the following endpoint must be consumed:
  1. https://sandbox-merchant.greenpay.me/subscriptions/list

Below is the step by step to list subscriptions in our API


1. Create the JSON object to be sent


JSON object structure example
  1. {
  2.     "merchantId": "merchantId provisto por GreenPay en el archivo de las credenciales",
  3.     "secret": "secret provisto por GreenPay en el archivo de las credenciales",
  4.     "pageSize": 25,
  5.     "page": 1,
  6.     "filters": {
  7.         "status": [
  8.             "ON_HOLD", "PENDING", "CANCELED"
  9.         ],
  10.         "user": "userId registrado cuando se creó la suscripción",
  11.         "minAmount": 0, //Mayor que cero
  12.         "maxAmount": 0, //Mayor que cero
  13.         "subsDate": "2019-06-20T06:00:51.582Z" //Timestamp de la fecha en que se creó la suscripción
  14.     }
  15. }
All parameters in the “filters” field are optional. That’s because if they don’t send the filters field, the service lists all the created merchant subscriptions, if it sends the filters it can list 1 or more according to the parameters allowed by the API.

Parameters description
  1. secret: secret provided by Greenpay.
  2. merchant: merchantId provided by Greenpay.
  3. pageSize: number of records that the service must return
  4. page: page that must return the service.

Recommendations
  1. The parameter “page” must be a number greater than zero
  1. The parameter “pageSize” must be a number between one and one hundred.

2. Send request


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

Once the  list subscriptions request 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 list subscriptions. The following code shows an example of the response received.

  1. {
  2.     "status": "SUCCESS",
  3.     "code": 200,
  4.     "result": {
  5.         "entries": [
  6.             {
  7.                 "id": "5625d026579f64b63f250631220f8836",
  8.                 "status": "NOT_PAID",
  9.                 "user_id": "Aaron",
  10.                 "description": "subscription description",
  11.                 "currency": "CRC",
  12.                 "amount": "10",
  13.                 "startdate": "1536991200000",
  14.                 "enddate": "1544853600000",
  15.                 "cadence": "EVERY 1 MONTH",
  16.                 "next_payment_date": "2019-01-15T00:00:00.000Z"
  17.             },
  18.             {
  19.                 "id": "2d374b16dfc4937a7429cbd73636f7ba",
  20.                 "status": "NOT_PAID",
  21.                 "user_id": "Aaron",
  22.                 "description": "subscription description",
  23.                 "currency": "CRC",
  24.                 "amount": "10",
  25.                 "startdate": "1536991200000",
  26.                 "enddate": "1544853600000",
  27.                 "cadence": "EVERY 15 DAY",
  28.               "next_payment_date": "2019-01-27T00:00:00.000Z"
  29.             }
  30.         ],
  31.         "page": 1,
  32.         "totalEntries": 15,
  33.         "totalPages": 1
  34.     },
  35.     "errors": []
  36. }
Below is a javascript example of the list subscriptions endpoint request. This function also obtains the JSON’s “body” that is received in response.
  1. var unirest = require("unirest");

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

  3. req.headers({
  4.  "Postman-Token": "93d00f6a-5af4-4dd1-b540-5b705107b615",
  5.  "cache-control": "no-cache",
  6.  "Content-Type": "application/json"
  7. });

  8. req.type("json");
  9. req.send({
  10.  "secret": "QUY5MzBEMkRDMzVCMDFCRDc2NzEwRjZCQjE3NjhFNkE0NjhEQ0MxRjkxQzkzMjAwNzVDNUVGNkY5RTc0N0M0NzkzNUEyQUZFQjczMEYyODEyRjJEMDc5Q0ExNTk1NTA0NjdCMkNBODg1N0Q4MzY2MjI0NEREMUVGQjk4NTcwMzg=",
  11.  "merchantId": "143b28c9-32ad-4635-8ed8-d6abfb6863a0",
  12.  "pageSize": 100,
  13.  "page": 1
  14. });

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

  17.  console.log(res.body);
  18. });
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. }
  • Bad request, check params

If you try to use the service by sending unaccepted values in the pageSize and page parameters, the returned will be as the following.

  1. {
  2.    "status": "FAIL",
  3.    "code": 400,
  4.    "result": [],
  5.    "errors": [
  6.        "Bad request, check params"
  7.    ]
  8. }


    • Related Articles

    • List payment subscriptions

      For this service the following endpoint must be consumed:  https://sandbox-merchant.greenpay.me/subscriptions/list/payments Below is the step by step to list payment subscriptions in our API: 1. Create the JSON object to be sent JSON structure ...
    • 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 ...
    • General information - plugins

       Greenpay offers the possibility to integrate the checkout service on Magento 1.9 and Wordpress platforms through plugins. The functionalities provided by each plugin are the following:  Magento Checkout web form Wordpress Checkout web form ...
    • Woocommerce plugin

      To consider Before adding our plugin, you must make sure you have the WooCommerce activated on the WordPress platform. Steps for using the service 1. Wordpress Enter your Wordpress store as an “administrator” user. Select “Plugins --> add new” from ...
    • Create subscription

      For this service, the following endpoint must be consumed:  https://sandbox-merchant.greenpay.me/subscriptions Step by step to successfully create a subscription in our API : 1. Create the JSON object to be sent It must contain the following ...