dongzi3434 2017-03-21 17:06
浏览 53
已采纳

Paypal返回url不使用php和html表单

I have payments set up (using php) so that when a customer returns to the success.php file (after payment process on Paypal using an IPN listener) they are added to the db with a new membership number, which is also generated in the success.php file. The process works fine if the customer pays as a guest, they are returned to the success.php page as they should be. However, if the customer logs in to paypal rather than paying as a guest they are redirected to the Paypal user account page instead of back to the success.php page on my site. This means the payment has been taken but their membership number is not created or added to the db.

Is there a way to force ALL customers back to my success page or should the code to create the new member be added to the ipn listener (ipn.php) file so it wouldn't matter if they didn't come back to the success page?

This is the code I use in the checkout page to set the return url.

<form action="<?php echo $paypalURL; ?>" method="post">
           <!-- Identify your business so that you can collect the payments. -->
           <input type="hidden" name="business" value="<?php echo $paypalID; ?>">

           <!-- Specify a Buy Now button. -->
           <input type="hidden" name="cmd" value="_xclick">

           <!-- Specify details about the item that buyers will purchase. -->
           <input type="hidden" name="item_name" value="<?php echo $item_name; ?>">
           <input type="hidden" name="item_number" value="<?php echo $item_number; ?>">
           <input type="hidden" name="amount" value="<?php echo $price; ?>">
           <input type="hidden" name="currency_code" value="GBP">

           <!-- Specify URLs -->
           <input type='hidden' name='cancel_return' value='http://example.com/payment-cancelled'>
                 <input type='hidden' name='return' value='http://example.com/thanks-for-joining/'>

           <!-- Display the payment button. -->
           <input type="submit" name="submit" class="button" value="Pay Now">
       </form>

I should add that I have only tested this in sandbox mode so far, so if anyone knows if this is a sandbox only issue, please let me know.

UPDATE: Further testing shows that the return url no longer works with a guest check out either. This has only started happening since sandbox payments are going through the new payment pages (screenshot attached).

Has paypal changed the method of requesting a return url?

Paypal payment screen shot

  • 写回答

1条回答 默认 最新

  • duan5801 2017-03-25 12:55
    关注

    I fought with a few ways of integrating paypal's payments into my site. From what I've read here on stackoverflow, on paypal's site, and all over the web, it is probably best to put all of that backend work into your listener. You could set up something on the front-end to prep your DB for the customer, but the major problem with using the success page for this information is that:

    1) your customers could just enter the URL of your success page if known
    2) A customer can choose not to be redirected after paypal and may not return to your site at all (this is the best reason as I can see it).
    3) Sometimes paypal redirects, but the listener may not have received paypals response of completed, pending, .etc (this is why they wait 10sec before redirection), so you do not want the user to go elsewhere or have been verified prematurely.

    Honestly, placing all the code in your listener is quite simple as well and reduces miscommunication between your success page and paypal. As for testing, I just used the IPN simulator to test my code and it was fine.

    As for the redirect URL, there are a few redudancies in paypal, if you use buttons, the option 3 (I believe) will provide a return URL that overrides the others. I'm not sure about using sandbox, but make sure you have .sandbox.paypal in your code to ensure it works (https://gist.github.com/xcommerce-gists/3440401#file-completelistener-php).

    I hope this helps.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line