Learn what's new with PayPal Subscriptions

not_here
Moderator
Moderator

The new PayPal Subscriptions includes:

Read all about these new features in our blog, PayPal Presents the New Subscriptions Experience today. 

 

Want to learn more? Check out our: 

 

Login to Me Too
6 REPLIES 6

sandsh1234567
Contributor
Contributor

I am looking for a plug and play solution to enable subscriptions on my website. Can you guys please guide me through it? thanks.

Login to Me Too

synagen
Contributor
Contributor

Hi. What sort of functionality do you need? The answer will depend on the level of flexibility you need. Creating subscriptions in Paypal is quite simple, but if you need your system to programmatically alter them, that's a major challenge. On our website, https://calltaker.co, we have implemented 4 different subscription plans, where the customer chooses the plan they want, and then the customer's subscription gets created by the system automatically, with the actual monthly fee dependent on the number of registered users they have (i.e., "per seat" billing). The only action the customer needs to do is to log into Paypal and authorise the subscription.

Login to Me Too

synagen
Contributor
Contributor

Has anyone been able to get quantity updating on quantity-based subscriptions working with PHP? I've spent months trying to get it working. I've tried the raw CURL code, as per the developer docs and returned "PAYMENT_IN_PROGRESS" error. When using the PHP libraries, I get a 204 (no content) response and the subscription is not changed.

CURL code:

curl -v -X POST https://api-m.paypal.com/v1/billing/subscriptions/I-4PAEKHKDNA81/revise -H "Content-Type: application/json" -H "Authorization: Basic base64_encode($paypal_client_id.':'.$paypal_secret)" -d '{"quantity":"5"}' 
(the base64 stuff is just showing how I used PHP to create a base64 version of client_id:client_secret for inserting into the CURL command)

 

PHP code:

 <?php

namespace PayPal\Api;
require '/opt/bitnami/php/bin/vendor/autoload.php';
use PayPalCheckoutSdk\Orders\OrdersPatchRequest;
use PayPalCheckoutSdk\Orders\OrdersGetRequest;
use PayPalCheckoutSdk\Orders\OrdersCreateRequest;
use PayPalCheckoutSdk\Core\PayPalHttpClient;
use PayPalCheckoutSdk\Core\ProductionEnvironment;
include('globals.php'); // defines Paypal client_id, client_secret, etc.
$subscrID ='I-YT07M8NCEMRN'; // hard coded for test
ini_set('error_reporting', E_ALL); // or error_reporting(E_ALL);
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');

$environment=new ProductionEnvironment($paypal_client_id, $paypal_secret);
$client = new PayPalHttpClient($environment);
$request = new OrdersCreateRequest();
$request->prefer("return=representation");
$request->body =[
"intent" => "CAPTURE",
"purchase_units" => [[
"reference_id" => $subscrID,
"amount" => [
"value" => "1.77",
"currency_code" => "USD"
]
]],
"redirect_urls" => [
"cancel_url" => "https://calltaker.co/cancel",
"return_url" => "https://calltaker.co/return"
]
];
$createdOrder = $client->execute($request);
$request2 = new OrdersPatchRequest($createdOrder->result->id);
$request2->body = [
0=>[
"op" => "add",
"path" => "/purchase_units/@reference_id=='$subscrID'/description",
"value" => "3 user license"
],
1=>[
"op" => "replace",
"path" => "/purchase_units/@reference_id=='$subscrID'/amount",
"resource"=>[
"quantity"=>"3"
],
"value" => [
"currency_code" => "USD",
"value" => "1.56",
"quantity" => "3"
]
]
];
try {
// Call API with your client and get a response for your call
$response2 = $client->execute($request2);

// If call returns body in response, you can get the deserialized version from the result attribute of the response
print_r($response2);
}catch (HttpException $ex) {
echo $ex->statusCode;
print_r($ex->getMessage());
}
$space4='&nbsp; &nbsp; &nbsp; &nbsp; ';
foreach($response2 as $key=>$value)
{
print "$key = ";
if (is_array($value)) {
print "(array):<BR>";
foreach($value as $key2=>$value2) {
print $space4.$key2."=";
if (is_array($value2)) {
print "(array):<BR>";
foreach($value2 as $key3=>$value3) print $space4.$space4."$key3=$value3<BR>";
}
else print "$value2<BR>";
}
}
else print "$value<BR>";
}

?>

Login to Me Too

pabloapico
Contributor
Contributor

It appears that quanitity updates do not work for subscriptions API
I followed the documentation and it just does not work

Login to Me Too

AdamGreen
Contributor
Contributor

hi! very strange, but it worked for me

Login to Me Too

AdamGreen
Contributor
Contributor

 

 

"reference_id" => $subscrID, 

"amount" => [ "value" => "1.77", 

"currency_code" => "USD" ] ]], 

"redirect_urls" => [ "cancel_url" => "https://calltaker.co/return", 

"return_url" => "https://calltaker.co/return"

 

 

here you need to make changes according to your example and everything will work out. Try it. If not, contact the experts from [removed], they will help you. 

Login to Me Too

Haven't Found your Answer?

It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.