PayPal – Cancel Pre-approved Payment using API and PA key

Quetion:
How would I cancel a pre-approved payment using PayPal’s API operations? I have the Pre-approval key of the payment to be cancelled but I can’t find a way to do it.
I did some digging over the internet and found this CancelPreapproval API Operation but that document is not very helping for a starter like me. Few things are missing like what would be the link where I’d send the cancel request? Can’t find any example. Need help.

I did tried cancelling the payment by using this code but it fails.

$security_user_id = $neworder->security_user_id;
$security_password = $neworder->security_password;
$security_signature = $neworder->security_signature;
$security_application_id = $neworder->security_application_id;

$headers_array = array("X-PAYPAL-SECURITY-USERID" => $security_user_id,
    "X-PAYPAL-SECURITY-PASSWORD" => $security_password,
    "X-PAYPAL-SECURITY-SIGNATURE" => $security_signature,
    "X-PAYPAL-APPLICATION-ID" => $security_application_id,
    "X-PAYPAL-REQUEST-DATA-FORMAT" => "NV",
    "X-PAYPAL-RESPONSE-DATA-FORMAT" => "JSON",
);

    $pay_result = wp_remote_request('https://svcs.sandbox.paypal.com/AdaptivePayments/Preapproval', array('method' => 'POST', 'timeout' => 20, 'headers' => $headers_array, 'body' => $maincode));

Related posts

1 comment

  1. This PayPal PHP SDK will make it very quick and easy for you. Just extract it into your project structure as you would any other class, and make sure to setup the config file correctly with your own sandbox and/or live PayPal credentials.

    Then you can look in the /templates and you’ll see a CancelPreapproval.php setup and ready to go. It’ll be fully functional. All you’ll have to do is plug in your preapproval key and it’ll handle the rest for you successfully.

    There are lots of /samples and there is a file in /templates for pretty much every API call PayPal has.

    You can get this done within minutes using that class. Let me know if you have any specific questions about it.

Comments are closed.