我已经基于 ExpressCheckout 向导在 cakePHP3.x 网站中实现了 ExpressCheckoutDG。 ( https://devtools-paypal.com/integrationwizard/ )
所以支付过程是在一个专门打开的框架中实现的。
一切顺利,直到付款完成并且 Paypal 调用返回 URL。 在调用名为confirm的方法结束时,我不知道如何关闭Paypal框架并返回到指定的url。
我的确认方法是:
public function confirm() {
$this->log($this->request->url . ' confirm', 'debug' );
$this->loadModel('Orders');
$PaymentOption = "PayPal";
if ( $PaymentOption == "PayPal" )
{
$res = $this->GetExpressCheckoutDetails( $_REQUEST['token'] );
/**
* I removed this part of code as it doesn't concern the problem
*/
$resArray = $this->ConfirmPayment ( $token, $paymentType, $currencyCodeType, $payerID, $finalPaymentAmount, $items );
$ack = strtoupper($resArray["ACK"]);
$this->log($this->request->url . ' confirm :' . $ack, 'debug' );
if( $ack == "SUCCESS" || $ack == "SUCCESSWITHWARNING" )
{
/**
* I removed this part of code as it doesn't concern the problem
*/
/*
* Here I save the transaction
*/
// Add javascript to close Digital Goods frame. You may want to add more javascript code to
// display some info message indicating status of purchase in the parent window
$this->Flash->success(__("transaction successfully completed"));
$this->log($this->request->url . ' confirm : display confirm.ctp', 'debug' );
/*
* So the problem is here: What to do to close the Paypal frame, AND return to a given page of my website??
*/
//$this->redirect(['controller' => 'Sites', 'action' => 'view']);
$this->set(compact('ack'));
}
else
{
//Display a user friendly Error on the page using any of the following error information returned by PayPal
$ErrorCode = urldecode($resArray["L_ERRORCODE0"]);
$ErrorShortMsg = urldecode($resArray["L_SHORTMESSAGE0"]);
$ErrorLongMsg = urldecode($resArray["L_LONGMESSAGE0"]);
$ErrorSeverityCode = urldecode($resArray["L_SEVERITYCODE0"]);
echo "DoExpressCheckoutDetails API call failed. ";
echo "Detailed Error Message: " . $ErrorLongMsg;
echo "Short Error Message: " . $ErrorShortMsg;
echo "Error Code: " . $ErrorCode;
echo "Error Severity Code: " . $ErrorSeverityCode;
$this->Flash->error(__("votre achat n'a pas été accepté"));
$this->set(compact('ack'));
}
}
$this->set(compact('ack'));
}
如您所见,付款过程进行得很顺利,直到尝试完成:
2015-02-20 11:00:38 Debug: pros/Sitemessages/checkout checkout
2015-02-20 11:00:38 Debug: pros/Sitemessages/checkout SetExpressCheckoutDG
2015-02-20 11:00:38 Debug: pros/Sitemessages/checkout hash_call
2015-02-20 11:00:41 Debug: pros/Sitemessages/checkout deformatNVP
2015-02-20 11:00:41 Debug: pros/Sitemessages/checkout deformatNVP
2015-02-20 11:00:41 Debug: pros/Sitemessages/checkout hash_call: closing
2015-02-20 11:00:41 Debug: pros/Sitemessages/checkout RedirectToPayPalDG
2015-02-20 11:01:15 Debug: pros/Sitemessages/confirm confirm
2015-02-20 11:01:15 Debug: pros/Sitemessages/confirm GetExpressCheckoutDetails
2015-02-20 11:01:15 Debug: pros/Sitemessages/confirm hash_call
2015-02-20 11:01:18 Debug: pros/Sitemessages/confirm deformatNVP
2015-02-20 11:01:18 Debug: pros/Sitemessages/confirm deformatNVP
2015-02-20 11:01:18 Debug: pros/Sitemessages/confirm hash_call: closing
2015-02-20 11:01:18 Debug: pros/Sitemessages/confirm ConfirmPayment
2015-02-20 11:01:18 Debug: pros/Sitemessages/confirm hash_call
2015-02-20 11:01:23 Debug: pros/Sitemessages/confirm deformatNVP
2015-02-20 11:01:23 Debug: pros/Sitemessages/confirm deformatNVP
2015-02-20 11:01:23 Debug: pros/Sitemessages/confirm hash_call: closing
2015-02-20 11:01:23 Debug: pros/Sitemessages/confirm confirm :SUCCESS
2015-02-20 11:01:23 Notice: pros/Sitemessages/confirm transaction successfully saved
2015-02-20 11:01:23 Debug: pros/Sitemessages/confirm confirm : display confirm.ctp
这是我的 confirm.ctp 文件:
<?php if ( $ack == "SUCCESS" || $ack == "SUCCESSWITHWARNING" ):?>
<script>
alert("Payment Successful");
// add relevant message above or remove the line if not required
window.onload = function(){
if(window.opener){
window.close();
}
else{
if(top.dg.isOpen() == true){
top.dg.closeFlow();
return true;
}
}
};
</script>
<?php else:?>
<script>
alert("Payment failed");
// add relevant message above or remove the line if not required
window.onload = function(){
if(window.opener){
window.close();
}
else{
if(top.dg.isOpen() == true){
top.dg.closeFlow();
return true;
}
}
};
</script>
<?php endif;?>
关于关闭 Paypal Frame 并返回给定 url 的解决方案有什么想法吗?
最佳答案
您需要有一个页面,除了用于关闭窗口的 javascript 之外什么都没有。这就是您要设置为返回 URL 和取消 URL 的内容,以便窗口简单地关闭。
Here's a demo我用我的 PHP class library for PayPal 放在一起这将向您展示如何使其发挥作用。
关于cakephp - 如何在 cakePHP 3.x 中正确实现 ExpressCheckout?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28627809/