Mage_AmazonPayments_Model_Api_Asp_Fps Class Reference

Inheritance diagram for Mage_AmazonPayments_Model_Api_Asp_Fps:

Mage_AmazonPayments_Model_Api_Asp_Abstract Mage_AmazonPayments_Model_Api_Abstract Varien_Object

List of all members.

Public Member Functions

 getRequest ($actionCode)
 process ($request)

Public Attributes

const SERVICE_VERSION = '2008-09-17'
const ACTION_CODE_CANCEL = 'Cancel'
const ACTION_CODE_SETTLE = 'Settle'
const ACTION_CODE_REFUND = 'Refund'
const EXCEPTION_INVALID_ACTION_CODE = 10031
const EXCEPTION_INVALID_REQUEST = 10031
const EXCEPTION_INVALID_RESPONSE = 10032

Protected Member Functions

 _getResponse ($requestActionCode, $responseBody)
 _getServiceUrl ()
 _addRequiredParameters ($request)
 _signRequest ($request)
 _call ($serviceUrl, $params)
 _throwExeptionInvalidActionCode ()


Detailed Description

Definition at line 34 of file Fps.php.


Member Function Documentation

_addRequiredParameters ( request  )  [protected]

Add required params to FPS request

Parameters:
object Mage_AmazonPayments_Model_Api_Asp_Fps_Request_Abstract
Returns:
Mage_AmazonPayments_Model_Api_Asp_Fps_Request_Abstract

Definition at line 158 of file Fps.php.

00159     {
00160         return $request->setData('AWSAccessKeyId', $this->_getConfig('access_key'))
00161                     ->setData('Timestamp', gmdate("Y-m-d\TH:i:s.\\0\\0\\0\\Z", time()))
00162                     ->setData('Version', self::SERVICE_VERSION)
00163                     ->setData('SignatureVersion', '1');
00164     } 

_call ( serviceUrl,
params 
) [protected]

Send request to Amazon FPS service and return response body

Parameters:
string $serviceUrl
array $params
Returns:
Varien_Simplexml_Element

Definition at line 185 of file Fps.php.

00186     {
00187         $tmpArray = array(); 
00188         foreach ($params as $kay => $value) {
00189             $tmpArray[] = $kay . '=' . urlencode($value);
00190         }
00191         $requestBody = implode('&', $tmpArray);
00192         
00193         $http = new Varien_Http_Adapter_Curl();
00194         $http->setConfig(array('timeout' => 30));
00195         $http->write(Zend_Http_Client::POST, $serviceUrl, '1.1', array(), $requestBody);
00196 
00197         $responseBody = $http->read();
00198         $responseBody = preg_split('/^\r?$/m', $responseBody, 2);
00199         $responseBody = trim($responseBody[1]);
00200         
00201         $responseBody = new Varien_Simplexml_Element($responseBody);
00202 
00203         $http->close();
00204         return $responseBody;
00205     }

_getResponse ( requestActionCode,
responseBody 
) [protected]

Return FPS response model for response body

Parameters:
string $requestActionCode
string $responseBody
Returns:
Mage_AmazonPayments_Model_Api_Asp_Fps_Response_Abstract

Definition at line 86 of file Fps.php.

00087     {
00088         switch ($requestActionCode) {
00089             case self::ACTION_CODE_CANCEL: 
00090                 $responseModelPath = 'amazonpayments/api_asp_fps_response_cancel';
00091                 break;  
00092             case self::ACTION_CODE_SETTLE:
00093                 $responseModelPath = 'amazonpayments/api_asp_fps_response_settle';
00094                 break;  
00095             case self::ACTION_CODE_REFUND:
00096                 $responseModelPath = 'amazonpayments/api_asp_fps_response_refund';
00097                 break;  
00098             default: $this->_throwExeptionInvalidActionCode();
00099         }
00100     
00101         $actionResponse = Mage::getSingleton($responseModelPath);
00102         if ($actionResponse->init($responseBody)) {
00103             return $actionResponse;
00104         }
00105         
00106         $errorResponse = Mage::getSingleton('amazonpayments/api_asp_fps_response_error');
00107         if ($errorResponse->init($responseBody)) {
00108             return $errorResponse;
00109         }
00110 
00111         throw new Exception(
00112             Mage::helper('amazonpayments')->__('Response body is not valid FPS respons'), 
00113             self::EXCEPTION_INVALID_RESPONSE
00114         );
00115     }

