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.
- {
- "subscriptionId": "id returned when subscription was created",
- "merchantId": "your merchantid",
- "secret": "your secret",
- }
Parameters description
- subscriptionId: Identifier received in response when a subscription is created
- secret: secret provided by Greenpay.
- merchant: merchantId provided by Greenpay.
2. Send manual payment request
An HTTP POST request must be sent to the manual payment endpoint, with the JSON containing the subscription data.
Once the 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”. The following
code shows an example of the response received.
- {
- "status": "SUCCESS",
- "code": 200,
- "result": {
- "status": "approved",
- "orderStatus": "ACTIVE",
- "merchantId": "143b28c9-32ad-4635-8ed8-d6abfb6863a0",
- "order": {
- "order_reference": "9541b344c3d45d421acd454d61251cde_2",
- "subscriptionId": "9541b344c3d45d421acd454d61251cde",
- "user": "UserBot",
- "amount": 100,
- "currency": "USD",
- "date": "2018-12-11T06:00:00.000Z",
- "authorization": "533735",
- "details": "",
- "errors": [],
- "reason": "Manual payment"
- }
- }
- }
Below is a javascript example of the subscriptions manual payment endpoint request. This function also obtains the JSON’s “body” received in response.
- var unirest = require("unirest");
- var req = unirest("POST", "
- https://sandbox-merchant.greenpay.me/subscriptions/pay");
- req.headers({
- "cache-control": "no-cache",
- "Content-Type": "application/json"
- });
- req.type("json");
- req.send({
- "subscriptionId": "b69cd5773eac06bf25a702bac02e8079",
- "secret": "QUY5MzBEMkRDMzVCMDFCRDc2NzEwRjZCQjE3NjhFNkE0NjhEQ0MxRjkxQzkzMjAwNzVDNUVGNkY5RTc0N0M0NzkzNUEyQUZFQjczMEYyODEyRjJEMDc5Q0ExNTk1NTA0NjdCMkNBODg1N0Q4MzY2MjI0NEREMUVGQjk4NTcwMzg=",
- "merchantId": "143b28c9-32ad-4635-8ed8-d6abfb6863a0"
- });
- req.end(function (res) {
- if (res.error) throw new Error(res.error);
- console.log(res.body);
- });
- req.headers({
- "cache-control": "no-cache",
- "Content-Type": "application/json"
- });
- req.type("json");
- req.send({
- "subscriptionId": "b69cd5773eac06bf25a702bac02e8079",
- "secret": "QUY5MzBEMkRDMzVCMDFCRDc2NzEwRjZCQjE3NjhFNkE0NjhEQ0MxRjkxQzkzMjAwNzVDNUVGNkY5RTc0N0M0NzkzNUEyQUZFQjczMEYyODEyRjJEMDc5Q0ExNTk1NTA0NjdCMkNBODg1N0Q4MzY2MjI0NEREMUVGQjk4NTcwMzg=",
- "merchantId": "143b28c9-32ad-4635-8ed8-d6abfb6863a0"
- });
- req.end(function (res) {
- if (res.error) throw new Error(res.error);
- console.log(res.body);
- });
3. Possible errors
- Merchant doesn't exist
When trying to update a subscription with invalid credentials, the response returned will be the following.
Invalid credentials - response example
- {
- "code": 500,
- "status": "FAIL",
- "result": [],
- "errors": [
- ""Merchant doesn't exist"."
- ]
- }
- Subscription not found. Impossible to manually pay.
When trying to manually pay for an inactive subscription or in the On Hold state, the response returned will be the following
Subscription not found response example
- {
- "code": 500,
- "status": "FAIL",
- "result": [],
- "errors": [
- "Subscription not found. Impossible to manually pay."
- ]
- }