A good way to check if the payment form was left off in between - api

We use PayPal to accept donations on our website. The problem we're facing is usually this happens that a user clicks on the pay button on our website but then for some reason drops from PayPal.
Is there a way through the PayPal API we could check that the user for some reason left off the transaction or maybe his transaction was denied.

No there is not; keep track of that drop off yourself if they don't come back or you don't get a resulting transaction.
If you are not using an API to accept the donations, then to be notified of resulting transactions you can use Webhooks. A parameter you can use for reconciliation is custom, which can be set at the moment the user clicks 'Pay' and you redirect them to PayPal.
(But if you are using an API, then the API is your notification already)

Related

How does one associate a website user with a Paypal subscription?

I am implementing subscriptions to a premium service on a website using Paypal as the payment service. I have successfully created a Catalog Product and Billing Plan through the API, and I am able to get to the payment page on Paypal, but it's not clear how I'm supposed to persist a user identifier through the purchase process.
I assumed it would be something along the lines of passing a user id somewhere, but there's nothing in the Paypal documentation about this. I need to be able to let the user make a purchase and have the Paypal webhook send the confirmation to an endpoint on my site, and that's where I'd expect to get their user id to toggle the subscription on their account on my end.
Is there something I'm missing? There has to be a way to do this cause I'd imagine it's a pretty common use case. If anyone has information or has done this before, I'd love to hear. Thanks.
The only truly secure way I've found when using javascript SDK, is to securely generate a unique custom_id on your server side associated with the user.
Then when you create the buttons, the 'createSubscription' function takes custom_id as a parameter.
Then use a webhook to receive events from your subscription and the custom_id will be present in the body of all BILLING.SUBSCRIPTION events under resource.custom_id.
I am able to get to the payment page on PayPal,
You are vague about what you are doing here. There are multiple ways (and some ways have multiple versions) of accepting subscriptions via PayPal, so it is important that you provide full details about the method you are using.
The time to associate a created subscription ID with a user ID is when it is approved, in the onApprove function if you are using a Smart Payment Button: https://developer.paypal.com/docs/subscriptions/integrate/#4-create-a-subscription

Paypal rest api express checkout with no shipping field (WebProfile handling)

I'm using Paypal rest api to make payment
the workflow is:
Create payment
Redirect to approval Url
User approved (return back to my site)
Execute payment
But there's one thing that I don't want users re-filling shipping address again because it was filled in my website.
So I change the workflow to:
Create web profile (set no shipping field)
Get web profile ID
Create payment with experienceProfileId given
Redirect to approval Url
User approved (return back to my site)
Execute payment
But I found this will create a lots WebProfile every time user request payment.
I think it is crazy to do:
create and delete it later again and again
attempt listing WebProfiles and check which is the one I want to use every time while creating payment
store experienceProfileId as a constant
What is the best practice for handling WebProfile or does there any solution just hiding shipping address while user approving payments?
Maybe this is not the answer regarding this "WebProfile". As a fact, I dont know what exactly "WebProfile" does or is.
I worked on the same Workflow these days. As you wrote I needed to predefine some address. For me it was obvious, that I have to do the database-stuff on my Website. Then I exactly define the order, shipping_address, etc. and send the users to Paypal.
If you predefine the new ShippingAddress() to your ´new ItemList()´ by
$itemlist->setShippingAddress($shippingaddress) the user cannot change it within the Process.
http://i.imgur.com/nAg8jxU.png
Maybe this helps you a little.

Get transaction details in real time, Paypal

I am creating a website and instead of using a fully featured shopping cart I want to use the Paypal API to "automate" some functionality.
By that, the user clicks on the "buy now" button goes and makes payment to paypal, and I want them to be redirected back to my site so I can process some info for my database. I looked into IPN but it seems like an overkill. Is there any simpler way of doing it?
You should look at either IPN or Express Checkout.
If you are using web standard payments it is important to note that a customer does not have to return to your page, once they hit pay on the Paypal site - the transaction is complete. Hence relying on them to return to your page to do a database update is a bad idea. This is where IPN comes into play.
Express Checkout gets around this by allowing the customer to authorize on Paypal and complete a transaction on your site. Passing the data directly to your site once the transaction is complete.

