Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields | Protected Member Functions | Protected Attributes
Directpost Class Reference
Inheritance diagram for Directpost:
Authorizenet TransparentInterface ConfigInterface MethodInterface ConfigInterface

Public Member Functions

 __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\Directpost\Request\Factory $requestFactory, \Magento\Authorizenet\Model\Directpost\Response\Factory $responseFactory, \Magento\Authorizenet\Model\TransactionService $transactionService, \Magento\Framework\HTTP\ZendClientFactory $httpClientFactory, \Magento\Sales\Model\OrderFactory $orderFactory, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Quote\Api\CartRepositoryInterface $quoteRepository, \Magento\Sales\Model\Order\Email\Sender\OrderSender $orderSender, \Magento\Sales\Api\TransactionRepositoryInterface $transactionRepository, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[], \Magento\Sales\Api\PaymentFailuresInterface $paymentFailures=null)
 
 setDataHelper (\Magento\Authorizenet\Helper\Data $dataHelper)
 
 validate ()
 
 authorize (\Magento\Payment\Model\InfoInterface $payment, $amount)
 
 capture (\Magento\Payment\Model\InfoInterface $payment, $amount)
 
 void (\Magento\Payment\Model\InfoInterface $payment)
 
 refund (\Magento\Payment\Model\InfoInterface $payment, $amount)
 
 getCgiUrl ()
 
 getRelayUrl ($storeId=null)
 
 getResponse ()
 
 initialize ($paymentAction, $stateObject)
 
 generateRequestFromOrder (\Magento\Sales\Model\Order $order)
 
 setResponseData (array $postData)
 
 validateResponse ()
 
 process (array $responseData)
 
 checkResponseCode ()
 
 checkTransId ()
 
 getConfigInterface ()
 
 getValue ($key, $storeId=null)
 
 setIsInitializeNeeded ($isInitializeNeeded=true)
 
 canCapture ()
 
 fetchTransactionInfo (\Magento\Payment\Model\InfoInterface $payment, $transactionId)
 
 setMethodCode ($methodCode)
 
 setPathPattern ($pathPattern)
 
- Public Member Functions inherited from Authorizenet
 __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=[])
 
 canUseForCurrency ($currencyCode)
 
 getAcceptedCurrencyCodes ()
 
 cancel (\Magento\Payment\Model\InfoInterface $payment)
 
 fetchTransactionFraudDetails ($transactionId)
 
- Public Member Functions inherited from MethodInterface
 getCode ()
 
 getFormBlockType ()
 
 getTitle ()
 
 setStore ($storeId)
 
 getStore ()
 
 canOrder ()
 
 canAuthorize ()
 
 canCapturePartial ()
 
 canCaptureOnce ()
 
 canRefund ()
 
 canRefundPartialPerInvoice ()
 
 canVoid ()
 
 canUseInternal ()
 
 canUseCheckout ()
 
 canEdit ()
 
 canFetchTransactionInfo ()
 
 fetchTransactionInfo (InfoInterface $payment, $transactionId)
 
 isGateway ()
 
 isOffline ()
 
 isInitializeNeeded ()
 
 canUseForCountry ($country)
 
 canUseForCurrency ($currencyCode)
 
 getInfoBlockType ()
 
 getInfoInstance ()
 
 setInfoInstance (InfoInterface $info)
 
 order (\Magento\Payment\Model\InfoInterface $payment, $amount)
 
 authorize (\Magento\Payment\Model\InfoInterface $payment, $amount)
 
 capture (\Magento\Payment\Model\InfoInterface $payment, $amount)
 
 refund (\Magento\Payment\Model\InfoInterface $payment, $amount)
 
 cancel (\Magento\Payment\Model\InfoInterface $payment)
 
 void (\Magento\Payment\Model\InfoInterface $payment)
 
 canReviewPayment ()
 
 acceptPayment (InfoInterface $payment)
 
 denyPayment (InfoInterface $payment)
 
 getConfigData ($field, $storeId=null)
 
 assignData (DataObject $data)
 
 isAvailable (CartInterface $quote=null)
 
 isActive ($storeId=null)
 
 getConfigPaymentAction ()
 

Data Fields

const METHOD_CODE = 'authorizenet_directpost'
 
- Data Fields inherited from Authorizenet
const CGI_URL = 'https://secure.authorize.net/gateway/transact.dll'
 
const REQUEST_METHOD_CC = 'CC'
 
const REQUEST_TYPE_AUTH_CAPTURE = 'AUTH_CAPTURE'
 
const REQUEST_TYPE_AUTH_ONLY = 'AUTH_ONLY'
 
const REQUEST_TYPE_CAPTURE_ONLY = 'CAPTURE_ONLY'
 
const REQUEST_TYPE_CREDIT = 'CREDIT'
 
const REQUEST_TYPE_VOID = 'VOID'
 
const REQUEST_TYPE_PRIOR_AUTH_CAPTURE = 'PRIOR_AUTH_CAPTURE'
 
const RESPONSE_DELIM_CHAR = '(~)'
 
const RESPONSE_CODE_APPROVED = 1
 
const RESPONSE_CODE_DECLINED = 2
 
const RESPONSE_CODE_ERROR = 3
 
