Mage_Paypal_Model_Direct Class Reference

Inheritance diagram for Mage_Paypal_Model_Direct:

Mage_Payment_Model_Method_Cc Mage_Payment_Model_Method_Abstract Varien_Object

List of all members.

Public Member Functions

 canUseForCurrency ($currencyCode)
 getApi ()
 getSession ()
 getCheckout ()
 getQuote ()
 getRedirectUrl ()
 getCountryRegionId ()
 getPaymentAction ()
 authorize (Varien_Object $payment, $amount)
 capture (Varien_Object $payment, $amount)
 onOrderValidate (Mage_Sales_Model_Order_Payment $payment)
 void (Varien_Object $payment)
 refund (Varien_Object $payment, $amount)

Protected Attributes

 $_code = 'paypal_direct'
 $_isGateway = true
 $_canAuthorize = true
 $_canCapture = true
 $_canCapturePartial = false
 $_canRefund = false
 $_canVoid = true
 $_canUseInternal = true
 $_canUseCheckout = true
 $_canUseForMultishipping = true
 $_canSaveCc = false
 $_allowCurrencyCode = array('AUD', 'CAD', 'CZK', 'DKK', 'EUR', 'HKD', 'HUF', 'ILS', 'JPY', 'MXN', 'NOK', 'NZD', 'PLN', 'GBP', 'SGD', 'SEK', 'CHF', 'USD')


Detailed Description

PayPal Direct Module

Author:
Magento Core Team <core@magentocommerce.com>

Definition at line 33 of file Direct.php.


Member Function Documentation

authorize ( Varien_Object payment,
amount 
)

Authorize

Parameters:
Varien_Object $orderPayment
Returns:
Mage_Payment_Model_Abstract

Reimplemented from Mage_Payment_Model_Method_Abstract.

Definition at line 127 of file Direct.php.

00128     {
00129         $api = $this->getApi()
00130             ->setPaymentType($this->getPaymentAction())
00131             ->setAmount($amount)
00132             ->setBillingAddress($payment->getOrder()->getBillingAddress())
00133             ->setShippingAddress($payment->getOrder()->getShippingAddress())
00134             ->setEmail($payment->getOrder()->getCustomerEmail())
00135             ->setPayment($payment)
00136             ->setInvNum($payment->getOrder()->getIncrementId());
00137 
00138         if ($api->callDoDirectPayment()!==false) {
00139             $payment
00140                 ->setStatus('APPROVED')
00141                 ->setCcTransId($api->getTransactionId())
00142                 ->setCcAvsStatus($api->getAvsCode())
00143                 ->setCcCidStatus($api->getCvv2Match());
00144 
00145             #$payment->getOrder()->addStatusToHistory(Mage::getStoreConfig('payment/paypal_direct/order_status'));
00146         } else {
00147             $e = $api->getError();
00148             if (isset($e['short_message'])) {
00149                 $message = $e['short_message'];
00150             } else {
00151                 $message = Mage::helper('paypal')->__('There has been an error processing your payment. Please try later or contact us for help.');
00152             }
00153             if (isset($e['long_message'])) {
00154                 $message .= ': '.$e['long_message'];
00155             }
00156             Mage::throwException($message);
00157         }
00158         return $this;
00159     }

canUseForCurrency ( currencyCode  ) 

Check method for processing with base currency

Parameters:
string $currencyCode
Returns:
boolean

Reimplemented from Mage_Payment_Model_Method_Abstract.

Definition at line 59 of file Direct.php.

00060     {
00061         if (!in_array($currencyCode, $this->_allowCurrencyCode)) {
00062             return false;
00063         }
00064         return true;
00065     }

capture ( Varien_Object payment,
amount 
)

Capture payment

Parameters:
Varien_Object $orderPayment
Returns:
Mage_Payment_Model_Abstract

Reimplemented from Mage_Payment_Model_Method_Abstract.

Definition at line 161 of file Direct.php.

