提交 a6e149fd 编写于 作者: T Terry

支付宝支付调整

上级 1618f38e
......@@ -20,7 +20,10 @@ class StandardController extends AppfrontController
{
public $enableCsrfValidation = false;
/**
* 在网站下单页面,选择支付宝支付方式后,
* 跳转到支付宝支付页面前准备的部分。
*/
public function actionStart()
{
//$AopSdkFile = Yii::getAlias('@fecshop/lib/alipay/AopSdk.php');
......@@ -29,19 +32,23 @@ class StandardController extends AppfrontController
return Yii::$service->payment->alipay->start();
}
// 2.Review 从paypal确认后返回
/**
* 从支付宝支付成功后,跳转返回 fec-shop 的部分
*/
public function actionReview()
{
Yii::$service->payment->alipay->review();
//$trade_no = Yii::$app->request->get('trade_no');
//$out_trade_no = Yii::$app->request->get('out_trade_no');
//if($trade_no && $out_trade_no){
// echo Yii::$service->payment->alipay->review($trade_no,$out_trade_no);
//}
$reviewStatus = Yii::$service->payment->alipay->review();
if($reviewStatus){
$successRedirectUrl = Yii::$service->payment->getStandardSuccessRedirectUrl();
return Yii::$service->url->redirect($successRedirectUrl);
}else{
echo Yii::$service->helper->errors->get('<br/>');
return;
}
}
/**
* IPN,支付宝消息接收部分
*/
public function actionIpn()
{
\Yii::info('alipay ipn begin', 'fecshop_debug');
......@@ -80,67 +87,4 @@ class StandardController extends AppfrontController
}
*/
/*
public $enableCsrfValidation = false;
private $use_local_certs = true;
public function actionStart()
{
Yii::$service->page->theme->layoutFile = 'blank.php';
$data = $this->getBlock()->getLastData();
if (is_array($data) && !empty($data)) {
return $this->render($this->action->id, $data);
} else {
return Yii::$service->url->redirectByUrlKey('checkout/onepage');
}
}
public function actionIpn()
{
\Yii::info('paypal ipn begin', 'fecshop_debug');
$post = Yii::$app->request->post();
if (is_array($post) && !empty($post)) {
$post = \Yii::$service->helper->htmlEncode($post);
ob_start();
ob_implicit_flush(false);
var_dump($post);
$post_log = ob_get_clean();
\Yii::info($post_log, 'fecshop_debug');
//Yii::$service->payment->paypal->receiveIpn($post);
}
}
public function actionTest()
{
$url = 'https://www.sandbox.paypal.com/cgi-bin/webscr?invoice=1000000124&first_name=test&discount=7.11&mc_shipping=0.00&mc_currency=EUR&payer_status=verified&shipping_discount=0.00&payment_fee=&address_status=unconfirmed&payment_gross=&settle_currency=USD&address_zip=212121&address_country_code=FR&txn_type=cart&num_cart_items=3&mc_handling=0.00&verify_sign=AuRlNZvMOhdn8iDWY5YoMB9iRTDzAZppqkxKbGiGEUvmwrFAdvscLpXK&payer_id=FKL4V7D5GCACY&option_selection2_1=L&option_selection2_2=L&charset=windows-1252&tax1=0.00&receiver_id=H4KXD885J8LV2&tax2=0.00&tax3=0.00&mc_handling1=0.00&mc_handling2=0.00&mc_handling3=0.00&item_name1=Reindeer+Pattern+Glitter+Christmas+Dress&tax=0.00&item_name2=Sweet+Polka+Dot+Open+Back+Summer+Dress+For+Women&item_name3=fast_shipping&payment_type=instant&mc_shipping1=0.00&address_street=2121%0D%0A23232&mc_shipping2=0.00&mc_shipping3=0.00&txn_id=9NN80505PR451120Y&exchange_rate=1.29364&mc_gross_1=40.34&quantity1=2&mc_gross_2=30.69&quantity2=1&item_number1=22221&protection_eligibility=Eligible&mc_gross_3=18.51&quantity3=1&item_number2=sk0003&item_number3=Fast+Shipping%28+5-10+work+days%29&custom=&option_selection1_1=black&option_selection1_2=red&business=zqy234api1-facilitator%40126.com&residence_country=US&last_name=facilitator&address_state=Hautes-Alpes&payer_business_name=test+facilitator%27s+Test+Store&payer_email=zqy234api1-facilitator-1%40126.com&option_name2_1=My+size&option_name2_2=size&settle_amount=103.09&address_city=2121&payment_status=Completed&payment_date=22%3A40%3A06+Feb+20%2C+2017+PST&transaction_subject=&receiver_email=zqy234api1-facilitator%40126.com&mc_fee=2.74&notify_version=3.8&shipping_method=Default&address_country=France&mc_gross=82.43&test_ipn=1&insurance_amount=0.00&address_name=1111+22&option_name1_1=My+color&option_name1_2=color&ipn_track_id=26d73da3782c3&cmd=_notify-validate';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
curl_setopt($ch, CURLOPT_SSLVERSION, 6);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
// This is often required if the server is missing a global cert bundle, or is using an outdated one.
if ($this->use_local_certs) {
curl_setopt($ch, CURLOPT_CAINFO, __DIR__ . '/cert/cacert.pem');
}
curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Connection: Close']);
$res = curl_exec($ch);
echo $res;
}
*/
}
......@@ -21,31 +21,33 @@ class StandardController extends AppfrontController
public $enableCsrfValidation = false;
/**
* 在网站下单页面,选择支付宝支付方式后,
* 跳转到支付宝支付页面前准备的部分。
* 在网站下单页面,选择支付宝支付方式后,
* 跳转到支付宝支付页面前准备的部分。
*/
public function actionStart()
{
//$AopSdkFile = Yii::getAlias('@fecshop/lib/alipay/AopSdk.php');
//require($AopSdkFile);
echo '支付宝支付跳转中...';
echo '支付宝支付跳转中...';
return Yii::$service->payment->alipay->start();
}
/**
* 从支付宝支付成功后,跳转返回 fec-shop 的部分
* 从支付宝支付成功后,跳转返回 fec-shop 的部分
*/
public function actionReview()
{
Yii::$service->payment->alipay->review();
//$trade_no = Yii::$app->request->get('trade_no');
//$out_trade_no = Yii::$app->request->get('out_trade_no');
//if($trade_no && $out_trade_no){
// echo Yii::$service->payment->alipay->review($trade_no,$out_trade_no);
//}
$reviewStatus = Yii::$service->payment->alipay->review();
if($reviewStatus){
$successRedirectUrl = Yii::$service->payment->getStandardSuccessRedirectUrl();
return Yii::$service->url->redirect($successRedirectUrl);
}else{
echo Yii::$service->helper->errors->get('<br/>');
return;
}
}
/**
* IPN,支付宝消息接收部分
* IPN,支付宝消息接收部分
*/
public function actionIpn()
{
......@@ -85,67 +87,4 @@ class StandardController extends AppfrontController
}
*/
/*
public $enableCsrfValidation = false;
private $use_local_certs = true;
public function actionStart()
{
Yii::$service->page->theme->layoutFile = 'blank.php';
$data = $this->getBlock()->getLastData();
if (is_array($data) && !empty($data)) {
return $this->render($this->action->id, $data);
} else {
return Yii::$service->url->redirectByUrlKey('checkout/onepage');
}
}
public function actionIpn()
{
\Yii::info('paypal ipn begin', 'fecshop_debug');
$post = Yii::$app->request->post();
if (is_array($post) && !empty($post)) {
$post = \Yii::$service->helper->htmlEncode($post);
ob_start();
ob_implicit_flush(false);
var_dump($post);
$post_log = ob_get_clean();
\Yii::info($post_log, 'fecshop_debug');
//Yii::$service->payment->paypal->receiveIpn($post);
}
}
public function actionTest()
{
$url = 'https://www.sandbox.paypal.com/cgi-bin/webscr?invoice=1000000124&first_name=test&discount=7.11&mc_shipping=0.00&mc_currency=EUR&payer_status=verified&shipping_discount=0.00&payment_fee=&address_status=unconfirmed&payment_gross=&settle_currency=USD&address_zip=212121&address_country_code=FR&txn_type=cart&num_cart_items=3&mc_handling=0.00&verify_sign=AuRlNZvMOhdn8iDWY5YoMB9iRTDzAZppqkxKbGiGEUvmwrFAdvscLpXK&payer_id=FKL4V7D5GCACY&option_selection2_1=L&option_selection2_2=L&charset=windows-1252&tax1=0.00&receiver_id=H4KXD885J8LV2&tax2=0.00&tax3=0.00&mc_handling1=0.00&mc_handling2=0.00&mc_handling3=0.00&item_name1=Reindeer+Pattern+Glitter+Christmas+Dress&tax=0.00&item_name2=Sweet+Polka+Dot+Open+Back+Summer+Dress+For+Women&item_name3=fast_shipping&payment_type=instant&mc_shipping1=0.00&address_street=2121%0D%0A23232&mc_shipping2=0.00&mc_shipping3=0.00&txn_id=9NN80505PR451120Y&exchange_rate=1.29364&mc_gross_1=40.34&quantity1=2&mc_gross_2=30.69&quantity2=1&item_number1=22221&protection_eligibility=Eligible&mc_gross_3=18.51&quantity3=1&item_number2=sk0003&item_number3=Fast+Shipping%28+5-10+work+days%29&custom=&option_selection1_1=black&option_selection1_2=red&business=zqy234api1-facilitator%40126.com&residence_country=US&last_name=facilitator&address_state=Hautes-Alpes&payer_business_name=test+facilitator%27s+Test+Store&payer_email=zqy234api1-facilitator-1%40126.com&option_name2_1=My+size&option_name2_2=size&settle_amount=103.09&address_city=2121&payment_status=Completed&payment_date=22%3A40%3A06+Feb+20%2C+2017+PST&transaction_subject=&receiver_email=zqy234api1-facilitator%40126.com&mc_fee=2.74&notify_version=3.8&shipping_method=Default&address_country=France&mc_gross=82.43&test_ipn=1&insurance_amount=0.00&address_name=1111+22&option_name1_1=My+color&option_name1_2=color&ipn_track_id=26d73da3782c3&cmd=_notify-validate';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
curl_setopt($ch, CURLOPT_SSLVERSION, 6);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
// This is often required if the server is missing a global cert bundle, or is using an outdated one.
if ($this->use_local_certs) {
curl_setopt($ch, CURLOPT_CAINFO, __DIR__ . '/cert/cacert.pem');
}
curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Connection: Close']);
$res = curl_exec($ch);
echo $res;
}
*/
}
......@@ -62,7 +62,8 @@ class Alipay extends Service
/**
* 初始化 $this->_AopClient
*/
protected function initParam(){
protected function initParam()
{
if(!$this->_AopClient){
$this->_AopClient = new \AopClient;
$this->_AopClient->gatewayUrl = $this->gatewayUrl;
......@@ -91,7 +92,8 @@ class Alipay extends Service
* 在支付宝的业务通知中,只有交易通知状态为TRADE_SUCCESS或TRADE_FINISHED时,
* 支付宝才会认定为买家付款成功。
*/
protected function validateReviewOrder($out_trade_no,$total_amount,$seller_id,$auth_app_id){
protected function validateReviewOrder($out_trade_no,$total_amount,$seller_id,$auth_app_id)
{
if(!$this->_order){
$this->_order = Yii::$service->order->getByIncrementId($out_trade_no);
Yii::$service->payment->setPaymentMethod($this->_order['payment_method']);
......@@ -130,7 +132,8 @@ class Alipay extends Service
* 支付宝 支付成功后,返回网站,调用该函数进行支付宝订单支付状态查询
* 如果支付成功,则修改订单状态为支付成功状态。
*/
protected function actionReview(){
protected function actionReview()
{
$this->initParam();
$trade_no = Yii::$app->request->get('trade_no');
$out_trade_no = Yii::$app->request->get('out_trade_no');
......@@ -138,7 +141,7 @@ class Alipay extends Service
$seller_id = Yii::$app->request->get('seller_id');
$auth_app_id = Yii::$app->request->get('auth_app_id');
//验证订单的合法性
if(!$this->validateReviewOrder($out_trade_no,$total_amount,$seller_id,$auth_app_id)){
if (!$this->validateReviewOrder($out_trade_no,$total_amount,$seller_id,$auth_app_id)){
return false;
}
......@@ -153,17 +156,16 @@ class Alipay extends Service
$result = $this->_AopClient->execute($this->_alipayRequest);
$responseNode = str_replace(".", "_", $this->_alipayRequest->getApiMethodName()) . "_response";
$resultCode = $result->$responseNode->code;
if(!empty($resultCode)&&$resultCode == 10000){
$this->paymentSuccess($out_trade_no,$trade_no,false);
if (!empty($resultCode)&&$resultCode == 10000) {
$this->paymentSuccess($out_trade_no,$trade_no);
// 清空购物车
Yii::$service->cart->clearCartProductAndCoupon();
// 跳转 success_redirect_url
$successRedirectUrl = Yii::$service->payment->getStandardSuccessRedirectUrl();
//echo $successRedirectUrl;exit;
return Yii::$service->url->redirect($successRedirectUrl);
return true;
} else {
echo 'resultCode:'.$resultCode."<br/>";
echo "alipay payment fail";
Yii::$service->helper->errors->add('alipay payment fail,resultCode:'.$resultCode);
return false;
}
}
......@@ -172,14 +174,15 @@ class Alipay extends Service
* 您开启log后,可以在@app/runtime/fecshop_logs
* 文件夹下执行:tail -f fecshop_debug.log , 来查看log输出。
*/
public function receiveIpn(){
public function receiveIpn()
{
Yii::info('alipay service receiveIpn():begin init param', 'fecshop_debug');
$this->initParam();
Yii::info('alipay service receiveIpn():begin rsaCheck', 'fecshop_debug');
// 验签
$checkV2Status = $this->_AopClient->rsaCheckV1($_POST, '' ,$this->signType);
Yii::info('alipay service receiveIpn():rsacheck end', 'fecshop_debug');
if($checkV2Status){
if ($checkV2Status) {
Yii::info('alipay service receiveIpn():rsacheck success', 'fecshop_debug');
$trade_no = Yii::$app->request->post('trade_no');
$out_trade_no = Yii::$app->request->post('out_trade_no');
......@@ -195,14 +198,15 @@ class Alipay extends Service
Yii::info('alipay service receiveIpn(): [ trade_status: ]'.$trade_status, 'fecshop_debug');
//验证订单的合法性
if(!$this->validateReviewOrder($out_trade_no,$total_amount,$seller_id,$auth_app_id)){
if (!$this->validateReviewOrder($out_trade_no,$total_amount,$seller_id,$auth_app_id)) {
Yii::info('alipay service receiveIpn(): validate order fail', 'fecshop_debug');
return false;
}
Yii::info('alipay service receiveIpn():validate order success', 'fecshop_debug');
if(self::TRADE_SUCCESS == $trade_status){
if (self::TRADE_SUCCESS == $trade_status){
Yii::info('alipay service receiveIpn():alipay trade success ', 'fecshop_debug');
if($this->paymentSuccess($out_trade_no,$trade_no)){
if ($this->paymentSuccess($out_trade_no,$trade_no)){
Yii::info('alipay service receiveIpn():update order status success', 'fecshop_debug');
return true;
......@@ -214,7 +218,6 @@ class Alipay extends Service
}
}
/**
* @property $increment_id | String 订单号
* @property $sendEmail | boolean 是否发送邮件
......@@ -222,12 +225,17 @@ class Alipay extends Service
*/
protected function paymentSuccess($increment_id,$trade_no,$sendEmail = true)
{
if(!$this->_order){
if (!$this->_order) {
$this->_order = Yii::$service->order->getByIncrementId($increment_id);
Yii::$service->payment->setPaymentMethod($this->_order['payment_method']);
}
// 如果订单状态已经是processing,那么,不需要更改订单状态了。
if ($this->_order['order_status'] == Yii::$service->order->payment_status_processing){
return true;
}
$order = $this->_order;
if(isset($order['increment_id']) && $order['increment_id']){
if (isset($order['increment_id']) && $order['increment_id']) {
// 如果支付成功,则更改订单状态为支付成功
$order->order_status = Yii::$service->order->payment_status_processing;
$order->txn_id = $trade_no; // 支付宝的交易号
......@@ -236,9 +244,8 @@ class Alipay extends Service
// 得到当前的订单信息
$orderInfo = Yii::$service->order->getOrderInfoByIncrementId($order['increment_id']);
// 发送新订单邮件
if($sendEmail){
Yii::$service->email->order->sendCreateEmail($orderInfo);
}
Yii::$service->email->order->sendCreateEmail($orderInfo);
return true;
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册