magento 添加支付宝国际卡 vida 和 masterCard
一:后台支付方式添加模块
<?xml version="1.0"?>
<!--
/**
* Copyright
* @author blog.itiwin.cn
*/
-->
<config>
<sections>
<payment>
<groups>
<alipayforcard_payment module="alipayforcard">
<label>More AlipayForcard Payment</label>
<frontend_type>text</frontend_type>
<sort_order>300</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>0</show_in_store>
<fields>
<active translate="label">
<label>Enabled</label>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_yesno</source_model>
<sort_order>1</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>0</show_in_store>
</active>
<title translate="label">
<label>Title</label>
<frontend_type>text</frontend_type>
<sort_order>2</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>0</show_in_store>
</title>
<gateway translate="label">
<label>Gateway</label>
<frontend_type>text</frontend_type>
<sort_order>4</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>0</show_in_store>
</gateway>
<partner_id translate="label">
<label>Partner ID</label>
<frontend_type>text</frontend_type>
<sort_order>5</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>0</show_in_store>
</partner_id>
<security_code translate="label">
<label>Security Code</label>
<frontend_type>text</frontend_type>
<sort_order>6</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>0</show_in_store>
</security_code>
<seller_email translate="label">
<label>Seller Email</label>
<frontend_type>text</frontend_type>
<sort_order>7</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>0</show_in_store>
</seller_email>
<transport translate="label">
<label>Transport</label>
<frontend_type>select</frontend_type>
<source_model>alipayforcard/source_transport</source_model>
<sort_order>8</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</transport>
<order_status translate="label">
<label>New order status</label>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_order_status</source_model>
<sort_order>12</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>0</show_in_store>
</order_status>
<order_status_payment_accepted translate="label">
<label>Order status when payment accepted by AlipayForcard</label>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_order_status</source_model>
<sort_order>13</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>0</show_in_store>
</order_status_payment_accepted>
<order_status_payment_refused translate="label">
<label>Order status when payment refused by AlipayForcard</label>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_order_status</source_model>
<sort_order>14</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>0</show_in_store>
</order_status_payment_refused>
<allowspecific translate="label">
<label>Payment from applicable countries</label>
<frontend_type>allowspecific</frontend_type>
<sort_order>15</sort_order>
<source_model>adminhtml/system_config_source_payment_allspecificcountries</source_model>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</allowspecific>
<specificcountry translate="label">
<label>Payment from Specific countries</label>
<frontend_type>multiselect</frontend_type>
<sort_order>16</sort_order>
<source_model>adminhtml/system_config_source_country</source_model>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</specificcountry>
<sort_order translate="label">
<label>Sort order</label>
<frontend_type>text</frontend_type>
<sort_order>17</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>0</show_in_store>
</sort_order>
</fields>
</alipayforcard_payment>
</groups>
</payment>
</sections>
</config>
二:后台配置好后,前台显示支付方式,当点击saveorder时候,跳转执行改插件
public function returnAction()
{
if ($this->getRequest()->isPost())
{
$postData = $this->getRequest()->getPost();
$method = 'post';
} else if ($this->getRequest()->isGet())
{
$postData = $this->getRequest()->getQuery();
$method = 'get';
} else
{
return;
}
$alipayforcard = Mage::getModel('alipayforcard/payment');
$partner=$alipayforcard->getConfigData('partner_id');
$security_code=$alipayforcard->getConfigData('security_code');
$sign_type='MD5';
$mysign="";
$_input_charset='utf-8';
$transport=$alipayforcard->getConfigData('transport');
if($transport == "https") {
$gateway = "https://www.alipayforcard.com/cooperate/gateway.do?";
} else {
$gateway = "http://notify.alipayforcard.com/trade/notify_query.do?";
}
if($transport == "https") {
$veryfy_url = $gateway. "service=notify_verify" ."&partner=" .$partner. "¬ify_id=".$postData["notify_id"];
} else {
$veryfy_url = $gateway. "partner=".$partner."¬ify_id=".$postData["notify_id"];
}
$veryfy_result="";
//$veryfy_result = $this->get_verify($veryfy_url);
$post = $this->para_filter($postData);
$sort_post = $this->arg_sort($post);
$arg="";
while (list ($key, $val) = each ($sort_post)) {
$arg.=$key."=".$val."&";
}
$prestr="";
$prestr = substr($arg,0,count($arg)-2);
$mysign = $this->sign($prestr.$security_code);
//Mage::log(strpos($veryfy_result,"true"));
$model = Mage::getModel('alipayforcard/payment');
if($postData['trade_status'] == 'TRADE_SUCCESS' or $postData['trade_status'] == 'TRADE_FINISHED') { //µÈ´ýÂò¼Ò¸¶¿î
$order = Mage::getModel('sales/order');
$order->loadByIncrementId($postData['out_trade_no']);
try{
$order->addStatusToHistory(
$model->getConfigData('order_status_payment_accepted'),
Mage::helper('alipayforcard')->__('Payment Success')
);
$order->setState(Mage_Sales_Model_Order::STATE_PROCESSING,
$model->getConfigData('order_status_payment_accepted'),
Mage::helper('alipayforcard')->__('Payment Success')
);
$order->sendNewOrderEmail();
$order->save();
$this->_redirect('checkout/onepage/success');
//echo "Success";
} catch(Exception $e){
Mage::log($e);
}
}
else {
try{
$order->addStatusToHistory(
$model->getConfigData('order_status_payment_refused'),
Mage::helper('alipayforcard')->__('Payment refused by AlipayForcard:').$postData['trade_status']. $postData['error_code'],
true
);
$order->save();
$order->sendOrderUpdateEmail();
$this->_redirect('checkout/onepage/failure');
echo "Fail";
} catch(Exception $e){
}
}
}
(责任编辑:好模板) |