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
00034 abstract class Mage_AmazonPayments_Model_Api_Abstract extends Varien_Object
00035 {
00036
00037
00038
00039 const PAYMENT_TYPE_AUTH = 'Authorization';
00040 const USER_ACTION_COMMIT = 'commit';
00041
00042
00043
00044
00045 protected static $HMAC_SHA1_ALGORITHM = 'sha1';
00046
00047
00048
00049
00050 protected $paymentCode;
00051
00052
00053
00054
00055
00056
00057 public function setPaymentCode($paymentCode)
00058 {
00059 if(is_null($this->paymentCode)) {
00060 $this->paymentCode = $paymentCode;
00061 $this->setData(Mage::getStoreConfig('payment/' . $paymentCode));
00062 }
00063 }
00064
00065
00066
00067
00068
00069
00070 public function getPayServiceUrl()
00071 {
00072 if ($this->getSandboxFlag()) {
00073 return $this->getData('sandbox_pay_service_url');
00074 }
00075 return $this->getData('pay_service_url');
00076 }
00077
00078
00079
00080
00081
00082
00083
00084
00085 public function getConfigData($key, $default = false)
00086 {
00087 if (!$this->hasData($key)) {
00088 $value = Mage::getStoreConfig('payment/' . $paymentCode . '/' . $key);
00089 if (is_null($value) || false===$value) {
00090 $value = $default;
00091 }
00092 $this->setData($key, $value);
00093 }
00094 return $this->getData($key);
00095 }
00096
00097
00098
00099
00100
00101
00102
00103 public function checkSignParams($params)
00104 {
00105 if (is_array($params) && isset($params[$this->getRequestSignatureParamName()])) {
00106 $paramSignature = $params[$this->getRequestSignatureParamName()];
00107 unset($params[$this->getRequestSignatureParamName()]);
00108 $generateSignature = $this->_getSignatureForArray($params, $this->getSecretKey());
00109 return $paramSignature == $generateSignature;
00110 }
00111
00112 return false;
00113 }
00114
00115
00116
00117
00118
00119
00120
00121 public function signParams($params)
00122 {
00123 $signature = $this->_getSignatureForArray($params, $this->getSecretKey());
00124 $params[$this->getRequestSignatureParamName()] = $signature;
00125 return $params;
00126 }
00127
00128
00129
00130
00131
00132
00133
00134
00135 protected function _getSignatureForArray($array, $secretKey)
00136 {
00137 uksort($array, 'strcasecmp');
00138 $tmpString = '';
00139 foreach ($array as $paramName => $paramValue) {
00140 $tmpString = $tmpString . $paramName . $paramValue;
00141 }
00142 return $this->_getSignatureForString($tmpString, $secretKey);
00143 }
00144
00145
00146
00147
00148
00149
00150
00151
00152 protected function _getSignatureForString($string, $secretKey)
00153 {
00154 $rawHmac = hash_hmac(self::$HMAC_SHA1_ALGORITHM, $string, $secretKey, true);
00155 return base64_encode($rawHmac);
00156 }
00157 }