Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to cancel the Paypal Billing Agreement using REST API with PHP code

We have implemented "Billing Plan & Agreements" in our website as explained on http://paypal.github.io/PayPal-PHP-SDK/sample/.

We have implemented weekly recurring payment and just want to cancel the billing agreement through the API.

like image 641
Ravee Sunshine Avatar asked Feb 06 '23 03:02

Ravee Sunshine


1 Answers

You need to create a object of Agreement & AgreementStateDescriptor and using object of Agreement call the cancel() method. Below is the code example using PHP.

        $agreementId = "I-ABACAGAH";                  
        $agreement = new Agreement();            

        $agreement->setId($agreementId);
        $agreementStateDescriptor = new AgreementStateDescriptor();
        $agreementStateDescriptor->setNote("Cancel the agreement");

        try {
            $agreement->cancel($agreementStateDescriptor, $this->_apiContext);
            $cancelAgreementDetails = Agreement::get($agreement->getId(), $this->_apiContext);                
        } catch (Exception $ex) {                  
        }
like image 59
Mohd Bashir Avatar answered Feb 07 '23 17:02

Mohd Bashir