title: Magento Refund programmatically
body: <p>Hy,</p>
  
  <p>i'm trying to create a refund programmatically : </p>
  
  <pre><code>//get order magento
  
  $orderMagento = Mage::getModel('sales/order')-&gt;loadByIncrementId($realOrderIncrementId );
  if($orderMagento-&gt;getStatus() == Mage_Sales_Model_Order::STATE_CANCELED){
  //création de l'avoir
  $convertOrder = new Mage_Sales_Model_Convert_Order ();
  $creditMemo = $convertOrder-&gt;toCreditmemo ( $orderMagento );
  
  $items = $orderMagento-&gt;getAllItems ();
  $totalQty = 0;
  
  foreach ( $items as $item ) {
    $_eachCreditMemoItem = $convertOrder-&gt;itemToCreditmemoItem ( $item );
    $_eachCreditMemoItem-&gt;setQty ($item-&gt;getQtyInvoiced());
    $_eachCreditMemoItem-&gt;register ();
    $creditMemo-&gt;addItem ( $_eachCreditMemoItem );
    $totalQty += $item-&gt;getQtyInvoiced ();
  } 
  
  $creditMemo-&gt;refund();
  $creditMemo-&gt;setTotalQty ( $totalQty );
  $orderCreditMemoStatusCode = Mage_Sales_Model_Order::STATE_CLOSED;
  $orderCreditMemoStatusComment = '[OK]Remboursement des article : ';
  $saveTransaction = Mage::getModel('core/resource_transaction')-&gt;addObject ($creditMemo )-&gt;addObject ( $orderMagento )-&gt;save ();
  $orderMagento-&gt;addStatusToHistory ( $orderCreditMemoStatusCode, $orderCreditMemoStatusComment, false );
  $orderMagento-&gt;save ();
  }
  </code></pre>
  
  <p>This code create a credit memo but all amount are null (BaseGrandTotal = 0.00€, etc...)</p>
  
  <p>So where is the problem ?</p>
  
  <p>Thanks you</p>