Paypal IPN verified. What to do if I need to refound? - php

I'm selling from my php site and I accept paypal payments, I've got a limited number of products, buyers have them in their carts, and availability is not enough for them all.
If they pay with paypal at the same time I need to refound one of them.
Is this approach correct, or is it preferable to check availability before the payment IPN notification?

That sounds like a poor user flow. Once you get verification that an item is sold, reduce your inventory in your database. Before sending them to Paypal, verify that you have enough inventory to fulfill their order.
If you get a scenario where say you have one item left and two users were directed to Paypal to purchase it, whoever you receive notification of successful payment first, gets it. The other, you can do a few things:
Place the item on backorder, let the user know when it'll come in with an estimate. When it comes in, send it to them.
Allow the user to choose whether they want the backorder, or to cancel their order, in which case they get a refund
If, once a product sells out, there are none left forever, you can immediately issue a refund.

Related

Paypal Recurring Payments - How to prevent duplicates?

So I've been using paypal recurring payments for about a year now, and for the most part it works well (with IPN verification after payment goes through, etc...)
One issue I have run into is sometimes my customers will set up multiple payment profiles, which I definitely don't want them to do. Then I have to go in + refund payments and cancel additional profiles.
I was curious if anyone had any suggestions to prevent users from doing this, or WHERE I should prevent this from occurring.
After the IPN notification hits my server, users can't purchase again, but sometimes this can take 30 seconds, or an hour. So then my user goes back in thinking it didn't go through and purchases again.
My process is pretty much this:
Page 1 (user selects options)
Paypal API: SetExpressCheckout
Page 2 (user goes to paypal, logs in, accepts agreement)
Page 3 (I create the agreement)
Paypal API: GetExpressCheckoutDetails
Paypal API: CreateRecurringPaymentsProfile
I would think somewhere on Page 3 I should do a check, but I'm not 100% sure HOW I should go about it. Simply make an association w/PayerID they they tried to purchase something here then prevent it ongoing?
What do people recommend?
Thanks!
After creating the first recurring payment profile, in the response you will get a profile id and a profile status which should be 'ActiveProfile'. I would recommend that you save it, and do a check before he selects any subscription(or product) again on Page 1.

Paypal IPN Inventory Control

I have been developing an online retail shop.
It is written in php and uses paypal and IPN to handle payments.
I have written my own shopping cart. When the user wants to checkout they click on the checkout button which has the standard cart upload function wrapped around the button and the user is taken to paypal to complete payment. Paypal then sends me an IPN to notify me of the payment.
My question is, at what point should I store the order and when should the stock levels be reduced?
The standard process flow is that I have right now is as follows:
User adds item to cart.
If item is now sold out or the quantity added is more than available, the cart is updated to reflect this.
However, stock added to the cart does not reduce stock levels.
User clicks checkout.
The cart is loaded into an order record in the db AND the stock levels are reduced.
User is taken to paypal to complete payment.
(a) User completes payment.
(b) User does not complete payment by either returning to website or going somewhere else / closing browser.
(Optional) User clicks return to website.
User sees a 'thank you, order complete' complete page.
Nothing is processed relating to the order table since paypal will send IPN anyway.
Paypal sends IPN
Update order with the transaction status
As you may see, there are some issues with this process. If the customer leaves the paypal page without completing payment I will have a 'dangling' order and since stock levels are also reduced this stock will not be available to other customers! A solution to this is to manually 'clean' the database every so often.
Alternatives?
option I) Do not store the order in the database until a 'completed transaction' IPN is received, then use the cart info stored in the session to create an order and reduce stock levels. However, sessions can expire and paypal payments might take days depending on payment.
option II) Store the order as is now but do not reduce stock levels until completed transaction IPN is received. This still has the issue of dangling orders but at least no stock will have to be re added again when cleaning up, I'll just have to remove the orders. Another problem with this though is that if multiple people order at similar times and thus collectively their orders contain quantities that exceed stock. This could be quite chaotic when the system receives completed IPNS and then reduces stock levels to negative quantities!
I have looked everywhere on the internet for some sort of help, but it is not mentioned anywhere! Everyone just skips to how IPN should be handled. I just don't understand how other people could not have had this problem?!
Please help!
You're dealing with the same problem that airline reservation systems have for ages. Use the same solution ie
1.Upon user clicking checkout (while being redirected to Paypal)
reduce inventory count
place a timestamp in the database along with a state that this order is temporary
2a. Once you receive an IPN ie know the billing has been successful
change state of the order to permanent
2b. Have a cron job that runs every few minutes to track temporary orders. If temporary orders are from a time greater than what you allow eg 20 mins then:
remove the temporary order from database
undo the change in inventory count
As both a merchant and a developer, I prefer to adjust inventory stock with the IPN, even if that IPN is pending (eg. an eCheck). The chance of 2 customers going through checkout at the same time with your last remaining stock is typically low. If you do have high enough volume and low stock levels (why would you?) then you may want to do something in the cart to place locks on the items for the duration of the session timeout.
Make sure your order processing code returns the inventory to stock if the order is canceled or returned.

Paypal Buy now button without shipping anything?