00162     {
00163         $api = $this->getApi()
00164             ->setPaymentType(Mage_Paypal_Model_Api_Nvp::PAYMENT_TYPE_SALE)
00165             ->setAmount($amount)
00166             ->setBillingAddress($payment->getOrder()->getBillingAddress())
00167             ->setShippingAddress($payment->getOrder()->getShippingAddress())
00168             ->setEmail($payment->getOrder()->getCustomerEmail())
00169             ->setPayment($payment)
00170             ->setInvNum($payment->getOrder()->getIncrementId());
00171         ;
00172         if ($payment->getCcTransId()) {
00173             $api->setAuthorizationId($payment->getCcTransId())
00174                 ->setCompleteType('NotComplete');
00175             $result = $api->callDoCapture()!==false;
00176         } else {
00177             $result = $api->callDoDirectPayment()!==false;
00178         }
00179         if ($result) {
00180             $payment
00181                 ->setStatus('APPROVED')
00182                 //->setCcTransId($api->getTransactionId())
00183                 ->setLastTransId($api->getTransactionId())
00184                 ->setCcAvsStatus($api->getAvsCode())
00185                 ->setCcCidStatus($api->getCvv2Match());
00186 
00187             #$payment->getOrder()->addStatusToHistory(Mage::getStoreConfig('payment/paypal_direct/order_status'));
00188         } else {
00189             $e = $api->getError();
00190             if (isset($e['short_message'])) {
00191                 $message = $e['short_message'];
00192             } else {
00193                 $message = Mage::helper('paypal')->__('There has been an error processing your payment. Please try later or contact us for help.');
00194             }
00195             if (isset($e['long_message'])) {
00196                 $message .= ': '.$e['long_message'];
00197             }
00198             Mage::throwException($message);
00199         }
00200         return $this;
00201     }

getApi (  ) 

Get Paypal API Model

Returns:
Mage_Paypal_Model_Api_Nvp

Definition at line 72 of file Direct.php.

00073     {
00074         return Mage::getSingleton('paypal/api_nvp');
00075     }

getCheckout (  ) 

Get checkout session namespace

Returns:
Mage_Checkout_Model_Session

Definition at line 92 of file Direct.php.

00093     {
00094         return Mage::getSingleton('checkout/session');
00095     }

getCountryRegionId (  ) 

Definition at line 112 of file Direct.php.

00113     {
00114         $a = $this->getApi()->getShippingAddress();
00115         return $this;
00116     }

getPaymentAction (  ) 

Definition at line 118 of file Direct.php.

00119     {
00120         $paymentAction = $this->getConfigData('payment_action');
00121         if (!$paymentAction) {
00122             $paymentAction = Mage_Paypal_Model_Api_Nvp::PAYMENT_TYPE_AUTH;
00123         }
00124         return $paymentAction;
00125     }

getQuote (  ) 

Get current quote

Returns:
Mage_Sales_Model_Quote

Definition at line 102 of file Direct.php.

00103     {
00104         return $this->getCheckout()->getQuote();
00105     }

getRedirectUrl (  ) 

Definition at line 107 of file Direct.php.

00108     {
00109         return $this->getApi()->getRedirectUrl();
00110     }

getSession (  ) 

Get paypal session namespace

Returns:
Mage_Paypal_Model_Session

Definition at line 82 of file Direct.php.

00083     {
00084         return Mage::getSingleton('paypal/session');
00085     }

onOrderValidate ( Mage_Sales_Model_Order_Payment payment  ) 

Definition at line 203 of file Direct.php.

00204     {
00205         $api = $this->getApi()
00206             ->setPaymentType($this->getPaymentAction())
00207             ->setAmount($payment->getOrder()->getGrandTotal())
00208             ->setBillingAddress($payment->getOrder()->getBillingAddress())
00209             ->setPayment($payment)
00210             ->setInvNum($payment->getOrder()->getIncrementId());
00211 
00212         if ($api->callDoDirectPayment()!==false) {
00213             $payment
00214                 ->setStatus('APPROVED')
00215                 ->setCcTransId($api->getTransactionId())
00216                 ->setCcAvsStatus($api->getAvsCode())
00217                 ->setCcCidStatus($api->getCvv2Match());
00218 
00219             #$payment->getOrder()->addStatusToHistory(Mage::getStoreConfig('payment/paypal_direct/order_status'));
00220         } else {
00221             $e = $api->getError();
00222             if (isset($e['short_message'])) {
00223                 $message = $e['short_message'];
00224             } else {
00225                 $message = Mage::helper('paypal')->__('There has been an error processing your payment. Please try later or contact us for help.');
00226             }
00227             if (isset($e['long_message'])) {
00228                 $message .= ': '.$e['long_message'];
00229             }
00230             $payment
00231                 ->setStatus('ERROR')
00232                 ->setStatusDescription($message);
00233         }
00234         return $this;
00235     }

refund ( Varien_Object payment,
amount 
)

