title: How can I retrieve shopping cart contents, shipping details and ancillary fees (tax, discounts, etc) for my custom payment method?
body: <p>I'm tasked to write a custom payment method for Magento CE, and tinkered with it for the last couple of weeks. Although I'm an experienced developer, this was my first serious brush with php and Magento itself.</p>
  
  <p>Please note this a web payment gateway, so I'm using</p>
  
  <pre><code>public function getOrderPlaceRedirectUrl() { ... }
  </code></pre>
  
  <p>In my Payment Method Model to redirect the customer to the external url successfully. </p>
  
  <p>The issue that kept me stuck for a full day is how to retrieve checkout shopping cart contents, shipping details and ancillary fees (tax, discounts, etc). This info needs to be sent to the payment method API.</p>
  
  <p>The code I've been using in my Payment Method Model is something like this:</p>
  
  <pre><code>$order_id = Mage::getSingleton("checkout/session")-&gt;getLastRealOrderId();
  $order = Mage::getModel('sales/order')-&gt;loadByIncrementId($order_id);
  $oBillingAddress = $order-&gt;getBillingAddress(); //this works ok
  $total = number_format($order-&gt;getBaseGrandTotal(), 2, '', ''); //this too
  
  /* The following code won't work */
  
  $oShippingAddress = $order-&gt;getShippingAddress(); // is unset!?
  $oShippingAddress-&gt;getSameAsBilling(); //HOW can I check this?
  
  $amount = array();
  $quantity = array();
  $sku = array();
  $description = array();
  
  $cart_items = $order()-&gt;getAllVisibleItems();
  foreach ($cart_items as $item) {
     $amount[] = number_format($item-&gt;getPrice(), 2, '', ''); //ok
     $quantity[] = $item-&gt;getQtyToInvoice(); // is empty...
     $sku[] = $item-&gt;getSku(); // nothing either??
     $description[] = $item-&gt;getName(); //this is working
  }
  </code></pre>
  
  <p>Please, wizards of Magento, tell what am I doing wrong here?</p>
  
  <p>Magento dev has been very frustrating, mainly for its lack of straightforward documentation. I'm sure it's very customizable and what not, but the abuse of php's magic functions and it's cumbersome structure has been challenging - at the least.</p>