Paypal ipn processing and dropdown option/price buttons logic

I read lots of post from various sites including paypal documentations. But I have some quesitons wihch I couldnt solve those. One of them is that how to design the codes after receiving the ipn message. Ofcourse I make my code I am able to optain and process the variables of message. like payment status and I am able to save them into database. But the point is that how should I desing the code to control the payment to overcome my requirements. I know the post become long but I feel the need of this explanation. So I have a site which works with membership with payment. Site is check after login the membership trial is expired or not if it is expired it shows a div in fornt of the site wihch includes the paypal buttons and redirect to paypal payment screen when button is clicked. User shodul have ability to choos membership period like 6 or 12 mounths (by dropdown paypal button). When the user finalize his payment ipn is trrigerd and I get the datas but all my members dont have to have a paypal account so they can use therid credit card directli and if I understand correctly the transfer of money can take some time to be recevied by me. Which time interval I should set the members approved flag is true ? I am confused about this. If I approve him after ipn is sent is there a possibility an error can occure while transferring me. How the process works.
other problem is the dropdown button. when I set option/price button when I click the button an error page is shown after redirecting to my selling page. It does not redirect to the payment page.
Realy sorry for my long post but I dont know how can I descirebethe situtation in a short way
If you need to wait until funds are available, you should test the value of "payment_status" in the verified IPN message for "Completed".
An eCheck can take from 3-5 days for collection (sometimes longer; you can see the estimated hold time in your account) and has payment_status="Pending". Once collected, you will get another IPN message with "Completed".
Note that the user never sees the IPN process. Normally you set up the conditions (in a table or something that is persistent enough), then send the user to PayPal. When the user comes back from PayPal, your code (at the "return_url") checks the table to see if Payment had completed successfully (perhaps a flag, which was set by your IPN handler code that is called by/communicated with PayPal when the user leaves PayPal gracefully).

Is this processus to pay a user, reliable and safe?

I'm working on a project that require my application to pay the user to his paypal account when he asks it.
Here's how I did it so far:
The (logged) user goes to the Pay page that will list all his Payments (received or not)
He enters his Paypal email and his application (mine) password (for security)
The POST page get a list of all the Payments that have status="UNPAID" for that user and update the status to "WORKING" (to avoid the user to refresh the page before the whole process is done and resend the same amount of money)
We count the total amount to pay in that list (a simple for)
The amount is sent to Paypal via Paypal Adaptive Payment API (request: PAY)
The response is checked, if completed, the list status is set to "COMPLETED", if not, the list is reverted to "UNPAID" (the SQL update is made via a WHERE id IN(x, y, z) in case a second Payment request has been made during that time.
A message is then displayed to the user
But I need your help, I'm in front of one risky problem I'd like to avoid, and I would know how you would do:
If the user hit refresh on the process page, I don't want to send him twice (or more) the amount (The "WORKING" lock is here for that, but what happens if the user hit refresh before I set the lock ?)
Rare possible: what happens if the user hit f5 after the lock "WORKING" is made, but before the request to paypal, and a new payment is received. By following what I did, just one item (the new) would be get and set to WORKING, but all others previous payment would be losts
How would you do? What is the best way to make it to be 100% reliable?
Thanks for your help
Note:
The steps between 4 to 6 is made via a PlayFramework jobs, called with now() and awaiting() the result
you can:
prevent double post via JQuery
use the checkAuthenticity() method to validate the request
do a GET redirect after processing the POST (so they can't submit the same 2 times even by mistake)
do the payment processing asynchronous (see below)
For the payment, instead of calling the job, set the id's of payments in a queue (or table in the database) and a job that runs once per minute that processes that table if it has some data. When the user does the POST you redirect to a page that says that you are processing the payments and will notify if there is some issue. You can notify the user later via a UI warning using comet or via mail.
That way you don't link the request to the processing, and you won't have threading/racing issues, as well as being able to detect stale requests (payments already done) if you do a sequential processing.