Magento Forum

   
Getting shopping cart details within callDoDirectPayment()—in Paypal Nvp.php file
 
mitc0185
Jr. Member
 
Total Posts:  21
Joined:  2008-06-22
 

I’m using the Paypal Direct payment method, and am trying to extend it to send the details of the customer’s shopping cart along with other payment information to paypal. I’ve figured out how to extend callDoDirectPayment() to send the data, but now I need to get the actual shopping cart information within this function.

How do I do that in Magento? Do I need to include the Cart.php file in order to use it? I’m not totally familiar with the Magento architecture so any help is appreciated!

Here’s the bit of code I’m looking at:

public function callDoDirectPayment()
    
{
        $p 
$this->getPayment();
        
$a $this->getBillingAddress();
        
$s $this->getShippingAddress();

        
$nvpArr = array(
            
'PAYMENTACTION'  => $this->getPaymentType(),
            
'AMT'            => $this->getAmount(),
            
'CURRENCYCODE'   => $this->getCurrencyCode(),
            
'BUTTONSOURCE'   => $this->getButtonSourceDp(),

            
'CREDITCARDTYPE' => $this->getCcTypeName($p->getCcType()),
            
'ACCT'           => $p->getCcNumber(),
            
'EXPDATE'        => sprintf('dd'$p->getCcExpMonth(), $p->getCcExpYear()),
            
'CVV2'           => $p->getCcCid(),

            
'FIRSTNAME'      => $a->getFirstname(),
            
'LASTNAME'       => $a->getLastname(),
            
'STREET'         => $a->getStreet(1),
            
'CITY'           => $a->getCity(),
            
'STATE'          => $a->getRegionCode(),
            
'ZIP'            => $a->getPostcode(),
            
'COUNTRYCODE'    => 'US'// only US supported for direct payment
            
'EMAIL'          => $this->getEmail(),

            
'SHIPTONAME'     => $s->getName(),
            
'SHIPTOSTREET'   => $s->getStreet(1),
            
'SHIPTOSTREET2'   => $s->getStreet(2),
            
'SHIPTOCITY'     => $s->getCity(),
            
'SHIPTOSTATE'    => ($s->getRegionCode() ? $s->getRegionCode() : $s->getRegion()),
            
'SHIPTOZIP'      => $s->getPostcode(),
            
'SHIPTOCOUNTRYCODE' => $s->getCountry(),
            
/* Added by EKM to test for Shopping Cart Payment */
            
'L_NAME0'       => 'Massage Bolster Pillow Half Round Black',
            
'L_NUMBER0'     => 'Pllw-h-B',
            
'L_QTY0'        => 1,
            
'L_TAXAMT0'     => 0,
            
'L_AMT0'        => 19.99,
            
/* End modification */
        
);

Where I’ve added addtional fields at the end I need to have a for loop that inserts the items from the customer’s shopping cart. Just need to get the data from Magento , but don’t know how!

 
Magento Community Magento Community
Magento Community
Magento Community
 
mitc0185
Jr. Member
 
Total Posts:  21
Joined:  2008-06-22
 

For anyone who’s interested, this change to Nvp.php is working for me…

public function callDoDirectPayment()
    
{
        $p 
$this->getPayment();
        
$a $this->getBillingAddress();
        
$s $this->getShippingAddress();
        
$c Mage::getSingleton('checkout/cart')->getCartInfo(); // Added by EKM

        
$nvpArr = array(
            
'PAYMENTACTION'  => $this->getPaymentType(),
            
'AMT'            => $this->getAmount(),
            
'CURRENCYCODE'   => $this->getCurrencyCode(),
            
'BUTTONSOURCE'   => $this->getButtonSourceDp(),

            
'CREDITCARDTYPE' => $this->getCcTypeName($p->getCcType()),
            
'ACCT'           => $p->getCcNumber(),
            
'EXPDATE'        => sprintf('dd'$p->getCcExpMonth(), $p->getCcExpYear()),
            
'CVV2'           => $p->getCcCid(),

            
'FIRSTNAME'      => $a->getFirstname(),
            
'LASTNAME'       => $a->getLastname(),
            
'STREET'         => $a->getStreet(1),
            
'CITY'           => $a->getCity(),
            
'STATE'          => $a->getRegionCode(),
            
'ZIP'            => $a->getPostcode(),
            
'COUNTRYCODE'    => 'US'// only US supported for direct payment
            
'EMAIL'          => $this->getEmail(),

            
'SHIPTONAME'     => $s->getName(),
            
'SHIPTOSTREET'   => $s->getStreet(1),
            
'SHIPTOSTREET2'   => $s->getStreet(2),
            
'SHIPTOCITY'     => $s->getCity(),
            
'SHIPTOSTATE'    => ($s->getRegionCode() ? $s->getRegionCode() : $s->getRegion()),
            
'SHIPTOZIP'      => $s->getPostcode(),
            
'SHIPTOCOUNTRYCODE' => $s->getCountry(),
        );
        
#echo "<pre>".print_r($nvpArr,1)."</pre>"; die;

        /* Added by EKM to include Shopping Cart Details */
        
$item_amt 0;
        for (
$i=0$i count($c->_data['items']); $i++) {
            $nvpArr[
'L_NAME' $i]      $c->_data['items'][$i]->_data['product_name'];
            
$nvpArr['L_NUMBER' $i]    $c->_data['items'][$i]->_data['thumbnail_object']->_data['sku'];
            
$nvpArr['L_QTY' $i]       number_format($c->_data['items'][$i]->_data['qty']0);
            
$nvpArr['L_AMT' $i]       number_format($c->_data['items'][$i]->_data['price']2"."'');
            
$item_amt                   $item_amt + ($c->_data['items'][$i]->_data['price'
                                                        
$c->_data['items'][$i]->_data['qty']); // build total
        
}
        $nvpArr[
'ITEMAMT'number_format($item_amt2".""");
        
$nvpArr['TAXAMT'number_format($nvpArr['AMT'$item_amt2".""");
        
/* End modification */

        
$resArr $this->call('DoDirectPayment'$nvpArr);

        if (
false===$resArr{
            
return false;
        
}

        $this
->setTransactionId($resArr['TRANSACTIONID']);
        
$this->setAmount($resArr['AMT']);
        
$this->setAvsCode($resArr['AVSCODE']);
        
$this->setCvv2Match($resArr['CVV2MATCH']);

        return 
$resArr;
    
}

 
Magento Community Magento Community
Magento Community
Magento Community
 
faridk
Jr. Member
 
Total Posts:  5
Joined:  2008-07-06
 

thx for the solution it worked for me!
now, were you able to come up with something similar for the express checkout as well?

 
Magento Community Magento Community
Magento Community
Magento Community
 
mitc0185
Jr. Member
 
Total Posts:  21
Joined:  2008-06-22
 

We’re not offering express checkout on our site so I haven’t done anything with that—would be interested in seeing if you’re able to come up with anything though.

 
Magento Community Magento Community
Magento Community
Magento Community
 
mitc0185
Jr. Member
 
Total Posts:  21
Joined:  2008-06-22
 

With the 1.1.2 upgrade the Mage::getSingleton(’checkout/cart’)->getCartInfo(); line no longer returned any data (I believe the function was removed by the Magento team.

Here’s my revision to callDoDirectPayment() which seems to work the same as what I had before:

public function callDoDirectPayment()
    
{
        $p 
$this->getPayment();
        
$a $this->getBillingAddress();
        
$s $this->getShippingAddress();


        
$nvpArr = array(
            
'PAYMENTACTION'  => $this->getPaymentType(),
            
'AMT'            => $this->getAmount(),
            
'CURRENCYCODE'   => $this->getCurrencyCode(),
            
'BUTTONSOURCE'   => $this->getButtonSourceDp(),

            
'CREDITCARDTYPE' => $this->getCcTypeName($p->getCcType()),
            
'ACCT'           => $p->getCcNumber(),
            
'EXPDATE'        => sprintf('&#x02;d&#x02;d'$p->getCcExpMonth(), $p->getCcExpYear()),
            
'CVV2'           => $p->getCcCid(),

            
'FIRSTNAME'      => $a->getFirstname(),
            
'LASTNAME'       => $a->getLastname(),
            
'STREET'         => $a->getStreet(1),
            
'CITY'           => $a->getCity(),
            
'STATE'          => $a->getRegionCode(),
            
'ZIP'            => $a->getPostcode(),
            
'COUNTRYCODE'    => 'US'// only US supported for direct payment
            
'EMAIL'          => $this->getEmail(),

            
'SHIPTONAME'     => $s->getName(),
            
'SHIPTOSTREET'   => $s->getStreet(1),
            
'SHIPTOSTREET2'   => $s->getStreet(2),
            
'SHIPTOCITY'     => $s->getCity(),
            
'SHIPTOSTATE'    => ($s->getRegionCode() ? $s->getRegionCode() : $s->getRegion()),
            
'SHIPTOZIP'      => $s->getPostcode(),
            
'SHIPTOCOUNTRYCODE' => $s->getCountry(),
        );

#echo "<pre>".print_r($nvpArr,1)."</pre>"; die;

        /* Added by EKM to include Shopping Cart Details */
        
$item_amt 0;
        
$i 0;
        foreach (
Mage::getSingleton('checkout/cart')->getItems() as $item{
            $nvpArr[
'L_NAME' $i]      $item->_data['name'];
            
$nvpArr['L_NUMBER' $i]    $item->_data['sku'];
            
$nvpArr['L_QTY' $i]       number_format($item->_data['qty']0);
            
$nvpArr['L_AMT' $i]       number_format($item->_data['price']2"."'');
            
$item_amt                   $item_amt + ($item->_data['price'
                                                        
$item->_data['qty']); // build total
            
$i++;
        
}
        $nvpArr[
'ITEMAMT'number_format($item_amt2".""");
        
$nvpArr['TAXAMT'number_format($nvpArr['AMT'$item_amt2".""");
        
/* End modification */

        
$resArr $this->call('DoDirectPayment'$nvpArr);

        if (
false===$resArr{
            
return false;
        
}

        $this
->setTransactionId($resArr['TRANSACTIONID']);
        
$this->setAmount($resArr['AMT']);
        
$this->setAvsCode($resArr['AVSCODE']);
        
$this->setCvv2Match($resArr['CVV2MATCH']);

        return 
$resArr;
    
}

 
Magento Community Magento Community
Magento Community
Magento Community
 
gpotts
Jr. Member
 
Total Posts:  1
Joined:  2009-08-11
 

This method works, except that with configurable products you get multiple items.

For instance, if a user bought ‘Item A’ in ‘blue’ you would see:

Item A - $20.00
Item A - Blue - $0.00

Has anyone worked out a way to consolidate these? I see that it does it in the PayPal Standard payment method, but even when I try to replicate this, I can’t seem to get it to work. I always end up with just ‘Item A’ and no option details. What I’d like to see is just:

Item A - Blue - $20.00

Thanks!

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
    Back to top