I have a buy now (pay now) button but when a user pays, I'll get a notification that the user pays but i can't get the money unless i shipped the item to the User.
I don't have items to be shipped! I want the button to be something like the donation button, if someone pays i get the money immediately.
But I don't want DONATIONS, I am actually using the pay now and NOT the buy now button so there's nothing to buy, but you pay for something like a VIP service
I don't want to use the subscription button because I want the user to pay as many times as he wants, the more times he pays the more service he gets.
So how can i get the money from the pay now without having to deliver any items?
Update
#BillyMoon I am actually giving something but not a physical item you know - i don't know how to explain it, like when you buy chips from facebook zinga poker game, the user can pay many times and get more chips.
or like when you pay on facebook to advertise something there, you can pay many times if you want to have many ads, I can give you guys many examples!!
Haven't you played any games, or paid to any service, where you get something, but not a physical item?
#Robert
I host a competition on my site, if you pay 3$, you'll get a chance to enter the competition, if you pay twice you'll get more chance of winning, you can subscribe to my site without paying but you won't be entering the competition and you won't have a chance to win (i don't want to give more details until I launch the site) but you see the main idea
I was testing the buy now button so i made the value of it 0.10$ (which is the minimum value possible) just for testing coz i am from lebanon, not allowed to use and don't know how to use sandbox
so i paid twice, just to see if everything is working so i should receive 0.20$ right?
i go to my paypal, I can see that i paid twice but the money wasn't added to my paypal let me show you, I had 0.86$ before i paid to this account. but this amount didn't increase
Although I received the payments, my paypal balance is still the same
Turn off shipping address collection by setting no_shipping to '1'.
This will remove the 'Print shipping label' option, and not include the shipping address for you.
A billing address will still be required on the credit card entry screen (obviously).
Set <input type="hidden" name="no_shipping" value="1">

Dealing with two people buying a unique item in an online shop at the same time

I'm creating a simple online shop with PHP integrated with PayPal that sells unique items. What I'm wondering is how other shops deal with multiple people attempting to go through the payment process with the same item.
This is my current draft strategy:
Items have three status types: available, on hold & sold.
As a user moves to the PayPal payment page it checks the status of all the items in the cart to ensure they're available. It also sets the item's status to "on hold" until they either come back after payment is confirmed or it times out (10 minutes? Not sure what this should be).
Is this standard practice or is there a more practical way I should be going about this?
Thanks in advance!
Have a look at Dell's UK outlet. When someone adds a system to their shopping basket it is held and not available to other customers. If it isn't purchased, the item is removed from the basket after 15mins of inactivity and is then available to other customers.
I would say the first part of your strategy is correct - as you move to the payment page, flag all the products as 'on hold'
When the user has finished the payment, you will get a postback from Paypal which lets you know if the authorisation was successful or not (and possibly also allows you to check the CSC/CVV2 result), and at that point you have the option of either accepting the payment, or rejecting it.
On receipt of the postback you should also check whether the items are still on hold. If they have timed out you can reject the payment and display a message 'sorry - timeout exceeded' or somesuch.
This method also allows you to work out an ideal timeout period if you keep track of how often customers run into the timeout, so you can extend the timeout from (eg) 5 to 10 minutes if too many are timing out, or shorten it if none are timing out.
This is a fairly common issue with fixed inventory systems such as venue, transport/airline tix etc.
I like the airline model where once you get the itinery you want and click select, you get a page with passenger info with a message saying, seats on hold and you now have xx(10/15) minutes to complete the purchase. Everything becomes explicit at that time. For other unique/one of a kind item, I'd think a message on any page, that the user clicks on, saying you have xx(mins) remaining to complete the purchase would be a big motivator for "on the edge" buyers !
woot.com is notorious for this problem but their solution works well. After payment information is verified the user is brought to a page with a small amount of text saying something like "your order is in, we are verifying inventory".
It looks like the paypal API has a "RefundTransaction" message so something like that might not be possible. But the user experience could be awkward if your going to the paypal website then coming back to your site.
This is much like booking theatre tickets or similar online and yes the way you describe is generally the way it works. At some point the item is "reserved" in the system and either the customer completes the transaction or the item is released after some time for others to buy.
Of course at what point you reserve the item (when it's added to the cart, at the point you send them off to pay etc) is up to you. I would expect putting it in the cart would be the best choice as it makes it less likely someone will build up a basket of stuff only to find half of it is no longer available at the checkout.

PHP - Paypal product timeout

I have finally got my paypal system working using IPN and a reservation system to ensure that two people do not buy the same product.
The problem is, the reservations last for 10 mins on my application. If a user reserves the product the 'timer' starts, he clicks pay and ends up on paypals website. He then leaves the computer for 10 mins and comes back. He then buys it. By now though the reservation is up and it is possible that someone else could have already bought it.
Is it possible to send a time limit with the paypal IPN request to stop this happening?
As far as I know, you cannot specify that a transaction has to close within a certain amount of time with paypal.
However, I see two options you can use:
Offer a full refund if they purchase and the product is not available. You would check during the ipn notification of the purchase and if it is not available, then refund. You might be penalized by paypal if this happens a lot, but I don't have a lot of experience with offering refunds.
You can specify that the button needs to check inventory see "Step 2 – Tracking Inventory With Your Buy Now Button" in the standard payments guide. Once the product becomes sold out, you use the api to notify paypal the inventory is zero (if there is an api, you might have to use the website for this), and they should be able to notify the user there is zero inventory. I don't have experience with this either, but it seems more complicated than #1, and I would probably go with #1 if this didn't happen a lot. I think in the end you still end up having to issue a refund if the user goes through with the transaction even after seeing there is zero inventory, but I'm not sure about the wording in the docs.

Categories