<?php
/**
* Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@magentocommerce.com so we can send you a copy immediately.
*
* @category CosmoCommerce
* @package CosmoCommerce_Alipay
* @copyright Copyright (c) 2009 CosmoCommerce,LLC. (http://www.cosmocommerce.com)
* @contact :
* T: +86-021-66346672
* L: Shanghai,China
* M:sales@cosmocommerce.com
*/
class CosmoCommerce_Alipay_Model_Payment extends Mage_Payment_Model_Method_Abstract
{
protected $_code = 'alipay_payment';
protected $_formBlockType = 'alipay/form';
// Alipay return codes of payment
const RETURN_CODE_ACCEPTED = 'Success';
const RETURN_CODE_TEST_ACCEPTED = 'Success';
const RETURN_CODE_ERROR = 'Fail';
// Payment configuration
protected $_isGateway = false;
protected $_canAuthorize = true;
protected $_canCapture = true;
protected $_canCapturePartial = false;
protected $_canRefund = false;
protected $_canVoid = false;
protected $_canUseInternal = false;
protected $_canUseCheckout = true;
protected $_canUseForMultishipping = false;
// Order instance
protected $_order = null;
/**
* Returns Target URL
*
* @return string Target URL
*/
public function getAlipayUrl()
{
$url = $this->getConfigData('transport').'://'.$this->getConfigData('gateway');
return $url;
}
/**
* Return back URL
*
* @return string URL
*/
protected function getReturnURL()
{
return Mage::getUrl('checkout/onepage/success', array('_secure' => true));
}
/**
* Return URL for Alipay success response
*
* @return string URL
*/
protected function getSuccessURL()
{
return Mage::getUrl('checkout/onepage/success', array('_secure' => true));
}
/**
* Return URL for Alipay failure response
*
* @return string URL
*/
protected function getErrorURL()
{
return Mage::getUrl('alipay/payment/error', array('_secure' => true));
}
/**
* Return URL for Alipay notify response
*
* @return string URL
*/
protected function getNotifyURL()
{
return Mage::getUrl('alipay/payment/notify/', array('_secure' => true));
}
/**
* Capture payment
*
* @param Varien_Object $orderPayment
* @return Mage_Payment_Model_Abstract
*/
public function capture(Varien_Object $payment, $amount)
{
$payment->setStatus(self::STATUS_APPROVED)
->setLastTransId($this->getTransactionId());
return $this;
}
/**
* Form block description
*
* @return object
*/
public function createFormBlock($name)
{
$block = $this->getLayout()->createBlock('alipay/form_payment', $name);
$block->setMethod($this->_code);
$block->setPayment($this->getPayment());
return $block;
}
/**
* Return Order Place Redirect URL
*
* @return string Order Redirect URL
*/
public function getOrderPlaceRedirectUrl()
{
return Mage::getUrl('alipay/payment/redirect');
}
/**
* Return Standard Checkout Form Fields for request to Alipay
*
* @return array Array of hidden form fields
*/
public function getStandardCheckoutFormFields()
{
$session = Mage::getSingleton('checkout/session');
$order = $this->getOrder();
if (!($order instanceof Mage_Sales_Model_Order)) {
Mage::throwException($this->_getHelper()->__('Cannot retrieve order object'));
}
$parameter = array('service' => $this->getConfigData('service_type'),
'partner' => $this->getConfigData('partner_id'),
'return_url' => $this->getReturnURL(),
'notify_url' => $this->getNotifyURL(),
'_input_charset' => 'utf-8',
'subject' => $order->getRealOrderId(),
'body' => $order->getRealOrderId(),
'out_trade_no' => $order->getRealOrderId(), // order ID
'logistics_fee' => '0.00', //because magento has shipping system, it has included shipping price
'logistics_payment' => 'BUYER_PAY', //always
'logistics_type' => 'EXPRESS', //Only three shipping method:POST,EMS,EXPRESS
'price' => sprintf('%.2f', $order->getBaseGrandTotal()) ,
'payment_type' => '1',
'quantity' => '1', // For the moment, the parameter of price is total price, so the quantity is 1.
'show_url' => Mage::getUrl(),
'seller_email' => $this->getConfigData('seller_email')
);
$parameter = $this->para_filter($parameter);
$security_code = $this->getConfigData('security_code');
$sign_type = 'MD5';
$sort_array = array();
$arg = "";
$sort_array = $this->arg_sort($parameter); //$parameter
while (list ($key, $val) = each ($sort_array)) {
$arg.=$key."=".$this->charset_encode($val,$parameter['_input_charset'])."&";
}
$prestr = substr($arg,0,count($arg)-2);
$mysign = $this->sign($prestr.$security_code);
$fields = array();
$sort_array = array();
$arg = "";
$sort_array = $this->arg_sort($parameter); //$parameter
while (list ($key, $val) = each ($sort_array)) {
$fields[$key] = $this->charset_encode($val,'utf-8');
}
$fields['sign'] = $mysign;
$fields['sign_type'] = $sign_type;
return $fields;
}
public function sign($prestr) {
$mysign = md5($prestr);
return $mysign;
}
public function para_filter($parameter) {
$para = array();
while (list ($key, $val) = each ($parameter)) {
if($key == "sign" || $key == "sign_type" || $val == "")continue;
else $para[$key] = $parameter[$key];
}
return $para;
}
public function arg_sort($array) {
ksort($array);
reset($array);
return $array;
}
public function charset_encode($input,$_output_charset ,$_input_charset ="GBK" ) {
$output = "";
if($_input_charset == $_output_charset || $input ==null) {
$output = $input;
} elseif (function_exists("mb_convert_encoding")){
$output = mb_convert_encoding($input,$_output_charset,$_input_charset);
} elseif(function_exists("iconv")) {
$output = iconv($_input_charset,$_output_charset,$input);
} else die("sorry, you have no libs support for charset change.");
return $output;
}
/**
* Return authorized languages by Alipay
*
* @param none
* @return array
*/
protected function _getAuthorizedLanguages()
{
$languages = array();
foreach (Mage::getConfig()->getNode('global/payment/alipay_payment/languages')->asArray() as $data)
{
$languages[$data['code']] = $data['name'];
}
return $languages;
}
/**
* Return language code to send to Alipay
*
* @param none
* @return String
*/
protected function _getLanguageCode()
{
// Store language
$language = strtoupper(substr(Mage::getStoreConfig('general/locale/code'), 0, 2));
// Authorized Languages
$authorized_languages = $this->_getAuthorizedLanguages();
if (count($authorized_languages) === 1)
{
$codes = array_keys($authorized_languages);
return $codes[0];
}
if (array_key_exists($language, $authorized_lang
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
共22个文件
php:14个
xml:4个
phtml:2个
CosmoCommerce Alipay Payment Gateway for Magento 我们做支付接口很久了,发现的确由于收费限制了很多人去用支付模块,因此开源出来,让更多的人用magento,了解magento做生态环境才是我们的愿景.希望大家可以支持! If you like this module,please support us to continue open source! Alipay(支付宝) : www.alipay.com CosmoCommerce: www.cosmocommerce.com Source Code:git OpenSource Support Information: Email:opensource@cosmocommerce.com Tel: +86-021-66346672 Cosmo Mao Welcome your feedback, thanks!
资源推荐
资源详情
资源评论
收起资源包目录
Cosmo_Community_AlipayPaymentGateway-1.3.2.4.tgz (22个子文件)
package.xml 5KB
Cosmo_Community_AlipayPaymentGateway-1.3.2.4
en_US
CosmoCommerce_Alipay.csv 2KB
CosmoCommerce
Alipay
etc
config.xml 5KB
system.xml 9KB
Model
Mysql4
Setup.php 817B
Api
Debug
Collection.php 936B
Debug.php 925B
Source
Transport.php 1KB
Servicetype.php 1KB
Language.php 1KB
Api
Debug.php 898B
Payment.php 9KB
sql
alipay_setup
mysql4-install-0.1.0.php 751B
Helper
Data.php 807B
Block
Error.php 804B
Redirect.php 2KB
Form.php 930B
controllers
PaymentController.php 7KB
frontend
default
default
template
alipay
error.phtml 901B
form.phtml 4KB
zh_CN
CosmoCommerce_Alipay.csv 1KB
modules
CosmoCommerce_Alipay.xml 1018B
共 22 条
- 1
资源评论
- keith_2932012-10-25很好!可惜提供的文件不全!
- carloshjc2013-01-03好像是官方的那个,不知道怎么装呢,正测试
cneeeetg
- 粉丝: 7
- 资源: 12
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功