'Laravel How to make Paypal cancel a user-signed plan
I'm doing a subscription system, and I would like that when the user upgrades or downgrades the plan, cancel the previous subscription on paypal and create a new one. It is already creating a new one, but it does not cancel the previous one. Current code:
$old_agreement = new \PayPal\Api\Agreement();
$old_agreement->setId("I-G0JJ5A9KMR--");
$agreementStateDescriptor = new \PayPal\Api\AgreementStateDescriptor();
$agreementStateDescriptor->setNote("Cancel the agreement");
try {
$old_agreement->cancel($agreementStateDescriptor, $this->_apiContext);
$cancelAgreementDetails = Agreement::get($old_agreement->getId(), $this->_apiContext);
} catch (Exception $ex) {
Log::error($ex);
}
Solution 1:[1]
You're using a deprecated SDK and an old version of PayPal Subscriptions that is not compatible with the current version of PayPal Subscriptions.
The current version of PayPal Subscriptions is not compatible with the old one, and it does not use Agreements.
It uses Products, Plans, and Subscriptions only. Subscriptions have the same I-########### format as those old agreements.
There is no SDK for the current version of PayPal Subscriptions. When implementing API calls for the current version, as desired, you must obtain an access token using the client_id and secret and do the HTTPS API calls yourself, with no server SDK.
(The current Checkout-PHP-SDK has some non-subscription PHP code that you might want to adapt and use as a base, but it has nothing specific to subscriptions.)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Preston PHX |
