Mage_AmazonPayments_Model_Payment_Asp Class Reference

Inheritance diagram for Mage_AmazonPayments_Model_Payment_Asp:

Mage_Payment_Model_Method_Abstract Varien_Object

List of all members.

Public Member Functions

 getConfig ($path)
 isAvailable ($quote=null)
 getApi ()
 getNotification ()
 setOrder ($order)
 getOrder ()
 getOrderPlaceRedirectUrl ()
 getPayRedirectUrl ()
 getPayRedirectParams ()
 processEventRedirect ()
 processEventReturnSuccess ()
 processEventReturnCancel ()
 initialize ($paymentAction, $stateObject)
 processNotification ($requestParams)
 capture (Varien_Object $payment, $amount)
 processInvoice ($invoice, $payment)
 processCreditmemo ($creditmemo, $payment)
 cancel (Varien_Object $payment)

Protected Member Functions

 _log ($request, $response= '')
 _mail ($template, array $variables=array())

Protected Attributes

 $_isGateway = false
 $_canAuthorize = false
 $_canCapture = true
 $_canCapturePartial = false
 $_canRefund = true
 $_canVoid = true
 $_canUseInternal = false
 $_canUseCheckout = true
 $_canUseForMultishipping = false
 $_isInitializeNeeded = true
 $_formBlockType = 'amazonpayments/asp_form'
 $_code = 'amazonpayments_asp'
 $_order


Detailed Description

Definition at line 34 of file Asp.php.


Member Function Documentation

_log ( request,
response = '' 
) [protected]

Add item in to log storage

Parameters:
string $request
string $response
Returns:
Mage_AmazonPayments_Model_Payment_Asp

Definition at line 139 of file Asp.php.

00140     {
00141         $debug = Mage::getModel('amazonpayments/api_debug')
00142             ->setRequestBody($request)
00143             ->setResponseBody($response)
00144             ->save();
00145         return $this;
00146     }

_mail ( template,
array variables = array() 
) [protected]

Send mail

Parameters:
string $template
array $variables
Returns:
Mage_AmazonPayments_Model_Payment_Asp

Definition at line 155 of file Asp.php.

00156     {
00157         $mailTemplate = Mage::getModel('core/email_template');
00158         $mailTemplate->setDesignConfig(array('area' => 'frontend'))
00159                     ->sendTransactional(
00160                         $this->getConfig($template),
00161                         $this->getConfig('email_sender_identity'),
00162                         $this->getConfig('report_email'),
00163                         null,
00164                         $variables
00165                     );  
00166         return $this;
00167     }

cancel ( Varien_Object payment  ) 

rewrited for Mage_Payment_Model_Method_Abstract

Reimplemented from Mage_Payment_Model_Method_Abstract.

Definition at line 393 of file Asp.php.

00394     {
00395         if (!is_null($payment->getCcTransId()) &&
00396             is_null($payment->getLastTransId())) {
00397 
00398             $transactionId = $payment->getCcTransId();
00399             $response = $this->getApi()
00400                 ->setStoreId($payment->getOrder()->getStoreId())
00401                 ->cancel($transactionId);
00402 
00403             if ($response->getStatus() == Mage_AmazonPayments_Model_Api_Asp_Fps_Response_Abstract::STATUS_ERROR) {
00404                 Mage::throwException(
00405                     Mage::helper('amazonpayments')->__('Order was not cancelled. Amazon Simple Pay service error: [%s] %s', $response->getCode(), $response->getMessage())
00406                 );
00407             }
00408 
00409             if ($response->getStatus() == Mage_AmazonPayments_Model_Api_Asp_Fps_Response_Abstract::STATUS_CANCELLED) {
00410                 $payment->getOrder()->setState(
00411                     Mage_Sales_Model_Order::STATE_CANCELED,
00412                     true,
00413                     Mage::helper('amazonpayments')->__('Payment authorization cancelled with Amazon Simple Pay service.'),
00414                     $notified = false
00415                 )->save();
00416             }
00417         }
00418         return $this;
00419     }

capture ( Varien_Object payment,
amount 
)

rewrited for Mage_Payment_Model_Method_Abstract

Reimplemented from Mage_Payment_Model_Method_Abstract.

Definition at line 299 of file Asp.php.

00300     {
00301         if (is_null($payment->getCcTransId())) {
00302             Mage::throwException(
00303                 Mage::helper('amazonpayments')->__('Order was not captured online. Authorization confirmation is required.')
00304             );
00305         }
00306         return $this;
00307     }

