Example #1
0
 /**
  * Receives webhook events from Roadrunner
  */
 public function execute()
 {
     $this->_logger->addDebug('paystandmagento/webhook/paystand endpoint was hit');
     $body = @file_get_contents('php://input');
     $json = json_decode($body);
     $this->_logger->addDebug(">>>>> body=" . print_r($body, TRUE));
     if (isset($json->resource->meta->source) && $json->resource->meta->source == "magento 2") {
         $quoteId = $json->resource->meta->quote;
         $this->_logger->addDebug('magento 2 webhook identified with quote id = ' . $quoteId);
         $this->_order->loadByAttribute('quote_id', $quoteId);
         if (!empty($this->_order->getIncrementId())) {
             $this->_logger->addDebug('current order increment id = ' . $this->_order->getIncrementId());
             $state = $this->_order->getState();
             $this->_logger->addDebug('current order state = ' . $state);
             $status = $this->_order->getStatus();
             $this->_logger->addDebug('current order status = ' . $status);
             $storeScope = \Magento\Store\Model\ScopeInterface::SCOPE_STORE;
             if ($this->scopeConfig->getValue(self::USE_SANDBOX, $storeScope)) {
                 $base_url = 'https://api.paystand.co/v3';
             } else {
                 $base_url = 'https://api.paystand.com/v3';
             }
             $url = $base_url . "/events/" . $json->id . "/verify";
             $auth_header = array("x-publishable-key: " . $this->scopeConfig->getValue(self::PUBLISHABLE_KEY, $storeScope));
             $curl = $this->buildCurl("POST", $url, json_encode($json), $auth_header);
             $response = $this->runCurl($curl);
             $this->_logger->addDebug("http_response_code is " . $this->http_response_code);
             if (FALSE !== $response && $this->http_response_code == 200) {
                 if ($json->resource->object = "payment") {
                     switch ($json->resource->status) {
                         case 'posted':
                             $state = 'pending';
                             $status = 'pending';
                             break;
                         case 'paid':
                             $state = 'processing';
                             $status = 'processing';
                             break;
                         case 'failed':
                             $state = 'closed';
                             $status = 'closed';
                             break;
                         case 'canceled':
                             $state = 'canceled';
                             $status = 'canceled';
                             break;
                     }
                 }
                 $this->_order->setState($state);
                 $this->_order->setStatus($status);
                 $this->_order->save();
                 $this->_logger->addDebug('new order state = ' . $state);
                 $this->_logger->addDebug('new order status = ' . $status);
             } else {
                 $this->_logger->addDebug('event verify failed');
             }
         }
     }
 }
Example #2
0
 /**
  * Perform order state and status assertions depending on currency code
  *
  * @param \Magento\Sales\Model\Order $order
  * @param string $currencyCode
  */
 protected function _assertOrder($order, $currencyCode)
 {
     if ($currencyCode == 'USD') {
         $this->assertEquals('complete', $order->getState());
         $this->assertEquals('complete', $order->getStatus());
     } else {
         $this->assertEquals('payment_review', $order->getState());
         $this->assertEquals('fraud', $order->getStatus());
     }
 }
 /**
  * {@inheritdoc}
  */
 public function canView(\Magento\Sales\Model\Order $order)
 {
     $customerId = $this->customerSession->getCustomerId();
     $availableStatuses = $this->orderConfig->getVisibleOnFrontStatuses();
     if ($order->getId() && $order->getCustomerId() && $order->getCustomerId() == $customerId && in_array($order->getStatus(), $availableStatuses, true)) {
         return true;
     }
     return false;
 }
