cancel
Showing results for 
Search instead for 
Did you mean: 

Learn what's new with PayPal Subscriptions

Options
MTS_Christina
Moderator
Posted on

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: 

 

3 REPLIES 3

Learn what's new with PayPal Subscriptions

Options
sandsh1234567
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.

Learn what's new with PayPal Subscriptions

Options
synagen
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.

Learn what's new with PayPal Subscriptions

Options
synagen
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>";
}

?>

Haven't Found your Answer?

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