Cosmo_Community_AlipayPaymentGateway - Version 1.4.1.0

Version Notes

8-1 security fix

Download this release

Release Info

Developer Magento Core Team
Extension Cosmo_Community_AlipayPaymentGateway
Version 1.4.1.0
Comparing to
See all releases


Code changes from version 1.4.0.3 to 1.4.1.0

app/code/community/CosmoCommerce/Alipay/Model/Payment.php CHANGED
@@ -148,6 +148,13 @@ class CosmoCommerce_Alipay_Model_Payment extends Mage_Payment_Model_Method_Abstr
148
  Mage::throwException($this->_getHelper()->__('Cannot retrieve order object'));
149
  }
150
 
 
 
 
 
 
 
 
151
  $parameter = array('service' => $this->getConfigData('service_type'),
152
  'partner' => $this->getConfigData('partner_id'),
153
  'return_url' => $this->getReturnURL(),
@@ -159,7 +166,7 @@ class CosmoCommerce_Alipay_Model_Payment extends Mage_Payment_Model_Method_Abstr
159
  'logistics_fee' => '0.00', //because magento has shipping system, it has included shipping price
160
  'logistics_payment' => 'BUYER_PAY', //always
161
  'logistics_type' => 'EXPRESS', //Only three shipping method:POST,EMS,EXPRESS
162
- 'price' => sprintf('%.2f', $order->getBaseGrandTotal()) ,
163
  'payment_type' => '1',
164
  'quantity' => '1', // For the moment, the parameter of price is total price, so the quantity is 1.
165
  'show_url' => Mage::getUrl(),
148
  Mage::throwException($this->_getHelper()->__('Cannot retrieve order object'));
149
  }
150
 
