我在cakePHP3.x网站上实现了ExpressCheckoutDG,基于ExpressCheckout向导。 (https://devtools-paypal.com/integrationwizard/)
因此,付款程序是在专用的开放框架中实现的。
一切顺利,直到付款完成,Paypal调用返回网址。 在名为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框架并回到给定网址的解决方案的任何想法?
答案 0 :(得分:1)
除了关闭窗口的javascript之外,你需要一个没有任何内容的页面。这就是您要设置的返回网址和取消网址,以便窗口关闭。
Here's a demo我使用我的PHP class library for PayPal整理了一些内容,告诉您如何使其发挥作用。
答案 1 :(得分:0)
抱歉,我发现了自己的错误。 我必须在ctp文件的开头添加以下行。
<?php $this->layout=false?>