PayPal ReturnUrl不传递参数(PayPal ReturnUrl doesn't pass parameters)

编程入门 行业动态 更新时间:2024-10-28 20:31:15
PayPal ReturnUrl不传递参数(PayPal ReturnUrl doesn't pass parameters)

我正在尝试使用PayPal PHP SDK将paypal整合到我的网站中。 Eveything似乎正在工作,除非在成功或失败后,返回网址既不包括我定义的参数也不包括paypal返回的参数,如paymentId,PayerID和令牌。 这是我的php文件:

use PayPal\Api\Payer; use PayPal\Api\Details; use PayPal\Api\Amount; use PayPal\Api\Transaction; use PayPal\Api\Payment; use PayPal\Api\RedirectUrls; use PayPal\Exception\PayPalConnectionException; require './paypal.php'; $payer = new Payer(); $details= new Details(); $amount= new Amount(); $transaction = new Transaction(); $payment = new Payment(); $redirectUrls=new RedirectUrls(); //payer $payer->setPaymentMethod('paypal'); //details $details->setShipping('2.00') ->setTax('0.00') ->setSubtotal('20.00'); //amount $amount->setCurrency('USD') ->setTotal('22.00') ->setDetails($details); //transcation $transaction->setAmount($amount) ->setDescription('Membership'); //payment $payment->setIntent('sale') ->setPayer($payer) ->setTransactions([$transaction]); //redirect $redirectUrls->setReturnUrl('http://localhost/test/add-funds.php?approved=true') ->setCancelUrl('http://localhost/test/add-funds.php?approved=false'); $payment->setRedirectUrls($redirectUrls); try{ $payment->create($api); //generate and store hash //prepare and execute transaction storage }catch(PayPalConnectionException $e){ echo $e->getData(); header('Location:../test/add-funds.php'); } $approvalUrl = $payment->getApprovalLink(); header('Location:'.$approvalUrl);

这是我的paypal.php文件

use PayPal\Rest\ApiContext; use PayPal\Auth\OAuthTokenCredential; $client='client'; $secret='secret'; $api= new ApiContext(new OAuthTokenCredential($client,$secret)); $api->setConfig([ 'mode' => 'sandbox', 'http.ConnectionTimeOut'=> 30, 'log.LogEnabled' => false, 'log.FileName' => '', 'log.LogLevel' =>'FINE', 'validation.level'=>'log' ]);

编辑:$ payment-> create($ api)之后; 我还检查$ payment-> getId()它是否具有正确的值。

I'm trying to use PayPal PHP SDK to integerate paypal into my website. Eveything seems to be working except after Success or Fail the return url doesn't include neither the parameters defined by me nor ones returned by paypal such as paymentId, PayerID & token. Here is my php file:

use PayPal\Api\Payer; use PayPal\Api\Details; use PayPal\Api\Amount; use PayPal\Api\Transaction; use PayPal\Api\Payment; use PayPal\Api\RedirectUrls; use PayPal\Exception\PayPalConnectionException; require './paypal.php'; $payer = new Payer(); $details= new Details(); $amount= new Amount(); $transaction = new Transaction(); $payment = new Payment(); $redirectUrls=new RedirectUrls(); //payer $payer->setPaymentMethod('paypal'); //details $details->setShipping('2.00') ->setTax('0.00') ->setSubtotal('20.00'); //amount $amount->setCurrency('USD') ->setTotal('22.00') ->setDetails($details); //transcation $transaction->setAmount($amount) ->setDescription('Membership'); //payment $payment->setIntent('sale') ->setPayer($payer) ->setTransactions([$transaction]); //redirect $redirectUrls->setReturnUrl('http://localhost/test/add-funds.php?approved=true') ->setCancelUrl('http://localhost/test/add-funds.php?approved=false'); $payment->setRedirectUrls($redirectUrls); try{ $payment->create($api); //generate and store hash //prepare and execute transaction storage }catch(PayPalConnectionException $e){ echo $e->getData(); header('Location:../test/add-funds.php'); } $approvalUrl = $payment->getApprovalLink(); header('Location:'.$approvalUrl);

this is my paypal.php file

use PayPal\Rest\ApiContext; use PayPal\Auth\OAuthTokenCredential; $client='client'; $secret='secret'; $api= new ApiContext(new OAuthTokenCredential($client,$secret)); $api->setConfig([ 'mode' => 'sandbox', 'http.ConnectionTimeOut'=> 30, 'log.LogEnabled' => false, 'log.FileName' => '', 'log.LogLevel' =>'FINE', 'validation.level'=>'log' ]);

Edit: After $payment->create($api); I also check $payment->getId() it has the proper value.

最满意答案

事实证明问题出在add-funds.php中,它将用户重定向到另一个页面,并且所有参数都在此过程中丢失。 我发布的代码工作正常。

It turned out the problem was in add-funds.php which was redirecting user to another page and all parameters were getting lost in the process. The code I posted works properly.

更多推荐

本文发布于:2023-08-07 20:02:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1465687.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:参数   ReturnUrl   PayPal   pass   parameters

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!