const RESPONSE_CODE_HELD = 4
 
const RESPONSE_REASON_CODE_APPROVED = 1
 
const RESPONSE_REASON_CODE_PENDING_REVIEW_AUTHORIZED = 252
 
const RESPONSE_REASON_CODE_PENDING_REVIEW = 253
 
const RESPONSE_REASON_CODE_PENDING_REVIEW_DECLINED = 254
 
const TRANSACTION_FRAUD_STATE_KEY = 'is_transaction_fraud'
 
const REAL_TRANSACTION_ID_KEY = 'real_transaction_id'
 
const GATEWAY_ACTIONS_LOCKED_STATE_KEY = 'is_gateway_actions_locked'
 
- Data Fields inherited from MethodInterface
const ACTION_ORDER = 'order'
 
const ACTION_AUTHORIZE = 'authorize'
 
const ACTION_AUTHORIZE_CAPTURE = 'authorize_capture'
 
const CHECK_USE_FOR_COUNTRY = 'country'
 
const CHECK_USE_FOR_CURRENCY = 'currency'
 
const CHECK_USE_CHECKOUT = 'checkout'
 
const CHECK_USE_INTERNAL = 'internal'
 
const CHECK_ORDER_TOTAL_MIN_MAX = 'total'
 
const CHECK_ZERO_TOTAL = 'zero_total'
 
const GROUP_OFFLINE = 'offline'
 

Protected Member Functions

 processCapture ($result, $payment)
 
 processRefund (\Magento\Framework\DataObject $payment, $amount)
 
 fillPaymentByResponse (\Magento\Framework\DataObject $payment)
 
 matchAmount ($amount)
 
 processOrder (\Magento\Sales\Model\Order $order)
 
 processPaymentFraudStatus (\Magento\Sales\Model\Order\Payment $payment)
 
 addStatusComment (\Magento\Sales\Model\Order\Payment $payment)
 
 declineOrder (\Magento\Sales\Model\Order $order, $message='', $voidPayment=true)
 
 getRealParentTransactionId ($payment)
 
 addStatusCommentOnUpdate (\Magento\Sales\Model\Order\Payment $payment, \Magento\Framework\DataObject $response, $transactionId)
 
 getTransactionResponse ($transactionId)
 
- Protected Member Functions inherited from Authorizenet
 getFraudFilters ($fraudFilters)
 
 getRequest ()
 
 isGatewayActionsLocked ($payment)
 

Protected Attributes

 $_formBlockType = \Magento\Payment\Block\Transparent\Info::class
 
 $_infoBlockType = \Magento\Payment\Block\Info::class
 
 $_isGateway = true
 
 $_canAuthorize = true
 
 $_canCapture = true
 
 $_canRefund = true
 
 $_canRefundInvoicePartial = true
 
 $_canVoid = true
 
 $_canFetchTransactionInfo = true
 
 $_isInitializeNeeded = true
 
 $storeManager
 
 $quoteRepository
 
 $response
 
 $orderSender
 
 $orderFactory
 
 $transactionRepository
 
- Protected Attributes inherited from Authorizenet
 $dataHelper
 
 $requestFactory
 
 $responseFactory
 
 $transactionService
 
 $_debugReplacePrivateDataKeys = ['merchantAuthentication', 'x_login']
 
 $httpClientFactory
 

Detailed Description

Authorize.net DirectPost payment method model. @SuppressWarnings(PHPMD.TooManyFields) @SuppressWarnings(PHPMD.CouplingBetweenObjects) @SuppressWarnings(PHPMD.ExcessiveClassComplexity)

Definition at line 18 of file Directpost.php.

Constructor & Destructor Documentation

◆ __construct()

__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\Directpost\Request\Factory  $requestFactory,
\Magento\Authorizenet\Model\Directpost\Response\Factory  $responseFactory,
\Magento\Authorizenet\Model\TransactionService  $transactionService,
\Magento\Framework\HTTP\ZendClientFactory  $httpClientFactory,
\Magento\Sales\Model\OrderFactory  $orderFactory,
\Magento\Store\Model\StoreManagerInterface  $storeManager,
\Magento\Quote\Api\CartRepositoryInterface  $quoteRepository,
\Magento\Sales\Model\Order\Email\Sender\OrderSender  $orderSender,
\Magento\Sales\Api\TransactionRepositoryInterface  $transactionRepository,
\Magento\Framework\Model\ResourceModel\AbstractResource  $resource = null,
\Magento\Framework\Data\Collection\AbstractDb  $resourceCollection = null,
array  $data = [],
\Magento\Sales\Api\PaymentFailuresInterface  $paymentFailures = null 
)
Parameters
\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\Directpost\Request\Factory$requestFactory
\Magento\Authorizenet\Model\Directpost\Response\Factory$responseFactory
\Magento\Authorizenet\Model\TransactionService$transactionService
\Magento\Framework\HTTP\ZendClientFactory$httpClientFactory
\Magento\Sales\Model\OrderFactory$orderFactory
\Magento\Store\Model\StoreManagerInterface$storeManager
\Magento\Quote\Api\CartRepositoryInterface$quoteRepository
\Magento\Sales\Model\Order\Email\Sender\OrderSender$orderSender
\Magento\Sales\Api\TransactionRepositoryInterface$transactionRepository
\Magento\Framework\Model\ResourceModel\AbstractResource$resource
\Magento\Framework\Data\Collection\AbstractDb$resourceCollection
array$data
\Magento\Sales\Api\PaymentFailuresInterface | null$paymentFailures@SuppressWarnings(PHPMD.ExcessiveParameterList)

