1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19:
20: abstract class Phoenix_Moneybookers_Model_Abstract extends Mage_Payment_Model_Method_Abstract
21: {
22: 23: 24:
25: protected $_code = 'moneybookers_abstract';
26:
27: protected $_formBlockType = 'moneybookers/form';
28: protected $_infoBlockType = 'moneybookers/info';
29:
30: 31: 32:
33: protected $_isGateway = true;
34: protected $_canAuthorize = true;
35: protected $_canCapture = true;
36: protected $_canCapturePartial = false;
37: protected $_canRefund = false;
38: protected $_canVoid = false;
39: protected $_canUseInternal = false;
40: protected $_canUseCheckout = true;
41: protected $_canUseForMultishipping = false;
42:
43: protected $_paymentMethod = 'abstract';
44: protected $_defaultLocale = 'en';
45: protected $_supportedLocales = array('cn', 'cz', 'da', 'en', 'es', 'fi', 'de', 'fr', 'gr', 'it', 'nl', 'ro', 'ru', 'pl', 'sv', 'tr');
46: protected $_hidelogin = '1';
47:
48: protected $_order;
49:
50: 51: 52: 53: 54:
55: public function getOrder()
56: {
57: if (!$this->_order) {
58: $this->_order = $this->getInfoInstance()->getOrder();
59: }
60: return $this->_order;
61: }
62:
63: 64: 65: 66:
67: public function getOrderPlaceRedirectUrl()
68: {
69: return Mage::getUrl('moneybookers/processing/payment');
70: }
71:
72: 73: 74: 75: 76: 77: 78:
79: public function capture(Varien_Object $payment, $amount)
80: {
81: $payment->setStatus(self::STATUS_APPROVED)
82: ->setTransactionId($this->getTransactionId())
83: ->setIsTransactionClosed(0);
84:
85: return $this;
86: }
87:
88: 89: 90: 91: 92: 93:
94: public function cancel(Varien_Object $payment)
95: {
96: $payment->setStatus(self::STATUS_DECLINED)
97: ->setTransactionId($this->getTransactionId())
98: ->setIsTransactionClosed(1);
99:
100: return $this;
101: }
102:
103: 104: 105: 106: 107:
108: public function getUrl()
109: {
110: return 'https://www.moneybookers.com/app/payment.pl';
111: }
112:
113: 114: 115: 116: 117:
118: public function getLocale()
119: {
120: $locale = explode('_', Mage::app()->getLocale()->getLocaleCode());
121: if (is_array($locale) && !empty($locale) && in_array($locale[0], $this->_supportedLocales)) {
122: return $locale[0];
123: }
124: return $this->getDefaultLocale();
125: }
126:
127: 128: 129: 130: 131:
132: public function getFormFields()
133: {
134: $order_id = $this->getOrder()->getRealOrderId();
135: $billing = $this->getOrder()->getBillingAddress();
136: if ($this->getOrder()->getBillingAddress()->getEmail()) {
137: $email = $this->getOrder()->getBillingAddress()->getEmail();
138: } else {
139: $email = $this->getOrder()->getCustomerEmail();
140: }
141:
142: $params = array(
143: 'merchant_fields' => 'partner',
144: 'partner' => 'magento',
145: 'pay_to_email' => Mage::getStoreConfig(Phoenix_Moneybookers_Helper_Data::XML_PATH_EMAIL),
146: 'transaction_id' => $order_id,
147: 'return_url' => Mage::getUrl('moneybookers/processing/success', array('transaction_id' => $order_id)),
148: 'cancel_url' => Mage::getUrl('moneybookers/processing/cancel', array('transaction_id' => $order_id)),
149: 'status_url' => Mage::getUrl('moneybookers/processing/status'),
150: 'language' => $this->getLocale(),
151: 'amount' => round($this->getOrder()->getGrandTotal(), 2),
152: 'currency' => $this->getOrder()->getOrderCurrencyCode(),
153: 'recipient_description' => $this->getOrder()->getStore()->getWebsite()->getName(),
154: 'firstname' => $billing->getFirstname(),
155: 'lastname' => $billing->getLastname(),
156: 'address' => $billing->getStreet(-1),
157: 'postal_code' => $billing->getPostcode(),
158: 'city' => $billing->getCity(),
159: 'country' => $billing->getCountryModel()->getIso3Code(),
160: 'pay_from_email' => $email,
161: 'phone_number' => $billing->getTelephone(),
162: 'detail1_description' => Mage::helper('moneybookers')->__('Order ID'),
163: 'detail1_text' => $order_id,
164: 'payment_methods' => $this->_paymentMethod,
165: 'hide_login' => $this->_hidelogin,
166: 'new_window_redirect' => '1'
167: );
168:
169:
170: if ($billing->getDob()) {
171: $params['date_of_birth'] = Mage::app()->getLocale()->date($billing->getDob(), null, null, false)->toString('dmY');
172: }
173:
174: return $params;
175: }
176: 177: 178: 179:
180: public function isInitializeNeeded()
181: {
182: return true;
183: }
184:
185: 186: 187: 188: 189:
190: public function initialize($paymentAction, $stateObject)
191: {
192: $state = Mage_Sales_Model_Order::STATE_PENDING_PAYMENT;
193: $stateObject->setState($state);
194: $stateObject->setStatus(Mage_Sales_Model_Order::STATE_PENDING_PAYMENT);
195: $stateObject->setIsNotified(false);
196: }
197:
198: 199: 200: 201: 202:
203: public function getConfigPaymentAction()
204: {
205: $paymentAction = $this->getConfigData('payment_action');
206: return empty($paymentAction) ? true : $paymentAction;
207: }
208: }
209: