Paypal subscription flow - paypal

I need some clarification about the best way to combine paypal subscription in my website registration flow.
The steps for registration:
user chose a price plan by clicking on paypal subscribe button
the use complete payment on paypal form
the user return back to my site to fill registration form.
How can I be sure that the user that fill the site registration form payed for the subscription on paypal and didn't got directly to the registration page?
How can I know on which subscription button the user clicked and how much he paid?
Is there any tutorial that describes such a scenario and which api call I should do?

The smart subscription button has an on approval type of action with the subscriptionId. Use this to send to the backend (or your cloud hosted function) and it will do the follow:
check that its valid
use that paypal email and check that no user with that email exists
use that email to create a new account (add to auth and database with the subscriptionId, planId, paypalId, paypalEmail (incase they change away from this), name, etc.)
send that user a password change email / welcome email
respond with success and kick them to the success page which tells them to check their email and spam
Note: for paid-only accounts make sure you don't have an auth sign up page, only a paypal button subscribe page as the sign up page.

Related

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 send money from website

on paypals page, you can click on 'send money' enter the email address and $$amount and hit send... and then paypal asks for login etc...
what I want to know, is there a way, I can essentially submit that form with the email address and $$ already populated
something like paypal.com/sendmoney?to_email=xyz#xyz.com&&amount=25.00
I want to be able to provide my users with a link that already contains the info so they dont have to click the link and then fill in the details when they get to the page..
You can't do that directly with the PayPal page, but you could build your own version of that page using the Adaptive Payments API, specifically Pay.

Can I generate custom Dwolla buttons for each of my users with just their Dwolla ID and my Application Key

So my web application will have users, and each user has customers. Each customer has their own customer page where they can see and pay the user any remaining balance on their account.
I want to create "Pay Now" buttons that link to the user's Dwolla account, and return the customer back to my site after they have submitted the payment. I don't want to make each user generate their own button though. Is there any I can generate a button for them with my own application key and their Dwolla ID?
You wouldn't use Dwolla payment buttons for scenario. You can simply integrate with our Off-Site Gateway API. Check out the Server-to-Server workflow here.
Essentially, your webapp will POST to Dwolla some details about the checkout you’re trying to create (destination, amount, etc.) and Dwolla will respond with a CheckoutId.
From there, you'll use the CheckoutId to construct a URL which you'll send the user off to by means of a redirect or a link.
Here's a demo of what this flow would look like to a user.

Send an e-mail to PayPal buyer

I'm introducing PayPal Digital Goods for Express Checkout on a web site. For an user who is logged in, a valid checkout results in an update in the user's profile on the website, which in order allows to access more content.
The owner wants to add support for clients which aren't yet logged in to the web site. We handled this by introducing a landing page with an unique URL, which the user is redirected to after payment and which can be used to create a new account or mark an existing account as paid. If the user doesn't want to do this immediately, the URL of the landing page is persistent and bookmarkable.
However, in case the client doesn't want to log-in immediately and fails to bookmark their unique link, we'd want to additionally send a confirmation e-mail which would contain the link.
Paypal sends a receipt e-mail to the buyer right after purchase. Can I somehow insert additional message for the client in that e-mail?
If not, is there any other PayPal API feature which would let me send a message to the client's e-mail registered with PayPal?
Unfortunately you won't be able add or modify the content in the email message sent by Paypal. They lock down those type of things for security purposes.
However, you can send your own confirmation email once you receive notification that the payment has been completed. Whether you are using PHP or another server side language, you should be able to collect the email address from the variables returned by PayPal and send a custom email using the mail function. Since you create a custom landing page for the user, you can simply send it from here.

Triggering an action after Paypal Buy-Now purchase is complete

I've got a web application with a form where users can sign up for a seminar. The process is currently as follows:
Register for seminar
Registration success page with Paypal Buy-Now button to make payment
Paypal payment
Registration completion page
At present, emails are sent to the admin and the user at step 2 after registering confirming their registration. This needs to be changed so that the emails are actually sent in step 4, after payment has been made.
The application is built in ASP.NET, and all of the code to send emails, etc is all done. I'm curious as to what is the best way to trigger a process on the main website using the users details after they have completed the Paypal payment process.
From what I can see, there are the following options:
Store the data in the session. When the user returns to the registration completion page, retrieve the information and send the emails. My concern with this is that I've worked on a project in the past implementing this and it never worked very well, with the session getting lost.
Store the data in the database. Have the Paypal redirect include the transaction details in the querystring to the return page, which can retrieve the registration details using the email address and send the emails. However, this may not work if the email address used on Paypal is different from the one used to register (which is quite likely in this scenario).
Post all the details to Paypal, so that they are included in the transaction. Downsides: Won't send confirmation email to the user, only the admin (and assuming that the Paypal email address is the same as the email to which payment notifications should be sent). Also not sure if this can be used with hosted buttons.
I'm sure this is a common problem, and any advice would be appreciated. Thanks.
Use paypal instant payment notification
When the order is placed on your site, put it into a db table, with whatever you need to record. I then have an OrderId (from the db table) that I pass to paypal as an 'invoice' field, this gets passed back via ipn with a payment status etc.