Definition at line 161 of file Directpost.php.

185  {
186  $this->orderFactory = $orderFactory;
187  $this->storeManager = $storeManager;
188  $this->quoteRepository = $quoteRepository;
189  $this->response = $responseFactory->create();
190  $this->orderSender = $orderSender;
191  $this->transactionRepository = $transactionRepository;
192  $this->_code = static::METHOD_CODE;
193  $this->paymentFailures = $paymentFailures ? : ObjectManager::getInstance()
194  ->get(\Magento\Sales\Api\PaymentFailuresInterface::class);
195 
196  parent::__construct(
197  $context,
198  $registry,
199  $extensionFactory,
200  $customAttributeFactory,
201  $paymentData,
202  $scopeConfig,
203  $logger,
204  $moduleList,
205  $localeDate,
206  $dataHelper,
211  $resource,
212  $resourceCollection,
213  $data
214  );
215  }
$resource
Definition: bulk.php:12
$logger

Member Function Documentation

◆ addStatusComment()

addStatusComment ( \Magento\Sales\Model\Order\Payment  $payment)
protected

Add status comment

Parameters
\Magento\Sales\Model\Order\Payment$payment
Returns
$this

Definition at line 777 of file Directpost.php.

778  {
779  try {
780  $transactionId = $this->getResponse()->getXTransId();
781  $data = $this->transactionService->getTransactionDetails($this, $transactionId);
782  $transactionStatus = (string)$data->transaction->transactionStatus;
783  $fdsFilterAction = (string)$data->transaction->FDSFilterAction;
784 
785  if ($payment->getIsTransactionPending()) {
786  $message = 'Amount of %1 is pending approval on the gateway.<br/>'
787  . 'Transaction "%2" status is "%3".<br/>'
788  . 'Transaction FDS Filter Action is "%4"';
789  $message = __(
790  $message,
791  $payment->getOrder()->getBaseCurrency()->formatTxt($this->getResponse()->getXAmount()),
792  $transactionId,
793  $this->dataHelper->getTransactionStatusLabel($transactionStatus),
794  $this->dataHelper->getFdsFilterActionLabel($fdsFilterAction)
795  );
796  $payment->getOrder()->addStatusHistoryComment($message);
797  }
798  } catch (\Exception $e) {
799  $this->getPsrLogger()->critical($e);
800  //this request is optional
801  }
802  return $this;
803  }
__()
Definition: __.php:13
$message
$payment
Definition: order.php:17

◆ addStatusCommentOnUpdate()

addStatusCommentOnUpdate ( \Magento\Sales\Model\Order\Payment  $payment,
\Magento\Framework\DataObject  $response,
  $transactionId 
)
protected
Parameters
\Magento\Sales\Model\Order\Payment$payment
\Magento\Framework\DataObject$response
string$transactionId
Returns
$this

Definition at line 930 of file Directpost.php.

