/**
  * Prepare request to gateway
  *
  * @param \Magento\Framework\DataObject|\Magento\Payment\Model\InfoInterface $payment
  * @return \Magento\Authorizenet\Model\Request
  * @link http://www.authorize.net/support/AIM_guide.pdf
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 protected function buildRequest(\Magento\Framework\DataObject $payment)
 {
     /** @var \Magento\Sales\Model\Order $order */
     $order = $payment->getOrder();
     $this->setStore($order->getStoreId());
     $request = $this->getRequest()->setXType($payment->getAnetTransType())->setXMethod(self::REQUEST_METHOD_CC);
     if ($order && $order->getIncrementId()) {
         $request->setXInvoiceNum($order->getIncrementId());
     }
     if ($payment->getAmount()) {
         $request->setXAmount($payment->getAmount(), 2);
         $request->setXCurrencyCode($order->getBaseCurrencyCode());
     }
     switch ($payment->getAnetTransType()) {
         case self::REQUEST_TYPE_AUTH_CAPTURE:
             $request->setXAllowPartialAuth($this->getConfigData('allow_partial_authorization') ? 'True' : 'False');
             break;
         case self::REQUEST_TYPE_AUTH_ONLY:
             $request->setXAllowPartialAuth($this->getConfigData('allow_partial_authorization') ? 'True' : 'False');
             break;
         case self::REQUEST_TYPE_CREDIT:
             /**
              * Send last 4 digits of credit card number to authorize.net
              * otherwise it will give an error
              */
             $request->setXCardNum($payment->getCcLast4());
             $request->setXTransId($payment->getXTransId());
             break;
         case self::REQUEST_TYPE_VOID:
             $request->setXTransId($payment->getXTransId());
             break;
         case self::REQUEST_TYPE_PRIOR_AUTH_CAPTURE:
             $request->setXTransId($payment->getXTransId());
             break;
         case self::REQUEST_TYPE_CAPTURE_ONLY:
             $request->setXAuthCode($payment->getCcAuthCode());
             break;
     }
     if (!empty($order)) {
         $billing = $order->getBillingAddress();
         if (!empty($billing)) {
             $request->setXFirstName($billing->getFirstname())->setXLastName($billing->getLastname())->setXCompany($billing->getCompany())->setXAddress($billing->getStreetLine(1))->setXCity($billing->getCity())->setXState($billing->getRegion())->setXZip($billing->getPostcode())->setXCountry($billing->getCountry())->setXPhone($billing->getTelephone())->setXFax($billing->getFax())->setXCustId($order->getCustomerId())->setXCustomerIp($order->getRemoteIp())->setXCustomerTaxId($billing->getTaxId())->setXEmail($order->getCustomerEmail())->setXEmailCustomer($this->getConfigData('email_customer'))->setXMerchantEmail($this->getConfigData('merchant_email'));
         }
         $shipping = $order->getShippingAddress();
         if (!empty($shipping)) {
             $request->setXShipToFirstName($shipping->getFirstname())->setXShipToLastName($shipping->getLastname())->setXShipToCompany($shipping->getCompany())->setXShipToAddress($shipping->getStreetLine(1))->setXShipToCity($shipping->getCity())->setXShipToState($shipping->getRegion())->setXShipToZip($shipping->getPostcode())->setXShipToCountry($shipping->getCountry());
         }
         $request->setXPoNum($payment->getPoNumber())->setXTax($order->getBaseTaxAmount())->setXFreight($order->getBaseShippingAmount());
     }
     if ($payment->getCcNumber()) {
         $request->setXCardNum($payment->getCcNumber())->setXExpDate(sprintf('%02d-%04d', $payment->getCcExpMonth(), $payment->getCcExpYear()))->setXCardCode($payment->getCcCid());
     }
     return $request;
 }
Example #2
0
 /**
  * Return request object with information for 'authorization' or 'sale' action
  *
  * @param Object|Payment $payment
  * @param float $amount
  * @return DataObject
  */
 protected function _buildPlaceRequest(DataObject $payment, $amount)
 {
     $request = $this->buildBasicRequest();
     $request->setAmt(round($amount, 2));
     $request->setAcct($payment->getCcNumber());
     $request->setExpdate(sprintf('%02d', $payment->getCcExpMonth()) . substr($payment->getCcExpYear(), -2, 2));
     $request->setCvv2($payment->getCcCid());
     $order = $payment->getOrder();
     $request->setCurrency($order->getBaseCurrencyCode());
     $request = $this->fillCustomerContacts($order, $request);
     return $request;
 }
Example #3
0
 /**
  * Assign data to info model instance
  *
  * @param \Magento\Framework\DataObject|mixed $data
  * @return $this
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function assignData(\Magento\Framework\DataObject $data)
 {
     $additionalData = $data->getData(PaymentInterface::KEY_ADDITIONAL_DATA);
     if (!is_object($additionalData)) {
         $additionalData = new DataObject($additionalData ?: []);
     }
     /** @var DataObject $info */
     $info = $this->getInfoInstance();
     $info->addData(['cc_type' => $additionalData->getCcType(), 'cc_owner' => $additionalData->getCcOwner(), 'cc_last_4' => substr($additionalData->getCcNumber(), -4), 'cc_number' => $additionalData->getCcNumber(), 'cc_cid' => $additionalData->getCcCid(), 'cc_exp_month' => $additionalData->getCcExpMonth(), 'cc_exp_year' => $additionalData->getCcExpYear(), 'cc_ss_issue' => $additionalData->getCcSsIssue(), 'cc_ss_start_month' => $additionalData->getCcSsStartMonth(), 'cc_ss_start_year' => $additionalData->getCcSsStartYear()]);
     return $this;
 }