GET list of billing agreements using Paypal REST api - mongodb

I am working with the relatively new Paypal REST api and have successfully been able to create billing plans, approve billing plans, get a list of my billing plans, create billing-agreements (subscriptions), execute billing-agreements, and find specific billing-agreements.
I would like to be able to retrieve (GET) a list of billing-agreements, similar to how I can get a lit of billing-plans. This is not shown in the documentation as being available. Does anyone know of a way of doing this? Since there is no webHook available for subscription cancellations (or any subscription events) and no way to get a list of agreements, this leaves developers with no efficient way to handle cancellations (especially since users can cancel via Paypal without visiting the site). My current method/plan to handle this is to loop through all subscriptions that I have stored in my MongoDB (I store them when they are executed successfully), and send a request to Paypal for that specific agreement. I check its 'state' and update my MongoDB if they don't match.
There must be a better way.

I had the same problem, my first solution was almost identical to yours: I query the state of agreement upon user login and update the state in my db accordingly.
Later, I start to use IPN as my solution as suggested in this github comment by Tony: https://github.com/paypal/PayPal-Python-SDK/issues/69#issuecomment-69647946

Related

Fetching new PayPal transactions for a Personal Account

I own a personal PayPal account and am coming up with the design for a personal financing application. I intend to use the APIs provided by PayPal to fetch recent activity on my account to automate some of the information entry (at the moment, most of my transactions go through PayPal).
I've rooted through the API documentation, and I haven't been able to find any sort of endpoint I could use to fetch my recent account history.
I did find a question previously asked and answered about two years ago stating that the only way to do this was by getting a Premier account, which I'd rather avoid due to not knowing if there's any costs associated with such. I'd also like to note that despite my Personal status, I still get notifications on my Android phone stating that I've spent money.
Which brings me to the title question: does PayPal's API expose some endpoint I missed that allows me (the user) to programmatically browse my history, find new transactions, and mark them down with little input from me, or at the very least register to receive notice from PayPal that a new transaction has appeared?
You can pull transaction history using the TransactionSearch API. Then you can get individual transaction details using GetTransactionDetails.
You may also want to look into IPN, which will automatically POST transaction data to a URL you specify as a listener. That listener can receiver the data from PayPal and update your own database, send custom email notifications, hit 3rd party web services, etc.

Paypal Rest API vs Classic Sdk

I am working with paypal first time.
I have a product and I want to integrate paypal with it.
I want to achieve the following tasks :
Client comes to my website and select a plan,which is a monthly recurring plan.
Then client is redirected to Paypal for payment.
Client makes payment.
Return backs to home page.
I have gone through the documentation of paypal and I have the following questions.
What should I use REST API or Classic Sdk, as I want to create Recurring Profile,Work with EXPRESS-CHECKOUT and REFERENCE TRANSACTIONS.
I have customers all over globe and it is stated in the documentation that, for the customers in Germany and China , I have to use REFERENCE TRANSACTION.
Some where in the documentation of Merchant SDK it is stated that the classic API's will be deprecated, so is it a good approach to use Classic SDK
I also wanted to track the transactions(payment) made by user, so that I can show him the amount that is deducted in each month in his profile details.
Please suggest a feasible solution to my problem.
Thanks in advance.
Here's what I use. I went to Web Payments Standard and created a Subscription button. (I like the unencrypted variety, but you can encrypt if you want.) In there, you set the terms of the subscription, as well as where to post the IPN message. When the IPN message comes back, you deal with it. You'll get a subscr_signup at the start along with a subscr_payment. Then, on renewals, you'll get a subscr_payment again. What I like to do is store every verified IPN message in the database for my customer.
For handling the management of those subscriptions for things like tracking info, refunds, subscription cancellations, and voids, you'll need to use NVP API, which is a very simple API. If you stored in a database every IPN message with all those fields, then you should be able to pass certain fields of those to the NVP API in order to get what you need done.
If you're worried about longevity of the APIs, then don't. All they do when they deprecate APIs is stop giving you good docs on them. They still let those older versions run. If they didn't, there would be major upheaval on the web with web commerce products breaking all over the place. However, that said, if you want to prepare for the future, then get on the Braintree Payments API because PayPal bought Braintree and that's the future of their API.

PayPal REST Subscriptions API not showing price in order summary

I am testing the PayPal REST API for subscriptions in the sandbox environment, and have noticed that, when going to the approval URL returned after creating an agreement, no price is shown under the order summary pane on the left of the page. A description is shown but no price/tax etc.
The plan id is passed to the call to create an agreement, which contains the information that I would expect to see as a user when approving the payment. Is this a bug or is there something that I am supposed to enable in the merchant account, or perhaps something additional that needs to be sent when creating the agreement? I've read other posts regarding this on stack overflow (although they predate the creation of the subscriptions REST API) talking about passing a transaction field, but this isn't valid in the subscriptions create agreement schema.
Your observations are (currently) correct. As REST API based Billing Plans are based on Express Checkout Recurring Payments, you're going to see a similar behavior.
Right now, there are two options:
You populate the description with more agreement details.
You pass a regular description and make sure the customer is aware of the billing terms before your execute the agreement.
Going forward, we're likely going to include this info in some later updates. I'm following up with that to make sure a user story is filed for this.

Best practice for integrating a single PayPal subscription?

