Пример #1
0
 public function confirmDeliveryAndSendInvoice($order)
 {
     $invoices = array();
     $invoiceNumbers = array();
     if ($order->hasInvoices()) {
         foreach ($order->getInvoiceCollection() as $invoiceItem) {
             $invoices[] = $invoiceItem;
             $invoiceNumbers[] = $invoiceItem->getIncrementId();
         }
     }
     $pdf = Mage::getModel('sales/order_pdf_invoice')->getPdf($invoices);
     $pdfData = $pdf->render();
     $documentNumber = join(', ', $invoiceNumbers);
     $issueDate = strtotime($order->getCreatedAt());
     $dueDateDays = intval(Mage::getStoreConfig('payment/ipcpaygate/invipay_base_duedate'));
     $dueDate = $issueDate + $dueDateDays * 60 * 60 * 24;
     $client = $this->getApiClient();
     $request = new PaymentManagementData();
     $request->setPaymentId($order->getInvipayPaymentId());
     $request->setDoConfirmDelivery(true);
     $conversionData = new OrderToInvoiceData();
     $conversionData->setInvoiceDocumentNumber($documentNumber);
     $conversionData->setIssueDate(date('Y-m-d', $issueDate));
     $conversionData->setDueDate(date('Y-m-d', $dueDate));
     $request->setConversionData($conversionData);
     $document = new FileData();
     $document->setName('Zamowienie_nr_' . $order->getEntityId() . '.pdf');
     $document->setMimeType('application/pdf');
     $document->setContentFromBin($pdfData);
     $request->setDocument($document);
     $result = $client->managePayment($request);
     $order->setInvipayDeliveryConfirmed(true);
     $order->setInvipayCompleted(true);
     $order->save();
 }
Пример #2
0
 public function managePaymentRequestIfApplicable($order)
 {
     $context = Context::getContext();
     if ($order->hasInvoice() && count($order->getHistory($context->language->id, Configuration::get('PS_OS_DELIVERED'), true, 0)) > 0) {
         $paymentRequest = new InvipayPaymentRequest(InvipayPaymentRequest::getIdByOrderId($order->id));
         if (!$paymentRequest->completed) {
             $order_invoice_list = $order->getInvoicesCollection();
             $pdf = new PDF($order_invoice_list, PDF::TEMPLATE_INVOICE, $context->smarty);
             $pdfData = $pdf->render(false);
             $invoiceNumbers = array();
             $issueDate = $order->date_add;
             foreach ($order_invoice_list as $invoice) {
                 $invoiceNumbers[] = $invoice->getInvoiceNumberFormatted($context->language->id, $context->shop !== null ? $context->shop->id : null);
                 $issueDate = $invoice->date_add;
             }
             $documentNumber = join(', ', $invoiceNumbers);
             $issueDate = strtotime($issueDate);
             $config = $this->loadConfiguration();
             $dueDateDays = (int) $config['BASE_DUE_DATE'];
             $dueDate = $issueDate + $dueDateDays * 60 * 60 * 24;
             $client = $this->getApiClient();
             $request = new PaymentManagementData();
             $request->setPaymentId($paymentRequest->payment_id);
             $request->setDoConfirmDelivery(true);
             $conversionData = new OrderToInvoiceData();
             $conversionData->setInvoiceDocumentNumber($documentNumber);
             $conversionData->setIssueDate(date('Y-m-d', $issueDate));
             $conversionData->setDueDate(date('Y-m-d', $dueDate));
             $request->setConversionData($conversionData);
             $document = new FileData();
             $document->setName($order->reference . '.pdf');
             $document->setMimeType('application/pdf');
             $document->setContentFromBin($pdfData);
             $request->setDocument($document);
             $client->managePayment($request);
             $paymentRequest->delivery_confirmed = true;
             $paymentRequest->completed = true;
             $paymentRequest->save();
         }
     }
 }