Exemplo n.º 1
0
 private function setupOrder($orderData)
 {
     //Set up order mock
     foreach ($orderData['data_fields'] as $key => $value) {
         $this->order->setData($key, $value);
     }
 }
Exemplo n.º 2
0
 /**
  * @param array $orderData
  * @param array $invoiceData
  * @param array $expectedResults
  * @dataProvider collectDataProvider
  */
 public function testCollect($orderData, $invoiceData, $expectedResults)
 {
     $roundingDelta = [];
     //Set up order mock
     foreach ($orderData['data_fields'] as $key => $value) {
         $this->order->setData($key, $value);
     }
     /** @var \Magento\Sales\Model\Order\Invoice[] $previousInvoices */
     $previousInvoices = [];
     foreach ($orderData['previous_invoices'] as $previousInvoiceData) {
         $previousInvoice = $this->getMockBuilder('\\Magento\\Sales\\Model\\Order\\Invoice')->disableOriginalConstructor()->setMethods(['isCanceled', '__wakeup'])->getMock();
         $previousInvoice->setData('shipping_amount', $previousInvoiceData['shipping_amount']);
         $previousInvoices[] = $previousInvoice;
     }
     $this->order->expects($this->once())->method('getInvoiceCollection')->will($this->returnValue($previousInvoices));
     //Set up invoice mock
     /** @var \Magento\Sales\Model\Order\Invoice\Item[] $invoiceItems */
     $invoiceItems = [];
     foreach ($invoiceData['items'] as $itemKey => $invoiceItemData) {
         $invoiceItems[$itemKey] = $this->getInvoiceItem($invoiceItemData);
     }
     $this->invoice->expects($this->once())->method('getAllItems')->will($this->returnValue($invoiceItems));
     $this->invoice->expects($this->once())->method('isLast')->will($this->returnValue($invoiceData['is_last']));
     foreach ($invoiceData['data_fields'] as $key => $value) {
         $this->invoice->setData($key, $value);
     }
     $this->invoice->expects($this->any())->method('roundPrice')->will($this->returnCallback(function ($price, $type) use(&$roundingDelta) {
         if (!isset($roundingDelta[$type])) {
             $roundingDelta[$type] = 0;
         }
         $roundedPrice = round($price + $roundingDelta[$type], 2);
         $roundingDelta[$type] = $price - $roundedPrice;
         return $roundedPrice;
     }));
     $this->model->collect($this->invoice);
     //verify invoice data
     foreach ($expectedResults['invoice_data'] as $key => $value) {
         $this->assertEquals($value, $this->invoice->getData($key));
     }
     //verify invoice item data
     foreach ($expectedResults['invoice_items'] as $itemKey => $itemData) {
         $invoiceItem = $invoiceItems[$itemKey];
         foreach ($itemData as $key => $value) {
             $this->assertEquals($value, $invoiceItem->getData($key));
         }
     }
 }
Exemplo n.º 3
0
 /**
  * @desc order comments or history
  * @param type $order
  */
 protected function _addStatusHistoryComment()
 {
     $success_result = strcmp($this->_success, 'true') == 0 || strcmp($this->_success, '1') == 0 ? 'true' : 'false';
     $success = !empty($this->_reason) ? "{$success_result} <br />reason:{$this->_reason}" : $success_result;
     if ($this->_eventCode == Notification::REFUND || $this->_eventCode == Notification::CAPTURE) {
         $currency = $this->_order->getOrderCurrencyCode();
         // check if it is a full or partial refund
         $amount = $this->_value;
         $orderAmount = (int) $this->_adyenHelper->formatAmount($this->_order->getGrandTotal(), $currency);
         $this->_debugData['_addStatusHistoryComment amount'] = 'amount notification:' . $amount . ' amount order:' . $orderAmount;
         if ($amount == $orderAmount) {
             //                $this->_order->setAdyenEventCode($this->_eventCode . " : " . strtoupper($success_result));
             $this->_order->setData('adyen_notification_event_code', $this->_eventCode . " : " . strtoupper($success_result));
         } else {
             //                $this->_order->setAdyenEventCode("(PARTIAL) " . $this->_eventCode . " : " . strtoupper($success_result));
             $this->_order->setData('adyen_notification_event_code', "(PARTIAL) " . $this->_eventCode . " : " . strtoupper($success_result));
         }
     } else {
         //            $this->_order->setAdyenEventCode($this->_eventCode . " : " . strtoupper($success_result));
         $this->_order->setData('adyen_notification_event_code', $this->_eventCode . " : " . strtoupper($success_result));
     }
     // if payment method is klarna or openinvoice/afterpay show the reservartion number
     if (($this->_paymentMethod == "klarna" || $this->_paymentMethod == "afterpay_default" || $this->_paymentMethod == "openinvoice") && ($this->_klarnaReservationNumber != null && $this->_klarnaReservationNumber != "")) {
         $klarnaReservationNumberText = "<br /> reservationNumber: " . $this->_klarnaReservationNumber;
     } else {
         $klarnaReservationNumberText = "";
     }
     if ($this->_boletoPaidAmount != null && $this->_boletoPaidAmount != "") {
         $boletoPaidAmountText = "<br /> Paid amount: " . $this->_boletoPaidAmount;
     } else {
         $boletoPaidAmountText = "";
     }
     $type = 'Adyen HTTP Notification(s):';
     $comment = __('%1 <br /> eventCode: %2 <br /> pspReference: %3 <br /> paymentMethod: %4 <br /> success: %5 %6 %7', $type, $this->_eventCode, $this->_pspReference, $this->_paymentMethod, $success, $klarnaReservationNumberText, $boletoPaidAmountText);
     // If notification is pending status and pending status is set add the status change to the comment history
     if ($this->_eventCode == Notification::PENDING) {
         $pendingStatus = $this->_getConfigData('pending_status', 'adyen_abstract', $this->_order->getStoreId());
         if ($pendingStatus != "") {
             $this->_order->addStatusHistoryComment($comment, $pendingStatus);
             $this->_debugData['_addStatusHistoryComment'] = 'Created comment history for this notification with status change to: ' . $pendingStatus;
             return;
         }
     }
     // if manual review is accepted and a status is selected. Change the status through this comment history item
     if ($this->_eventCode == Notification::MANUAL_REVIEW_ACCEPT && $this->_getFraudManualReviewAcceptStatus() != "") {
         $manualReviewAcceptStatus = $this->_getFraudManualReviewAcceptStatus();
         $this->_order->addStatusHistoryComment($comment, $manualReviewAcceptStatus);
         $this->_debugData['_addStatusHistoryComment'] = 'Created comment history for this notification with status change to: ' . $manualReviewAcceptStatus;
         return;
     }
     $this->_order->addStatusHistoryComment($comment);
     $this->_debugData['_addStatusHistoryComment'] = 'Created comment history for this notification';
 }
