How to automatically send a custom PayPal shopping basket after checking inventory / price

G'day all

PREMISE:

I created a special store that has the PayPal option for payment. In general, the PayPal option works as follows:

  • The user adds items to the shopping cart (if they are in stock)
  • User selects delivery destination
  • Click Check Now
  • The user registers or enters delivery / payment data.
  • The user is provided with a payment page to enter card details or click the "Pay with PayPal" button.

The Pay with PayPal button is what I want to adapt. I currently have a php function that takes all the items from the users basket and converts them into a PayPal form, which is then displayed on the page. This form contains all PayPal information, including items, quantities, sizes, shipping costs, business data, return / cancel / IPN URLs, etc.

PROBLEM:

If the user fills out his shopping basket on a specific day and goes through the verification procedure to the payment page, the PayPal form is just generated there (including the prices and quantities of goods that are currently in order)

They leave their computer without , by clicking the "Pay with PayPal" button, perhaps for a few days to think about it. At the same time, prices / stocks change for goods in their basket.

Even if I installed the incomplete carts for removal, say, after 24 hours, the user already has a PayPal form, so you can still click “Pay with PayPal” even a few months later, using the old inventory levels and prices!

DECISION:

I see several options here and open suggestions for each (or even a better solution!)

  • Install the “Payments” and “Cart” pages using the terrible “Refresh” meta tag so that they are updated every day and check php promotions / price before the page loads. Thus, if stocks or prices have changed, the user will be presented with the latest prices. (This is not my preferred option)

  • Instead of creating a PayPal form on the "Payment" page, click the "Pay with PayPal" button to send the user to another php page (for example, "process_paypal.php"), which performs all the necessary checks, and if there are any problems, A message can be sent to the user. (So ​​far, so good). Then (and this is the part I'm struggling with), if everything is ok, generate a form and automatically submit it by redirecting the user to the PayPal website to log in (I know that this can be done quite easily using jQuery or Javascript, but if possible, I would prefer a PHP solution if such a thing exists? I'm not very familiar with cURL, so I don’t know, is used for)

  • You're telling me?!:)

Appreciate any help you can give on this.

Ben Avery

+4
source share
1 answer

Personally, in this case, I used the paypal callback URL to reject the purchase if the cart does not exist.

What would you do is only answer their IPN challenge with success if the cart exists in your system. Otherwise, fail.

I believe PayPal has a setting to decline payments that do not receive a successful response.

Edit: just looked at the code (some time has passed since I did this). What we ended up with was initiating a return using the PayPal API based on the IPN call. In my opinion, this is quite acceptable for this, since the client does not bear any responsibility.

+1
source

Source: https://habr.com/ru/post/1415534/


All Articles