refund the amount with transaction id

public

Parameters:
string $payment Varien_Object object
Returns:
Mage_Payment_Model_Abstract

Reimplemented from Mage_Payment_Model_Method_Abstract.

Definition at line 275 of file Direct.php.

00276       {
00277           $error = false;
00278           if($payment->getRefundTransactionId() && $amount>0){
00279               $api = $this->getApi();
00280               $api->setPayment($payment);
00281               //we can refund the amount full or partial so it is good to set up as partial refund
00282               $api->setTransactionId($payment->getRefundTransactionId())
00283                 ->setRefundType(Mage_Paypal_Model_Api_Nvp::REFUND_TYPE_PARTIAL)
00284                 ->setAmount($amount);
00285 
00286              if ($api->callRefundTransaction()!==false){
00287                  $payment->setStatus('SUCCESS')
00288                     ->setCcTransId($api->getTransactionId());
00289              }else{
00290                $e = $api->getError();
00291                $error = $e['short_message'].': '.$e['long_message'];
00292              }
00293         }else{
00294             $error = Mage::helper('paypal')->__('Error in refunding the payment');
00295         }
00296         if ($error !== false) {
00297             Mage::throwException($error);
00298         }
00299         return $this;
00300       }

void ( Varien_Object payment  ) 

void

public

Parameters:
string $payment Varien_Object object
Returns:
Mage_Payment_Model_Abstract

Reimplemented from Mage_Payment_Model_Method_Abstract.

Definition at line 244 of file Direct.php.

00245     {
00246         $error = false;
00247         if($payment->getVoidTransactionId()){
00248             $api = $this->getApi();
00249             $api->setPayment($payment);
00250             $api->setAuthorizationId($payment->getVoidTransactionId());
00251             if ($api->callDoVoid()!==false){
00252                  $payment->setStatus('SUCCESS')
00253                     ->setCcTransId($api->getTransactionId());
00254             }else{
00255                $e = $api->getError();
00256                $error = $e['short_message'].': '.$e['long_message'];
00257             }
00258         }else{
00259             $payment->setStatus('ERROR');
00260             $error = Mage::helper('paypal')->__('Invalid transaction id');
00261         }
00262         if ($error !== false) {
00263             Mage::throwException($error);
00264         }
00265         return $this;
00266     }


Member Data Documentation

$_allowCurrencyCode = array('AUD', 'CAD', 'CZK', 'DKK', 'EUR', 'HKD', 'HUF', 'ILS', 'JPY', 'MXN', 'NOK', 'NZD', 'PLN', 'GBP', 'SGD', 'SEK', 'CHF', 'USD') [protected]

Definition at line 51 of file Direct.php.

$_canAuthorize = true [protected]

Reimplemented from Mage_Payment_Model_Method_Abstract.

Definition at line 41 of file Direct.php.

$_canCapture = true [protected]

Reimplemented from Mage_Payment_Model_Method_Abstract.

Definition at line 42 of file Direct.php.

$_canCapturePartial = false [protected]

Reimplemented from Mage_Payment_Model_Method_Abstract.

Definition at line 43 of file Direct.php.

$_canRefund = false [protected]

Reimplemented from Mage_Payment_Model_Method_Abstract.

Definition at line 44 of file Direct.php.

$_canSaveCc = false [protected]

Reimplemented from Mage_Payment_Model_Method_Cc.

Definition at line 49 of file Direct.php.

$_canUseCheckout = true [protected]

Reimplemented from Mage_Payment_Model_Method_Abstract.

Definition at line 47 of file Direct.php.

$_canUseForMultishipping = true [protected]

Reimplemented from Mage_Payment_Model_Method_Abstract.

Definition at line 48 of file Direct.php.

$_canUseInternal = true [protected]

Reimplemented from Mage_Payment_Model_Method_Abstract.

Definition at line 46 of file Direct.php.

$_canVoid = true [protected]

Reimplemented from Mage_Payment_Model_Method_Abstract.

Definition at line 45 of file Direct.php.

$_code = 'paypal_direct' [protected]

Reimplemented from Mage_Payment_Model_Method_Abstract.

Definition at line 35 of file Direct.php.

$_isGateway = true [protected]

Availability options

Reimplemented from Mage_Payment_Model_Method_Abstract.

Definition at line 40 of file Direct.php.


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

Generated on Sat Jul 4 17:24:33 2009 for Magento by  doxygen 1.5.8