00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 abstract class Mage_Payment_Model_Method_Abstract extends Varien_Object
00033 {
00034 const ACTION_AUTHORIZE = 'authorize';
00035 const ACTION_AUTHORIZE_CAPTURE = 'authorize_capture';
00036
00037 const STATUS_UNKNOWN = 'UNKNOWN';
00038 const STATUS_APPROVED = 'APPROVED';
00039 const STATUS_ERROR = 'ERROR';
00040 const STATUS_DECLINED = 'DECLINED';
00041 const STATUS_VOID = 'VOID';
00042 const STATUS_SUCCESS = 'SUCCESS';
00043
00044 protected $_code;
00045 protected $_formBlockType = 'payment/form';
00046 protected $_infoBlockType = 'payment/info';
00047
00048
00049
00050
00051 protected $_isGateway = false;
00052 protected $_canAuthorize = false;
00053 protected $_canCapture = false;
00054 protected $_canCapturePartial = false;
00055 protected $_canRefund = false;
00056 protected $_canRefundInvoicePartial = false;
00057 protected $_canVoid = false;
00058 protected $_canUseInternal = true;
00059 protected $_canUseCheckout = true;
00060 protected $_canUseForMultishipping = true;
00061 protected $_isInitializeNeeded = false;
00062
00063 public function __construct()
00064 {
00065
00066 }
00067
00068
00069
00070
00071
00072
00073 public function canAuthorize()
00074 {
00075 return $this->_canAuthorize;
00076 }
00077
00078
00079
00080
00081
00082
00083 public function canCapture()
00084 {
00085 return $this->_canCapture;
00086 }
00087
00088
00089
00090
00091
00092
00093 public function canCapturePartial()
00094 {
00095 return $this->_canCapturePartial;
00096 }
00097
00098
00099
00100
00101
00102
00103 public function canRefund()
00104 {
00105 return $this->_canRefund;
00106 }
00107
00108
00109
00110
00111
00112
00113 public function canRefundPartialPerInvoice()
00114 {
00115 return $this->_canRefundInvoicePartial;
00116 }
00117
00118
00119
00120
00121
00122
00123
00124 public function canVoid(Varien_Object $payment)
00125 {
00126 return $this->_canVoid;
00127 }
00128
00129
00130
00131
00132
00133
00134
00135 public function canUseInternal()
00136 {
00137 return $this->_canUseInternal;
00138 }
00139
00140
00141
00142
00143
00144
00145 public function canUseCheckout()
00146 {
00147 return $this->_canUseCheckout;
00148 }
00149
00150
00151
00152
00153
00154
00155 public function canUseForMultishipping()
00156 {
00157 return $this->_canUseForMultishipping;
00158 }
00159
00160
00161
00162
00163
00164
00165 public function canEdit()
00166 {
00167 return true;
00168 }
00169
00170
00171
00172
00173
00174
00175 public function isGateway()
00176 {
00177 return $this->_isGateway;
00178 }
00179
00180
00181
00182
00183
00184
00185 public function isInitializeNeeded()
00186 {
00187 return $this->_isInitializeNeeded;
00188 }
00189
00190
00191
00192
00193
00194
00195 public function canUseForCountry($country)
00196 {
00197
00198
00199
00200 if($this->getConfigData('allowspecific')==1){
00201 $availableCountries = explode(',', $this->getConfigData('specificcountry'));
00202 if(!in_array($country, $availableCountries)){
00203 return false;
00204 }
00205
00206 }
00207 return true;
00208 }
00209
00210
00211
00212
00213
00214
00215
00216 public function canUseForCurrency($currencyCode)
00217 {
00218 return true;
00219 }
00220
00221
00222
00223
00224
00225
00226 protected function _getHelper()
00227 {
00228 return Mage::helper('payment');
00229 }
00230
00231
00232
00233
00234
00235
00236 public function getCode()
00237 {
00238 if (empty($this->_code)) {
00239 Mage::throwException($this->_getHelper()->__('Can not retrieve payment method code'));
00240 }
00241 return $this->_code;
00242 }
00243
00244
00245
00246
00247
00248
00249 public function getFormBlockType()
00250 {
00251 return $this->_formBlockType;
00252 }
00253
00254
00255
00256
00257
00258
00259 public function getInfoBlockType()
00260 {
00261 return $this->_infoBlockType;
00262 }
00263
00264
00265
00266
00267
00268
00269 public function getInfoInstance()
00270 {
00271 $instance = $this->getData('info_instance');
00272 if (!($instance instanceof Mage_Payment_Model_Info)) {
00273 Mage::throwException($this->_getHelper()->__('Can not retrieve payment iformation object instance'));
00274 }
00275 return $instance;
00276 }
00277
00278
00279
00280
00281
00282
00283
00284 public function validate()
00285 {
00286
00287
00288
00289 $paymentInfo = $this->getInfoInstance();
00290 if ($paymentInfo instanceof Mage_Sales_Model_Order_Payment) {
00291 $billingCountry = $paymentInfo->getOrder()->getBillingAddress()->getCountryId();
00292 } else {
00293 $billingCountry = $paymentInfo->getQuote()->getBillingAddress()->getCountryId();
00294 }
00295 if (!$this->canUseForCountry($billingCountry)) {
00296 Mage::throwException($this->_getHelper()->__('Selected payment type is not allowed for billing country.'));
00297 }
00298 return $this;
00299 }
00300
00301
00302
00303
00304
00305
00306
00307 public function authorize(Varien_Object $payment, $amount)
00308 {
00309 if (!$this->canAuthorize()) {
00310 Mage::throwException($this->_getHelper()->__('Authorize action is not available'));
00311 }
00312 return $this;
00313 }
00314
00315
00316
00317
00318
00319
00320
00321 public function capture(Varien_Object $payment, $amount)
00322 {
00323 if (!$this->canCapture()) {
00324 Mage::throwException($this->_getHelper()->__('Capture action is not available'));
00325 }
00326
00327 return $this;
00328 }
00329
00330 public function processInvoice($invoice, $payment)
00331 {
00332 $invoice->setTransactionId($payment->getLastTransId());
00333 return $this;
00334 }
00335
00336 public function processBeforeRefund($invoice, $payment)
00337 {
00338 $payment->setRefundTransactionId($invoice->getTransactionId());
00339 return $this;
00340 }
00341
00342
00343
00344
00345
00346
00347
00348
00349 public function refund(Varien_Object $payment, $amount)
00350 {
00351
00352 if (!$this->canRefund()) {
00353 Mage::throwException($this->_getHelper()->__('Refund action is not available'));
00354 }
00355
00356
00357 return $this;
00358 }
00359
00360 public function processCreditmemo($creditmemo, $payment)
00361 {
00362 $creditmemo->setTransactionId($payment->getLastTransId());
00363 return $this;
00364 }
00365
00366
00367
00368
00369
00370
00371
00372 public function cancel(Varien_Object $payment)
00373 {
00374 return $this;
00375 }
00376
00377 public function processBeforeVoid($invoice, $payment)
00378 {
00379 $payment->setVoidTransactionId($invoice->getTransactionId());
00380 return $this;
00381 }
00382
00383
00384
00385
00386
00387
00388
00389 public function void(Varien_Object $payment)
00390 {
00391 if (!$this->canVoid($payment)) {
00392 Mage::throwException($this->_getHelper()->__('Void action is not available'));
00393 }
00394 return $this;
00395 }
00396
00397
00398
00399
00400
00401
00402 public function getTitle()
00403 {
00404 return $this->getConfigData('title');
00405 }
00406
00407
00408
00409
00410
00411
00412
00413 public function getConfigData($field, $storeId = null)
00414 {
00415 if (null === $storeId) {
00416 $storeId = $this->getStore();
00417 }
00418 $path = 'payment/'.$this->getCode().'/'.$field;
00419 return Mage::getStoreConfig($path, $storeId);
00420 }
00421
00422
00423
00424
00425
00426
00427
00428 public function assignData($data)
00429 {
00430 if (is_array($data)) {
00431 $this->getInfoInstance()->addData($data);
00432 }
00433 elseif ($data instanceof Varien_Object) {
00434 $this->getInfoInstance()->addData($data->getData());
00435 }
00436 return $this;
00437 }
00438
00439
00440
00441
00442
00443
00444 public function prepareSave()
00445 {
00446 return $this;
00447 }
00448
00449
00450
00451
00452
00453
00454 public function isAvailable($quote=null)
00455 {
00456 return true;
00457 }
00458
00459
00460
00461
00462
00463
00464
00465
00466 public function initialize($paymentAction, $stateObject)
00467 {
00468 return $this;
00469 }
00470
00471 }