9 use Magento\Framework\HTTP\ZendClientFactory;
16 abstract class Authorizenet extends \Magento\Payment\Model\Method\Cc
21 const CGI_URL =
'https://secure.authorize.net/gateway/transact.dll';
129 \
Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory,
134 \
Magento\Framework\Module\ModuleListInterface $moduleList,
135 \
Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate,
155 $customAttributeFactory,
188 if (!$this->hasData(
'_accepted_currency')) {
189 $acceptedCurrencyCodes = $this->dataHelper->getAllowedCurrencyCodes();
190 $acceptedCurrencyCodes[] = $this->getConfigData(
'currency');
191 $this->setData(
'_accepted_currency', $acceptedCurrencyCodes);
193 return $this->_getData(
'_accepted_currency');
216 $responseXmlDocument = $this->transactionService->getTransactionDetails($this, $transactionId);
217 $response = new \Magento\Framework\DataObject();
219 if (empty($responseXmlDocument->transaction->FDSFilters->FDSFilter)) {
224 $this->dataHelper->getFdsFilterActionLabel((
string)$responseXmlDocument->transaction->FDSFilterAction)
226 $response->setAvsResponse((
string)$responseXmlDocument->transaction->AVSResponse);
227 $response->setCardCodeResponse((
string)$responseXmlDocument->transaction->cardCodeResponse);
228 $response->setCavvResponse((
string)$responseXmlDocument->transaction->CAVVResponse);
244 foreach ($fraudFilters->FDSFilter as $filer) {
246 'name' => (string)$filer->name,
247 'action' => $this->dataHelper->getFdsFilterActionLabel((
string)$filer->action)
261 $request = $this->requestFactory->create()
263 ->setXDelimData(
'True')
264 ->setXRelayResponse(
'False')
265 ->setXTestRequest($this->getConfigData(
'test') ?
'TRUE' :
'FALSE')
266 ->setXLogin($this->getConfigData(
'login'))
267 ->setXTranKey($this->getConfigData(
'trans_key'));
285 $this->setStore(
$order->getStoreId());
287 ->setXType($payment->getAnetTransType())
288 ->setXMethod(self::REQUEST_METHOD_CC);
299 switch (
$payment->getAnetTransType()) {
301 $request->setXAllowPartialAuth($this->getConfigData(
'allow_partial_authorization') ?
'True' :
'False');
304 $request->setXAllowPartialAuth($this->getConfigData(
'allow_partial_authorization') ?
'True' :
'False');
326 $billing =
$order->getBillingAddress();
327 if (!empty($billing)) {
328 $request->setXFirstName($billing->getFirstname())
329 ->setXLastName($billing->getLastname())
330 ->setXCompany($billing->getCompany())
331 ->setXAddress($billing->getStreetLine(1))
332 ->setXCity($billing->getCity())
333 ->setXState($billing->getRegion())
334 ->setXZip($billing->getPostcode())
335 ->setXCountry($billing->getCountryId())
336 ->setXPhone($billing->getTelephone())
337 ->setXFax($billing->getFax())
338 ->setXCustId(
$order->getCustomerId())
339 ->setXCustomerIp(
$order->getRemoteIp())
340 ->setXCustomerTaxId($billing->getTaxId())
341 ->setXEmail(
$order->getCustomerEmail())
342 ->setXEmailCustomer($this->getConfigData(
'email_customer'))
343 ->setXMerchantEmail($this->getConfigData(
'merchant_email'));
346 $shipping =
$order->getShippingAddress();
347 if (!empty($shipping)) {
348 $request->setXShipToFirstName($shipping->getFirstname())
349 ->setXShipToLastName($shipping->getLastname())
350 ->setXShipToCompany($shipping->getCompany())
351 ->setXShipToAddress($shipping->getStreetLine(1))
352 ->setXShipToCity($shipping->getCity())
353 ->setXShipToState($shipping->getRegion())
354 ->setXShipToZip($shipping->getPostcode())
355 ->setXShipToCountry($shipping->getCountryId());
359 ->setXTax(
$order->getBaseTaxAmount())
360 ->setXFreight(
$order->getBaseShippingAmount());
365 ->setXExpDate(sprintf(
'%02d-%04d',
$payment->getCcExpMonth(),
$payment->getCcExpYear()))
366 ->setXCardCode(
$payment->getCcCid());
379 protected function postRequest(\
Magento\Authorizenet\Model\Request
$request)
381 $result = $this->responseFactory->create();
383 $client = $this->httpClientFactory->create();
385 $debugData = [
'url' =>
$url,
'request' =>
$request->getData()];
386 $client->setUri(
$url);
387 $client->setConfig([
'maxredirects' => 0,
'timeout' => 30]);
390 $request->setData($key, str_replace(self::RESPONSE_DELIM_CHAR,
'',
$value));
393 $request->setXDelimChar(self::RESPONSE_DELIM_CHAR);
394 $client->setParameterPost(
$request->getData());
400 $debugData[
'response'] = $responseBody;
401 }
catch (\Exception $e) {
403 ->setXResponseReasonCode($e->getCode())
404 ->setXResponseReasonText($e->getMessage());
406 throw new \Magento\Framework\Exception\LocalizedException(
407 $this->dataHelper->wrapGatewayError($e->getMessage())
410 $this->_debug($debugData);
413 $r = explode(self::RESPONSE_DELIM_CHAR, $responseBody);
415 $result->setXResponseCode((
int)str_replace(
'"',
'', $r[0]))
416 ->setXResponseReasonCode((
int)str_replace(
'"',
'', $r[2]))
417 ->setXResponseReasonText($r[3])
420 ->setXInvoiceNum($r[7])
424 ->setData(
'x_MD5_Hash', $r[37])
425 ->setXAccountNumber($r[50]);
427 throw new \Magento\Framework\Exception\LocalizedException(
428 __(
'Something went wrong in the payment gateway.')
442 return $payment->getAdditionalInformation(self::GATEWAY_ACTIONS_LOCKED_STATE_KEY);
canUseForCurrency($currencyCode)
getFraudFilters($fraudFilters)
const GATEWAY_ACTIONS_LOCKED_STATE_KEY
const RESPONSE_REASON_CODE_APPROVED
fetchTransactionFraudDetails($transactionId)
const RESPONSE_REASON_CODE_PENDING_REVIEW_DECLINED
getAcceptedCurrencyCodes()
const REQUEST_TYPE_AUTH_ONLY
const RESPONSE_REASON_CODE_PENDING_REVIEW
const TRANSACTION_FRAUD_STATE_KEY
const RESPONSE_CODE_ERROR
const RESPONSE_REASON_CODE_PENDING_REVIEW_AUTHORIZED
const RESPONSE_CODE_DECLINED
cancel(\Magento\Payment\Model\InfoInterface $payment)
const REQUEST_TYPE_CREDIT
const RESPONSE_CODE_APPROVED
const REQUEST_TYPE_PRIOR_AUTH_CAPTURE
const REQUEST_TYPE_CAPTURE_ONLY
__construct(\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory, \Magento\Framework\Api\AttributeValueFactory $customAttributeFactory, \Magento\Payment\Helper\Data $paymentData, \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Payment\Model\Method\Logger $logger, \Magento\Framework\Module\ModuleListInterface $moduleList, \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate, \Magento\Authorizenet\Helper\Data $dataHelper, \Magento\Authorizenet\Model\Request\Factory $requestFactory, \Magento\Authorizenet\Model\Response\Factory $responseFactory, TransactionService $transactionService, ZendClientFactory $httpClientFactory, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[])
const RESPONSE_DELIM_CHAR
const REQUEST_TYPE_AUTH_CAPTURE
isGatewayActionsLocked($payment)
$_debugReplacePrivateDataKeys
const REAL_TRANSACTION_ID_KEY