Home is for the experience. Projects are for the ones who are interested!

How To Update Merchant Preferences In Paypal Billing Plan PHP

How To Update Merchant Preferences In Paypal Billing Plan PHP

In this tutorial I will show you how to update merchang preferences in paypal billing plan, even if there are a lot of tutorials and paypal's documentaiton is pretty good, they have some issues already opened on gitrhub from last years and it seems nobody solve them, so if you want to implement some functions in your application you need to find workarounds. The last issue I found at their API is that you can't get the billing plan id from agreement after you create them and return the user to the website. I can get plan from agreement, but billing plang object does not nhave the id within, so when I call getId() it returns NULL.

So, now, I need to pass the plan id to the return url and when user comes back on website I will be able to get the plan id from url with $_get. To do that I need to change marchant preferences object, because return_url is in it. To change the return url you need to use the following bunch of code:

$patch = new Patch();				
$value = new PayPalModel('{"return_url":"'.$successURL.'"}');  
$patch->setOp('replace')
   ->setPath('/merchant_preferences')
   ->setValue($value);
$patchRequest = new PatchRequest();
$patchRequest->addPatch($patch);
$output->update($patchRequest, $apiContext);
$plan = Plan::get($output->getId(), $apiContext);

You will have to change $successsURL var with your own, you can pass how many parameters you want, and then, after the user will be redirected back to the website you will be able to get all these parameters from url with $_get. Until the issue with getId() from agreement will be solve by their team, I hope this method will work. Let me know how this method is working for you.

Leave a Reply

Your email address will not be published. Required fields are marked *