getApi (  ) 

Get singleton with AmazonPayments ASP API Model

Returns:
Mage_AmazonPayments_Model_Api_Asp

Definition at line 89 of file Asp.php.

00090     {
00091         return Mage::getSingleton('amazonpayments/api_asp');
00092     }

getConfig ( path  ) 

Get value from the module config

Parameters:
string $path
Returns:
string

Definition at line 71 of file Asp.php.

00072     {
00073         return Mage::getStoreConfig('payment/' . $this->_code . '/' . $path);
00074     }    

getNotification (  ) 

Get singleton with AmazonPayments ASP Notification Model

Returns:
Mage_AmazonPayments_Model_Payment_Asp_Notification

Definition at line 99 of file Asp.php.

00100     {
00101         return Mage::getSingleton('amazonpayments/payment_asp_notification');
00102     }

getOrder (  ) 

Get model of current order

Returns:
Mage_Sales_Model_Order

Definition at line 121 of file Asp.php.

00122     {
00123         if (!$this->_order) {
00124             $paymentInfo = $this->getInfoInstance();
00125             $this->_order = Mage::getModel('sales/order')->loadByIncrementId(
00126                 $paymentInfo->getOrder()->getRealOrderId()
00127             );
00128         }
00129         return $this->_order;
00130     }

getOrderPlaceRedirectUrl (  ) 

rewrited for Mage_Payment_Model_Method_Abstract

Definition at line 172 of file Asp.php.

00173     {
00174         return Mage::getUrl('amazonpayments/asp/pay');
00175     }

getPayRedirectParams (  ) 

Return pay params for current order

Returns:
array

Definition at line 192 of file Asp.php.

00193     {
00194         $orderId = $this->getOrder()->getRealOrderId();
00195         $amount = Mage::app()->getStore()->roundPrice($this->getOrder()->getBaseGrandTotal());
00196         $currencyCode = $this->getOrder()->getBaseCurrency();
00197         
00198         $urlModel = Mage::getModel('core/url')
00199             ->setUseSession(false);
00200         
00201         return $this->getApi()->getPayParams(
00202             $orderId, 
00203             $amount, 
00204             $currencyCode,
00205             $urlModel->getUrl('amazonpayments/asp/returnCancel'),
00206             $urlModel->getUrl('amazonpayments/asp/returnSuccess'),
00207             $urlModel->getUrl('amazonpayments/asp/notification')
00208             );
00209     }

getPayRedirectUrl (  ) 

Return Amazon Simple Pay payment url

Returns:
string

Definition at line 182 of file Asp.php.

00183     {
00184         return $this->getApi()->getPayUrl();
00185     }

initialize ( paymentAction,
stateObject 
)

rewrited for Mage_Payment_Model_Method_Abstract

Reimplemented from Mage_Payment_Model_Method_Abstract.

Definition at line 257 of file Asp.php.

00258     {
00259         $state = Mage_Sales_Model_Order::STATE_NEW;
00260         $stateObject->setState($state);
00261         $stateObject->setStatus(Mage::getSingleton('sales/order_config')->getStateDefaultStatus($state));
00262         $stateObject->setIsNotified(false);
00263         return $this;
00264     }

isAvailable ( quote = null  ) 

rewrited for Mage_Payment_Model_Method_Abstract

Reimplemented from Mage_Payment_Model_Method_Abstract.

Definition at line 79 of file Asp.php.

00080     {
00081         return $this->getConfig('active');
00082     }

processCreditmemo ( creditmemo,
payment 
)

rewrited for Mage_Payment_Model_Method_Abstract

Reimplemented from Mage_Payment_Model_Method_Abstract.

Definition at line 353 of file Asp.php.

