public function startTransaction(Order $order, UrlInterface $url) { $config = new Config($this->_scopeConfig); $config->configureSDK(); $total = $order->getGrandTotal(); $items = $order->getAllVisibleItems(); $orderId = $order->getIncrementId(); $quoteId = $order->getQuoteId(); $currency = $order->getOrderCurrencyCode(); $returnUrl = $url->getUrl('paynl/checkout/finish/'); $exchangeUrl = $url->getUrl('paynl/checkout/exchange/'); $paymentOptionId = $this->getPaymentOptionId(); $arrBillingAddress = $order->getBillingAddress()->toArray(); $arrShippingAddress = $order->getShippingAddress()->toArray(); $enduser = array('initials' => substr($arrBillingAddress['firstname'], 0, 1), 'lastName' => $arrBillingAddress['lastname'], 'phoneNumber' => $arrBillingAddress['telephone'], 'emailAddress' => $arrBillingAddress['email']); $address = array(); $arrAddress = \Paynl\Helper::splitAddress($arrBillingAddress['street']); $address['streetName'] = $arrAddress[0]; $address['houseNumber'] = $arrAddress[1]; $address['zipCode'] = $arrBillingAddress['postcode']; $address['city'] = $arrBillingAddress['city']; $address['country'] = $arrBillingAddress['country_id']; $shippingAddress = array(); $arrAddress2 = \Paynl\Helper::splitAddress($arrShippingAddress['street']); $shippingAddress['streetName'] = $arrAddress2[0]; $shippingAddress['houseNumber'] = $arrAddress2[1]; $shippingAddress['zipCode'] = $arrShippingAddress['postcode']; $shippingAddress['city'] = $arrShippingAddress['city']; $shippingAddress['country'] = $arrShippingAddress['country_id']; $data = array('amount' => $total, 'returnUrl' => $returnUrl, 'paymentMethod' => $paymentOptionId, 'description' => $orderId, 'extra1' => $orderId, 'extra2' => $quoteId, 'exchangeUrl' => $exchangeUrl, 'currency' => $currency); $data['address'] = $address; $data['shippingAddress'] = $shippingAddress; $data['enduser'] = $enduser; $arrProducts = array(); foreach ($items as $item) { $arrItem = $item->toArray(); if ($arrItem['price_incl_tax'] != null) { $product = array('id' => $arrItem['product_id'], 'name' => $arrItem['name'], 'price' => $arrItem['price_incl_tax'], 'qty' => $arrItem['qty_ordered'], 'tax' => $arrItem['tax_amount']); } $arrProducts[] = $product; } //shipping $shippingCost = $order->getShippingAddress()->getShippingInclTax(); $shippingTax = $order->getShippingAddress()->getShippingTaxAmount(); $shippingDescription = $order->getShippingAddress()->getShippingDescription(); $arrProducts[] = array('id' => 'shipping', 'name' => $shippingDescription, 'price' => $shippingCost, 'qty' => 1, 'tax' => $shippingTax); // kortingen $discount = $order->getSubtotal() - $order->getSubtotalWithDiscount(); if ($discount > 0) { $arrProducts[] = array('id' => 'discount', 'name' => __('Discount'), 'price' => $discount * -1, 'qty' => 1, 'tax' => 0); } $data['products'] = $arrProducts; if ($config->isTestMode()) { $data['testmode'] = 1; } $data['ipaddress'] = $order->getRemoteIp(); $transaction = \Paynl\Transaction::start($data); return $transaction->getRedirectUrl(); }
/** * 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'); } } } }
/** * Get order instance based on last order ID * * @return \Magento\Sales\Model\Order */ public function getLastRealOrder() { $orderId = $this->getLastRealOrderId(); if ($this->_order !== null && $orderId == $this->_order->getIncrementId()) { return $this->_order; } $this->_order = $this->_orderFactory->create(); if ($orderId) { $this->_order->loadByIncrementId($orderId); } return $this->_order; }
/** * @param \Magento\Sales\Model\Order $order * @return array */ public function getBasicData(\Magento\Sales\Model\Order $order) { $incrementId = $order->getIncrementId(); $billingAddress = $order->getBillingAddress(); $data = ['amount' => $order->getGrandTotal() * 100, 'desc' => __('Order # %1', [$incrementId]), 'first_name' => $billingAddress->getFirstname(), 'last_name' => $billingAddress->getLastname(), 'email' => $order->getCustomerEmail(), 'session_id' => $this->extOrderIdHelper->generate($order), 'order_id' => $incrementId]; $paytype = $this->session->getPaytype(); if ($paytype) { $data['pay_type'] = $paytype; $this->session->setPaytype(null); } return $data; }
/** * Set entity data to request * * @param \Magento\Sales\Model\Order $order * @param \Magento\Authorizenet\Model\Directpost $paymentMethod * @return $this */ public function setDataFromOrder(\Magento\Sales\Model\Order $order, \Magento\Authorizenet\Model\Directpost $paymentMethod) { $payment = $order->getPayment(); $this->setXType($payment->getAnetTransType()); $this->setXFpSequence($order->getQuoteId()); $this->setXInvoiceNum($order->getIncrementId()); $this->setXAmount($payment->getBaseAmountAuthorized()); $this->setXCurrencyCode($order->getBaseCurrencyCode()); $this->setXTax(sprintf('%.2F', $order->getBaseTaxAmount()))->setXFreight(sprintf('%.2F', $order->getBaseShippingAmount())); //need to use strval() because NULL values IE6-8 decodes as "null" in JSON in JavaScript, //but we need "" for null values. $billing = $order->getBillingAddress(); if (!empty($billing)) { $this->setXFirstName(strval($billing->getFirstname()))->setXLastName(strval($billing->getLastname()))->setXCompany(strval($billing->getCompany()))->setXAddress(strval($billing->getStreetLine(1)))->setXCity(strval($billing->getCity()))->setXState(strval($billing->getRegion()))->setXZip(strval($billing->getPostcode()))->setXCountry(strval($billing->getCountry()))->setXPhone(strval($billing->getTelephone()))->setXFax(strval($billing->getFax()))->setXCustId(strval($billing->getCustomerId()))->setXCustomerIp(strval($order->getRemoteIp()))->setXCustomerTaxId(strval($billing->getTaxId()))->setXEmail(strval($order->getCustomerEmail()))->setXEmailCustomer(strval($paymentMethod->getConfigData('email_customer')))->setXMerchantEmail(strval($paymentMethod->getConfigData('merchant_email'))); } $shipping = $order->getShippingAddress(); if (!empty($shipping)) { $this->setXShipToFirstName(strval($shipping->getFirstname()))->setXShipToLastName(strval($shipping->getLastname()))->setXShipToCompany(strval($shipping->getCompany()))->setXShipToAddress(strval($shipping->getStreetLine(1)))->setXShipToCity(strval($shipping->getCity()))->setXShipToState(strval($shipping->getRegion()))->setXShipToZip(strval($shipping->getPostcode()))->setXShipToCountry(strval($shipping->getCountry())); } $this->setXPoNum(strval($payment->getPoNumber())); return $this; }
/** * Get order request data as array * * @param \Magento\Sales\Model\Order $order * @return array */ protected function _getOrderData(\Magento\Sales\Model\Order $order) { $request = ['invoice' => $order->getIncrementId(), 'address_override' => 'true', 'currency_code' => $order->getBaseCurrencyCode(), 'buyer_email' => $order->getCustomerEmail()]; // append to request billing address data if ($billingAddress = $order->getBillingAddress()) { $request = array_merge($request, $this->_getBillingAddress($billingAddress)); } // append to request shipping address data if ($shippingAddress = $order->getShippingAddress()) { $request = array_merge($request, $this->_getShippingAddress($shippingAddress)); } return $request; }
/** * @param \Magento\Sales\Model\Order $order * @return array */ public function getBasicData(\Magento\Sales\Model\Order $order) { $incrementId = $order->getIncrementId(); return ['currencyCode' => $order->getOrderCurrencyCode(), 'totalAmount' => $order->getGrandTotal() * 100, 'extOrderId' => $this->extOrderIdHelper->generate($order), 'description' => __('Order # %1', [$incrementId])]; }
/** * @param Order $order */ public function validateCoinGateCallback(Order $order) { try { if (!$order || !$order->getIncrementId()) { $request_order_id = filter_input(INPUT_POST, 'order_id') ? filter_input(INPUT_POST, 'order_id') : filter_input(INPUT_GET, 'order_id'); throw new \Exception('Order #' . $request_order_id . ' does not exists'); } $payment = $order->getPayment(); $get_token = filter_input(INPUT_GET, 'token'); $token1 = $get_token ? $get_token : ''; $token2 = $payment->getAdditionalInformation('coingate_order_token'); if ($token2 == '' || $token1 != $token2) { throw new \Exception('Tokens do match.'); } $request_id = filter_input(INPUT_POST, 'id') ? filter_input(INPUT_POST, 'id') : filter_input(INPUT_GET, 'id'); $this->coingate->getOrder($request_id); if (!$this->coingate->success) { throw new \Exception('CoinGate Order #' . $request_id . ' does not exist'); } if (!is_array($this->coingate->response)) { throw new \Exception('Something wrong with callback'); } if ($this->coingate->response['status'] == 'paid') { $order->setState(Order::STATE_PROCESSING, TRUE)->setStatus($order->getConfig()->getStateDefaultStatus(Order::STATE_PROCESSING))->save(); } elseif (in_array($this->coingate->response['status'], array('invalid', 'expired', 'canceled'))) { $order->setState(Order::STATE_CANCELED, TRUE)->setStatus($order->getConfig()->getStateDefaultStatus(Order::STATE_CANCELED))->save(); } } catch (\Exception $e) { exit('Error occurred: ' . $e); } }
/** * Add order details to payment request * @param DataObject $request * @param Order $order * @return void */ public function addRequestOrderInfo(DataObject $request, Order $order) { $id = $order->getId(); // for auth request order id is not exists yet if (!empty($id)) { $request->setPonum($id); } $orderIncrementId = $order->getIncrementId(); $request->setCustref($orderIncrementId)->setInvnum($orderIncrementId)->setComment1($orderIncrementId); }
/** * Returns order increment id * * @return string */ public function getOrderIncrementId() { return $this->order->getIncrementId(); }
/** * Get data for Header esction of RSS feed * * @return array */ protected function getHeader() { $title = __('Order # %1 Notification(s)', $this->order->getIncrementId()); $newUrl = $this->urlBuilder->getUrl('sales/order/view', ['order_id' => $this->order->getId()]); return ['title' => $title, 'description' => $title, 'link' => $newUrl, 'charset' => 'UTF-8']; }
/** * @param Order $order */ public function validateKhipuCallback(Order $order) { try { if (!$order || !$order->getIncrementId()) { throw new \Exception('Order #' . $_REQUEST['order_id'] . ' does not exists'); } $payment = $order->getPayment(); $notificationToken = isset($_POST['notification_token']) ? $_POST['notification_token'] : ''; if ($notificationToken == '') { throw new \Exception('Invalid notification token.'); } $configuration = new \Khipu\Configuration(); $configuration->setSecret($this->getConfigData('merchant_secret')); $configuration->setReceiverId($this->getConfigData('merchant_id')); $configuration->setPlatform('magento2-khipu', Payment::KHIPU_MAGENTO_VERSION); $client = new \Khipu\ApiClient($configuration); $payments = new \Khipu\Client\PaymentsApi($client); try { $paymentResponse = $payments->paymentsGet($notificationToken); } catch (\Khipu\ApiException $exception) { throw new \Exception(print_r($exception->getResponseObject(), TRUE)); } if ($paymentResponse->getReceiverId() != $this->getConfigData('merchant_id')) { throw new \Exception('Invalid receiver id'); } if ($paymentResponse->getTransactionId() != $payment->getAdditionalInformation('khipu_order_token')) { throw new \Exception('Invalid transaction id'); } if ($paymentResponse->getStatus() != 'done') { throw new \Exception('Payment not done'); } if ($paymentResponse->getAmount() != number_format($order->getGrandTotal(), $this->getDecimalPlaces($order->getOrderCurrencyCode()), '.', '')) { throw new \Exception('Amount mismatch'); } if ($paymentResponse->getCurrency() != $order->getOrderCurrencyCode()) { throw new \Exception('Currency mismatch'); } $order->setState(Order::STATE_PROCESSING, TRUE)->setStatus($order->getConfig()->getStateDefaultStatus(Order::STATE_PROCESSING))->save(); } catch (\Exception $e) { exit('Error occurred: ' . $e); } }
/** * Retrieve order status url key * * @param \Magento\Sales\Model\Order $order * @return string */ public function getStatusUrlKey($order) { $data = array('order_id' => $order->getId(), 'increment_id' => $order->getIncrementId(), 'customer_id' => $order->getCustomerId()); return base64_encode(json_encode($data)); }
/** * Retrieve order status url key * * @param \Magento\Sales\Model\Order $order * @return string */ protected function getUrlKey($order) { $data = ['order_id' => $order->getId(), 'increment_id' => $order->getIncrementId(), 'customer_id' => $order->getCustomerId()]; return base64_encode(json_encode($data)); }
/** * test method getIncrementId() */ public function testGetIncrementId() { $this->assertEquals($this->incrementId, $this->order->getIncrementId()); }
/** * Loading the case * @param Order $order * @return \Signifyd\Connect\Model\Casedata */ public function getCase(Order $order) { /** @var $case \Signifyd\Connect\Model\Casedata */ $case = $this->_objectManager->get('Signifyd\\Connect\\Model\\Casedata'); $case->load($order->getIncrementId()); return $case; }
/** * Retrieve order item value by key * * @param \Magento\Sales\Model\Order $order * @param string $key * @return string * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ public function getOrderItemValue(\Magento\Sales\Model\Order $order, $key) { $escape = true; switch ($key) { case 'order_increment_id': $value = $order->getIncrementId(); break; case 'created_at': $value = $this->formatDate($order->getCreatedAt(), \IntlDateFormatter::SHORT, true); break; case 'shipping_address': $value = $order->getShippingAddress() ? $this->escapeHtml($order->getShippingAddress()->getName()) : __('N/A'); break; case 'order_total': $value = $order->formatPrice($order->getGrandTotal()); $escape = false; break; case 'status_label': $value = $order->getStatusLabel(); break; case 'view_url': $value = $this->getUrl('sales/order/view', ['order_id' => $order->getId()]); break; default: $value = $order->getData($key) ? $order->getData($key) : __('N/A'); break; } return $escape ? $this->escapeHtml($value) : $value; }
/** * Get order request data as array * * @param \Magento\Sales\Model\Order $order * @return array */ protected function _getOrderData(\Magento\Sales\Model\Order $order) { $request = array('subtotal' => $this->_formatPrice($this->_formatPrice($order->getPayment()->getBaseAmountAuthorized()) - $this->_formatPrice($order->getBaseTaxAmount()) - $this->_formatPrice($order->getBaseShippingAmount())), 'tax' => $this->_formatPrice($order->getBaseTaxAmount()), 'shipping' => $this->_formatPrice($order->getBaseShippingAmount()), 'invoice' => $order->getIncrementId(), 'address_override' => 'true', 'currency_code' => $order->getBaseCurrencyCode(), 'buyer_email' => $order->getCustomerEmail()); // append to request billing address data if ($billingAddress = $order->getBillingAddress()) { $request = array_merge($request, $this->_getBillingAddress($billingAddress)); } // append to request shipping address data if ($shippingAddress = $order->getShippingAddress()) { $request = array_merge($request, $this->_getShippingAddress($shippingAddress)); } return $request; }
/** * @param \Magento\Sales\Model\Order $order * @return string */ public function generate(\Magento\Sales\Model\Order $order) { $try = $this->transactionResource->getLastTryByOrderId($order->getId()) + 1; return $order->getIncrementId() . ':' . $this->dateTime->timestamp() . ':' . $try; }