Example #4
0
 /**
  * Set appropriate state to order or add status to order history
  *
  * @param Order $order
  * @param string $orderState
  * @param string $orderStatus
  * @param bool $isCustomerNotified
  * @return void
  */
 protected function updateOrder(Order $order, $orderState, $orderStatus, $isCustomerNotified)
 {
     // add message if order was put into review during authorization or capture
     $message = $order->getCustomerNote();
     $originalOrderState = $order->getState();
     $originalOrderStatus = $order->getStatus();
     switch (true) {
         case $message && $originalOrderState == Order::STATE_PAYMENT_REVIEW:
             $order->addStatusToHistory($originalOrderStatus, $message, $isCustomerNotified);
             break;
         case $message:
         case $originalOrderState && $message:
         case $originalOrderState != $orderState:
         case $originalOrderStatus != $orderStatus:
             $order->setState($orderState)->setStatus($orderStatus)->addStatusHistoryComment($message)->setIsCustomerNotified($isCustomerNotified);
             break;
         default:
             break;
     }
 }
Example #5
0
 /**
  * Is order visible
  *
  * @param Order $order
  * @return bool
  */
 protected function isVisible(Order $order)
 {
     return !in_array($order->getStatus(), $this->_orderConfig->getInvisibleOnFrontStatuses());
 }
Example #6
0
 /**
  * Loads the order info from a Magento order model.
  *
  * @param Order $order the order model.
  * @return \NostoOrder
  */
 public function build(Order $order)
 {
     $nostoOrder = new \NostoOrder();
     try {
         $nostoCurrency = new NostoCurrencyCode($order->getOrderCurrencyCode());
         $nostoOrder->setOrderNumber($order->getId());
         $nostoOrder->setExternalRef($order->getRealOrderId());
         $nostoOrder->setCreatedDate(new NostoDate(strtotime($order->getCreatedAt())));
         $nostoOrder->setPaymentProvider(new NostoOrderPaymentProvider($order->getPayment()->getMethod()));
         if ($order->getStatus()) {
             $nostoStatus = new NostoOrderStatus();
             $nostoStatus->setCode($order->getStatus());
             $nostoStatus->setLabel($order->getStatusLabel());
             $nostoOrder->setStatus($nostoStatus);
         }
         foreach ($order->getAllStatusHistory() as $item) {
             if ($item->getStatus()) {
                 $nostoStatus = new NostoOrderStatus();
                 $nostoStatus->setCode($item->getStatus());
                 $nostoStatus->setLabel($item->getStatusLabel());
                 $nostoStatus->setCreatedAt(new NostoDate(strtotime($item->getCreatedAt())));
                 $nostoOrder->addHistoryStatus($nostoStatus);
             }
         }
         // Set the buyer information
         $nostoBuyer = new NostoOrderBuyer();
         $nostoBuyer->setFirstName($order->getCustomerFirstname());
         $nostoBuyer->setLastName($order->getCustomerLastname());
         $nostoBuyer->setEmail($order->getCustomerEmail());
         $nostoOrder->setBuyer($nostoBuyer);
         // Add each ordered item as a line item
         /** @var Item $item */
         foreach ($order->getAllVisibleItems() as $item) {
             $nostoItem = new NostoOrderItem();
             $nostoItem->setItemId((int) $this->buildItemProductId($item));
             $nostoItem->setQuantity((int) $item->getQtyOrdered());
             $nostoItem->setName($this->buildItemName($item));
             try {
                 $nostoItem->setUnitPrice(new NostoPrice($this->_priceHelper->getItemFinalPriceInclTax($item)));
             } catch (\NostoInvalidArgumentException $E) {
                 $nostoItem->setUnitPrice(new NostoPrice(0));
             }
             $nostoItem->setCurrency($nostoCurrency);
             $nostoOrder->addItem($nostoItem);
         }
         // Add discounts as a pseudo line item
         if (($discount = $order->getDiscountAmount()) < 0) {
             $nostoItem = new NostoOrderItem();
             $nostoItem->setItemId(-1);
             $nostoItem->setQuantity(1);
             $nostoItem->setName($this->buildDiscountRuleDescription($order));
             $nostoItem->setUnitPrice(new NostoPrice($discount));
             $nostoItem->setCurrency($nostoCurrency);
             $nostoOrder->addItem($nostoItem);
         }
         // Add shipping and handling as a pseudo line item
         if (($shippingInclTax = $order->getShippingInclTax()) > 0) {
             $nostoItem = new NostoOrderItem();
             $nostoItem->setItemId(-1);
             $nostoItem->setQuantity(1);
             $nostoItem->setName('Shipping and handling');
             $nostoItem->setUnitPrice(new NostoPrice($shippingInclTax));
             $nostoItem->setCurrency($nostoCurrency);
             $nostoOrder->addItem($nostoItem);
         }
     } catch (Exception $e) {
         $this->_logger->error($e, ['exception' => $e]);
     }
     return $nostoOrder;
 }