00354     {
00355 
00356         $transactionId = $creditmemo->getInvoice()->getTransactionId();
00357 
00358         if (!is_null($transactionId) &&
00359             is_null($creditmemo->getTransactionId())) {
00360 
00361             $amount = Mage::app()->getStore()->roundPrice($creditmemo->getBaseGrandTotal());
00362             $currencyCode = $payment->getOrder()->getBaseCurrency();
00363             $referenseID = $creditmemo->getInvoice()->getIncrementId();
00364             $response = $this->getApi()
00365                 ->setStoreId($payment->getOrder()->getStoreId())
00366                 ->refund($transactionId, $amount, $currencyCode, $referenseID);
00367 
00368             if ($response->getStatus() == Mage_AmazonPayments_Model_Api_Asp_Fps_Response_Abstract::STATUS_ERROR) {
00369                 Mage::throwException(
00370                     Mage::helper('amazonpayments')->__('Invoice was not refunded. Amazon Simple Pay service error: [%s] %s', $response->getCode(), $response->getMessage())
00371                 );
00372             }
00373 
00374             if ($response->getStatus() == Mage_AmazonPayments_Model_Api_Asp_Fps_Response_Abstract::STATUS_SUCCESS ||
00375                 $response->getStatus() == Mage_AmazonPayments_Model_Api_Asp_Fps_Response_Abstract::STATUS_PENDING) {
00376 
00377                 $creditmemo->setTransactionId($response->getTransactionId());
00378                 $creditmemo->addComment(Mage::helper('amazonpayments')->__('Payment refunded online. Waiting for refund confirmation from Amazon Simple Pay service.'));
00379                 $creditmemo->setState(Mage_Sales_Model_Order_Creditmemo::STATE_OPEN);
00380 
00381                 $payment->getOrder()->addStatusToHistory(
00382                   $payment->getOrder()->getStatus(),
00383                   Mage::helper('amazonpayments')->__('Payment refunded online with Amazon Simple Pay service. Creditmemo was created. Waiting for refund confirmation from Amazon Simple Pay service.')
00384                 )->save();
00385             }
00386         }
00387         return $this;
00388     }

processEventRedirect (  ) 

When a customer redirect to Amazon Simple Pay site

Returns:
Mage_AmazonPayments_Model_Payment_Asp

Definition at line 216 of file Asp.php.

00217     {
00218         $this->getOrder()->addStatusToHistory(
00219            $this->getOrder()->getStatus(),
00220            Mage::helper('amazonpayments')->__('Customer was redirected to Amazon Simple Pay site')
00221         )->save();
00222         return $this;
00223     }

processEventReturnCancel (  ) 

Customer canceled payment and successfully returned from Amazon Simple Pay site

Returns:
Mage_AmazonPayments_Model_Payment_Asp

Definition at line 245 of file Asp.php.

00246     {
00247         $this->getOrder()->addStatusToHistory(
00248            $this->getOrder()->getStatus(),
00249            Mage::helper('amazonpayments')->__('Customer canceled payment and successfully returned from Amazon Simple Pay site')
00250         )->save();
00251         return $this;
00252     }

processEventReturnSuccess (  ) 

When a customer successfully returned from Amazon Simple Pay site

Returns:
Mage_AmazonPayments_Model_Payment_Asp

Definition at line 230 of file Asp.php.

00231     {
00232         $this->getOrder()->sendNewOrderEmail();
00233         $this->getOrder()->addStatusToHistory(
00234            $this->getOrder()->getStatus(),
00235            Mage::helper('amazonpayments')->__('Customer successfully returned from Amazon Simple Pay site')
00236         )->save();
00237         return $this;
00238     }

processInvoice ( invoice,
payment 
)

rewrited for Mage_Payment_Model_Method_Abstract

Reimplemented from Mage_Payment_Model_Method_Abstract.

Definition at line 312 of file Asp.php.

00313     {
00314         if (!is_null($payment->getCcTransId()) &&
00315             is_null($payment->getLastTransId()) &&
00316             is_null($invoice->getTransactionId())) {
00317 
00318             $amount = Mage::app()->getStore()->roundPrice($invoice->getBaseGrandTotal());
00319             $currencyCode = $payment->getOrder()->getBaseCurrency();
00320             $transactionId = $payment->getCcTransId();
00321             $response = $this->getApi()
00322                 ->setStoreId($payment->getOrder()->getStoreId())
00323                 ->capture($transactionId, $amount, $currencyCode);
00324 
00325             if ($response->getStatus() == Mage_AmazonPayments_Model_Api_Asp_Fps_Response_Abstract::STATUS_ERROR) {
00326                 Mage::throwException(
00327                     Mage::helper('amazonpayments')->__('Order was not captured. Amazon Simple Pay service error: [%s] %s', $response->getCode(), $response->getMessage())
00328                 );
00329             }
00330 
00331             if ($response->getStatus() == Mage_AmazonPayments_Model_Api_Asp_Fps_Response_Abstract::STATUS_SUCCESS ||
00332                 $response->getStatus() == Mage_AmazonPayments_Model_Api_Asp_Fps_Response_Abstract::STATUS_PENDING) {
00333 
00334                 $payment->setForcedState(Mage_Sales_Model_Order_Invoice::STATE_OPEN);
00335                 $payment->setLastTransId($response->getTransactionId());
00336 
00337                 $invoice->setTransactionId($response->getTransactionId());
00338                 $invoice->addComment(Mage::helper('amazonpayments')->__('Invoice was created (online capture). Waiting for capture confirmation from Amazon Simple Pay service.'));
00339 
00340                 $payment->getOrder()->addStatusToHistory(
00341                   $payment->getOrder()->getStatus(),
00342                   Mage::helper('amazonpayments')->__('Payment was captured online with Amazon Simple Pay service. Invoice was created. Waiting for capture confirmation from payment service.')
00343                 )->save();
00344 
00345             }
00346         }
00347         return $this;
00348     }