_getServiceUrl (  )  [protected]

Return Amazon FPS service url

Returns:
string

Definition at line 144 of file Fps.php.

00145     {
00146         if ($this->_isSandbox()) {
00147             return $this->_getConfig('fps_service_url_sandbox');
00148         }
00149         return $this->_getConfig('fps_service_url');
00150     }

_signRequest ( request  )  [protected]

Add signature param to FPS request

Parameters:
object Mage_AmazonPayments_Model_Api_Asp_Fps_Request_Abstract
Returns:
Mage_AmazonPayments_Model_Api_Asp_Fps_Request_Abstract

Definition at line 172 of file Fps.php.

00173     {
00174         $signature = $this->_getSignatureForArray($request->getData(), $this->_getConfig('secret_key'));
00175         return $request->setData('Signature', $signature);
00176     }

_throwExeptionInvalidActionCode (  )  [protected]

Throw exeption: Invalid action code

Definition at line 210 of file Fps.php.

00211     {
00212         throw new Exception(
00213             Mage::helper('amazonpayments')->__('Invalid action code'), 
00214             self::EXCEPTION_INVALID_ACTION_CODE
00215         );
00216     }

getRequest ( actionCode  ) 

Return FPS request model

Parameters:
string $actionCode
Returns:
Mage_AmazonPayments_Model_Api_Asp_Fps_Request_Abstract

Definition at line 61 of file Fps.php.

00062     {
00063         switch ($actionCode) {
00064             case self::ACTION_CODE_CANCEL: 
00065                 $requestModelPath = 'amazonpayments/api_asp_fps_request_cancel';
00066                 break;  
00067             case self::ACTION_CODE_SETTLE:
00068                 $requestModelPath = 'amazonpayments/api_asp_fps_request_settle';
00069                 break;  
00070             case self::ACTION_CODE_REFUND:
00071                 $requestModelPath = 'amazonpayments/api_asp_fps_request_refund';
00072                 break;  
00073             default: $this->_throwExeptionInvalidActionCode();
00074         }
00075 
00076         return Mage::getSingleton($requestModelPath)->init($actionCode); 
00077     }

process ( request  ) 

Process FPS request

Parameters:
object Mage_AmazonPayments_Model_Api_Asp_Fps_Request_Abstract $request
Returns:
Mage_AmazonPayments_Model_Api_Asp_Fps_Response_Abstract

Definition at line 123 of file Fps.php.

00124     {
00125         if (!$request->isValid()) {
00126             throw new Exception(
00127                 Mage::helper('amazonpayments')->__('Invalid request'), 
00128                 self::EXCEPTION_INVALID_REQUEST
00129             );
00130         }
00131         
00132         $request = $this->_addRequiredParameters($request);
00133         $request = $this->_signRequest($request);
00134 
00135         $responseBody = $this->_call($this->_getServiceUrl(), $request->getData());
00136         return $this->_getResponse($request->getActionCode(), $responseBody);
00137     }


Member Data Documentation

const ACTION_CODE_CANCEL = 'Cancel'

Definition at line 44 of file Fps.php.

const ACTION_CODE_REFUND = 'Refund'

Definition at line 46 of file Fps.php.

const ACTION_CODE_SETTLE = 'Settle'

Definition at line 45 of file Fps.php.

Definition at line 51 of file Fps.php.

Definition at line 52 of file Fps.php.

Definition at line 53 of file Fps.php.

const SERVICE_VERSION = '2008-09-17'

Definition at line 39 of file Fps.php.


The documentation for this class was generated from the following file:

Generated on Sat Jul 4 17:23:31 2009 for Magento by  doxygen 1.5.8