Version Notes
Cybersource Simple Redirect Payment Method
Download this release
Release Info
Developer | Softaddicts.com |
Extension | Cybersource_Simple_Redirect |
Version | 0.1.3 |
Comparing to | |
See all releases |
Version 0.1.3
- app/code/community/Payment/.DS_Store +0 -0
- app/code/community/Payment/Cybersource/.DS_Store +0 -0
- app/code/community/Payment/Cybersource/Block/Failure.php +17 -0
- app/code/community/Payment/Cybersource/Block/Form.php +19 -0
- app/code/community/Payment/Cybersource/Block/Info.php +22 -0
- app/code/community/Payment/Cybersource/Block/Redirect.php +39 -0
- app/code/community/Payment/Cybersource/Helper/Data.php +28 -0
- app/code/community/Payment/Cybersource/Model/.DS_Store +0 -0
- app/code/community/Payment/Cybersource/Model/Cybersource.php +167 -0
- app/code/community/Payment/Cybersource/Model/System/Config/Source/Modes.php +21 -0
- app/code/community/Payment/Cybersource/controllers/ProcessController.php +165 -0
- app/code/community/Payment/Cybersource/etc/config.xml +105 -0
- app/code/community/Payment/Cybersource/etc/system.xml +123 -0
- app/etc/modules/Payment_Cybersource.xml +12 -0
- package.xml +18 -0
app/code/community/Payment/.DS_Store
ADDED
Binary file
|
app/code/community/Payment/Cybersource/.DS_Store
ADDED
Binary file
|
app/code/community/Payment/Cybersource/Block/Failure.php
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Cybersource Block Failure
|
5 |
+
*
|
6 |
+
* @category Payment
|
7 |
+
* @package Payment_Cybersource
|
8 |
+
* @author Andrew Moskal <andrew.moskal@softaddicts.com>
|
9 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
10 |
+
*/
|
11 |
+
|
12 |
+
class Payment_Cybersource_Block_Failure extends Mage_Core_Block_Template {
|
13 |
+
|
14 |
+
protected function _construct() {
|
15 |
+
parent::_construct();
|
16 |
+
}
|
17 |
+
}
|
app/code/community/Payment/Cybersource/Block/Form.php
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
|
4 |
+
/**
|
5 |
+
* Cybersource Block Form
|
6 |
+
*
|
7 |
+
* @category Payment
|
8 |
+
* @package Payment_Cybersource
|
9 |
+
* @author Andrew Moskal <andrew.moskal@softaddicts.com>
|
10 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
11 |
+
*/
|
12 |
+
|
13 |
+
class Payment_Cybersource_Block_Form extends Mage_Payment_Block_Form {
|
14 |
+
|
15 |
+
protected function _construct() {
|
16 |
+
parent::_construct();
|
17 |
+
}
|
18 |
+
|
19 |
+
}
|
app/code/community/Payment/Cybersource/Block/Info.php
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Cybersource Block Info
|
5 |
+
*
|
6 |
+
* @category Payment
|
7 |
+
* @package Payment_Cybersource
|
8 |
+
* @author Andrew Moskal <andrew.moskal@softaddicts.com>
|
9 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
10 |
+
*/
|
11 |
+
|
12 |
+
class Payment_Cybersource_Block_Info extends Mage_Payment_Block_Info {
|
13 |
+
|
14 |
+
protected function _construct() {
|
15 |
+
parent::_construct();
|
16 |
+
}
|
17 |
+
|
18 |
+
public function getMethodCode() {
|
19 |
+
return $this->getInfo()->getMethodInstance()->getCode();
|
20 |
+
}
|
21 |
+
|
22 |
+
}
|
app/code/community/Payment/Cybersource/Block/Redirect.php
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Cybersource Block Redirect
|
5 |
+
*
|
6 |
+
* @category Payment
|
7 |
+
* @package Payment_Cybersource
|
8 |
+
* @author Andrew Moskal <andrew.moskal@softaddicts.com>
|
9 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
10 |
+
*/
|
11 |
+
|
12 |
+
class Payment_Cybersource_Block_Redirect extends Mage_Core_Block_Abstract {
|
13 |
+
|
14 |
+
protected function _toHtml() {
|
15 |
+
$standard = $this->getOrder()->getPayment()->getMethodInstance();
|
16 |
+
|
17 |
+
$form = new Varien_Data_Form();
|
18 |
+
$form->setAction($standard->getCybersourceUrl())
|
19 |
+
->setId('payment_form')
|
20 |
+
->setName('payment_form')
|
21 |
+
->setMethod('POST')
|
22 |
+
->setUseContainer(true);
|
23 |
+
|
24 |
+
foreach ($standard->getFormFields() as $field => $value) {
|
25 |
+
$form->addField($field, 'hidden', array('name' => $field, 'value' => $value));
|
26 |
+
}
|
27 |
+
|
28 |
+
$html = '<html><body>';
|
29 |
+
$html.='<div>';
|
30 |
+
$html.= $this->__('Redirecting to CyberSource Payment Gateway ...');
|
31 |
+
$html.='</div>';
|
32 |
+
$html.= $form->toHtml();
|
33 |
+
$html.= '<script type="text/javascript">document.getElementById("payment_form").submit();</script>';
|
34 |
+
$html.= '</body></html>';
|
35 |
+
|
36 |
+
return $html;
|
37 |
+
}
|
38 |
+
|
39 |
+
}
|
app/code/community/Payment/Cybersource/Helper/Data.php
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Cybersource Data Helper
|
5 |
+
*
|
6 |
+
* @category Payment
|
7 |
+
* @package Payment_Cybersource
|
8 |
+
* @author Andrew Moskal <andrew.moskal@softaddicts.com>
|
9 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
10 |
+
*/
|
11 |
+
|
12 |
+
class Payment_Cybersource_Helper_Data extends Mage_Core_Helper_Abstract {
|
13 |
+
|
14 |
+
public function getConfig($field, $default = null) {
|
15 |
+
$value = Mage::getStoreConfig('payment/cybersource/' . $field);
|
16 |
+
|
17 |
+
return ('' === trim($value)) ? $default : $value;
|
18 |
+
}
|
19 |
+
|
20 |
+
public function getHashSign($params) {
|
21 |
+
$fieldsToSign = explode(",", $params['signed_field_names']);
|
22 |
+
foreach ($fieldsToSign as $field) {
|
23 |
+
$dataToSign[] = $field . "=" . $params[$field];
|
24 |
+
}
|
25 |
+
return base64_encode(hash_hmac('sha256', implode(",", $dataToSign), $this->getConfig('secret_key'), true));
|
26 |
+
}
|
27 |
+
|
28 |
+
}
|
app/code/community/Payment/Cybersource/Model/.DS_Store
ADDED
Binary file
|
app/code/community/Payment/Cybersource/Model/Cybersource.php
ADDED
@@ -0,0 +1,167 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Cybersource Model
|
5 |
+
*
|
6 |
+
* @category Payment
|
7 |
+
* @package Payment_Cybersource
|
8 |
+
* @author Andrew Moskal <andrew.moskal@softaddicts.com>
|
9 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
10 |
+
*/
|
11 |
+
|
12 |
+
class Payment_Cybersource_Model_Cybersource extends Mage_Payment_Model_Method_Abstract {
|
13 |
+
|
14 |
+
const CYBERSOURCE_PAYMENT_TEST_URL = 'https://testsecureacceptance.cybersource.com/pay';
|
15 |
+
const CYBERSOURCE_PAYMENT_LIVE_URL = 'https://secureacceptance.cybersource.com/pay';
|
16 |
+
|
17 |
+
|
18 |
+
protected $_code = 'cybersource';
|
19 |
+
protected $_formBlockType = 'cybersource/form';
|
20 |
+
protected $_infoBlockType = 'cybersource/info';
|
21 |
+
protected $_isGateway = false;
|
22 |
+
protected $_canAuthorize = false;
|
23 |
+
protected $_canCapture = true;
|
24 |
+
protected $_canCapturePartial = false;
|
25 |
+
protected $_canRefund = false;
|
26 |
+
protected $_canVoid = false;
|
27 |
+
protected $_canUseInternal = false;
|
28 |
+
protected $_canUseCheckout = true;
|
29 |
+
protected $_canUseForMultishipping = false;
|
30 |
+
|
31 |
+
public function validate() {
|
32 |
+
parent::validate();
|
33 |
+
return $this;
|
34 |
+
}
|
35 |
+
|
36 |
+
public function capture(Varien_Object $payment,$amount = null) {
|
37 |
+
$payment->setStatus(self::STATUS_APPROVED)->setLastTransId($this->getTransactionId());
|
38 |
+
return $this;
|
39 |
+
}
|
40 |
+
|
41 |
+
public function getCybersourceUrl() {
|
42 |
+
return (1 === (int)$this->getConfigData('mode'))?self::CYBERSOURCE_PAYMENT_LIVE_URL:self::CYBERSOURCE_PAYMENT_TEST_URL;
|
43 |
+
}
|
44 |
+
|
45 |
+
public function getOrderPlaceRedirectUrl() {
|
46 |
+
return Mage::getUrl('cybersource/process/redirect',array('_secure' => true));
|
47 |
+
}
|
48 |
+
|
49 |
+
protected function getSuccessUrl() {
|
50 |
+
return Mage::getUrl('cybersource/process/success', array('_secure' => true));
|
51 |
+
}
|
52 |
+
|
53 |
+
protected function getCancelUrl() {
|
54 |
+
return Mage::getUrl('cybersource/process/cancel', array('_secure' => true));
|
55 |
+
}
|
56 |
+
|
57 |
+
protected function getFailureUrl() {
|
58 |
+
return Mage::getUrl('cybersource/process/failure', array('_secure' => true));
|
59 |
+
}
|
60 |
+
|
61 |
+
protected function getResultUrl() {
|
62 |
+
return Mage::getUrl('cybersource/process/result', array('_secure' => true));
|
63 |
+
}
|
64 |
+
|
65 |
+
public function getCustomer() {
|
66 |
+
if (empty($this->_customer)) {
|
67 |
+
$this->_customer = Mage::getSingleton('customer/session')->getCustomer();
|
68 |
+
}
|
69 |
+
return $this->_customer;
|
70 |
+
}
|
71 |
+
|
72 |
+
public function getCheckout() {
|
73 |
+
if (empty($this->_checkout)) {
|
74 |
+
$this->_checkout = Mage::getSingleton('checkout/session');
|
75 |
+
}
|
76 |
+
return $this->_checkout;
|
77 |
+
}
|
78 |
+
|
79 |
+
public function getQuote() {
|
80 |
+
if (empty($this->_quote)) {
|
81 |
+
$this->_quote = $this->getCheckout()->getQuote();
|
82 |
+
}
|
83 |
+
return $this->_quote;
|
84 |
+
}
|
85 |
+
|
86 |
+
public function getOrder() {
|
87 |
+
if (empty($this->_order)) {
|
88 |
+
$order = Mage::getModel('sales/order');
|
89 |
+
$order->loadByIncrementId($this->getCheckout()->getLastRealOrderId());
|
90 |
+
$this->_order = $order;
|
91 |
+
}
|
92 |
+
return $this->_order;
|
93 |
+
}
|
94 |
+
|
95 |
+
public function getEmail() {
|
96 |
+
$email = $this->getOrder()->getCustomerEmail();
|
97 |
+
if (!$email) {
|
98 |
+
$email = $this->getQuote()->getBillingAddress()->getEmail();
|
99 |
+
}
|
100 |
+
return $email;
|
101 |
+
}
|
102 |
+
|
103 |
+
public function getOrderAmount() {
|
104 |
+
return sprintf('%.2f', $this->getOrder()->getGrandTotal());
|
105 |
+
}
|
106 |
+
|
107 |
+
public function getOrderCurrency() {
|
108 |
+
$currency = $this->getOrder()->getOrderCurrency();
|
109 |
+
return is_object($currency)? $currency->getCurrencyCode():null;
|
110 |
+
}
|
111 |
+
|
112 |
+
public function getHashSign($fields) {
|
113 |
+
return Mage::helper('cybersource')->getHashSign($fields);
|
114 |
+
}
|
115 |
+
|
116 |
+
public function getFormFields() {
|
117 |
+
$order = $this->getOrder();
|
118 |
+
$fields = array();
|
119 |
+
|
120 |
+
$fields['profile_id'] = $this->getConfigData('profile_id');
|
121 |
+
$fields['access_key'] = $this->getConfigData('access_key');
|
122 |
+
$fields['transaction_uuid'] = Mage::helper('core')->uniqHash();
|
123 |
+
$fields['signed_field_names'] = '';
|
124 |
+
|
125 |
+
$fields['unsigned_field_names'] = '';
|
126 |
+
$fields['signed_date_time'] = gmdate("Y-m-d\TH:i:s\Z");
|
127 |
+
$fields['locale'] = 'en';
|
128 |
+
$fields['transaction_type'] = 'sale';
|
129 |
+
$fields['reference_number'] = $order->getRealOrderId();
|
130 |
+
$fields['amount'] = $this->getOrderAmount();
|
131 |
+
$fields['currency'] = $this->getOrderCurrency();
|
132 |
+
|
133 |
+
$billingAddress = $order->getBillingAddress();
|
134 |
+
$fields['bill_to_address_city'] = $billingAddress->getCity();
|
135 |
+
$fields['bill_to_address_country'] = $billingAddress->getCountry();
|
136 |
+
$fields['bill_to_address_line1'] = $billingAddress->getStreet(1);
|
137 |
+
$fields['bill_to_address_line2'] = $billingAddress->getStreet(2);
|
138 |
+
$fields['bill_to_address_postal_code'] = $billingAddress->getPostcode();
|
139 |
+
$fields['bill_to_address_state'] = $billingAddress->getRegionCode();
|
140 |
+
$fields['bill_to_company_name'] = $billingAddress->getCompany();
|
141 |
+
|
142 |
+
$fields['bill_to_email'] = $this->getEmail();
|
143 |
+
$fields['bill_to_forename'] = $billingAddress->getFirstname();
|
144 |
+
$fields['bill_to_surname'] = $billingAddress->getLastname();
|
145 |
+
$fields['bill_to_phone'] = $billingAddress->getTelephone();
|
146 |
+
$fields['customer_ip_address'] = Mage::helper('core/http')->getRemoteAddr();
|
147 |
+
|
148 |
+
|
149 |
+
$items = $order->getAllItems();
|
150 |
+
$n = 0;
|
151 |
+
foreach ($items as $_item) {
|
152 |
+
$fields['item_' . $n . '_code'] = 'default';
|
153 |
+
$fields['item_' . $n . '_unit_price'] = sprintf("%01.2f", $_item->getPrice());
|
154 |
+
$fields['item_' . $n . '_sku'] = $_item->getSku();
|
155 |
+
$fields['item_' . $n . '_quantity'] = (int) $_item->getQtyOrdered();
|
156 |
+
$fields['item_' . $n . '_name'] = $_item->getName();
|
157 |
+
$n++;
|
158 |
+
}
|
159 |
+
|
160 |
+
$fields['line_item_count'] = $n;
|
161 |
+
$fields['signed_field_names'] = implode(',', array_keys($fields));
|
162 |
+
$fields['signature'] = $this->getHashSign($fields);
|
163 |
+
|
164 |
+
return $fields;
|
165 |
+
}
|
166 |
+
|
167 |
+
}
|
app/code/community/Payment/Cybersource/Model/System/Config/Source/Modes.php
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Cybersource Config Payment Modes
|
5 |
+
*
|
6 |
+
* @category Payment
|
7 |
+
* @package Payment_Cybersource
|
8 |
+
* @author Andrew Moskal <andrew.moskal@softaddicts.com>
|
9 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
10 |
+
*/
|
11 |
+
|
12 |
+
class Payment_Cybersource_Model_System_Config_Source_Modes {
|
13 |
+
|
14 |
+
public function toOptionArray() {
|
15 |
+
return array(
|
16 |
+
0 => Mage::helper('cybersource')->__('Test'),
|
17 |
+
1 => Mage::helper('cybersource')->__('Live'),
|
18 |
+
);
|
19 |
+
}
|
20 |
+
|
21 |
+
}
|
app/code/community/Payment/Cybersource/controllers/ProcessController.php
ADDED
@@ -0,0 +1,165 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Cybersource Process Controller
|
5 |
+
*
|
6 |
+
* @category Payment
|
7 |
+
* @package Payment_Cybersource
|
8 |
+
* @author Andrew Moskal <andrew.moskal@softaddicts.com>
|
9 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
10 |
+
*/
|
11 |
+
|
12 |
+
class Payment_Cybersource_ProcessController extends Mage_Core_Controller_Front_Action {
|
13 |
+
|
14 |
+
protected $_order;
|
15 |
+
|
16 |
+
protected function _getCheckout() {
|
17 |
+
return Mage::getSingleton('checkout/session');
|
18 |
+
}
|
19 |
+
|
20 |
+
public function getCybersource() {
|
21 |
+
return Mage::getSingleton('cybersource/cybersource');
|
22 |
+
}
|
23 |
+
|
24 |
+
public function getOrder() {
|
25 |
+
if (null === $this->_order) {
|
26 |
+
$session = Mage::getSingleton('checkout/session');
|
27 |
+
$this->_order = Mage::getModel('sales/order');
|
28 |
+
$this->_order->loadByIncrementId($session->getLastRealOrderId());
|
29 |
+
}
|
30 |
+
return $this->_order;
|
31 |
+
}
|
32 |
+
|
33 |
+
public function redirectAction() {
|
34 |
+
$order = $this->getOrder();
|
35 |
+
if (!$order->getId()) {
|
36 |
+
$this->norouteAction();
|
37 |
+
return;
|
38 |
+
}
|
39 |
+
|
40 |
+
$order->addStatusToHistory(
|
41 |
+
$order->getStatus(), $this->__('Customer was redirected to Cybersource.')
|
42 |
+
);
|
43 |
+
$order->save();
|
44 |
+
|
45 |
+
$this->getResponse()->setBody($this->getLayout()->createBlock('cybersource/redirect')->setOrder($order)->toHtml());
|
46 |
+
}
|
47 |
+
|
48 |
+
public function failureAction() {
|
49 |
+
$order = $this->getOrder();
|
50 |
+
if (!$order->getId()) {
|
51 |
+
$this->_redirect('checkout/cart');
|
52 |
+
return;
|
53 |
+
}
|
54 |
+
|
55 |
+
$order->cancel();
|
56 |
+
$order->addStatusToHistory(
|
57 |
+
$order->getStatus(), $this->__('Payment was failed.')
|
58 |
+
);
|
59 |
+
$order->save();
|
60 |
+
|
61 |
+
$this->_getCheckout()->addError($this->__('Payment has been failed.'));
|
62 |
+
$this->_redirect('checkout/cart');
|
63 |
+
}
|
64 |
+
|
65 |
+
public function resultAction() {
|
66 |
+
$request = $this->getRequest();
|
67 |
+
$params = $request->getParams();
|
68 |
+
|
69 |
+
if ($this->_validateResponse($params)) {
|
70 |
+
$rrNumber = isset($params['req_reference_number']) ? $params['req_reference_number'] : null;
|
71 |
+
$order = Mage::getModel('sales/order')->loadByIncrementId($rrNumber);
|
72 |
+
if ($order && $order->canInvoice()) {
|
73 |
+
$invoice = $order->prepareInvoice();
|
74 |
+
$invoice->register()->capture();
|
75 |
+
Mage::getModel('core/resource_transaction')
|
76 |
+
->addObject($invoice)
|
77 |
+
->addObject($invoice->getOrder())
|
78 |
+
->save();
|
79 |
+
$order->setState(Mage_Sales_Model_Order::STATE_PROCESSING, true);
|
80 |
+
$order->getPayment()->setLastTransId($params['transaction_id']);
|
81 |
+
$order->sendNewOrderEmail()
|
82 |
+
->setEmailSent(true)
|
83 |
+
->save();
|
84 |
+
}
|
85 |
+
}
|
86 |
+
}
|
87 |
+
|
88 |
+
public function cancelAction() {
|
89 |
+
$order = $this->getOrder();
|
90 |
+
if (!$order->getId()) {
|
91 |
+
$this->_redirect('checkout/cart');
|
92 |
+
return;
|
93 |
+
}
|
94 |
+
|
95 |
+
$order->cancel();
|
96 |
+
$order->addStatusToHistory(
|
97 |
+
$order->getStatus(), $this->__('Payment was canceled.')
|
98 |
+
);
|
99 |
+
$order->save();
|
100 |
+
|
101 |
+
$this->_getCheckout()->addError($this->__('Payment has been canceled.'));
|
102 |
+
$this->_redirect('checkout/cart');
|
103 |
+
return;
|
104 |
+
}
|
105 |
+
|
106 |
+
protected function _validateResponse($params) {
|
107 |
+
$rrNumber = isset($params['req_reference_number']) ? $params['req_reference_number'] : null;
|
108 |
+
$order = Mage::getModel('sales/order')->loadByIncrementId($rrNumber);
|
109 |
+
if (!$order) {
|
110 |
+
return false;
|
111 |
+
}
|
112 |
+
$errors = array();
|
113 |
+
if (isset($params['reason_code']) && !in_array((int)$params['reason_code'], array(100, 110))) {
|
114 |
+
$errors[] = 'reason_code is not 100 or 110';
|
115 |
+
}
|
116 |
+
|
117 |
+
if (isset($params['decision']) && 'ACCEPT' !== $params['decision']) {
|
118 |
+
$errors[] = 'decision is not accept';
|
119 |
+
}
|
120 |
+
|
121 |
+
$hashSign = Mage::helper('cybersource')->getHashSign($params);
|
122 |
+
$signature = isset($params['signature']) ? $params['signature'] : null;
|
123 |
+
if ($hashSign != $signature) {
|
124 |
+
$errors[] = 'singature is invalid';
|
125 |
+
}
|
126 |
+
|
127 |
+
return (0 === count($errors));
|
128 |
+
}
|
129 |
+
|
130 |
+
public function successAction() {
|
131 |
+
$order = $this->getOrder();
|
132 |
+
if (!$order->getId()) {
|
133 |
+
$this->_redirect('checkout/cart');
|
134 |
+
return;
|
135 |
+
}
|
136 |
+
|
137 |
+
$responseParams = $this->getRequest()->getParams();
|
138 |
+
$validateResponse = $this->_validateResponse($responseParams);
|
139 |
+
if ($validateResponse) {
|
140 |
+
|
141 |
+
$order->addStatusToHistory(
|
142 |
+
$order->getStatus(), $this->__('Customer successfully returned from CyberSource and payment was approved.')
|
143 |
+
);
|
144 |
+
$order->save();
|
145 |
+
|
146 |
+
$this->_redirect('checkout/onepage/success');
|
147 |
+
return;
|
148 |
+
} else {
|
149 |
+
$comment = '';
|
150 |
+
if (isset($responseParams['message'])) {
|
151 |
+
$comment .= '<br />Error: ';
|
152 |
+
$comment .= "'" . $responseParams['message'] . "'";
|
153 |
+
}
|
154 |
+
$order->cancel();
|
155 |
+
$order->addStatusToHistory(
|
156 |
+
$order->getStatus(), $this->__('Customer successfully returned from CyberSource. Payment was declined.') . $comment
|
157 |
+
);
|
158 |
+
$order->save();
|
159 |
+
|
160 |
+
$this->_getCheckout()->addError($this->__('There is an error processing your payment.' . $comment));
|
161 |
+
$this->_redirect('checkout/cart');
|
162 |
+
return;
|
163 |
+
}
|
164 |
+
}
|
165 |
+
}
|
app/code/community/Payment/Cybersource/etc/config.xml
ADDED
@@ -0,0 +1,105 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<config>
|
3 |
+
<modules>
|
4 |
+
<Payment_Cybersource>
|
5 |
+
<version>0.1.2</version>
|
6 |
+
</Payment_Cybersource>
|
7 |
+
</modules>
|
8 |
+
<global>
|
9 |
+
<models>
|
10 |
+
<cybersource>
|
11 |
+
<class>Payment_Cybersource_Model</class>
|
12 |
+
</cybersource>
|
13 |
+
</models>
|
14 |
+
<resources>
|
15 |
+
<cybersource_setup>
|
16 |
+
<setup>
|
17 |
+
<module>Payment_Cybersource</module>
|
18 |
+
</setup>
|
19 |
+
<connection>
|
20 |
+
<use>core_setup</use>
|
21 |
+
</connection>
|
22 |
+
</cybersource_setup>
|
23 |
+
<cybersource_write>
|
24 |
+
<connection>
|
25 |
+
<use>core_write</use>
|
26 |
+
</connection>
|
27 |
+
</cybersource_write>
|
28 |
+
<cybersource_read>
|
29 |
+
<connection>
|
30 |
+
<use>core_read</use>
|
31 |
+
</connection>
|
32 |
+
</cybersource_read>
|
33 |
+
</resources>
|
34 |
+
<blocks>
|
35 |
+
<cybersource>
|
36 |
+
<class>Payment_Cybersource_Block</class>
|
37 |
+
</cybersource>
|
38 |
+
</blocks>
|
39 |
+
<helpers>
|
40 |
+
<cybersource>
|
41 |
+
<class>Payment_Cybersource_Helper</class>
|
42 |
+
</cybersource>
|
43 |
+
</helpers>
|
44 |
+
</global>
|
45 |
+
<frontend>
|
46 |
+
<routers>
|
47 |
+
<cybersource>
|
48 |
+
<use>standard</use>
|
49 |
+
<args>
|
50 |
+
<module>Payment_Cybersource</module>
|
51 |
+
<frontName>cybersource</frontName>
|
52 |
+
</args>
|
53 |
+
</cybersource>
|
54 |
+
</routers>
|
55 |
+
<!-- <layout>
|
56 |
+
<updates>
|
57 |
+
<cybersource>
|
58 |
+
<file>cybersource.xml</file>
|
59 |
+
</cybersource>
|
60 |
+
</updates>
|
61 |
+
</layout>-->
|
62 |
+
</frontend>
|
63 |
+
<adminhtml>
|
64 |
+
<acl>
|
65 |
+
<resources>
|
66 |
+
<admin>
|
67 |
+
<children>
|
68 |
+
<system>
|
69 |
+
<children>
|
70 |
+
<config>
|
71 |
+
<children>
|
72 |
+
<Paymentinfo>
|
73 |
+
<title>Payment - All</title>
|
74 |
+
</Paymentinfo>
|
75 |
+
<paymentinfo>
|
76 |
+
<title>CyberSource SA/WM Info</title>
|
77 |
+
</paymentinfo>
|
78 |
+
<cybersource>
|
79 |
+
<title>CyberSource SA/WM Area</title>
|
80 |
+
</cybersource>
|
81 |
+
</children>
|
82 |
+
</config>
|
83 |
+
</children>
|
84 |
+
</system>
|
85 |
+
</children>
|
86 |
+
</admin>
|
87 |
+
</resources>
|
88 |
+
</acl>
|
89 |
+
</adminhtml>
|
90 |
+
<default>
|
91 |
+
<payment>
|
92 |
+
<cybersource>
|
93 |
+
<active>0</active>
|
94 |
+
<enable_log>1</enable_log>
|
95 |
+
<model>cybersource/cybersource</model>
|
96 |
+
<title>CyberSource Simple Redirect</title>
|
97 |
+
<mode>0</mode>
|
98 |
+
<order_status>pending</order_status>
|
99 |
+
<debug_flag>1</debug_flag>
|
100 |
+
<allowspecific>0</allowspecific>
|
101 |
+
<sort_order>1</sort_order>
|
102 |
+
</cybersource>
|
103 |
+
</payment>
|
104 |
+
</default>
|
105 |
+
</config>
|
app/code/community/Payment/Cybersource/etc/system.xml
ADDED
@@ -0,0 +1,123 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<config>
|
3 |
+
<sections>
|
4 |
+
<Paymentinfo translate="label" module="cybersource">
|
5 |
+
<label>Info</label>
|
6 |
+
<tab>Paymentall</tab>
|
7 |
+
<frontend_type>text</frontend_type>
|
8 |
+
<sort_order>999999</sort_order>
|
9 |
+
<show_in_default>1</show_in_default>
|
10 |
+
<show_in_website>1</show_in_website>
|
11 |
+
<show_in_store>1</show_in_store>
|
12 |
+
<groups>
|
13 |
+
<info>
|
14 |
+
<frontend_model>cybersource/system_config_info</frontend_model>
|
15 |
+
<sort_order>10</sort_order>
|
16 |
+
<show_in_default>1</show_in_default>
|
17 |
+
<show_in_website>1</show_in_website>
|
18 |
+
<show_in_store>1</show_in_store>
|
19 |
+
</info>
|
20 |
+
</groups>
|
21 |
+
</Paymentinfo>
|
22 |
+
<paymentinfo translate="label" module="cybersource">
|
23 |
+
<label>CyberSource Simple Redirect</label>
|
24 |
+
<tab>Paymentall</tab>
|
25 |
+
<frontend_type>text</frontend_type>
|
26 |
+
<sort_order>1000</sort_order>
|
27 |
+
<show_in_default>1</show_in_default>
|
28 |
+
<show_in_website>1</show_in_website>
|
29 |
+
<show_in_store>1</show_in_store>
|
30 |
+
<groups>
|
31 |
+
<info>
|
32 |
+
<frontend_model>cybersource/system_config_payment</frontend_model>
|
33 |
+
<sort_order>10</sort_order>
|
34 |
+
<show_in_default>1</show_in_default>
|
35 |
+
<show_in_website>1</show_in_website>
|
36 |
+
<show_in_store>1</show_in_store>
|
37 |
+
</info>
|
38 |
+
</groups>
|
39 |
+
</paymentinfo>
|
40 |
+
<payment>
|
41 |
+
<groups>
|
42 |
+
<cybersource module="cybersource">
|
43 |
+
<label>CyberSource Simple Redirect</label>
|
44 |
+
<frontend_type>text</frontend_type>
|
45 |
+
<sort_order>26</sort_order>
|
46 |
+
<show_in_default>1</show_in_default>
|
47 |
+
<show_in_website>1</show_in_website>
|
48 |
+
<show_in_store>1</show_in_store>
|
49 |
+
<fields>
|
50 |
+
<active translate="label">
|
51 |
+
<label>Enabled</label>
|
52 |
+
<frontend_type>select</frontend_type>
|
53 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
54 |
+
<sort_order>10</sort_order>
|
55 |
+
<show_in_default>1</show_in_default>
|
56 |
+
<show_in_website>1</show_in_website>
|
57 |
+
<show_in_store>1</show_in_store>
|
58 |
+
</active>
|
59 |
+
<title translate="label">
|
60 |
+
<label>Title</label>
|
61 |
+
<frontend_type>text</frontend_type>
|
62 |
+
<sort_order>20</sort_order>
|
63 |
+
<show_in_default>1</show_in_default>
|
64 |
+
<show_in_website>1</show_in_website>
|
65 |
+
<show_in_store>1</show_in_store>
|
66 |
+
</title>
|
67 |
+
<access_key translate="label">
|
68 |
+
<label>Access Key</label>
|
69 |
+
<frontend_type>text</frontend_type>
|
70 |
+
<sort_order>30</sort_order>
|
71 |
+
<show_in_default>1</show_in_default>
|
72 |
+
<show_in_website>1</show_in_website>
|
73 |
+
<show_in_store>1</show_in_store>
|
74 |
+
</access_key>
|
75 |
+
<profile_id translate="label">
|
76 |
+
<label>Profile ID</label>
|
77 |
+
<frontend_type>text</frontend_type>
|
78 |
+
<sort_order>40</sort_order>
|
79 |
+
<show_in_default>1</show_in_default>
|
80 |
+
<show_in_website>1</show_in_website>
|
81 |
+
<show_in_store>1</show_in_store>
|
82 |
+
</profile_id>
|
83 |
+
<secret_key translate="label">
|
84 |
+
<label>Secret Key</label>
|
85 |
+
<frontend_type>textarea</frontend_type>
|
86 |
+
<sort_order>50</sort_order>
|
87 |
+
<show_in_default>1</show_in_default>
|
88 |
+
<show_in_website>1</show_in_website>
|
89 |
+
<show_in_store>1</show_in_store>
|
90 |
+
</secret_key>
|
91 |
+
<mode translate="label">
|
92 |
+
<label>Mode</label>
|
93 |
+
<frontend_type>select</frontend_type>
|
94 |
+
<source_model>cybersource/system_config_source_modes</source_model>
|
95 |
+
<sort_order>60</sort_order>
|
96 |
+
<show_in_default>1</show_in_default>
|
97 |
+
<show_in_website>1</show_in_website>
|
98 |
+
<show_in_store>1</show_in_store>
|
99 |
+
</mode>
|
100 |
+
<allowspecific translate="label">
|
101 |
+
<label>Payment from applicable countries</label>
|
102 |
+
<frontend_type>allowspecific</frontend_type>
|
103 |
+
<sort_order>70</sort_order>
|
104 |
+
<source_model>adminhtml/system_config_source_payment_allspecificcountries</source_model>
|
105 |
+
<show_in_default>1</show_in_default>
|
106 |
+
<show_in_website>1</show_in_website>
|
107 |
+
<show_in_store>1</show_in_store>
|
108 |
+
</allowspecific>
|
109 |
+
<specificcountry translate="label">
|
110 |
+
<label>Payment from specific countries</label>
|
111 |
+
<frontend_type>multiselect</frontend_type>
|
112 |
+
<sort_order>80</sort_order>
|
113 |
+
<source_model>adminhtml/system_config_source_country</source_model>
|
114 |
+
<show_in_default>1</show_in_default>
|
115 |
+
<show_in_website>1</show_in_website>
|
116 |
+
<show_in_store>1</show_in_store>
|
117 |
+
</specificcountry>
|
118 |
+
</fields>
|
119 |
+
</cybersource>
|
120 |
+
</groups>
|
121 |
+
</payment>
|
122 |
+
</sections>
|
123 |
+
</config>
|
app/etc/modules/Payment_Cybersource.xml
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<config>
|
3 |
+
<modules>
|
4 |
+
<Payment_Cybersource>
|
5 |
+
<active>true</active>
|
6 |
+
<codePool>community</codePool>
|
7 |
+
<depends>
|
8 |
+
<Mage_Payment/>
|
9 |
+
</depends>
|
10 |
+
</Payment_Cybersource>
|
11 |
+
</modules>
|
12 |
+
</config>
|
package.xml
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<package>
|
3 |
+
<name>Cybersource_Simple_Redirect</name>
|
4 |
+
<version>0.1.3</version>
|
5 |
+
<stability>stable</stability>
|
6 |
+
<license uri="http://opensource.org/licenses/osl-3.0.php">Open Software License (OSL 3.0)</license>
|
7 |
+
<channel>community</channel>
|
8 |
+
<extends/>
|
9 |
+
<summary>Cybersource Simple Redirect Payment Method</summary>
|
10 |
+
<description>Cybersource Simple Redirect Payment Method</description>
|
11 |
+
<notes>Cybersource Simple Redirect Payment Method</notes>
|
12 |
+
<authors><author><name>Softaddicts.com</name><user>softaddicts</user><email>vlad@softaddicts.com</email></author></authors>
|
13 |
+
<date>2014-07-07</date>
|
14 |
+
<time>17:46:04</time>
|
15 |
+
<contents><target name="magecommunity"><dir name="Payment"><dir name="Cybersource"><dir name="Block"><file name="Failure.php" hash="56b01f33431c82ddd38922850b2cbf99"/><file name="Form.php" hash="775e5131067ccc24e2aa34673c323c79"/><file name="Info.php" hash="68ec7fc2c10f3e8cc3eece4b1602dc8f"/><file name="Redirect.php" hash="2935bdf06f0ef8463103e3271767c6fb"/></dir><dir name="Helper"><file name="Data.php" hash="d6ebdf1864724d7efa307fa926a39027"/></dir><dir name="Model"><file name="Cybersource.php" hash="f5db7c5de7f756dbe7ecd92e82a2b4f5"/><dir name="System"><dir name="Config"><dir name="Source"><file name="Modes.php" hash="c21a7a5fc7597d82453315feaa39bde0"/></dir></dir></dir><file name=".DS_Store" hash="3e697ae15b7cf2762d84090aec971499"/></dir><dir name="controllers"><file name="ProcessController.php" hash="9fbfc74e974a1120aac5fd7317384885"/></dir><dir name="etc"><file name="config.xml" hash="e20a82bec58d6e80d4d7674e4995ff4a"/><file name="system.xml" hash="56042aded90feca761cf8cb0c5f33405"/></dir><file name=".DS_Store" hash="2376f78e5743613c3c7155221160cb2a"/></dir><file name=".DS_Store" hash="2f26fd0935a4ef126b2064f7305aeadd"/></dir></target><target name="mageetc"><dir name="modules"><file name="Payment_Cybersource.xml" hash="a32953193d7e5617f2f611d115db11f1"/></dir></target></contents>
|
16 |
+
<compatible/>
|
17 |
+
<dependencies><required><php><min>5.3.2</min><max>5.6.0</max></php></required></dependencies>
|
18 |
+
</package>
|