11 use Magento\Payment\Helper\Formatter;
14 use Magento\Payment\Model\Method\ConfigInterfaceFactory;
92 'firstname' =>
'billtofirstname',
93 'lastname' =>
'billtolastname',
94 'address' =>
'billtostreet',
95 'city' =>
'billtocity',
96 'state' =>
'billtostate',
98 'country' =>
'billtocountry',
99 'phone' =>
'billtophone',
100 'email' =>
'billtoemail',
101 'nametoship' =>
'shiptofirstname',
102 'addresstoship' =>
'shiptostreet',
103 'citytoship' =>
'shiptocity',
104 'statetoship' =>
'shiptostate',
105 'ziptoship' =>
'shiptozip',
106 'countrytoship' =>
'shiptocountry',
107 'phonetoship' =>
'shiptophone',
108 'emailtoship' =>
'shiptoemail',
109 'faxtoship' =>
'shiptofax',
110 'method' =>
'tender',
111 'cscmatch' =>
'cvv2match',
114 'ccavsstatus' =>
'avsdata',
116 'transtime' =>
'transtime',
117 'expdate' =>
'expdate',
118 'securetoken' =>
'securetoken',
119 'securetokenid' =>
'securetokenid',
120 'authcode' =>
'authcode',
121 'hostcode' =>
'hostcode',
123 'cc_type' =>
'cardtype' 132 private $ccTypeMap = [
276 private $errorHandler;
305 \
Magento\Framework\Module\ModuleListInterface $moduleList,
306 \
Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate,
317 $this->gateway = $gateway;
322 $customAttributeFactory,
332 $this->errorHandler = $errorHandler;
344 return parent::isAvailable(
$quote) && $this->
getConfig()->isMethodAvailable($this->getCode());
369 return $this->
getConfig()->getPaymentAction();
385 $request->setTrxtype(self::TRXTYPE_AUTH_ONLY);
400 $infoInstance = $this->getInfoInstance();
402 $authorizedAmount = $infoInstance->getAmountAuthorized();
403 return abs($amountToPay - $authorizedAmount) < 0.00001 ? 0 : $amountToPay;
417 if (
$payment->getAdditionalInformation(self::PNREF)) {
418 $request = $this->buildBasicRequest();
420 $request->setTrxtype(self::TRXTYPE_SALE);
422 $payment->unsAdditionalInformation(self::PNREF);
424 $request = $this->buildBasicRequest();
427 if ($captureAmount) {
428 $request->setAmt($this->formatPrice($captureAmount));
434 $request->setTrxtype(self::TRXTYPE_SALE);
454 $request = $this->buildBasicRequest();
455 $request->setTrxtype(self::TRXTYPE_DELAYED_VOID);
461 $payment->setTransactionId(
463 )->setIsTransactionClosed(
465 )->setShouldCloseParentTransaction(
480 if ($this->getInfoInstance()->getAmountPaid()) {
481 $this->_canVoid =
false;
495 if (!
$payment->getOrder()->getInvoiceCollection()->count()) {
496 return $this->
void($payment);
513 $request = $this->buildBasicRequest();
514 $request->setTrxtype(self::TRXTYPE_CREDIT);
521 $payment->setTransactionId(
$response->getPnref())->setIsTransactionClosed(
true);
540 $payment->setTransactionId(
$response->getOrigpnref())->setIsTransactionClosed(0);
542 $payment->setIsTransactionApproved(
true);
544 $payment->setIsTransactionDenied(
true);
549 return $rawData ? $rawData : [];
560 if (in_array(
$status, [self::RESPONSE_CODE_APPROVED, self::RESPONSE_CODE_DECLINED_BY_MERCHANT])) {
573 if (!$this->config) {
574 $storeId = $this->storeManager->getStore($this->getStore())->getId();
576 $this->config = $this->configFactory->create();
578 $this->config->setStoreId(
$storeId);
579 $this->config->setMethodInstance($this);
580 $this->config->setMethod($this);
583 return $this->config;
595 __(
'Payment Gateway is unreachable at the moment. Please use another payment option.'),
610 $request = $this->buildBasicRequest();
627 public function buildBasicRequest()
634 $request->setUser($this->getConfigData(
'user'));
635 $request->setVendor($this->getConfigData(
'vendor'));
636 $request->setPartner($this->getConfigData(
'partner'));
637 $request->setPwd($this->getConfigData(
'pwd'));
638 $request->setVerbosity($this->getConfigData(
'verbosity'));
639 $request->setData(
'BUTTONSOURCE', $config->getBuildNotationCode());
640 $request->setTender(self::TENDER_CC);
656 throw new \Magento\Framework\Exception\State\InvalidTransitionException(
657 __(
"The verification transaction can't be voided. ")
659 }
elseif (
$response->getResultCode() != self::RESPONSE_CODE_APPROVED &&
662 throw new \Magento\Payment\Gateway\Command\CommandException(
__(
$response->getRespmsg()));
664 throw new \Magento\Payment\Gateway\Command\CommandException(
__(
$response->getRespmsg()));
676 return $this->
reviewPayment($payment, self::UPDATEACTION_APPROVED);
687 return $this->
reviewPayment($payment, self::UPDATEACTION_DECLINED_BY_MERCHANT);
699 $request = $this->buildBasicRequest();
701 $request->setTrxtype(self::TRXTYPE_ACCEPT_DENY);
702 $request->setOrigid($transactionId);
710 $payment->setTransactionId(
$response->getOrigpnref())->setIsTransactionClosed(0);
712 $payment->setIsTransactionApproved(
true);
714 $payment->setIsTransactionDenied(
true);
718 return ($rawData) ? $rawData : [];
730 $billing->getFirstname()
732 $billing->getLastname()
734 implode(
' ', $billing->getStreet())
738 $billing->getRegionCode()
740 $billing->getPostcode()
742 $billing->getCountryId()
756 $shipping->getFirstname()
757 )->setShiptolastname(
758 $shipping->getLastname()
760 implode(
' ', $shipping->getStreet())
764 $shipping->getRegionCode()
766 $shipping->getPostcode()
768 $shipping->getCountryId()
785 foreach ($this->_responseParamsMappings as $originKey => $key) {
793 $this->mapResponseAvsData(
801 $this->mapResponseBillToName(
809 $this->mapResponseCreditCardType(
837 $payment->setIsTransactionPending(
true);
841 throw new \Magento\Framework\Exception\LocalizedException(
857 $billing =
$order->getBillingAddress();
858 if (!empty($billing)) {
862 $shipping =
$order->getShippingAddress();
863 if (!empty($shipping)) {
883 $orderIncrementId =
$order->getIncrementId();
884 $request->setCustref($orderIncrementId)
885 ->setInvnum($orderIncrementId)
886 ->setComment1($orderIncrementId);
898 $this->_eventManager->dispatch(
899 'payment_method_assign_data_' . $this->getCode(),
907 $this->_eventManager->dispatch(
908 'payment_method_assign_data',
927 $request = $this->buildBasicRequest();
928 $request->setTrxtype(self::TRXTYPE_DELAYED_INQUIRY);
929 $transactionId =
$payment->getCcTransId() ?
$payment->getCcTransId() : $transactionId;
930 $request->setOrigid($transactionId);
943 private function mapResponseAvsData($avsAddr, $avsZip)
945 return isset($avsAddr, $avsZip) ? $avsAddr . $avsZip :
null;
955 private function mapResponseBillToName($billToFirstName, $billToLastName)
957 return isset($billToFirstName, $billToLastName)
958 ? implode(
' ', [$billToFirstName, $billToLastName])
968 private function mapResponseCreditCardType(
$ccType)
const TRXTYPE_DELAYED_VOICE
const RESPONSE_CODE_VOID_ERROR
fetchTransactionInfo(InfoInterface $payment, $transactionId)
assignData(DataObject $data)
const UPDATEACTION_DECLINED_BY_MERCHANT
elseif(isset( $params[ 'redirect_parent']))
capture(\Magento\Payment\Model\InfoInterface $payment, $amount)
denyPayment(InfoInterface $payment)
setAdditionalInformation($key, $value=null)
_getCaptureAmount($amount)
mapGatewayResponse(array $postData, DataObject $response)
reviewPayment(InfoInterface $payment, $action)
cancel(\Magento\Payment\Model\InfoInterface $payment)
const TRANSACTION_URL_TEST_MODE
fillCustomerContacts(DataObject $order, DataObject $request)
transactionInquiryRequest(InfoInterface $payment, $transactionId)
authorize(\Magento\Payment\Model\InfoInterface $payment, $amount)
const UPDATEACTION_APPROVED
static _isTransactionUnderReview($status)
setBilling(DataObject $request, $billing)
const TRXTYPE_DELAYED_CAPTURE
addRequestOrderInfo(DataObject $request, Order $order)
$_canFetchTransactionInfo
refund(\Magento\Payment\Model\InfoInterface $payment, $amount)
acceptPayment(InfoInterface $payment)
const RESPONSE_CODE_DECLINED_BY_MERCHANT
$_debugReplacePrivateDataKeys
$_canRefundInvoicePartial
void(\Magento\Payment\Model\InfoInterface $payment)
processErrors(DataObject $response)
_buildPlaceRequest(DataObject $payment, $amount)
postRequest(DataObject $request, ConfigInterface $config)
const RESPONSE_CODE_DECLINED_BY_FILTER
const RESPONSE_CODE_APPROVED
const RESPONSE_CODE_DECLINED
const RESPONSE_CODE_CAPTURE_ERROR
const TRXTYPE_DELAYED_VOID
isAvailable(\Magento\Quote\Api\Data\CartInterface $quote=null)
const RESPONSE_CODE_INVALID_AMOUNT
setShipping($request, $shipping)
const RESPONSE_CODE_FRAUDSERVICE_FILTER
setTransStatus($payment, $response)
__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\Store\Model\StoreManagerInterface $storeManager, ConfigInterfaceFactory $configFactory, Gateway $gateway, HandlerInterface $errorHandler, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[])
const TRXTYPE_ACCEPT_DENY
const TRXTYPE_DELAYED_INQUIRY