151
+ $currency_code = Mage::app()->getStore()->getCurrentCurrencyCode();
152
+ $converted_final_price = Mage::helper('directory')->currencyConvert($order->getBaseGrandTotal(), $currency_code, 'CNY');
153
+ if($converted_final_price){
154
+ $converted_final_price=$converted_final_price;
155
+ }else{
156
+ $converted_final_price=$order->getBaseGrandTotal();
157
+ }
158
  $parameter = array('service' => $this->getConfigData('service_type'),
159
  'partner' => $this->getConfigData('partner_id'),
160
  'return_url' => $this->getReturnURL(),
166
  'logistics_fee' => '0.00', //because magento has shipping system, it has included shipping price
167
  'logistics_payment' => 'BUYER_PAY', //always
168
  'logistics_type' => 'EXPRESS', //Only three shipping method:POST,EMS,EXPRESS
169
+ 'price' => sprintf('%.2f', $converted_final_price) ,
170
  'payment_type' => '1',
171
  'quantity' => '1', // For the moment, the parameter of price is total price, so the quantity is 1.
172
  'show_url' => Mage::getUrl(),
app/code/community/CosmoCommerce/Alipay/controllers/PaymentController.php CHANGED
@@ -78,7 +78,6 @@ class CosmoCommerce_Alipay_PaymentController extends Mage_Core_Controller_Front_
78
 
79
  public function notifyAction()
80
  {
81
-
82
  if ($this->getRequest()->isPost())
83
  {
84
  $postData = $this->getRequest()->getPost();
@@ -94,32 +93,161 @@ class CosmoCommerce_Alipay_PaymentController extends Mage_Core_Controller_Front_
94
  {
95
  return;
96
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
97
 
 
 
 
 
 
98
 
99
- if ($postData['trade_status'] == "TRADE_FINISHED")
100
- {
101
- $order = Mage::getModel('sales/order');
102
- $order->loadByIncrementId($postData['out_trade_no']);
103
- //$order->setAlipayTradeno($postData['trade_no']);
104
- $order->setStatus(Mage_Sales_Model_Order::STATE_PROCESSING);
105
- // $order->sendNewOrderEmail();
106
- $order->addStatusToHistory(
107
- $order->getStatus(),
108
- Mage::helper('alipay')->__('买家已付款, 等待卖家发货。'));
109
- try
110
- {
111
- $order->save();
112
- } catch(Exception $e)
113
- {
114
- ;
115
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
116
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
117
 
118
- }
 
 
 
 
119
 
120
- return;
 
 
121
  }
122
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
123
  /**
124
  * Alipay response router
125
  *
@@ -272,4 +400,41 @@ class CosmoCommerce_Alipay_PaymentController extends Mage_Core_Controller_Front_
272
  $this->renderLayout();
273
  Mage::getSingleton('checkout/session')->unsLastRealOrderId();
274
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
275
  }
78
 
79
  public function notifyAction()
80
  {
 
81
  if ($this->getRequest()->isPost())
82
  {
83
  $postData = $this->getRequest()->getPost();
93
  {
94
  return;
95
  }
96
+ $alipay = Mage::getModel('alipay/payment');
97
+
98
+ $partner=$alipay->getConfigData('partner_id');
99
+ $security_code=$alipay->getConfigData('security_code');
100
+ $sign_type='MD5';
101
+ $mysign="";
102
+ $_input_charset='utf-8';
103
+ $transport=$alipay->getConfigData('transport');
104
+
105
+ if($transport == "https") {
106
+ $gateway = "https://www.alipay.com/cooperate/gateway.do?";
107
+ } else {
108
+ $gateway = "http://notify.alipay.com/trade/notify_query.do?";
109
+ }
110
 
111
+ if($transport == "https") {
112
+ $veryfy_url = $gateway. "service=notify_verify" ."&partner=" .$partner. "&notify_id=".$postData["notify_id"];
113
+ } else {
114
+ $veryfy_url = $gateway. "partner=".$partner."&notify_id=".$postData["notify_id"];
115
+ }
116
 
117
+ $veryfy_result="";
118
+ $veryfy_result = $this->get_verify($veryfy_url);
119
+
120
+ $post = $this->para_filter($postData);
121
+
122
+
123
+ $sort_post = $this->arg_sort($post);
124
+
125
+ $arg="";
126
+ while (list ($key, $val) = each ($sort_post)) {
127
+
128
+ $arg.=$key."=".$val."&";
129
+ }
130
+ $prestr="";
131
+ $prestr = substr($arg,0,count($arg)-2); //去掉最后一个&号
132
+ $mysign = $this->sign($prestr.$security_code);
133
+
134
+
135
+ Mage::log(strpos($veryfy_result,"true"));
136
+
137
+ if ( $mysign == $postData["sign"]) {
138
+
139
+
140
+ if($postData['trade_status'] == 'WAIT_BUYER_PAY') { //等待买家付款
141
+
142
+ $order = Mage::getModel('sales/order');
143
+ $order->loadByIncrementId($postData['out_trade_no']);
144
+ //$order->setAlipayTradeno($postData['trade_no']);
145
+ // $order->sendNewOrderEmail();
146
+ $order->addStatusToHistory(
147
+ $order->getStatus(),
148
+ Mage::helper('alipay')->__('等待买家付款。'));
149
+ try{
150
+ $order->save();
151
+ echo "success";
152
+ } catch(Exception $e){
153
+
154
+ }
155
+ }
156
+ else if($postData['trade_status'] == 'WAIT_SELLER_SEND_GOODS') { //买家付款成功,等待卖家发货
157
+
158
+ $order = Mage::getModel('sales/order');
159
+ $order->loadByIncrementId($postData['out_trade_no']);
160
+ //$order->setAlipayTradeno($postData['trade_no']);
161
+ // $order->sendNewOrderEmail();
162
+ $order->addStatusToHistory(
163
+ $alipay->getConfigData('order_status_payment_accepted'),
164
+ Mage::helper('alipay')->__('买家付款成功,等待卖家发货。'));
165
+ try{
166
+ $order->save();
167
+ echo "success";
168
+ } catch(Exception $e){
169
+
170
+ }
171
+ }
172
+ else if($postData['trade_status'] == 'WAIT_BUYER_CONFIRM_GOODS') { //卖家已经发货等待买家确认
173
+
174
+ $order = Mage::getModel('sales/order');
175
+ $order->loadByIncrementId($postData['out_trade_no']);
176
+ //$order->setAlipayTradeno($postData['trade_no']);
177
+ // $order->sendNewOrderEmail();
178
+ $order->addStatusToHistory(
179
+ $alipay->getConfigData('order_status_payment_accepted'),
180
+ Mage::helper('alipay')->__('卖家已经发货等待买家确认。'));
181
+ try{
182
+ $order->save();
183
+ echo "success";
184
+ } catch(Exception $e){
185
+ }
186
 
187
+ }
188
+ else if($postData['trade_status'] == 'TRADE_FINISHED') {
189
+ $order = Mage::getModel('sales/order');
190
+ $order->loadByIncrementId($postData['out_trade_no']);
191
+ //$order->setAlipayTradeno($postData['trade_no']);
192
+ $order->setStatus(Mage_Sales_Model_Order::STATE_PROCESSING);
193
+ // $order->sendNewOrderEmail();
194
+ $order->addStatusToHistory(
195
+ $alipay->getConfigData('order_status_payment_accepted'),
196
+ Mage::helper('alipay')->__('买家已付款,交易成功结束。'));
197
+ try{
198
+ $order->save();
199
+ echo "success";
200
+ } catch(Exception $e){
201
+
202
+ }
203
 
204
+ }
205
+ else {
206
+ echo "fail";
207
+ Mage::log("x");
208
+ }
209
 
210
+ } else {
211
+ echo "fail";
212
+ }
213
  }
214
 
215
+ public function get_verify($url,$time_out = "60") {
216
+ $urlarr = parse_url($url);
217
+ $errno = "";
218
+ $errstr = "";
219
+ $transports = "";
220
+ if($urlarr["scheme"] == "https") {
221
+ $transports = "ssl://";
222
+ $urlarr["port"] = "443";
223
+ } else {
224
+ $transports = "tcp://";
225
+ $urlarr["port"] = "80";
226
+ }
227
+ $fp=@fsockopen($transports . $urlarr['host'],$urlarr['port'],$errno,$errstr,$time_out);
228
+ if(!$fp) {
229
+ die("ERROR: $errno - $errstr<br />\n");
230
+ } else {
231
+ fputs($fp, "POST ".$urlarr["path"]." HTTP/1.1\r\n");
232
+ fputs($fp, "Host: ".$urlarr["host"]."\r\n");
233
+ fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n");
234
+ fputs($fp, "Content-length: ".strlen($urlarr["query"])."\r\n");
235
+ fputs($fp, "Connection: close\r\n\r\n");
236
+ fputs($fp, $urlarr["query"] . "\r\n\r\n");
237
+ while(!feof($fp)) {
238
+ $info[]=@fgets($fp, 1024);
239
+ }
240
+ fclose($fp);
241
+ $info = implode(",",$info);
242
+ $arg="";
243
+ while (list ($key, $val) = each ($_POST)) {
244
+ $arg.=$key."=".$val."&";
245
+ }
246
+
247
+ return $info;
248
+ }
249
+
250
+ }
251
  /**
252
  * Alipay response router
253
  *
400
  $this->renderLayout();
401
  Mage::getSingleton('checkout/session')->unsLastRealOrderId();
402
  }
403
+
404
+
405
+
406
+ public function sign($prestr) {
407
+ $mysign = md5($prestr);
408
+ return $mysign;
409
+ }
410
+
411
+ public function para_filter($parameter) {
412
+ $para = array();
413
+ while (list ($key, $val) = each ($parameter)) {
414
+ if($key == "sign" || $key == "sign_type" || $val == "")continue;
415
+ else $para[$key] = $parameter[$key];
416
+
417
+ }
418
+ return $para;
419
+ }
420
+
421
+ public function arg_sort($array) {
422
+ ksort($array);
423
+ reset($array);
424
+ return $array;
425
+ }
426
+
427
+ public function charset_encode($input,$_output_charset ,$_input_charset ="GBK" ) {
428
+
429
+ $output = "";
430
+ if($_input_charset == $_output_charset || $input ==null) {
431
+ $output = $input;
432
+ } elseif (function_exists("mb_convert_encoding")){
433
+ $output = mb_convert_encoding($input,$_output_charset,$_input_charset);
434
+ } elseif(function_exists("iconv")) {
435
+ $output = iconv($_input_charset,$_output_charset,$input);
436
+ } else die("sorry, you have no libs support for charset change.");
437
+
438
+ return $output;
439
+ }
440
  }
app/code/community/CosmoCommerce/Alipay/etc/config.xml CHANGED
@@ -25,7 +25,7 @@
25
  <config>
26
  <modules>
27
  <CosmoCommerce_Alipay>
28
- <version>0.9.0</version>
29
  </CosmoCommerce_Alipay>
30
  </modules>
31
  <global>
25
  <config>
26
  <modules>
27
  <CosmoCommerce_Alipay>
28
+ <version>0.9.2</version>
29
  </CosmoCommerce_Alipay>
30
  </modules>
31
  <global>
app/code/community/CosmoCommerce/Alipay/sql/alipay_setup/mysql4-install-0.9.2.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @category CosmoCommerce
16
+ * @package CosmoCommerce_Alipay
17
+ * @copyright Copyright (c) 2009 CosmoCommerce,LLC. (http://www.cosmocommerce.com)
18
+ * @contact :
19
+ * T: +86-021-66346672
20
+ * L: Shanghai,China
21
+ * M:sales@cosmocommerce.com
22
+ */
23
+
24
+
25
+ $installer = $this;
package.xml CHANGED
@@ -1,9 +1,9 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Cosmo_Community_AlipayPaymentGateway</name>
4
- <version>1.4.0.3</version>
5
  <stability>stable</stability>
6
- <license>OSI</license>
7
  <channel>community</channel>
8
  <extends/>
9
  <summary>Alipay for magento payment gateway from CosmoCommerce .</summary>
@@ -11,8 +11,8 @@
11
  <notes>8-1 security fix</notes>
12
  <authors><author><name>AirForce</name><user>auto-converted</user><email>airforce.e@gmail.com</email></author><author><name>CosmoDev</name><user>auto-converted</user><email>it@cosmocommerce.com</email></author><author><name>CosmoSales</name><user>auto-converted</user><email>sales@cosmocommerce.com</email></author></authors>
13
  <date>2010-07-31</date>
14
- <time>21:11:49</time>
15
- <contents><target name="magecommunity"><dir name="CosmoCommerce"><dir name="Alipay"><dir name="Block"><file name="Error.php" hash="c817532072a449b23de43ceda3e3449e"/><file name="Form.php" hash="48c64059360ff2f0c44bf24d521748c3"/><file name="Redirect.php" hash="645e71d610a544ff82c4bb7880420d82"/></dir><dir name="controllers"><file name="PaymentController.php" hash="27a1a7a636ea1cf09014906848513729"/></dir><dir name="etc"><file name="config.xml" hash="62842c77f4ecb51c839c945198a0c3b1"/><file name="system.xml" hash="50bdd75296d629022d08f1483f1b5f74"/></dir><dir name="Helper"><file name="Data.php" hash="b43e523edae0133880db5321547e3656"/></dir><dir name="Model"><dir name="Api"><file name="Debug.php" hash="2bcb550e5be88d775d175d6606a33abf"/></dir><dir name="Mysql4"><dir name="Api"><dir name="Debug"><file name="Collection.php" hash="f087249aa312269b65777307045b68f7"/></dir><file name="Debug.php" hash="0706de6770627d74826e6c9926f9bf21"/></dir><file name="Setup.php" hash="3c10dc21599a9be8ec2ea026408d0273"/></dir><dir name="Source"><file name="Language.php" hash="b42df09453e0cc1926d47389add5b17f"/><file name="Servicetype.php" hash="7c143c2f425a4bdec40f9bc596b8da1b"/><file name="Transport.php" hash="25d4c26a05bce13d8efad5f0f54e3b71"/></dir><file name="Payment.php" hash="1b0796230f0c8c67ccdf30086e9ed50f"/></dir><dir name="sql"><dir name="alipay_setup"><file name="mysql4-install-0.1.0.php" hash="fb9240c68056ab9f023e3e205647401b"/></dir></dir></dir></dir></target><target name="magelocale"><dir name="en_US"><file name="CosmoCommerce_Alipay.csv" hash="3ab19412641b6649ee4ea1fca6a9c017"/></dir><dir name="zh_CN"><file name="CosmoCommerce_Alipay.csv" hash="0e61b9b81fd54140a5219a3a7f497c2c"/></dir></target><target name="magedesign"><dir name="frontend"><dir name="default"><dir name="default"><dir name="template"><dir name="alipay"><file name="error.phtml" hash="7d4db86d4b4f7248423949c8fd404eb9"/><file name="form.phtml" hash="10333be234e64a494305339ea1cae7c7"/></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="CosmoCommerce_Alipay.xml" hash="55e6434f09eb7bde74bc9da39a8be7eb"/></dir></target></contents>
16
  <compatible/>
17
  <dependencies/>
18
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Cosmo_Community_AlipayPaymentGateway</name>
4
+ <version>1.4.1.0</version>
5
  <stability>stable</stability>
6
+ <license>OSL</license>
7
  <channel>community</channel>
8
  <extends/>
9
  <summary>Alipay for magento payment gateway from CosmoCommerce .</summary>
11
  <notes>8-1 security fix</notes>
12
  <authors><author><name>AirForce</name><user>auto-converted</user><email>airforce.e@gmail.com</email></author><author><name>CosmoDev</name><user>auto-converted</user><email>it@cosmocommerce.com</email></author><author><name>CosmoSales</name><user>auto-converted</user><email>sales@cosmocommerce.com</email></author></authors>
13
  <date>2010-07-31</date>
14
+ <time>21:20:01</time>
15
+ <contents><target name="magecommunity"><dir name="CosmoCommerce"><dir name="Alipay"><dir name="Block"><file name="Error.php" hash="c817532072a449b23de43ceda3e3449e"/><file name="Form.php" hash="48c64059360ff2f0c44bf24d521748c3"/><file name="Redirect.php" hash="645e71d610a544ff82c4bb7880420d82"/></dir><dir name="controllers"><file name="PaymentController.php" hash="fd041717cc226f543ea620b64db9e893"/></dir><dir name="etc"><file name="config.xml" hash="73290c161116129e355057948876bd76"/><file name="system.xml" hash="50bdd75296d629022d08f1483f1b5f74"/></dir><dir name="Helper"><file name="Data.php" hash="b43e523edae0133880db5321547e3656"/></dir><dir name="Model"><dir name="Api"><file name="Debug.php" hash="2bcb550e5be88d775d175d6606a33abf"/></dir><dir name="Mysql4"><dir name="Api"><dir name="Debug"><file name="Collection.php" hash="f087249aa312269b65777307045b68f7"/></dir><file name="Debug.php" hash="0706de6770627d74826e6c9926f9bf21"/></dir><file name="Setup.php" hash="3c10dc21599a9be8ec2ea026408d0273"/></dir><dir name="Source"><file name="Language.php" hash="b42df09453e0cc1926d47389add5b17f"/><file name="Servicetype.php" hash="7c143c2f425a4bdec40f9bc596b8da1b"/><file name="Transport.php" hash="25d4c26a05bce13d8efad5f0f54e3b71"/></dir><file name="Payment.php" hash="5004e51317560503429fcd2fe1c5e90c"/></dir><dir name="sql"><dir name="alipay_setup"><file name="mysql4-install-0.1.0.php" hash="fb9240c68056ab9f023e3e205647401b"/><file name="mysql4-install-0.9.2.php" hash="fb9240c68056ab9f023e3e205647401b"/></dir></dir></dir></dir></target><target name="magelocale"><dir name="en_US"><file name="CosmoCommerce_Alipay.csv" hash="3ab19412641b6649ee4ea1fca6a9c017"/></dir><dir name="zh_CN"><file name="CosmoCommerce_Alipay.csv" hash="0e61b9b81fd54140a5219a3a7f497c2c"/></dir></target><target name="magedesign"><dir name="frontend"><dir name="default"><dir name="default"><dir name="template"><dir name="alipay"><file name="error.phtml" hash="7d4db86d4b4f7248423949c8fd404eb9"/><file name="form.phtml" hash="10333be234e64a494305339ea1cae7c7"/></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="CosmoCommerce_Alipay.xml" hash="55e6434f09eb7bde74bc9da39a8be7eb"/></dir></target></contents>
16
  <compatible/>
17
  <dependencies/>
18
  </package>