I'm new to PayPal and overwhelmed by all the possible approaches for integrating with PayPal.
As a start I want to implement one single subscription with monthly recurring payment. When the user returns to the site after fulfilling the payment, he/she will instantly be upgraded to "premium" member (digital product only - no shipping involved).
The first alternative I've looked into is the Express Checkout API, which looks ok, but is there any simpler way to do it?
Can I for example create a standard button (JS button or the form based), but still be able to verify the payment details when the user returns, using either the REST API, IPN or something else?
Any hints on best practices are appreciated.
Yes, there are entirely too many ways to solve this problem by now.
You can probably satisfy your requirements via buttons (aka Standard), Express Checkout (aka Pro) style APIs, or RESTful APIs, but there are a few gotchas to know:
First, PayPal has several products to do recurring payments; these products have functional differences and are tied to different integration styles. So (for example) PayPal's product called "subscriptions" (tied to Website Standard aka buttons) has different (and generally less flexible) capabilities than "recurring payments" (tied to Express Checkout) which in turn differs from "billing agreements" (tied to REST APIs, although the term "billing agreements" is also used in the express checkout recurring payments product). Oh, and there's another similar product tied to the Adaptive Payments suite of APIs.
Confused yet? Sorry. But it is important to determine whether the specific product you want to use will satisfy your requirements first before you do any integration, or you might end up redoing that integration work later (and potentially have to migrate customers, if you have already opened your business) in order to get access to specific features of another product later on. E.g., the subscriptions product has very limited ability for sellers to modify the subscriptions after they are set up. If that is OK, then great, use it -- it's simple to integrate. If I can oversimplify a bit: the Standard subscriptions product is the oldest and most limited; the Pro recurring payments is more flexible and mature; the REST billing agreement product is the newest, very flexible, but not yet as widely used; it may lack a feature you need today, but is the most likely to be continually improved going forward. I would not personally recommend the Adaptive product, although it also has its benefits.
Now, to your integration question: fortunately all these PayPal products can use IPNs. Unfortunately, IPNs are not instant. They generally arrive quickly (1-2 seconds) but delays can happen and it is quite awkward to be unable to process the customer. I would use IPNs only when shipping physical goods, not for immediate access to digital goods or in other cases where customers are waiting for a page from you. Fortunately, each of the other methods has a way to instantly determine the success of a PayPal action without waiting for an IPN:
Website Standard Payments will include GET or POST variables when it posts the user back to your site that will tell you about the outcome. If you use the Payment Data Transfer feature, these variables will include signature information so that you can post them back to PayPal & PayPal will verify their validity (so that a would-be thief could not fool you by engineering a post that looks like a PayPal success redirect).
The two API-based methods are even easier: the APIs themselves return all the information you need in the API response. So wherever in your code you make the call to create the subscription/agreement, if you get back a success then do your work to make your user premium.
There is the odd case of a user successfully paying and then getting "lost", as it were, e.g. the redirect failing/browser closing before they return to your site, or your site choking while trying to turn on the user. For this reason many people advise using IPNs, which PayPal will attempt to redeliver until you verify them back to PayPal. Not a bad idea, depending.
And of course you can call search & get details type APIs to get information about your transactions & agreements at PayPal -- although again, you will need to integrate with the right API that matches the product you are integrated with (e.g. Standard-based subscriptions won't show up if you ask the REST interface for billing agreements).
Hope this helps.

Create/UpdateRecurringPaymentsProfile - can clients use their PPal Accounts

I have looked around SO for this but I can't seem to find anything like it.
On my service, I wish to charge on a per-month basis depending on how many users my clients have.
So this question is split up into two parts.
What I want to know is it possible for a client to use their own paypal account (without entering any CC details) with conjunction with CreateRecurringPaymentsProfile via the NVP, I have looked through the documentation and can not discern anything. So clearly it is not possible to do it via NPV - From what I've seen so far.
i. If I do an Express-Checkout Subscription, I can do 20% change on total amount every 180 days (I DO NOT want to do this) - I want to be able to get the Profile via the IPN and then modify the monthly amount on as-need basis
ii. There was some mention of Referenced Transactions, but the Documentation is very confusing.
So say there is a way to create a recurring payment subscription via a PayPal Account on the PayPal website, next step is to be able to update the Subscription via UpdateRecurringPaymentsProfile NVP command.
While I am happy to pass on CC details (which already works great), I am just wondering if it is indeed possible create a button, which would create a Subscription - once on success an IPN request is sent back with the ProfileID which I can modify the Billing Amount by NVP.
So TL;DR;
The current flow I have
Register on our website
Enter CC Details
Backend submits the data to PayPal and if passed - continues on.
On any Account modifications, update Profile Monthly Amount Automatically.
The flow I want
Register on website
Click on an Authorize Button Redirected to PayPal
Login to their PayPal Account Create Recurring Profile.
On any Account modifications, update that Profile Monthly Amount Automatically.
edit to add - this is all working now, had to contact and harass PayPal directly for a lonngg time.
I'm a little confused because it sounds like you answered your own question, but then said that's not what you want..??
Express Checkout does exactly what you outlined at the end of your post, and it triggers an IPN just like any other PayPal transaction. You are indeed limited on how much you can adjust the amounts of profiles created with EC, though, just like you mentioned with the 20% every 180 days. If you create profiles with Payments Pro (DoDirectPayment or PayFlow) then you're not limited and you can adjust the amounts however much you need to whenever you need to.
Reference Transactions and Preapprovals may be something to look into as well. I actually wrote an article about what they are and how they differ from each other awhile back that you might be interested in.