Exemple #1
0
 public static function generateInvoice($items, $userSID, $subTotalPrice, $successPageUrl, $isRecurring = false)
 {
     $taxInfo = SJB_TaxesManager::getTaxInfoByUserSidAndPrice($userSID, $subTotalPrice);
     $totalPrice = SJB_InvoiceManager::getTotalPrice($subTotalPrice, $taxInfo['tax_amount'], $taxInfo['price_includes_tax']);
     $invoiceSID = null;
     if ($totalPrice > 0) {
         $invoiceSID = SJB_InvoiceManager::getExistingInvoiceSID($userSID, $items, $taxInfo, SJB_Invoice::INVOICE_STATUS_UNPAID, $isRecurring);
     }
     if (!$invoiceSID) {
         $invoiceInfo = array('user_sid' => $userSID, 'include_tax' => !empty($taxInfo['sid']) ? 1 : 0, 'total' => $totalPrice, 'sub_total' => $subTotalPrice, 'success_page_url' => $successPageUrl, 'status' => $totalPrice == 0 ? SJB_Invoice::INVOICE_STATUS_VERIFIED : SJB_Invoice::INVOICE_STATUS_UNPAID, 'tax_info' => $taxInfo, 'items' => $items, 'is_recurring' => $isRecurring);
         $invoice = new SJB_Invoice($invoiceInfo);
         SJB_InvoiceManager::saveInvoice($invoice);
         $invoiceSID = $invoice->getSID();
     }
     return $invoiceSID;
 }