Exemplo n.º 1
0
 /**
  * Post new invoice to Capayable
  *
  * @param $invoice
  * @return mixed
  */
 public function processApiInvoice($invoice)
 {
     $order_id = $invoice->getOrder()->getIncrementId();
     //$sender_email = Mage::getStoreConfig(Mage_Sales_Model_Order_Invoice::XML_PATH_EMAIL_IDENTITY);
     $sender_email = Mage::getStoreConfig('trans_email/ident_sales/email');
     // Initialize new api invoice
     $apiInvoice = new Tritac_CapayableApiClient_Models_Invoice();
     // Set required information
     $apiInvoice->setTransactionNumber($invoice->getTransactionId());
     $apiInvoice->setInvoiceNumber($invoice->getIncrementId());
     $apiInvoice->setInvoiceAmount($this->getHelper()->convertToCents($invoice->getGrandTotal()));
     $apiInvoice->setInvoiceDescription(Mage::helper('capayable')->__('Order') . ' ' . $order_id);
     // Don't change this line, it's used for filtering in de Capayable invoice mailbox
     // It's required to print the Order ID in the email subject when sending your invoice
     // Please strip the invoice ID when used to be sure no mixed up will occur between invoice and order IDs
     $apiInvoice->setInvoiceByEmail($sender_email, "{$order_id}");
     // Register new invoice with Capayable
     // Fetch Store ID and key pair for selected store (admin store is always 0)
     // Create new admin client, with correct key pair to process invoice
     $store_id = $invoice->getOrder()->getStore()->getId();
     $public_key = Mage::getStoreConfig('capayable/capayable/public_key', $store_id);
     $secret_key = Mage::getStoreConfig('capayable/capayable/secret_key', $store_id);
     $adminClient = new Tritac_CapayableApiClient_Client($public_key, $secret_key, $this->_helper->getMode());
     $isAccepted = $adminClient->registerInvoice($apiInvoice);
     return $isAccepted;
 }