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
00033 class Mage_PaypalUk_Model_Direct extends Mage_Payment_Model_Method_Cc
00034 {
00035 protected $_code = 'paypaluk_direct';
00036 protected $_formBlockType = 'paypaluk/direct_form';
00037 protected $_infoBlockType = 'paypaluk/direct_info';
00038 protected $_canSaveCc = false;
00039
00040
00041
00042
00043 protected $_isGateway = true;
00044 protected $_canAuthorize = true;
00045 protected $_canCapture = true;
00046 protected $_canCapturePartial = false;
00047 protected $_canRefund = false;
00048 protected $_canVoid = true;
00049 protected $_canUseInternal = true;
00050 protected $_canUseCheckout = true;
00051 protected $_canUseForMultishipping = true;
00052
00053 protected $_allowCurrencyCode = array('AUD', 'CAD', 'CZK', 'DKK', 'EUR', 'HKD', 'HUF', 'ILS', 'JPY', 'MXN', 'NOK', 'NZD', 'PLN', 'GBP', 'SGD', 'SEK', 'CHF', 'USD');
00054
00055
00056
00057
00058
00059
00060
00061 public function canUseForCurrency($currencyCode)
00062 {
00063 if (!in_array($currencyCode, $this->_allowCurrencyCode)) {
00064 return false;
00065 }
00066 return true;
00067 }
00068
00069
00070
00071
00072
00073 public function OtherCcType($type)
00074 {
00075 return (parent::OtherCcType($type) || $type=='SS');
00076 }
00077
00078
00079
00080
00081
00082
00083
00084
00085 public function assignData($data)
00086 {
00087
00088 if (!($data instanceof Varien_Object)) {
00089 $data = new Varien_Object($data);
00090 }
00091 parent::assignData($data);
00092 $info = $this->getInfoInstance();
00093
00094 if ($data->getCcType()=='SS') {
00095 $info->setCcSsIssue($data->getCcSsIssue())
00096 ->setCcSsStartMonth($data->getCcSsStartMonth())
00097 ->setCcSsStartYear($data->getCcSsStartYear())
00098 ;
00099 }
00100 return $this;
00101 }
00102
00103
00104
00105
00106
00107
00108 public function getApi()
00109 {
00110 return Mage::getSingleton('paypaluk/api_pro');
00111 }
00112
00113 public function authorize(Varien_Object $payment, $amount)
00114 {
00115 $api = $this->getApi()
00116 ->setTrxtype(Mage_PaypalUk_Model_Api_Pro::TRXTYPE_AUTH_ONLY)
00117 ->setAmount($amount)
00118 ->setBillingAddress($payment->getOrder()->getBillingAddress())
00119 ->setShippingAddress($payment->getOrder()->getShippingAddress())
00120 ->setPayment($payment);
00121
00122 if($api->callDoDirectPayment()!==false) {
00123 $payment
00124 ->setStatus('APPROVED')
00125 ->setPaymentStatus('AUTHORIZE')
00126 ->setCcTransId($api->getTransactionId())
00127 ->setCcAvsStatus($api->getAvsCode())
00128 ->setCcCidStatus($api->getCvv2Match());
00129 }else{
00130 $e = $api->getError();
00131 Mage::throwException($e['message']?$e['message']:Mage::helper('paypalUk')->__('There has been an error processing your payment. Please try later or contact us for help.'));
00132 }
00133
00134 }
00135
00136 public function capture(Varien_Object $payment, $amount)
00137 {
00138 if ($payment->getCcTransId()) {
00139 $trxType=Mage_PaypalUk_Model_Api_Pro::TRXTYPE_DELAYED_CAPTURE;
00140 } else {
00141
00142 $trxType=Mage_PaypalUk_Model_Api_Pro::TRXTYPE_SALE;
00143 }
00144
00145 $api = $this->getApi()
00146 ->setTrxtype($trxType)
00147 ->setAmount($amount)
00148 ->setTransactionId($payment->getCcTransId())
00149 ->setBillingAddress($payment->getOrder()->getBillingAddress())
00150 ->setShippingAddress($payment->getOrder()->getShippingAddress())
00151 ->setPayment($payment);
00152
00153 if ($api->callDoDirectPayment()!==false) {
00154 $payment
00155 ->setStatus('APPROVED')
00156 ->setPaymentStatus('CAPTURE')
00157 ->setCcTransId($api->getTransactionId())
00158 ->setCcAvsStatus($api->getAvsCode())
00159 ->setCcCidStatus($api->getCvv2Match());
00160 } else {
00161 $e = $api->getError();
00162 Mage::throwException($e['message']?$e['message']:Mage::helper('paypalUk')->__('There has been an error processing your payment. Please try later or contact us for help.'));
00163 }
00164
00165 return $this;
00166 }
00167
00168 public function canVoid(Varien_Object $payment)
00169 {
00170 if ($payment->getCcTransId()) {
00171 $api = $this->getApi()
00172 ->setTransactionId($payment->getCcTransId())
00173 ->setPayment($payment);
00174 if ($api->canVoid()!==false) {
00175 $payment->setStatus(self::STATUS_VOID);
00176 } else {
00177 $e = $api->getError();
00178 $payment->setStatus(self::STATUS_ERROR);
00179 $payment->setStatusDescription($e['message']);
00180 }
00181 } else {
00182 $payment->setStatus(self::STATUS_ERROR);
00183 $payment->setStatusDescription(Mage::helper('paypalUk')->__('Invalid transaction id'));
00184 }
00185 return $this;
00186 }
00187
00188 public function void(Varien_Object $payment)
00189 {
00190 $error = false;
00191 if ($payment->getVoidTransactionId()) {
00192 $api = $this->getApi()
00193 ->setTransactionId($payment->getVoidTransactionId())
00194 ->setPayment($payment);
00195
00196 if ($api->void()!==false) {
00197 $payment->setCcTransId($api->getTransactionId());
00198 $payment->setStatus(self::STATUS_VOID);
00199 } else {
00200 $e = $api->getError();
00201 $error = $e['message'];
00202 }
00203 } else {
00204 $error = Mage::helper('paypalUk')->__('Invalid transaction id');
00205 }
00206 if ($error !== false) {
00207 Mage::throwException($error);
00208 }
00209 return $this;
00210 }
00211
00212 public function refund(Varien_Object $payment, $amount)
00213 {
00214 $error = false;
00215 if (($payment->getRefundTransactionId() && $amount>0)) {
00216 $api = $this->getApi()
00217 ->setTransactionId($payment->getRefundTransactionId())
00218 ->setPayment($payment)
00219 ->setAmount($amount);
00220
00221 if ($api->refund()!==false) {
00222 $payment->setCcTransId($api->getTransactionId());
00223 $payment->setStatus(self::STATUS_SUCCESS);
00224 } else {
00225 $e = $api->getError();
00226 $error = $e['message'];
00227 }
00228 } else {
00229 $error = Mage::helper('paypalUk')->__('Error in refunding the payment');
00230 }
00231 if ($error !== false) {
00232 Mage::throwException($error);
00233 }
00234 return $this;
00235 }
00236
00237 }