3
votes

I'm using Paypal REST api (java) to perform recurring subscription.

The flow looks like this, and it is working:

  • I created a Plan (ok)
  • I activated a Plan (ok)
  • I created an Agreement (ok)
  • I redirect user to Paypal using the approval link (ok)
  • Paypal redirects user back to my site (ok)
  • I can execute agreement (ok)

I find out that as a buyer, I can login on paypal and manually cancel an agreement anytime.

The problem:

As a seller, I can see that buyer x canceled his agreement in 'profile > recurring payment dashboard', but how can I query this information with code? Assuming I have the Agreement Id. There is no such information giving inside the Agreement object.

Please point me in the right direction. Thank you

UPDATE:

My Agreement Object looks like this:

{
  "id": "I-HLK83FVHB5X2",
  "description": "item name goes here",
  "start_date": "2014-12-04T05:00:00Z",
  "plan": {
    "payment_definitions": [
      {
        "type": "TRIAL",
        "frequency_interval": "3",
        "frequency": "Month",
        "cycles": "1",
        "amount": {
          "currency": "CAD",
          "value": "900.00"
        },
        "charge_models": [
          {
            "type": "TAX",
            "amount": {
              "currency": "CAD",
              "value": "11.11"
            }
          },
          {
            "type": "SHIPPING",
            "amount": {
              "currency": "CAD",
              "value": "0.00"
            }
          }
        ]
      },
      {
        "type": "REGULAR",
        "frequency_interval": "1",
        "frequency": "Month",
        "cycles": "0",
        "amount": {
          "currency": "CAD",
          "value": "300.00"
        },
        "charge_models": [
          {
            "type": "TAX",
            "amount": {
              "currency": "CAD",
              "value": "22.22"
            }
          },
          {
            "type": "SHIPPING",
            "amount": {
              "currency": "CAD",
              "value": "0.00"
            }
          }
        ]
      }
    ],
    "merchant_preferences": {
      "setup_fee": {
        "currency": "CAD",
        "value": "0.00"
      },
      "max_fail_attempts": "0",
      "auto_bill_amount": "YES"
    }
  },
  "links": [
    {
      "href": "https://api.sandbox.paypal.com/v1/payments/billing-agreements/I-HLK83FVHB5X2/suspend",
      "rel": "suspend",
      "method": "POST"
    },
    {
      "href": "https://api.sandbox.paypal.com/v1/payments/billing-agreements/I-HLK83FVHB5X2/re-activate",
      "rel": "re_activate",
      "method": "POST"
    },
    {
      "href": "https://api.sandbox.paypal.com/v1/payments/billing-agreements/I-HLK83FVHB5X2/cancel",
      "rel": "cancel",
      "method": "POST"
    },
    {
      "href": "https://api.sandbox.paypal.com/v1/payments/billing-agreements/I-HLK83FVHB5X2/bill-balance",
      "rel": "self",
      "method": "POST"
    },
    {
      "href": "https://api.sandbox.paypal.com/v1/payments/billing-agreements/I-HLK83FVHB5X2/set-balance",
      "rel": "self",
      "method": "POST"
    }
  ]
}
1

1 Answers

1
votes

You have two options 1: Setup for receiving Paypal IPN (instant payment notification) so that they will notify you if agreement got canceled.

2: You can always retrieve agreement details as mentioned in https://developer.paypal.com/docs/api/#retrieve-an-agreement It will give you response like this

        {
        "id": "I-0LN988D3JACS",
        "state": "Pending",
        "description": "New Description",
        "plan": {
        "payment_definitions": [
          {
            "type": "REGULAR",
            "frequency": "Month",
            "amount": {
              "currency": "USD",
              "value": "100.00"
            },
            "charge_models": [
              {
                "type": "TAX",
                "amount": {
                  "currency": "USD",
                  "value": "12.00"
                }
              },
              {
                "type": "SHIPPING",
                "amount": {
                  "currency": "USD",
                  "value": "10.00"
                }
              }
            ],
            "cycles": "12",
            "frequency_interval": "2"
          }
        ],
        "merchant_preferences": {
          "setup_fee": {
            "currency": "USD",
            "value": "0.00"
          },
          "max_fail_attempts": "0",
          "auto_bill_amount": "YES"
        }
        },
        "links": [
        {
          "href": "https://api.sandbox.paypal.com/v1/payments/billing-agreements/I-0LN988D3JACS/suspend",
          "rel": "suspend",
          "method": "POST"
        },
        {
          "href": "https://api.sandbox.paypal.com/v1/payments/billing-agreements/I-0LN988D3JACS/re-activate",
          "rel": "re_activate",
          "method": "POST"
        },
        {
          "href": "https://api.sandbox.paypal.com/v1/payments/billing-agreements/I-0LN988D3JACS/cancel",
          "rel": "cancel",
          "method": "POST"
        },
        {
          "href": "https://api.sandbox.paypal.com/v1/payments/billing-agreements/I-0LN988D3JACS/bill-balance",
          "rel": "self",
          "method": "POST"
        },
        {
          "href": "https://api.sandbox.paypal.com/v1/payments/billing-agreements/I-0LN988D3JACS/set-balance",
          "rel": "self",
          "method": "POST"
        }
        ],
        "start_date": "2015-02-19T08:00:00Z",
        "agreement_details": {
        "outstanding_balance": {
          "currency": "USD",
          "value": "0.00"
        },
        "cycles_remaining": "12",
        "cycles_completed": "0",
        "final_payment_date": "2016-12-19T10:00:00Z",
        "failed_payment_count": "0"
        }
        }