Check if user have valid subscription on PayPal - paypal

In our app user is paying for one year of use during checkout and then after a year we are staring to charge subscription.
Let's say that users are identified by email. So, how can I verify that user have now an active subscription ?
I have seen a few posts that suggest to build webhook and listen to PayPal events.
In our flow the initial purchase will be on WordPress website with one of the subscriptions Plugins and then I need to "activate" subscription in the App.
Is the "webhook" the only possible option with PayPal?
I have seen something in Braintree SDK related to subscription, can this work?
Seems to me too complicated to build the whole system only to verify subscription. In Stripe, for example, you can proactively ask if the user has subscription.

The webhook PAYMENT.SALE.COMPLETED informs of every completed subscription payment. Use this information to continuously update your records of whether a user has a paid-for subscription.
If you need metadata for reconciliation of which subscription corresponds to which user (since however they are identified at PayPal may not correspond to however you identify them), you can set the parameter custom_id when creating the subscription, to any value of up to 127 characters.
If you need to download a transaction history of previous payments, you can get a report in CSV format from the https://www.paypal.com account interface, typically under Activity -> All Reports -> Activity Download. This can then be imported to a database to backfill any gap in your records that you don't have webhook events for.

Related

How to prevent users with Paypal subscription having trial to cancel and have another trial period

I have a SaaS with Paypal subscription.
In Paypal we can have a trial period as a part of the plan, which is managed by Paypal.
Is there any pattern to organize account deletion and subscription cancelation? I see some options?
Users can cancel subscription, but if they want to make a new subscription - they will get a new trial since it's a new subscription. I could get another plan without trial for this, but can't they substitute plan ID with the one with trial with some HTML knowledge?
Subscription cancelation can only be done together with account deletion. User can suspend subscription if he doesn't want to delete the account. Suspension is not exactly like cancelation, looks incomplete, like you may pay accidentally at some point.
Yes, a plan_id on the client side can be changed. You could conceivably create the subscription using the create subscription API call and fetch the ID of the created subscription instead, with a pattern similar to https://developer.paypal.com/demo/checkout/#/pattern/server
Subscriptions can always be cancelled in the payer's PayPal account.
Whatever solution you decide on, register for the webhook PAYMENT.SALE.COMPLETED and build you logic using that. For reconciliation, add a custom_id when the subscription is created; this can essentially be your own user ID or whatever other unique identifier you want.

PayPal subscription API onApprove

I'm trying to implement the PayPal Subscription API but I'm not sure about the process flow.
I use the react-paypal-js package to generate the subscription button.
The way the users are created on my website is only through the Paypal subscription.
The process is as follow:
The user choose a plan and click on the subscribe button
The PayPal window open and the user follows the subscription process on Paypal
The user is redirected to my website
Using webhooks or with the onApprove callback, I receive the newly created subscription, create a user on my website with the Paypal email address associated with the subscription.
It all works. My problem is that I need to check, before accepting the subscription, if I already have a local user with given email and in this case, I don't want to accept the subscription (as I would then have 2 subscriptions for the same user) and display a message saying that their is already an active (or suspended) subscription associated with the given email.
As far as I can tell, when the onApprove is called or the webhook is called, the subscription has already been processed and activated.
Thanks!
You don't have to design a system in which the PayPal email used to make the payment, and the email of the user used to log into your site, have a 1:1 relationship. Instead you can have the user log and create their account with you first (as they will always need that to manage something subscription-based) and then you will know there is no subscription associated with that user before displaying the PayPal Subscribe button. Then they can pay with any PayPal account (might be the same email, might be different)
As far as I can tell, when the onApprove is called or the webhook is called, the subscription has already been processed and activated.
That is the default behavior, yes. Per the above it shouldn't be ncessary, but you can change the subscription to start in an inactive state, and show a final review step on your site that will activate it via API. This is controlled by setting application_context -> user_action -> CONTINUE (vs default SUBSCRIBE_NOW). See the API reference for subscription create, and you would of course need to use the subscription activate API call as a final step after confirmation.

Paypal recurring payment response verification and match with paypal return page variable

I am working on a website to sell some advertisement concept online, where user can get the access of more options after opting a monthly subscription paying through recurring Paypal.
I have already implemented the recurring paypal functionality successfully except one thing. Like One can subscribe for the plan and monthly payments are deducted from the concerned account.
But I have no idea how to update my database after the first payment from the recurring paypal.
eg, a customer comes to the site, choose his options, went to paypal recurring part and made the transaction. Now I have one page , where the paypal returns the control, which is given on the return url. Now the problem is, in this page when I am updating the database, the paymanet status is pending.
Then after a while when the IPN response comes to the application, I wont able to update the earlier entry in my database, as I am not sure how to match these two entries, I mean upon which field the update query should be coded.
There's no point in updating the database at all until you get the money. When you get the money, the transaction contains everything you need to create or update the subscription.

Paypal Recurring Payment API CALL when taking money

I am writing a subscription where I need to provide users a month trial and charge $5.00 after trial is finished. I just found an amazing code to do that for me.
I also have setup paypalpro plus recurring payments
This is the link
https://github.com/krio/paypal-recurring-subscriptions
Questions:
1- How to make first month Free Trial?
2- I need to update users billing and update their payment in my database so it can calculate their subscription, how would i get to call from paypal to my files to update?
If you are using subscriptions and you are wanting to make the first month a free trial, you would need to pass over the following variables and values.
a1=0
p1=1
t1=M
You can find a description of all of the variables for subscriptions here.
If you are wanting to get updates back to your system/database to update your profiles and etc, you can use IPN to do this. Instant Payment Notification (IPN) is a message service that notifies you of events related to PayPal transactions. You can use it to automate back-office and administrative functions, such as fulfilling orders, tracking customers, and providing status and other information related to a transaction.

Get Transactions associated with a Recurring Payment Profile in Paypal

I have gone through nearly all the question related to Recurring Payment using Paypal and have not found a solution to my problem.
We are implementing a system that is subscription based on a monthly basis (fixed amount). We do not want to store CC details for security reasons, hence we are trying to use Website Payments Pro from Paypal.
Once a user agrees to recurring payments, we are creating a RecurringPaymentProfile for that user and are storing the returned Profile_Id for the user.
Now we need to get information about all the transactions related to this Recurring Profile_Id. This information is available when we login to the Paypal account but this needs to be automated so that the application is aware of all the payments and also of the current subscription of the user.
We have found two methods (possibly) to implement this.
1. IPN (Instant Payment Notification, for this we will have to create a service to listen to notifications, which seems to be cumbersome and is more informational than we require)
2. TransactionSearch (but this returns transactions for the Paypal account and not Profile_Id)
Since we just want to know the transaction history associated with the Recurring Profile and whether this months payment was successful (implying the user is active member), what is the best method to implement this ?
Thanks,
You're looking for the GetRecurringPaymentsProfileDetails API Operation. This operation will allow you to view a majority of the details associated with a recurring payment profile using a valid PROFILEID.
Relevant detail fields you may be interested in:
LASTPAYMENTDATE
The date of the last successful payment received for
this profile, in YYYY-MM-DD format.
LASTPAYMENTAMT
The amount of the last successful payment received for this profile.
FAILEDPAYMENTCOUNT
The total number of failed billing cycles for this profile.
NEXTBILLINGDATE
The next scheduled billing date, in YYYY-MM-DD format.
NUMCYCYLESCOMPLETED
The number of billing cycles completed in the
current active subscription period. A billing cycle is considered
completed when payment is collected or after retry attempts to collect
payment for the current billing cycle have failed.