Exemplo n.º 4
0
 /**
  * @param array $orderData
  * @param array $creditmemoData
  * @param array $expectedResults
  * @dataProvider collectDataProvider
  */
 public function testCollect($orderData, $creditmemoData, $expectedResults)
 {
     $roundingDelta = [];
     //Set up order mock
     foreach ($orderData['data_fields'] as $key => $value) {
         $this->order->setData($key, $value);
     }
     //Set up creditmemo mock
     /** @var \Magento\Sales\Model\Order\Creditmemo\Item[] $creditmemoItems */
     $creditmemoItems = [];
     foreach ($creditmemoData['items'] as $itemKey => $creditmemoItemData) {
         $creditmemoItems[$itemKey] = $this->getCreditmemoItem($creditmemoItemData);
     }
     $this->creditmemo->expects($this->once())->method('getAllItems')->will($this->returnValue($creditmemoItems));
     $this->creditmemo->expects($this->any())->method('isLast')->will($this->returnValue($creditmemoData['is_last']));
     foreach ($creditmemoData['data_fields'] as $key => $value) {
         $this->creditmemo->setData($key, $value);
     }
     $this->creditmemo->expects($this->any())->method('roundPrice')->will($this->returnCallback(function ($price, $type) use(&$roundingDelta) {
         if (!isset($roundingDelta[$type])) {
             $roundingDelta[$type] = 0;
         }
         $roundedPrice = round($price + $roundingDelta[$type], 2);
         $roundingDelta[$type] = $price - $roundedPrice;
         return $roundedPrice;
     }));
     $this->model->collect($this->creditmemo);
     //verify invoice data
     foreach ($expectedResults['creditmemo_data'] as $key => $value) {
         $this->assertEquals($value, $this->creditmemo->getData($key));
     }
     //verify invoice item data
     foreach ($expectedResults['creditmemo_items'] as $itemKey => $itemData) {
         $creditmemoItem = $creditmemoItems[$itemKey];
         foreach ($itemData as $key => $value) {
             $this->assertEquals($value, $creditmemoItem->getData($key));
         }
     }
 }
Exemplo n.º 5
0
 /**
  * Prepare payment for the order
  *
  * @param \Magento\Sales\Model\Order|\PHPUnit_Framework_MockObject_MockObject $order
  * @param array $mockedMethods
  * @return \Magento\Sales\Model\Order\Payment|\PHPUnit_Framework_MockObject_MockObject
  */
 protected function _prepareOrderPayment($order, $mockedMethods = [])
 {
     $payment = $this->getMockBuilder('Magento\\Sales\\Model\\Order\\Payment')->disableOriginalConstructor()->getMock();
     foreach ($mockedMethods as $method => $value) {
         $payment->expects($this->any())->method($method)->will($this->returnValue($value));
     }
     $payment->expects($this->any())->method('isDeleted')->will($this->returnValue(false));
     $order->setData(\Magento\Sales\Api\Data\OrderInterface::PAYMENTS, [$payment]);
     return $payment;
 }