/** * 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 = 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; }
/** * 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; }
/** * Returns currency code * * @return string */ public function getCurrencyCode() { return $this->order->getBaseCurrencyCode(); }
protected function _checkIpnRequest() { $request = $this->getRequest()->getPost(); $this->_order = $this->_getOrder($request['ordernumber']); // check order ID $orderId = $this->_order->getRealOrderId(); if ($orderId != $request['ordernumber']) { throw new \Magento\Framework\Exception\LocalizedException(__('Order not found')); } $this->_paymentInst = $this->_order->getPayment()->getMethodInstance(); // check merchant ID if ($this->_paymentInst->getConfigData('merchant') != $request['merchant_id']) { throw new \Magento\Framework\Exception\LocalizedException(__('Invalid merchant ID: ' . $request['merchant_id'])); } // failed operation if ('AS000' != $request['responsecode']) { throw new \Magento\Framework\Exception\LocalizedException($this->_paymentInst->getAssistErrors($request['responsecode'])); } // wrong test mode if ($this->_paymentInst->getConfigData('mode') != $request['testmode']) { throw new \Magento\Framework\Exception\LocalizedException(__('Wrong Test Mode.')); } // accept only Approve operations, cancel and capture are processed real time if ('100' != $request['operationtype']) { throw new \Magento\Framework\Exception\LocalizedException(__('Wrong Operation Type. Only Approve is supported by IPN.')); } // check currency if ($this->_order->getBaseCurrencyCode() != $request['ordercurrency']) { throw new \Magento\Framework\Exception\LocalizedException(__('Invalid currency: ' . $request['ordercurrency'])); } // check amount $orderAmount = number_format($this->_order->getGrandTotal(), 2, '.', ''); if ($orderAmount != $request['orderamount']) { throw new \Magento\Framework\Exception\LocalizedException(__('Invalid amount: ' . $request['orderamount'])); } /* if (Mage::helper('assist')->isResponseSecuredMd5()) { $x = array( $this->_paymentInst->getConfigData('merchant'), $request['ordernumber'], $request['amount'], $request['currency'], $request['orderstate'] ); if ($this->_paymentInst->secreyKey(implode("", $x)) != $request['checkvalue']) { Mage::throwException('Incorrect Checkvalue: ' . $request['checkvalue']); } } if (Mage::helper('assist')->isResponseSecuredPgp()) { $y = implode("", array( $this->_paymentInst->getConfigData('merchant'), $request['ordernumber'], $request['amount'], $request['currency'], $request['orderstate'] )); $keyFile = Mage::getBaseDir('var') . DS . 'assist' . DS . $this->_paymentInst->getConfigData('assist_key'); if ($this->_paymentInst->sign($y, $keyFile) != $request['signature']) { Mage::throwException('Incorrect Signature.'); } } */ return $request; }