934  {
935  if ($payment->getIsTransactionApproved()) {
936  $message = __(
937  'Transaction %1 has been approved. Amount %2. Transaction status is "%3"',
938  $transactionId,
939  $payment->getOrder()->getBaseCurrency()->formatTxt($payment->getAmountAuthorized()),
940  $this->dataHelper->getTransactionStatusLabel($response->getTransactionStatus())
941  );
942  $payment->getOrder()->addStatusHistoryComment($message);
943  } elseif ($payment->getIsTransactionDenied()) {
944  $message = __(
945  'Transaction %1 has been voided/declined. Transaction status is "%2". Amount %3.',
946  $transactionId,
947  $this->dataHelper->getTransactionStatusLabel($response->getTransactionStatus()),
948  $payment->getOrder()->getBaseCurrency()->formatTxt($payment->getAmountAuthorized())
949  );
950  $payment->getOrder()->addStatusHistoryComment($message);
951  }
952  return $this;
953  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
__()
Definition: __.php:13
$message
$payment
Definition: order.php:17

◆ authorize()

authorize ( \Magento\Payment\Model\InfoInterface  $payment,
  $amount 
)

Send authorize request to gateway

Parameters
\Magento\Framework\DataObject | \Magento\Payment\Model\InfoInterface$payment
float$amount
Returns
void @SuppressWarnings(PHPMD.UnusedFormalParameter)

Definition at line 246 of file Directpost.php.

247  {
248  $payment->setAdditionalInformation('payment_type', $this->getConfigData('payment_action'));
249  }
$payment
Definition: order.php:17
getConfigData($field, $storeId=null)

◆ canCapture()

canCapture ( )

Get whether it is possible to capture

Returns
bool

Implements MethodInterface.

Definition at line 885 of file Directpost.php.

◆ capture()

capture ( \Magento\Payment\Model\InfoInterface  $payment,
  $amount 
)

Send capture request to gateway

Parameters
\Magento\Framework\DataObject | \Magento\Payment\Model\InfoInterface$payment
float$amount
Returns
$this
Exceptions

Definition at line 259 of file Directpost.php.

260  {
261  if ($amount <= 0) {
262  throw new \Magento\Framework\Exception\LocalizedException(__('Invalid amount for capture.'));
263  }
264 
265  $payment->setAmount($amount);
266 
267  if ($payment->getParentTransactionId()) {
268  $payment->setAnetTransType(self::REQUEST_TYPE_PRIOR_AUTH_CAPTURE);
269  $payment->setXTransId($this->getRealParentTransactionId($payment));
270  } else {
271  $payment->setAnetTransType(self::REQUEST_TYPE_AUTH_CAPTURE);
272  }
273 
274  $result = $this->getResponse();
275  if (empty($result->getData())) {
276  $request = $this->buildRequest($payment);
277  $result = $this->postRequest($request);
278  }
279 
280  return $this->processCapture($result, $payment);
281  }
__()
Definition: __.php:13
$amount
Definition: order.php:14
$payment
Definition: order.php:17

◆ checkResponseCode()

checkResponseCode ( )

Check response code came from Authorize.net.

Returns
true in case of Approved response
Exceptions

Definition at line 637 of file Directpost.php.

638  {
639  switch ($this->getResponse()->getXResponseCode()) {
642  return true;
645  $errorMessage = $this->dataHelper->wrapGatewayError($this->getResponse()->getXResponseReasonText());
646  $order = $this->getOrderFromResponse();
647  $this->paymentFailures->handle((int)$order->getQuoteId(), $errorMessage);
648  throw new \Magento\Framework\Exception\LocalizedException($errorMessage);
649  default:
650  throw new \Magento\Framework\Exception\LocalizedException(
651  __('There was a payment authorization error.')
652  );
653  }
654  }
__()
Definition: __.php:13

◆ checkTransId()

checkTransId ( )

Check transaction id came from Authorize.net

Returns
true in case of right transaction id
Exceptions

Definition at line 662 of file Directpost.php.

663  {
664  if (!$this->getResponse()->getXTransId()) {
665  throw new \Magento\Framework\Exception\LocalizedException(
666  __('Please enter a transaction ID to authorize this payment.')
667  );
668  }
669  return true;
670  }
__()
Definition: __.php:13

◆ declineOrder()

declineOrder ( \Magento\Sales\Model\Order  $order,
  $message = '',
  $voidPayment = true 
)
protected

Register order cancellation. Return money to customer if needed.

Parameters
\Magento\Sales\Model\Order$order
string$message
bool$voidPayment
Returns
void

Definition at line 813 of file Directpost.php.

814  {
815  try {
816  $response = $this->getResponse();
817  if ($voidPayment
818  && $response->getXTransId()
819  && strtoupper($response->getXType()) == self::REQUEST_TYPE_AUTH_ONLY
820  ) {
821  $order->getPayment()
822  ->setTransactionId(null)
823  ->setParentTransactionId($response->getXTransId())
824  ->void($response);
825  }
826  $order->registerCancellation($message)->save();
827  } catch (\Exception $e) {
828  //quiet decline
829  $this->getPsrLogger()->critical($e);
830  }
831  }
$message

◆ fetchTransactionInfo()

fetchTransactionInfo ( \Magento\Payment\Model\InfoInterface  $payment,
  $transactionId 
)

Fetch transaction details info

Update transaction info if there is one placing transaction only

Parameters
\Magento\Payment\Model\InfoInterface$payment
string$transactionId
Returns
array

Definition at line 899 of file Directpost.php.

900  {
901  $transaction = $this->transactionRepository->getByTransactionId(
902  $transactionId,
903  $payment->getId(),
904  $payment->getOrder()->getId()
905  );
906 
907  $response = $this->getTransactionResponse($transactionId);
908  if ($response->getXResponseCode() == self::RESPONSE_CODE_APPROVED) {
909  if ($response->getTransactionStatus() == 'voided') {
910  $payment->setIsTransactionDenied(true);
911  $payment->setIsTransactionClosed(true);
912  $transaction->close();
913  } else {
914  $transaction->setAdditionalInformation(self::TRANSACTION_FRAUD_STATE_KEY, false);
915  $payment->setIsTransactionApproved(true);
916  }
917  } elseif ($response->getXResponseReasonCode() == self::RESPONSE_REASON_CODE_PENDING_REVIEW_DECLINED) {
918  $payment->setIsTransactionDenied(true);
919  }
920  $this->addStatusCommentOnUpdate($payment, $response, $transactionId);
921  return [];
922  }
$transaction
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$payment
Definition: order.php:17
addStatusCommentOnUpdate(\Magento\Sales\Model\Order\Payment $payment, \Magento\Framework\DataObject $response, $transactionId)
Definition: Directpost.php:930

◆ fillPaymentByResponse()

fillPaymentByResponse ( \Magento\Framework\DataObject  $payment)
protected

Fill payment with credit card data from response from Authorize.net.

Parameters
\Magento\Framework\DataObject$payment
Returns
void

Definition at line 612 of file Directpost.php.

613  {
614  $response = $this->getResponse();
615  $payment->setTransactionId($response->getXTransId())
616  ->setParentTransactionId(null)
617  ->setIsTransactionClosed(0)
618  ->setTransactionAdditionalInfo(self::REAL_TRANSACTION_ID_KEY, $response->getXTransId());
619 
620  if ($response->getXMethod() == self::REQUEST_METHOD_CC) {
621  $payment->setCcAvsStatus($response->getXAvsCode())
622  ->setCcLast4($payment->encrypt(substr($response->getXAccountNumber(), -4)));
623  }
624 
625  if ($response->getXResponseCode() == self::RESPONSE_CODE_HELD) {
626  $payment->setIsTransactionPending(true)
627  ->setIsFraudDetected(true);
628  }
629  }
$payment
Definition: order.php:17

◆ generateRequestFromOrder()

generateRequestFromOrder ( \Magento\Sales\Model\Order  $order)

Generate request object and fill its fields from Quote or Order object

Parameters
\Magento\Sales\Model\Order$orderQuote or order object.
Returns
\Magento\Authorizenet\Model\Directpost\Request

Definition at line 514 of file Directpost.php.

515  {
516  $request = $this->requestFactory->create()
517  ->setConstantData($this)
518  ->setDataFromOrder($order, $this)
519  ->signRequestData();
520 
521  $this->_debug(['request' => $request->getData()]);
522 
523  return $request;
524  }

◆ getCgiUrl()

getCgiUrl ( )

Get CGI url

Returns
string

Definition at line 449 of file Directpost.php.

450  {
451  $uri = $this->getConfigData('cgi_url');
452  return $uri ? $uri : self::CGI_URL;
453  }
getConfigData($field, $storeId=null)

◆ getConfigInterface()

getConfigInterface ( )

{inheritdoc}

Implements TransparentInterface.

Definition at line 852 of file Directpost.php.

853  {
854  return $this;
855  }

◆ getRealParentTransactionId()

getRealParentTransactionId (   $payment)
protected

Return additional information`s transaction_id value of parent transaction model

Parameters
\Magento\Sales\Model\Order\Payment$payment
Returns
string

Definition at line 839 of file Directpost.php.

840  {
841  $transaction = $this->transactionRepository->getByTransactionId(
842  $payment->getParentTransactionId(),
843  $payment->getId(),
844  $payment->getOrder()->getId()
845  );
846  return $transaction->getAdditionalInformation(self::REAL_TRANSACTION_ID_KEY);
847  }
$transaction
$payment
Definition: order.php:17

◆ getRelayUrl()

getRelayUrl (   $storeId = null)

Return URL on which Authorize.net server will return payment result data in hidden request.

Parameters
int$storeId
Returns
string

Definition at line 461 of file Directpost.php.

462  {
463  if ($storeId == null && $this->getStore()) {
464  $storeId = $this->getStore();
465  }
466  return $this->dataHelper->getRelayUrl($storeId);
467  }

◆ getResponse()

getResponse ( )

Return response.

Returns
\Magento\Authorizenet\Model\Directpost\Response

Definition at line 474 of file Directpost.php.

◆ getTransactionResponse()

getTransactionResponse (   $transactionId)
protected

This function returns full transaction details for a specified transaction ID.

Parameters
string$transactionId
Returns
\Magento\Framework\DataObject
Exceptions

Definition at line 986 of file Directpost.php.

987  {
988  $responseXmlDocument = $this->transactionService->getTransactionDetails($this, $transactionId);
989 
990  $response = new \Magento\Framework\DataObject();
991  $response->setXResponseCode((string)$responseXmlDocument->transaction->responseCode)
992  ->setXResponseReasonCode((string)$responseXmlDocument->transaction->responseReasonCode)
993  ->setTransactionStatus((string)$responseXmlDocument->transaction->transactionStatus);
994 
995  return $response;
996  }

◆ getValue()

getValue (   $key,
  $storeId = null 
)

Getter for specified value according to set payment method code

Parameters
mixed$key
null$storeId
Returns
mixed

Implements ConfigInterface.

Definition at line 864 of file Directpost.php.

865  {
866  return $this->getConfigData($key, $storeId);
867  }
getConfigData($field, $storeId=null)

◆ initialize()

initialize (   $paymentAction,
  $stateObject 
)

Instantiate state and set it to state object

Parameters
string$paymentAction
\Magento\Framework\DataObject$stateObject
Returns
void @SuppressWarnings(PHPMD.UnusedFormalParameter)

Implements MethodInterface.

Definition at line 487 of file Directpost.php.

488  {
489  $requestType = null;
490  switch ($paymentAction) {
492  $requestType = self::REQUEST_TYPE_AUTH_ONLY;
493  //intentional
495  $requestType = $requestType ?: self::REQUEST_TYPE_AUTH_CAPTURE;
496  $payment = $this->getInfoInstance();
497  $order = $payment->getOrder();
498  $order->setCanSendNewEmailFlag(false);
499  $payment->setBaseAmountAuthorized($order->getBaseTotalDue());
500  $payment->setAmountAuthorized($order->getTotalDue());
501  $payment->setAnetTransType($requestType);
502  break;
503  default:
504  break;
505  }
506  }
$payment
Definition: order.php:17

◆ matchAmount()

matchAmount (   $amount)
protected

Compare amount with amount from the response from Authorize.net.

Parameters
float$amount
Returns
bool

Definition at line 678 of file Directpost.php.

679  {
680  return sprintf('%.2F', $amount) == sprintf('%.2F', $this->getResponse()->getXAmount());
681  }
$amount
Definition: order.php:14

◆ process()

process ( array  $responseData)

Operate with order using data from $_POST which came from authorize.net by Relay URL.

Parameters
array$responseDatadata from Authorize.net from $_POST
Returns
void
Exceptions

Definition at line 566 of file Directpost.php.

567  {
568  $this->_debug(['response' => $responseData]);
569 
570  $this->setResponseData($responseData);
571 
572  //check MD5 error or others response errors
573  //throws exception on false.
574  $this->validateResponse();
575 
576  $response = $this->getResponse();
577  $responseText = $this->dataHelper->wrapGatewayError($response->getXResponseReasonText());
578  $isError = false;
579  if ($this->getOrderIncrementId()) {
580  $order = $this->getOrderFromResponse();
581  //check payment method
582  $payment = $order->getPayment();
583  if (!$payment || $payment->getMethod() != $this->getCode()) {
584  throw new \Magento\Framework\Exception\LocalizedException(
585  __('This payment didn\'t work out because we can\'t find this order.')
586  );
587  }
588  if ($order->getId()) {
589  //operate with order
590  $this->processOrder($order);
591  } else {
592  $isError = true;
593  }
594  } else {
595  $isError = true;
596  }
597 
598  if ($isError) {
599  $responseText = $responseText && !$response->isApproved()
600  ? $responseText
601  : __('This payment didn\'t work out because we can\'t find this order.');
602  throw new \Magento\Framework\Exception\LocalizedException($responseText);
603  }
604  }
__()
Definition: __.php:13
processOrder(\Magento\Sales\Model\Order $order)
Definition: Directpost.php:693
$payment
Definition: order.php:17

◆ processCapture()

processCapture (   $result,
  $payment 
)
protected

Process capture request

Parameters
\Magento\Authorizenet\Model\Directpost\Response$result
\Magento\Payment\Model\InfoInterface$payment
Returns
$this
Exceptions

Definition at line 291 of file Directpost.php.

292  {
293  switch ($result->getXResponseCode()) {
296  if (in_array(
297  $result->getXResponseReasonCode(),
298  [
302  ]
303  )
304  ) {
305  if (!$payment->getParentTransactionId()
306  || $result->getXTransId() != $payment->getParentTransactionId()
307  ) {
308  $payment->setTransactionId($result->getXTransId());
309  }
310  $payment->setIsTransactionClosed(0)
311  ->setTransactionAdditionalInfo(
312  self::REAL_TRANSACTION_ID_KEY,
313  $result->getXTransId()
314  );
315  return $this;
316  }
317  throw new \Magento\Framework\Exception\LocalizedException(
318  $this->dataHelper->wrapGatewayError($result->getXResponseReasonText())
319  );
322  throw new \Magento\Framework\Exception\LocalizedException(
323  $this->dataHelper->wrapGatewayError($result->getXResponseReasonText())
324  );
325  default:
326  throw new \Magento\Framework\Exception\LocalizedException(__('Payment capturing error.'));
327  }
328  }
__()
Definition: __.php:13
$payment
Definition: order.php:17

◆ processOrder()

processOrder ( \Magento\Sales\Model\Order  $order)
protected

Operate with order using information from Authorize.net. Authorize order or authorize and capture it.

Parameters
\Magento\Sales\Model\Order$order
Returns
void
Exceptions

Definition at line 693 of file Directpost.php.

694  {
695  try {
696  $this->checkResponseCode();
697  $this->checkTransId();
698  } catch (\Exception $e) {
699  //decline the order (in case of wrong response code) but don't return money to customer.
700  $message = $e->getMessage();
701  $this->declineOrder($order, $message, false);
702  throw $e;
703  }
704 
705  $response = $this->getResponse();
706 
707  //create transaction. need for void if amount will not match.
708  $payment = $order->getPayment();
710  $payment->getMethodInstance()->setIsInitializeNeeded(false);
711  $payment->getMethodInstance()->setResponseData($response->getData());
713  $payment->place();
714  $this->addStatusComment($payment);
715  $order->save();
716 
717  //match amounts. should be equals for authorization.
718  //decline the order if amount does not match.
719  if (!$this->matchAmount($payment->getBaseAmountAuthorized())) {
720  $message = __(
721  'Something went wrong: the paid amount doesn\'t match the order amount.'
722  . ' Please correct this and try again.'
723  );
724  $this->declineOrder($order, $message, true);
725  throw new \Magento\Framework\Exception\LocalizedException($message);
726  }
727 
728  try {
729  if (!$response->hasOrderSendConfirmation() || $response->getOrderSendConfirmation()) {
730  $this->orderSender->send($order);
731  }
732 
733  $quote = $this->quoteRepository->get($order->getQuoteId())->setIsActive(false);
734  $this->quoteRepository->save($quote);
735  } catch (\Exception $e) {
736  // do not cancel order if we couldn't send email
737  }
738  }
declineOrder(\Magento\Sales\Model\Order $order, $message='', $voidPayment=true)
Definition: Directpost.php:813
$quote
__()
Definition: __.php:13
$message
fillPaymentByResponse(\Magento\Framework\DataObject $payment)
Definition: Directpost.php:612
addStatusComment(\Magento\Sales\Model\Order\Payment $payment)
Definition: Directpost.php:777
$payment
Definition: order.php:17
processPaymentFraudStatus(\Magento\Sales\Model\Order\Payment $payment)
Definition: Directpost.php:746

◆ processPaymentFraudStatus()

processPaymentFraudStatus ( \Magento\Sales\Model\Order\Payment  $payment)
protected

Process fraud status

Parameters
\Magento\Sales\Model\Order\Payment$payment
Returns
$this

Definition at line 746 of file Directpost.php.

747  {
748  try {
749  $fraudDetailsResponse = $payment->getMethodInstance()
750  ->fetchTransactionFraudDetails($this->getResponse()->getXTransId());
751  $fraudData = $fraudDetailsResponse->getData();
752 
753  if (empty($fraudData)) {
754  $payment->setIsFraudDetected(false);
755  return $this;
756  }
757 
758  $fdsFilterAction = (string)$fraudDetailsResponse->getFdsFilterAction();
759  if ($this->fdsFilterActionIsReportOnly($fdsFilterAction) === false) {
760  $payment->setIsFraudDetected(true);
761  }
762 
763  $payment->setAdditionalInformation('fraud_details', $fraudData);
764  } catch (\Exception $e) {
765  //this request is optional
766  }
767 
768  return $this;
769  }
$payment
Definition: order.php:17

◆ processRefund()

processRefund ( \Magento\Framework\DataObject  $payment,
  $amount 
)
protected

Refund the amount with transaction id

Parameters
\Magento\Framework\DataObject$payment
float$amount
Returns
$this
Exceptions

Definition at line 404 of file Directpost.php.

405  {
406  if ($amount <= 0) {
407  throw new \Magento\Framework\Exception\LocalizedException(__('Invalid amount for refund.'));
408  }
409 
410  if (!$payment->getParentTransactionId()) {
411  throw new \Magento\Framework\Exception\LocalizedException(__('Invalid transaction ID.'));
412  }
413 
414  $payment->setAnetTransType(self::REQUEST_TYPE_CREDIT);
415  $payment->setAmount($amount);
416  $payment->setXTransId($this->getRealParentTransactionId($payment));
417 
418  $request = $this->buildRequest($payment);
419  $result = $this->postRequest($request);
420 
421  switch ($result->getXResponseCode()) {
423  if ($result->getXResponseReasonCode() == self::RESPONSE_REASON_CODE_APPROVED) {
424  if ($result->getXTransId() != $payment->getParentTransactionId()) {
425  $payment->setTransactionId($result->getXTransId());
426  }
427  $payment->setIsTransactionClosed(true)
428  ->setTransactionAdditionalInfo(self::REAL_TRANSACTION_ID_KEY, $result->getXTransId());
429  return $this;
430  }
431  throw new \Magento\Framework\Exception\LocalizedException(
432  $this->dataHelper->wrapGatewayError($result->getXResponseReasonText())
433  );
436  throw new \Magento\Framework\Exception\LocalizedException(
437  $this->dataHelper->wrapGatewayError($result->getXResponseReasonText())
438  );
439  default:
440  throw new \Magento\Framework\Exception\LocalizedException(__('Payment refunding error.'));
441  }
442  }
__()
Definition: __.php:13
$amount
Definition: order.php:14
$payment
Definition: order.php:17

◆ refund()

refund ( \Magento\Payment\Model\InfoInterface  $payment,
  $amount 
)

Refund the amount Need to decode last 4 digits for request.

Parameters
\Magento\Framework\DataObject | \Magento\Payment\Model\InfoInterface$payment
float$amount
Returns
$this
Exceptions

Definition at line 382 of file Directpost.php.

383  {
384  $last4 = $payment->getCcLast4();
385  $payment->setCcLast4($payment->decrypt($last4));
386  try {
387  $this->processRefund($payment, $amount);
388  } catch (\Exception $e) {
389  $payment->setCcLast4($last4);
390  throw $e;
391  }
392  $payment->setCcLast4($last4);
393  return $this;
394  }
processRefund(\Magento\Framework\DataObject $payment, $amount)
Definition: Directpost.php:404
$amount
Definition: order.php:14
$payment
Definition: order.php:17

◆ setDataHelper()

setDataHelper ( \Magento\Authorizenet\Helper\Data  $dataHelper)

Set data helper

Parameters
\Magento\Authorizenet\Helper\Data$dataHelper
Returns
void

Definition at line 223 of file Directpost.php.

224  {
225  $this->dataHelper = $dataHelper;
226  }

◆ setIsInitializeNeeded()

setIsInitializeNeeded (   $isInitializeNeeded = true)

Set initialization requirement state

Parameters
bool$isInitializeNeeded
Returns
void

Definition at line 875 of file Directpost.php.

876  {
877  $this->_isInitializeNeeded = (bool)$isInitializeNeeded;
878  }

◆ setMethodCode()

setMethodCode (   $methodCode)

Sets method code

Parameters
string$methodCode@SuppressWarnings(PHPMD.UnusedFormalParameter)
Returns
void

Implements ConfigInterface.

Definition at line 962 of file Directpost.php.

963  {
964  }

◆ setPathPattern()

setPathPattern (   $pathPattern)

Sets path pattern

Parameters
string$pathPattern@SuppressWarnings(PHPMD.UnusedFormalParameter)
Returns
void

Implements ConfigInterface.

Definition at line 973 of file Directpost.php.

974  {
975  }

◆ setResponseData()

setResponseData ( array  $postData)

Fill response with data.

Parameters
array$postData
Returns
$this

Definition at line 532 of file Directpost.php.

533  {
534  $this->getResponse()->setData($postData);
535  return $this;
536  }

◆ validate()

validate ( )

Do not validate payment form using server methods

Returns
bool

Implements MethodInterface.

Definition at line 233 of file Directpost.php.

234  {
235  return true;
236  }

◆ validateResponse()

validateResponse ( )

Validate response data. Needed in controllers.

Returns
bool true in case of validation success.
Exceptions

Definition at line 544 of file Directpost.php.

545  {
546  $response = $this->getResponse();
547  //md5 check
548  if (!$this->getConfigData('trans_md5')
549  || !$this->getConfigData('login')
550  || !$response->isValidHash($this->getConfigData('trans_md5'), $this->getConfigData('login'))
551  ) {
552  throw new \Magento\Framework\Exception\LocalizedException(
553  __('The transaction was declined because the response hash validation failed.')
554  );
555  }
556  return true;
557  }
__()
Definition: __.php:13
getConfigData($field, $storeId=null)

◆ void()

Void the payment through gateway

Parameters
\Magento\Framework\DataObject | \Magento\Payment\Model\InfoInterface$payment
Returns
$this
Exceptions

Definition at line 337 of file Directpost.php.

338  {
339  if (!$payment->getParentTransactionId()) {
340  throw new \Magento\Framework\Exception\LocalizedException(__('Invalid transaction ID.'));
341  }
342 
343  $payment->setAnetTransType(self::REQUEST_TYPE_VOID);
344  $payment->setXTransId($this->getRealParentTransactionId($payment));
345 
346  $request = $this->buildRequest($payment);
347  $result = $this->postRequest($request);
348 
349  switch ($result->getXResponseCode()) {
351  if ($result->getXResponseReasonCode() == self::RESPONSE_REASON_CODE_APPROVED) {
352  if ($result->getXTransId() != $payment->getParentTransactionId()) {
353  $payment->setTransactionId($result->getXTransId());
354  }
355  $payment->setIsTransactionClosed(1)
356  ->setShouldCloseParentTransaction(1)
357  ->setTransactionAdditionalInfo(self::REAL_TRANSACTION_ID_KEY, $result->getXTransId());
358  return $this;
359  }
360  throw new \Magento\Framework\Exception\LocalizedException(
361  $this->dataHelper->wrapGatewayError($result->getXResponseReasonText())
362  );
365  throw new \Magento\Framework\Exception\LocalizedException(
366  $this->dataHelper->wrapGatewayError($result->getXResponseReasonText())
367  );
368  default:
369  throw new \Magento\Framework\Exception\LocalizedException(__('Payment voiding error.'));
370  }
371  }
__()
Definition: __.php:13
$payment
Definition: order.php:17

Field Documentation

◆ $_canAuthorize

$_canAuthorize = true
protected

Definition at line 44 of file Directpost.php.

◆ $_canCapture

$_canCapture = true
protected

Definition at line 51 of file Directpost.php.

◆ $_canFetchTransactionInfo

$_canFetchTransactionInfo = true
protected

Definition at line 79 of file Directpost.php.

◆ $_canRefund

$_canRefund = true
protected

Definition at line 58 of file Directpost.php.

◆ $_canRefundInvoicePartial

$_canRefundInvoicePartial = true
protected

Definition at line 65 of file Directpost.php.

◆ $_canVoid

$_canVoid = true
protected

Definition at line 72 of file Directpost.php.

◆ $_formBlockType

$_formBlockType = \Magento\Payment\Block\Transparent\Info::class
protected

Definition at line 25 of file Directpost.php.

◆ $_infoBlockType

$_infoBlockType = \Magento\Payment\Block\Info::class
protected

Definition at line 30 of file Directpost.php.

◆ $_isGateway

$_isGateway = true
protected

Definition at line 37 of file Directpost.php.

◆ $_isInitializeNeeded

$_isInitializeNeeded = true
protected

Definition at line 86 of file Directpost.php.

◆ $orderFactory

$orderFactory
protected

Definition at line 113 of file Directpost.php.

◆ $orderSender

$orderSender
protected

Definition at line 106 of file Directpost.php.

◆ $quoteRepository

$quoteRepository
protected

Definition at line 96 of file Directpost.php.

◆ $response

$response
protected

Definition at line 101 of file Directpost.php.

◆ $storeManager

$storeManager
protected

Definition at line 91 of file Directpost.php.

◆ $transactionRepository

$transactionRepository
protected

Definition at line 118 of file Directpost.php.

◆ METHOD_CODE

const METHOD_CODE = 'authorizenet_directpost'

Definition at line 20 of file Directpost.php.


The documentation for this class was generated from the following file: