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_PaypalUk_Model_Api_Abstract extends Varien_Object
00033 {
00034 const PAYMENT_TYPE_SALE = 'authorize_capture';
00035 const PAYMENT_TYPE_AUTH = 'authorize';
00036 const PAYMENT_TYPE_ORDER = 'Order';
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
00048
00049 public function getConfigData($key, $default=false, $storeId = null)
00050 {
00051 if (!$this->hasData($key)) {
00052 if ($storeId === null && $this->getPayment() instanceof Varien_Object) {
00053 $storeId = $this->getPayment()->getOrder()->getStoreId();
00054 }
00055 $value = Mage::getStoreConfig('paypal/wpuk/'.$key, $storeId);
00056 if (is_null($value) || false===$value) {
00057 $value = $default;
00058 }
00059 $this->setData($key, $value);
00060 }
00061 return $this->getData($key);
00062 }
00063
00064 public function getSession()
00065 {
00066 return Mage::getSingleton('paypaluk/session');
00067 }
00068
00069 public function getUseSession()
00070 {
00071 if (!$this->hasData('use_session')) {
00072 $this->setUseSession(true);
00073 }
00074 return $this->getData('use_session');
00075 }
00076
00077 public function getSessionData($key, $default=false)
00078 {
00079 if (!$this->hasData($key)) {
00080 $value = $this->getSession()->getData($key);
00081 if ($this->getSession()->hasData($key)) {
00082 $value = $this->getSession()->getData($key);
00083 } else {
00084 $value = $default;
00085 }
00086 $this->setData($key, $value);
00087 }
00088 return $this->getData($key);
00089 }
00090
00091 public function setSessionData($key, $value)
00092 {
00093 if ($this->getUseSession()) {
00094 $this->getSession()->setData($key, $value);
00095 }
00096 $this->setData($key, $value);
00097 return $this;
00098 }
00099
00100 public function getApiUrl()
00101 {
00102 return $this->getConfigData('url');
00103 }
00104
00105 public function getApiUser()
00106 {
00107 return $this->getConfigData('user');
00108 }
00109
00110 public function getApiVendor()
00111 {
00112 return $this->getConfigData('vendor');
00113 }
00114
00115 public function getApiPassword()
00116 {
00117 return $this->getConfigData('pwd');
00118 }
00119
00120 public function getDebug()
00121 {
00122 return $this->getConfigData('debug_flag', true);
00123 }
00124
00125 public function getPartner()
00126 {
00127 return $this->getConfigData('partner', 'PayPalUK');
00128 }
00129
00130 public function getError()
00131 {
00132 return $this->getSessionData('error');
00133 }
00134
00135 public function setError($data)
00136 {
00137 return $this->setSessionData('error', $data);
00138 }
00139
00140
00141
00142
00143
00144
00145 public function getReturnUrl()
00146 {
00147 return Mage::getUrl($this->getConfigData('api_return_url', 'paypaluk/express/return'));
00148 }
00149
00150
00151
00152
00153
00154
00155 public function getCancelUrl()
00156 {
00157 return Mage::getUrl($this->getConfigData('api_cancel_url', 'paypaluk/express/cancel'));
00158 }
00159
00160
00161
00162
00163
00164
00165 public function getUserAction()
00166 {
00167 return $this->getSessionData('user_action', self::USER_ACTION_CONTINUE);
00168 }
00169
00170 public function setUserAction($data)
00171 {
00172 return $this->setSessionData('user_action', $data);
00173 }
00174
00175
00176
00177
00178
00179
00180 public function getToken()
00181 {
00182 return $this->getSessionData('token');
00183 }
00184
00185 public function setToken($data)
00186 {
00187 return $this->setSessionData('token', $data);
00188 }
00189
00190 public function getTransactionId()
00191 {
00192 return $this->getSessionData('transaction_id');
00193 }
00194
00195 public function setTransactionId($data)
00196 {
00197 return $this->setSessionData('transaction_id', $data);
00198 }
00199
00200 public function getAuthorizationId()
00201 {
00202 return $this->getSessionData('authorization_id');
00203 }
00204
00205 public function setAuthorizationId($data)
00206 {
00207 return $this->setSessionData('authorization_id', $data);
00208 }
00209
00210 public function getPayerId()
00211 {
00212 return $this->getSessionData('payer_id');
00213 }
00214
00215 public function setPayerId($data)
00216 {
00217 return $this->setSessionData('payer_id', $data);
00218 }
00219
00220
00221
00222
00223
00224
00225 public function getCompleteType()
00226 {
00227 return $this->getSessionData('complete_type');
00228 }
00229
00230 public function setCompleteType($data)
00231 {
00232 return $this->setSessionData('complete_type', $data);
00233 }
00234
00235
00236
00237
00238
00239
00240 public function getPaymentType()
00241 {
00242 return $this->getSessionData('payment_type');
00243 }
00244
00245 public function setPaymentType($data)
00246 {
00247 return $this->setSessionData('payment_type', $data);
00248 }
00249
00250
00251
00252
00253
00254
00255
00256
00257 public function getAmount()
00258 {
00259 return $this->getSessionData('amount');
00260 }
00261
00262 public function setAmount($data)
00263 {
00264 $data = sprintf('%.2f', $data);
00265 return $this->setSessionData('amount', $data);
00266 }
00267
00268 public function getCurrencyCode()
00269 {
00270
00271
00272 return $this->getSessionData('currency_code', Mage::app()->getStore()->getBaseCurrencyCode());
00273 }
00274
00275 public function setCurrencyCode($data)
00276 {
00277 return $this->setSessionData('currency_code', $data);
00278 }
00279
00280
00281 public function getButtonSourceEc()
00282 {
00283 return $this->getConfigData('button_source', 'Varien_Cart_EC_UK');
00284 }
00285
00286 public function getButtonSourceDp()
00287 {
00288 return $this->getConfigData('button_source', 'Varien_Cart_DP_UK');
00289 }
00290
00291
00292
00293
00294
00295
00296 public function getApiErrorUrl()
00297 {
00298 return Mage::getUrl($this->getConfigData('api_error_url', 'paypaluk/express/error'));
00299 }
00300
00301
00302
00303
00304 public function getCcTypes()
00305 {
00306 foreach (Mage::getSingleton('payment/config')->getCcTypes() as $code => $name) {
00307 $ccTypes[$code] = $name;
00308 }
00309 return $ccTypes;
00310 }
00311
00312 }