1. The API only receives the value ‘EVERY’ in the mode field.
2. The API only receives the value ‘MONTH’ int the unit field.
3. The currencies supported by Greenpay are USD (US Dollar), CRC (Costa Rican Colon), GTQ (Guatemalan Quetzal).
4. If the EndDate field is not sent, the subscription will not expire.
5. If the StartDate field is not sent, the subscription starts on the day it was registered.
6. The EndDate and StartDate fields are of type timestamp.
7. Charges are made at midnight.
- If the subscription was created with startDate, it will be charged that same day. Otherwise the payment will be executed on the registration day.
2. Send subscription request
An HTTP POST request must be sent to the subscriptions endpoint with the JSON that contains the subscription data.
Once the subscription request has been sent and has been successfully completed, a JSON object is obtained in response.
Upon receiving this response, the parameter that must be obtained from the JSON object is the “body”, since it contains the subscription result.
The following code shows an example of the subscription request response:
Down payment subscription response example
- {
- "status": 200,
- "subscriptionId": "c0e6009a015df5f9600c2062b41b0a81",
- "result": {
- "success": true,
- "initialPayment": {
- "orderId": "c0e6009a015df5f9600c2062b41b0a81_0",
- "authorization": "533793",
- "errors": []
- }
- },
- "errors": [],
- "_signature": "711b346c8dac7bdcb121c1ba4a919131b879e889f979b2e239cb70ea45f2eee2812031cbcafe3de77d7841179b2d02337219f24829bcf55d8f8d5c557ed422af1b094bb82ec6baa7dd6164e0c3dc5958f6731abb951a83dfe56133640cde3b24e695630ae27d0d2b8a9cbed9e974d8607d8d974a7e3553f5d7a62b2ded78e513",
- "nextPaymentDate": "2018-10-12"
- }
Subscription response without down payment example
- {
- "status": 200,
- "subscriptionId": "f82d93dc794470f7deef4ed3ed4afe1c",
- "result": {},
- "errors": [],
- "_signature": "6a7d2f00600598d3a19ef84e08b2b160c594aef4728b10b8525228bc9de3258ac73de40ff94d0238881ce73567b53b900d8b63689a77ffbf4de92ff9f9b9ac7f67fcc29fbf9400c2b5fb953d1abb350a5d986eee2bbc60267614bd8ef415cee78453f84f27797d3671a5f6f6845d46ce5f0c454577b5ec4400a52c9a3897a31b",
- "nextPaymentDate": "2018-10-12"
- }
Below is an javascript example of the subscription request endpoint . This function also obtains the JSON object “body” that’s received in response.
Subscription service POST request example
- var req = unirest("POST", "https://sandbox-merchant.greenpay.me/subscriptions");
-
- var data = {
- "secret": "ZjAzZWZhOGU2NmFkOTQ1NTdjYjA0ODI5NTY1MTc1YWQyNTM0YzdkM2ZmYmYxNWZjNTE4ZDNkMDIxZGQ4NTc4OTZhNjRjMGI1NjZmMDQwNjI4ZDg5ZDE4NmQ1MjEyZTQ2YzM3ZTg2ZjAxYTk1NGQ4MzE0NTE4ZTU0NjcyNTQ2OTA=",
- "merchantId": "d4975982-3c5d-4abe-bde5-b1414a6c890d",
- "terminal": "Magento-BNCR-Colones",
- "userId": "Guide example",
- "description": "subscription guide example",
- "currency": "USD",
- "tokens": [
- "968212cb-7481-414c-a504-ccaf76696d08"
- ],
- "initialPayment": {
- "amount": 100,
- "description": "Guide initial payment"
- },
- "subscription": [
- {
- "startDate": 1536991200000,
- "endDate": 1544853600000,
- "amount": 10,
- "cadence": {
- "mode": "EVERY",
- "unit": "MONTH",
- "every": 1
- }
- }
- ]
- }
-
- req.headers({
- "cache-control": "no-cache",
- "Content-Type": "application/json"
- });
-
- req.type("json");
- req.send(data);
-
- req.end(function (res) {
- if (res.error) throw new Error(res.error);
-
- console.log(res.body);
- });