processNotification ( requestParams  ) 

process Amazon Simple Pay notification request

Parameters:
array $requestParams
Returns:
Mage_AmazonPayments_Model_Payment_Asp

Definition at line 272 of file Asp.php.

00273     {
00274         if ($this->getConfig('debug_log')) {
00275             $this->_log('DEBUG ASP notification: ' . print_r($requestParams, 1));
00276         }
00277         
00278         try {
00279            $this->getNotification()->setPayment($this)->process($requestParams);
00280         } catch(Exception $e) {
00281             if ($this->getConfig('error_log')) {
00282                 $this->_log('ERROR ASP notification: ' . print_r($requestParams, 1), $e->getMessage());
00283             }
00284 
00285             if ($this->getConfig('report_error_to_email')) {
00286                 $variables = array();
00287                 $variables['request'] = print_r($requestParams, 1); 
00288                 $variables['error'] = $e->getMessage(); 
00289                 $this->_mail('email_template_notofication_error', $variables);
00290             }
00291         }
00292         
00293         return $this;
00294     }

setOrder ( order  ) 

Set model of current order

Parameters:
Mage_Sales_Model_Order $order
Returns:
Mage_AmazonPayments_Model_Payment_Asp

Definition at line 110 of file Asp.php.

00111     {
00112         $this->_order = $order;
00113         return $this;
00114     }


Member Data Documentation

$_canAuthorize = false [protected]

Reimplemented from Mage_Payment_Model_Method_Abstract.

Definition at line 40 of file Asp.php.

$_canCapture = true [protected]

Reimplemented from Mage_Payment_Model_Method_Abstract.

Definition at line 41 of file Asp.php.

$_canCapturePartial = false [protected]

Reimplemented from Mage_Payment_Model_Method_Abstract.

Definition at line 42 of file Asp.php.

$_canRefund = true [protected]

Reimplemented from Mage_Payment_Model_Method_Abstract.

Definition at line 43 of file Asp.php.

$_canUseCheckout = true [protected]

Reimplemented from Mage_Payment_Model_Method_Abstract.

Definition at line 46 of file Asp.php.

$_canUseForMultishipping = false [protected]

Reimplemented from Mage_Payment_Model_Method_Abstract.

Definition at line 47 of file Asp.php.

$_canUseInternal = false [protected]

Reimplemented from Mage_Payment_Model_Method_Abstract.

Definition at line 45 of file Asp.php.

$_canVoid = true [protected]

Reimplemented from Mage_Payment_Model_Method_Abstract.

Definition at line 44 of file Asp.php.

$_code = 'amazonpayments_asp' [protected]

rewrited for Mage_Payment_Model_Method_Abstract

Reimplemented from Mage_Payment_Model_Method_Abstract.

Definition at line 58 of file Asp.php.

$_formBlockType = 'amazonpayments/asp_form' [protected]

rewrited for Mage_Payment_Model_Method_Abstract

Reimplemented from Mage_Payment_Model_Method_Abstract.

Definition at line 53 of file Asp.php.

$_isGateway = false [protected]

rewrited for Mage_Payment_Model_Method_Abstract

Reimplemented from Mage_Payment_Model_Method_Abstract.

Definition at line 39 of file Asp.php.

$_isInitializeNeeded = true [protected]

Reimplemented from Mage_Payment_Model_Method_Abstract.

Definition at line 48 of file Asp.php.

$_order [protected]

current order

Definition at line 63 of file Asp.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