/** * * Trigger the order billing process * @param int $orderId * @param array $params * @return bool true|false success yes|no */ public function billOrder($orderId, $params) { if (!array_key_exists('receipt_type', $params['data'])) { $receiptType = Billing_Model_Receipt::TYPE_INVOICE; } else { $receiptType = $params['data']['receipt_type']; } $receipt = Billing_Model_Receipt::create($receiptType); // set base data of receipt if (array_key_exists('data', $params)) { $receipt->setFromArray($params['data']); } // if there is additional data given, in order to be injected into template if (array_key_exists('additionalTemplateData', $params)) { $receipt->setAdditionalData($params['additionalTemplateData']); } // set invoice date switch ($receiptType) { case Billing_Model_Receipt::TYPE_INVOICE: if (array_key_exists('invoice_date', $params['data'])) { // set given daten for invoice date $receipt->__set('invoice_date', new Zend_Date($params['data']['invoice_date'])); } else { // set current date for invoice date $receipt->__set('invoice_date', new Zend_Date()); } break; case Billing_Model_Receipt::TYPE_CREDIT: if (array_key_exists('credit_date', $params['data'])) { // set given daten for invoice date $receipt->__set('credit_date', new Zend_Date($params['data']['invoice_date'])); } else { // set current date for invoice date $receipt->__set('credit_date', new Zend_Date()); } break; } // set due date // 1) grab due_in_days from payment method // 2) add to invoice_date // shitty name chosen for paymentmethod of receipt -> payment_type // hack around it if (array_key_exists('payment_method_id', $params['data'])) { $receipt->__set('payment_method_id', $params['data']['payment_method_id']); } $dueDate = new Zend_Date(); $paymentMethod = $receipt->getForeignRecordBreakNull('payment_method_id', Billing_Controller_PaymentMethod::getInstance()); if ($paymentMethod instanceof Billing_Model_PaymentMethod) { $dueInDays = $paymentMethod->__get('due_in_days'); if ($dueInDays > 0) { $dueDate->add($dueInDays, Zend_Date::DAY); } } $receipt->__set('due_date', $dueDate); // finally attach receipt to order return $this->attachReceipt($receipt, $orderId, $params); }