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_Paypal_Model_Api_Abstract extends Varien_Object
00033 {
00034 const PAYMENT_TYPE_SALE = 'Sale';
00035 const PAYMENT_TYPE_ORDER = 'Order';
00036 const PAYMENT_TYPE_AUTH = 'Authorization';
00037
00038 const REFUND_TYPE_FULL = 'Full';
00039 const REFUND_TYPE_PARTIAL = 'Partial';
00040
00041 const COMPLETE = 'Complete';
00042 const NOTCOMPLETE = 'NotComplete';
00043
00044 const USER_ACTION_COMMIT = 'commit';
00045 const USER_ACTION_CONTINUE = 'continue';
00046
00047 public function getServerName()
00048 {
00049 if (!$this->hasServerName()) {
00050 $this->setServerName($_SERVER['SERVER_NAME']);
00051 }
00052 return $this->getData('server_name');
00053 }
00054
00055 public function getConfigData($key, $default=false, $storeId = null)
00056 {
00057 if (!$this->hasData($key)) {
00058 if ($storeId === null && $this->getPayment() instanceof Varien_Object) {
00059 $storeId = $this->getPayment()->getOrder()->getStoreId();
00060 }
00061 $value = Mage::getStoreConfig('paypal/wpp/'.$key, $storeId);
00062 if (is_null($value) || false===$value) {
00063 $value = $default;
00064 }
00065 $this->setData($key, $value);
00066 }
00067 return $this->getData($key);
00068 }
00069
00070 public function getSession()
00071 {
00072 return Mage::getSingleton('paypal/session');
00073 }
00074
00075 public function getUseSession()
00076 {
00077 if (!$this->hasData('use_session')) {
00078 $this->setUseSession(true);
00079 }
00080 return $this->getData('use_session');
00081 }
00082
00083 public function getSessionData($key, $default=false)
00084 {
00085 if (!$this->hasData($key)) {
00086 $value = $this->getSession()->getData($key);
00087 if ($this->getSession()->hasData($key)) {
00088 $value = $this->getSession()->getData($key);
00089 } else {
00090 $value = $default;
00091 }
00092 $this->setData($key, $value);
00093 }
00094 return $this->getData($key);
00095 }
00096
00097 public function setSessionData($key, $value)
00098 {
00099 if ($this->getUseSession()) {
00100 $this->getSession()->setData($key, $value);
00101 }
00102 $this->setData($key, $value);
00103 return $this;
00104 }
00105
00106 public function getSandboxFlag()
00107 {
00108 return $this->getConfigData('sandbox_flag', true);
00109 }
00110
00111 public function getApiUsername()
00112 {
00113 return $this->getConfigData('api_username');
00114 }
00115
00116 public function getApiPassword()
00117 {
00118 return $this->getConfigData('api_password');
00119 }
00120
00121 public function getApiSignature()
00122 {
00123 return $this->getConfigData('api_signature');
00124 }
00125
00126 public function getButtonSourceEc()
00127 {
00128 return $this->getConfigData('button_source_ec', 'Varien_Cart_EC_US');
00129 }
00130
00131 public function getButtonSourceDp()
00132 {
00133 return $this->getConfigData('button_source_dp', 'Varien_Cart_DP_US');
00134 }
00135
00136 public function getUseProxy()
00137 {
00138 return $this->getConfigData('use_proxy', false);
00139 }
00140
00141 public function getProxyHost()
00142 {
00143 return $this->getConfigData('proxy_host', '127.0.0.1');
00144 }
00145
00146 public function getProxyPort()
00147 {
00148 return $this->getConfigData('proxy_port', '808');
00149 }
00150
00151 public function getDebug()
00152 {
00153 return $this->getConfigData('debug_flag', true);
00154 }
00155
00156
00157
00158
00159
00160
00161 public function getApiErrorUrl()
00162 {
00163 return Mage::getUrl($this->getConfigData('api_error_url', 'paypal/express/error'));
00164 }
00165
00166
00167
00168
00169
00170
00171 public function getReturnUrl()
00172 {
00173 return Mage::getUrl($this->getConfigData('api_return_url', 'paypal/express/return'));
00174 }
00175
00176
00177
00178
00179
00180
00181 public function getCancelUrl()
00182 {
00183 return Mage::getUrl($this->getConfigData('api_cancel_url', 'paypal/express/cancel'));
00184 }
00185
00186
00187
00188
00189
00190
00191 public function getUserAction()
00192 {
00193 return $this->getSessionData('user_action', self::USER_ACTION_CONTINUE);
00194 }
00195
00196 public function setUserAction($data)
00197 {
00198 return $this->setSessionData('user_action', $data);
00199 }
00200
00201
00202
00203
00204
00205
00206 public function getToken()
00207 {
00208 return $this->getSessionData('token');
00209 }
00210
00211 public function setToken($data)
00212 {
00213 return $this->setSessionData('token', $data);
00214 }
00215
00216 public function getTransactionId()
00217 {
00218 return $this->getSessionData('transaction_id');
00219 }
00220
00221 public function setTransactionId($data)
00222 {
00223 return $this->setSessionData('transaction_id', $data);
00224 }
00225
00226 public function getAuthorizationId()
00227 {
00228 return $this->getSessionData('authorization_id');
00229 }
00230
00231 public function setAuthorizationId($data)
00232 {
00233 return $this->setSessionData('authorization_id', $data);
00234 }
00235
00236 public function getPayerId()
00237 {
00238 return $this->getSessionData('payer_id');
00239 }
00240
00241 public function setPayerId($data)
00242 {
00243 return $this->setSessionData('payer_id', $data);
00244 }
00245
00246
00247
00248
00249
00250
00251 public function getCompleteType()
00252 {
00253 return $this->getSessionData('complete_type');
00254 }
00255
00256 public function setCompleteType($data)
00257 {
00258 return $this->setSessionData('complete_type', $data);
00259 }
00260
00261
00262
00263
00264
00265
00266 public function getPaymentType()
00267 {
00268 return $this->getSessionData('payment_type');
00269 }
00270
00271 public function setPaymentType($data)
00272 {
00273 return $this->setSessionData('payment_type', $data);
00274 }
00275
00276
00277
00278
00279
00280
00281
00282
00283 public function getAmount()
00284 {
00285 return $this->getSessionData('amount');
00286 }
00287
00288 public function setAmount($data)
00289 {
00290 $data = sprintf('%.2f', $data);
00291 return $this->setSessionData('amount', $data);
00292 }
00293
00294 public function getCurrencyCode()
00295 {
00296
00297 return $this->getSessionData('currency_code', Mage::app()->getStore()->getBaseCurrencyCode());
00298 }
00299
00300 public function setCurrencyCode($data)
00301 {
00302 return $this->setSessionData('currency_code', $data);
00303 }
00304
00305
00306
00307
00308
00309
00310 public function getRefundType()
00311 {
00312 return $this->getSessionData('refund_type');
00313 }
00314
00315 public function setRefundType($data)
00316 {
00317 return $this->setSessionData('refund_type', $data);
00318 }
00319
00320 public function getError()
00321 {
00322 return $this->getSessionData('error');
00323 }
00324
00325 public function setError($data)
00326 {
00327 return $this->setSessionData('error', $data);
00328 }
00329
00330 public function getCcTypeName($ccType)
00331 {
00332 $types = array('AE'=>Mage::helper('paypal')->__('Amex'), 'VI'=>Mage::helper('paypal')->__('Visa'), 'MC'=>Mage::helper('paypal')->__('MasterCard'), 'DI'=>Mage::helper('paypal')->__('Discover'));
00333 return isset($types[$ccType]) ? $types[$ccType] : false;
00334 }
00335
00336 public function unsError()
00337 {
00338 return $this->setSessionData('error', null);
00339 }
00340 }