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 虚拟机打包apk出现错误
  • ¥30 最小化遗憾贪心算法上界
  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 逻辑谓词和消解原理的运用
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