Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you cancel a PayPal subscription through their api?

Tags:

paypal

On this page: Handling Recurring Payments

It says that it's possible to cancel a PayPal subscription using their API. Knowing the SubscriptionId can anyone give me some code example how to do this?

At the moment I do it manually which is a pain (I log into my PayPal account, find the subscription and cancel it).

I would like to automate this process basically.

like image 330
Anthony Avatar asked Nov 29 '25 00:11

Anthony


1 Answers

In perl it could be something like this:

#!/usr/bin/perl

use strict;
use LWP::UserAgent;

# Set values for $paypal_api_user, $paypal_api_pwd and 
# $paypal_api_signature from your paypal's profile
my $paypal_api_user = '....';
my $paypal_api_pwd  = '.....';
my $paypal_api_signature = '.....';

# Set subscription id
my $subscr_id = '....';

my $params = {
  'USER' => $paypal_api_user,
  'PWD' => $paypal_api_pwd,
  'SIGNATURE' => $paypal_api_signature,
  'VERSION' => '84.0',
  'METHOD' => 'ManageRecurringPaymentsProfileStatus',
  'PROFILEID' => $subscr_id,
  'ACTION' => 'Cancel',
};
my $ua = LWP::UserAgent->new();

my $res = $ua->post('https://api-3t.paypal.com/nvp', $params);

if ($res->is_error()) {
  # HTTP error
} else {
  # Success
}
like image 131
Alexey Avatar answered Dec 01 '25 07:12

Alexey



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!