Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Paypal Rest api: How to delete a billing plan?

Tags:

paypal

The paypal developer documentation explains the steps to create and activate a Billing plan.

Is there a way to delete a billing plan?

like image 796
Matthias Avatar asked Nov 29 '22 01:11

Matthias


2 Answers

An alternative way of deleting a BillingPlan (as per the original question) is to submit a patch request. Unfortunately this isn't too clear from looking at the API docs: https://developer.paypal.com/docs/api/payments.billing-plans/#plan_update

You want to patch the state of the BillingPlan into DELETED:

[
    {
        "path": "/",
        "value": {
            "state": "DELETED"
        },
        "op": "replace"
    }
]

Once patched, the deleted plan no longer shows up when you list all available plans via /v1/payments/billing-plans

like image 125
smiling_warrior Avatar answered Nov 30 '22 13:11

smiling_warrior


There is a way to DELETE a Billing Plan.

If you see the samples in the REST-PHP-SDK, there is a file named DeletePlan.php which has the code to delete the billing plan.

It goes something like this:

$createdPlan = require 'CreatePlan.php';

use PayPal\Api\Plan;

try {
    $result = $createdPlan->delete($apiContext);
} catch (Exception $ex) {
    ResultPrinter::printError("Deleted a Plan", "Plan", $createdPlan->getId(), null, $ex);
    exit(1);
}

ResultPrinter::printResult("Deleted a Plan", "Plan", $createdPlan->getId(), null, null);

return $createdPlan;

This worked for me. Hope this helps.

like image 37
maxxon15 Avatar answered Nov 30 '22 15:11

maxxon15