Example #7
0
 /**
  * @param bool $manualReviewComment
  * @param bool $createInvoice
  * @throws Exception
  */
 protected function _setPaymentAuthorized($manualReviewComment = true, $createInvoice = false)
 {
     $this->_adyenLogger->addAdyenNotificationCronjob('Set order to authorised');
     // if full amount is captured create invoice
     $currency = $this->_order->getOrderCurrencyCode();
     $amount = $this->_value;
     $orderAmount = (int) $this->_adyenHelper->formatAmount($this->_order->getGrandTotal(), $currency);
     // create invoice for the capture notification if you are on manual capture
     if ($createInvoice == true && $amount == $orderAmount) {
         $this->_adyenLogger->addAdyenNotificationCronjob('amount notification:' . $amount . ' amount order:' . $orderAmount);
         $this->_createInvoice();
     }
     // if you have capture on shipment enabled don't set update the status of the payment
     $captureOnShipment = $this->_getConfigData('capture_on_shipment', 'adyen_abstract', $this->_order->getStoreId());
     if (!$captureOnShipment) {
         $status = $this->_getConfigData('payment_authorized', 'adyen_abstract', $this->_order->getStoreId());
     }
     // virtual order can have different status
     if ($this->_order->getIsVirtual()) {
         $this->_adyenLogger->addAdyenNotificationCronjob('Product is a virtual product');
         $virtualStatus = $this->_getConfigData('payment_authorized_virtual');
         if ($virtualStatus != "") {
             $status = $virtualStatus;
         }
     }
     // check for boleto if payment is totally paid
     if ($this->_paymentMethodCode() == "adyen_boleto") {
         // check if paid amount is the same as orginal amount
         $orginalAmount = $this->_boletoOriginalAmount;
         $paidAmount = $this->_boletoPaidAmount;
         if ($orginalAmount != $paidAmount) {
             // not the full amount is paid. Check if it is underpaid or overpaid
             // strip the  BRL of the string
             $orginalAmount = str_replace("BRL", "", $orginalAmount);
             $orginalAmount = floatval(trim($orginalAmount));
             $paidAmount = str_replace("BRL", "", $paidAmount);
             $paidAmount = floatval(trim($paidAmount));
             if ($paidAmount > $orginalAmount) {
                 $overpaidStatus = $this->_getConfigData('order_overpaid_status', 'adyen_boleto');
                 // check if there is selected a status if not fall back to the default
                 $status = !empty($overpaidStatus) ? $overpaidStatus : $status;
             } else {
                 $underpaidStatus = $this->_getConfigData('order_underpaid_status', 'adyen_boleto');
                 // check if there is selected a status if not fall back to the default
                 $status = !empty($underpaidStatus) ? $underpaidStatus : $status;
             }
         }
     }
     $comment = "Adyen Payment Successfully completed";
     // if manual review is true use the manual review status if this is set
     if ($manualReviewComment == true && $this->_fraudManualReview) {
         // check if different status is selected
         $fraudManualReviewStatus = $this->_getFraudManualReviewStatus();
         if ($fraudManualReviewStatus != "") {
             $status = $fraudManualReviewStatus;
             $comment = "Adyen Payment is in Manual Review check the Adyen platform";
         }
     }
     $status = !empty($status) ? $status : $this->_order->getStatus();
     $this->_order->addStatusHistoryComment(__($comment), $status);
     $this->_adyenLogger->addAdyenNotificationCronjob('Order status is changed to authorised status, status is ' . $status);
 }