提交 d995982f 编写于 作者: R root

fecshop paypal payment ipn

上级 105677ee
......@@ -18,6 +18,7 @@ use fecshop\app\appfront\modules\AppfrontController;
class StandardController extends AppfrontController
{
public $enableCsrfValidation = false;
private $use_local_certs = true;
public function actionStart(){
Yii::$service->page->theme->layoutFile = 'blank.php';
......@@ -40,6 +41,28 @@ class StandardController extends AppfrontController
exit;
}
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, array('Connection: Close'));
$res = curl_exec($ch);
echo $res;
}
}
......
......@@ -33,6 +33,7 @@ return [
# 第三方支付网站的url
'payment_url'=>'https://www.sandbox.paypal.com/cgi-bin/webscr',
//'ipn_url' => 'https://ipnpb.sandbox.paypal.com/cgi-bin/webscr'
# 用户名
'user' => 'zqy234api1-facilitator@126.com',
# 账号
......
......@@ -378,7 +378,7 @@ class Coupon extends Service
$product_total = isset($cartProduct['product_total']) ? $cartProduct['product_total'] : 0;
if($product_total){
//var_dump($product_total);
$dc_price = Yii::$service->page->currency->getDefaultCurrencyPrice($product_total);
$dc_price = Yii::$service->page->currency->getBaseCurrencyPrice($product_total);
if($dc_price > $conditions){
# 事务更新购物侧的coupon 和优惠券的使用情况。
......@@ -433,4 +433,4 @@ class Coupon extends Service
}
}
}
\ No newline at end of file
}
......@@ -462,7 +462,7 @@ class Quote extends Service
public function getCouponCost($base_product_total,$coupon_code){
//echo '###'; var_dump($product_total);exit;
//list($base_product_total,$product_total) = $product_total;
//$dc_price = Yii::$service->page->currency->getDefaultCurrencyPrice($product_total);
//$dc_price = Yii::$service->page->currency->getBaseCurrencyPrice($product_total);
$dc_discount = Yii::$service->cart->coupon->getDiscount($coupon_code,$base_product_total);
//var_dump($dc_discount);exit;
return $dc_discount;
......@@ -559,4 +559,4 @@ class Quote extends Service
}
\ No newline at end of file
}
......@@ -122,14 +122,17 @@ class Currency extends Service
}
/**
* @property $current_price | Float 当前货币下的价格
* @return 默认货币下的价格
* 通过当前的货币价格得到默认货币的价格,这是一个反推的过程,
* 需要特别注意的是:这种反推方法换算得到的默认货币的价格,和原来的默认货币价格,
* @return 基础货币下的价格
* 通过当前的货币价格得到基础货币的价格,这是一个反推的过程,
* 需要特别注意的是:这种反推方法换算得到的基础货币的价格,和原来的基础货币价格,
* 可能有0.01的误差,因为默认货币换算成当前货币的算法为小数点后两位进一法得到的。
*/
protected function actionGetDefaultCurrencyPrice($current_price){
if(isset($this->currencys[$this->getCurrentCurrency()]['rate'])){
$rate = $this->currencys[$this->getCurrentCurrency()]['rate'];
protected function actionGetBaseCurrencyPrice($current_price,$current_currency=''){
if(!$current_currency){
$current_currency = $this->getCurrentCurrency();
}
if(isset($this->currencys[$current_currency]['rate'])){
$rate = $this->currencys[$current_currency]['rate'];
if($rate)
return ceil($current_price / $rate * 100)/100;
}
......
......@@ -11,6 +11,7 @@ use Yii;
use yii\base\InvalidValueException;
use yii\base\InvalidConfigException;
use fecshop\models\mysqldb\IpnMessage;
use fecshop\services\Service;
/**
* Payment Paypal services
* @author Terry Zhao <2358269014@qq.com>
......@@ -33,16 +34,26 @@ class Paypal extends Service
public $payment_status_processed = 'processed';
public $payment_status_voided = 'voided';
public $use_local_certs = true;
protected $_postData;
protected $_order;
public function receiveIpn(){
if($this->verifySecurity()){
# 验证数据是否已经发送
if($this->isNotDuplicate()){
# 验证数据是否被篡改。
if($this->isNotDistort()){
$this->updateOrderAndCoupon();
}else{
# 如果数据和订单数据不一致,而且,支付状态为成功,则此订单
......@@ -66,8 +77,6 @@ class Paypal extends Service
protected function getVerifyUrl(){
$urlParamStr = '';
if($this->_postData){
foreach ($this->_postData as $k => $v) {
$urlParamStr .= '&'.$k.'='.urlencode($v);
......@@ -81,16 +90,23 @@ class Paypal extends Service
}
protected function curlGet($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_TIMEOUT,60);
// Turn off the server and peer verification (TrustManager Concept).
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// Get response from the server.
$httpResponse = curl_exec($ch);
$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/paypal.crt");
}
curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: Close'));
$httpResponse = curl_exec($ch);
return $httpResponse;
}
......@@ -107,11 +123,11 @@ class Paypal extends Service
if(is_array($ipn) && !empty($ipn)){
return false;
}else{
$IpnMessage = new IpnMessage();
$IpnMessage = new IpnMessage;
$IpnMessage->txn_id = $this->_postData['txn_id'];
$IpnMessage->payment_status = $this->_postData['payment_status'];
$IpnMessage->updated_at = time();
$IpnMessage->Insert();
$IpnMessage->save();
return true;
}
}
......@@ -124,9 +140,9 @@ class Paypal extends Service
*/
protected function isNotDistort(){
//Yii::$app->mylog->log("begin isNotDistort..");
$increment_id = this->_postData['invoice'];
$mc_gross = this->_postData['mc_gross'];
$mc_currency = this->_postData['mc_currency'];
$increment_id = $this->_postData['invoice'];
$mc_gross = $this->_postData['mc_gross'];
$mc_currency = $this->_postData['mc_currency'];
if($increment_id && $mc_gross && $mc_currency){
$this->_order = Yii::$service->order->getByIncrementId($increment_id);;
......@@ -152,6 +168,9 @@ class Paypal extends Service
* 更新订单状态。
*/
public function updateOrderAndCoupon($orderstatus = ''){
if($this->_postData['txn_type']){
$this->_order->txn_type = $this->_postData['txn_type'];
}
......@@ -176,7 +195,7 @@ class Paypal extends Service
if($this->_postData['mc_fee']){
$this->_order->payment_fee = $this->_postData['mc_fee'];
$currency = $this->_postData['mc_currency'];
$this->_order->base_payment_fee = Currency::getBaseCurrencyFromOther($this->_postData['mc_fee'],$currency);
$this->_order->base_payment_fee = Yii::$service->page->currency->getBaseCurrencyPrice($this->_postData['mc_fee'],$currency);
}
if($this->_postData['payment_type']){
$this->_order->payment_type = $this->_postData['payment_type'];
......@@ -194,35 +213,33 @@ class Paypal extends Service
# 指定了订单状态
$this->_order->order_status = $orderstatus;
$this->_order->save();
$payment_status = strtolower($this->_postData['payment_status']);
//Yii::$app->mylog->log('save_'.$orderstatus);
}else{
switch (strtolower($this->_postData['payment_status'])) {
case $this->payment_status_completed :
$this->_order->order_status = Yii::$service->order->payment_status_processing;
# 更新订单信息
$this->_order->save();
# 更新库存
//$orderitem = Salesorderitem::find()->asArray()->where(['order_id'=>$this->_order->order_id])->all();
//Order::updateProductStockQty($orderitem);
# 更新coupon使用量
//$customer_id = $this->_order['customer_id'];
//$coupon_code = $this->_order['coupon_code'];
//if($customer_id && $coupon_code){
// Coupon::CouponTakeEffect($customer_id,$coupon_code);
//}
#LOG
//Yii::$app->mylog->log('save_'.Order::ORDER_PROCESSING);
break;
case $this->payment_status_failed :
$this->_order->order_status = Yii::$service->order->payment_status_canceled;
$this->_order->save();
break;
case $this->payment_status_refunded :
$this->_order->order_status = Yii::$service->order->payment_status_canceled;
$this->_order->save();
break;
default:
break;
$payment_status = strtolower($this->_postData['payment_status']);
if($payment_status == $this->payment_status_completed) {
$this->_order->order_status = Yii::$service->order->payment_status_processing;
# 更新订单信息
$this->_order->save();
# 更新库存
//$orderitem = Salesorderitem::find()->asArray()->where(['order_id'=>$this->_order->order_id])->all();
//Order::updateProductStockQty($orderitem);
# 更新coupon使用量
//$customer_id = $this->_order['customer_id'];
//$coupon_code = $this->_order['coupon_code'];
//if($customer_id && $coupon_code){
// Coupon::CouponTakeEffect($customer_id,$coupon_code);
//}
#LOG
//Yii::$app->mylog->log('save_'.Order::ORDER_PROCESSING);
}else if($payment_status == $this->payment_status_failed){
$this->_order->order_status = Yii::$service->order->payment_status_canceled;
$this->_order->save();
}else if($payment_status == $this->payment_status_refunded){
$this->_order->order_status = Yii::$service->order->payment_status_canceled;
$this->_order->save();
}else{
}
}
$innerTransaction->commit();
......
因为 它太大了无法显示 source diff 。你可以改为 查看blob
-----BEGIN CERTIFICATE-----
MIIFjDCCBHSgAwIBAgIQVeuz+EgDzKxFsKnpA78ETzANBgkqhkiG9w0BAQsFADB3
MQswCQYDVQQGEwJVUzEdMBsGA1UEChMUU3ltYW50ZWMgQ29ycG9yYXRpb24xHzAd
BgNVBAsTFlN5bWFudGVjIFRydXN0IE5ldHdvcmsxKDAmBgNVBAMTH1N5bWFudGVj
IENsYXNzIDMgRVYgU1NMIENBIC0gRzMwHhcNMTUwOTE4MDAwMDAwWhcNMTcwOTI5
MjM1OTU5WjCCARcxEzARBgsrBgEEAYI3PAIBAxMCVVMxGTAXBgsrBgEEAYI3PAIB
AgwIRGVsYXdhcmUxHTAbBgNVBA8TFFByaXZhdGUgT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YGCCsGAQUFBzAChhpo
dHRwOi8vc3Iuc3ltY2IuY29tL3NyLmNydDCCAXwGCisGAQQB1nkCBAIEggFsBIIB
aAFmAHYA3esdK3oNT6Ygi4GtgWhwfi6OnQHVXIiNPRHEzbbsvswAAAFSpFZ5PQAA
BAMARzBFAiB6j3nYN/CojD81wKOoDOhcUiK0EU32KilH3synHO5XEwIhAM2eM8Ws
vGK6rfGe8nJ4fGs9QMmXI3bTnRxcdWSeCem7AHUApLkJkLQYWBSHuxOizGdwCjw1
mAT5G9+443fNDsgN3BAAAAFSpFZ5bgAABAMARjBEAiApYKfEn4BLd4uZERNZ9/4e
w3NlCcoN9KcCVKesPx7OKwIgEyKaNe98YBdY9b4nw+KcJRzjZZIFJVIu7R53cfO1
wv4AdQBo9pj4H2SCvjqM7rkoHUz8cVFdZ5PURNEKZ6y7T0/7xAAAAVKkVnlXAAAE
AwBGMEQCIHQpjXQ06MfOV9DjzEnQm2CLPnui8P/lLyZrM6sEZvCNAiAziNOuyunX
wsaILVE7FMjg96sY02A0dsW/mGVPps7lJDANBgkqhkiG9w0BAQsFAAOCAQEAS6lk
IMx3CzCraVDTf97cfOL7k4T9eKcG6BQDmcDkSu/DXRUqgaG5/9w6r82A8HyPjh1X
BWlw0Zr6JZ87V8IxdYV/UQWKQLRnnEp9yaRT/4f/fbS9ObsQH3YmMbLDs2I2zAIB
ZdZuwaOv/PAR29XusH8fY//HNR2I2wTXGg8Ztpad6KT9gIqFfHvfSZ8VDSU9IdjN
fDlUABWAm1B+nDxoZWlyvHHmmOgw6m4wm5ANFul1hjAWeaR/TlWd20lj7iXUt+dW
GN/QMQ3a55rjwNQnA3s2WWuHGPaE/jMG17iiL2O/hUdIvLE9+wA+fWrey5//74xl
NeQitYiySDIepHGnng==
-----END CERTIFICATE-----
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册