/** * Call centinel api lookup method * * @param \Magento\Framework\Object $data * @return \Magento\Framework\Object */ public function callLookup($data) { $result = new \Magento\Framework\Object(); $month = strlen($data->getCardExpMonth()) == 1 ? '0' . $data->getCardExpMonth() : $data->getCardExpMonth(); $currencyCode = $data->getCurrencyCode(); $currencyNumber = isset(self::$_iso4217Currencies[$currencyCode]) ? self::$_iso4217Currencies[$currencyCode] : ''; if (!$currencyNumber) { return $result->setErrorNo(1)->setErrorDesc(__('Unsupported currency code: %1.', $currencyCode)); } $clientResponse = $this->_call('cmpi_lookup', ['Amount' => round($data->getAmount() * 100), 'CurrencyCode' => $currencyNumber, 'CardNumber' => $data->getCardNumber(), 'CardExpMonth' => $month, 'CardExpYear' => $data->getCardExpYear(), 'OrderNumber' => $data->getOrderNumber()]); $result->setErrorNo($clientResponse->getValue('ErrorNo')); $result->setErrorDesc($clientResponse->getValue('ErrorDesc')); $result->setTransactionId($clientResponse->getValue('TransactionId')); $result->setEnrolled($clientResponse->getValue('Enrolled')); $result->setAcsUrl($clientResponse->getValue('ACSUrl')); $result->setPayload($clientResponse->getValue('Payload')); $result->setEciFlag($clientResponse->getValue('EciFlag')); return $result; }
/** * It sets card`s data into additional information of payment model * * @param \Magento\Framework\Object $response * @param \Magento\Sales\Model\Order\Payment $payment * @return string */ protected function _registerCard(\Magento\Framework\Object $response, \Magento\Sales\Model\Order\Payment $payment) { $cardsStorage = $this->getCardsStorage($payment); $card = $cardsStorage->registerCard(); $card->setRequestedAmount($response->getRequestedAmount())->setBalanceOnCard($response->getBalanceOnCard())->setLastTransId($response->getTransactionId())->setProcessedAmount($response->getAmount())->setCcType($payment->getCcType())->setCcOwner($payment->getCcOwner())->setCcLast4($payment->getCcLast4())->setCcExpMonth($payment->getCcExpMonth())->setCcExpYear($payment->getCcExpYear())->setCcSsIssue($payment->getCcSsIssue())->setCcSsStartMonth($payment->getCcSsStartMonth())->setCcSsStartYear($payment->getCcSsStartYear()); $cardsStorage->updateCard($card); $this->_clearAssignedData($payment); return $card; }
/** * Compare two shipping options based on their amounts * * This function is used as a callback comparison function in shipping options sorting process * @see self::_prepareShippingOptions() * * @param \Magento\Framework\Object $option1 * @param \Magento\Framework\Object $option2 * @return int */ protected static function cmpShippingOptions(\Magento\Framework\Object $option1, \Magento\Framework\Object $option2) { if ($option1->getAmount() == $option2->getAmount()) { return 0; } return $option1->getAmount() < $option2->getAmount() ? -1 : 1; }
/** * Getter for details row amount * * @param \Magento\Framework\Object $row * @return string */ public function getItemDetailsRowAmount(\Magento\Framework\Object $row) { return $row->getAmount(); }
/** * Validate payment data * * This check is performed on payment information submission, as well as on placing order. * Workflow state is stored validation state model * * @param \Magento\Framework\Object $data * @return void * @throws \Magento\Framework\Model\Exception */ public function validate($data) { $newChecksum = $this->_generateChecksum($data->getPaymentMethodCode(), $data->getCardType(), $data->getCardNumber(), $data->getCardExpMonth(), $data->getCardExpYear(), $data->getAmount(), $data->getCurrencyCode()); $validationState = $this->_getValidationState($data->getCardType()); if (!$validationState) { $this->_resetValidationState(); return; } // check whether is authenticated before placing order if ($this->getIsPlaceOrder()) { if ($validationState->getChecksum() != $newChecksum) { throw new \Magento\Framework\Model\Exception(__('Payment information error. Please start over.')); } if ($validationState->isAuthenticateSuccessful()) { return; } throw new \Magento\Framework\Model\Exception(__('Please verify the card with the issuer bank before placing the order.')); } else { if ($validationState->getChecksum() != $newChecksum || !$validationState->isLookupSuccessful()) { $this->lookup($data); $validationState = $this->_getValidationState(); } if ($validationState->isLookupSuccessful()) { return; } throw new \Magento\Framework\Model\Exception(__('This card has failed validation and cannot be used.')); } }
/** * Prepare request to gateway * * @param \Magento\Framework\Object|\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\Object $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; }