Beispiel #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();
 }
require_once dirname(__FILE__) . "/../../PaygateApiClient.class.php";
require_once dirname(__FILE__) . "/../config.php";
$client = new PaygateApiClient(INVIPAY_API_URL, INVIPAY_API_KEY, INVIPAY_SIGNATURE_KEY);
$repository = dirname(__FILE__) . "/repository/";
$payments = scandir($repository);
Logger::info('Scanning payments repository');
foreach ($payments as $paymentFile) {
    if ($paymentFile != '.' && $paymentFile != '..') {
        Logger::info('Found payment data {0}', $paymentFile);
        $paymentData = unserialize(file_get_contents($repository . $paymentFile));
        $paymentId = $paymentData->getPaymentId();
        Logger::info('Payment {0} has status {1}', $paymentId, $paymentData->getStatus());
        if ($paymentData->getStatus() == PaymentRequestStatus::COMPLETED) {
            Logger::info('Finalizing payment {0}', $paymentId);
            $request = new PaymentManagementData();
            $request->setPaymentId($paymentId);
            $request->setDoConfirmDelivery(true);
            $conversionData = new OrderToInvoiceData();
            $conversionData->setInvoiceDocumentNumber("TestInvoice/1/2/3/" . uniqid());
            $conversionData->setIssueDate(date('Y-m-d', time()));
            $conversionData->setDueDate(date('Y-m-d', time() + 14 * 24 * 60 * 60));
            $request->setConversionData($conversionData);
            $document = new FileData();
            $document->setFromFile(dirname(__FILE__) . '/../test.pdf');
            $request->setDocument($document);
            $result = $client->managePayment($request);
            Logger::info('Result is: {0}', $result);
        }
    }
}
Beispiel #3
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();
         }
     }
 }