72 'VERSION' =>
'version',
73 'USER' =>
'api_username',
74 'PWD' =>
'api_password',
75 'SIGNATURE' =>
'api_signature',
76 'BUTTONSOURCE' =>
'build_notation_code',
79 'SUBJECT' =>
'business_account',
82 'PAYMENTACTION' =>
'payment_action',
83 'RETURNURL' =>
'return_url',
84 'CANCELURL' =>
'cancel_url',
85 'INVNUM' =>
'inv_num',
87 'CORRELATIONID' =>
'correlation_id',
88 'SOLUTIONTYPE' =>
'solution_type',
89 'GIROPAYCANCELURL' =>
'giropay_cancel_url',
90 'GIROPAYSUCCESSURL' =>
'giropay_success_url',
91 'BANKTXNPENDINGURL' =>
'giropay_bank_txn_pending_url',
92 'IPADDRESS' =>
'ip_address',
93 'NOTIFYURL' =>
'notify_url',
94 'RETURNFMFDETAILS' =>
'fraud_management_filters_enabled',
96 'REFUNDTYPE' =>
'refund_type',
98 'REDIRECTREQUIRED' =>
'redirect_required',
99 'SUCCESSPAGEREDIRECTREQUESTED' =>
'redirect_requested',
100 'REQBILLINGADDRESS' =>
'require_billing_address',
102 'PAGESTYLE' =>
'page_style',
103 'HDRIMG' =>
'hdrimg',
104 'HDRBORDERCOLOR' =>
'hdrbordercolor',
105 'HDRBACKCOLOR' =>
'hdrbackcolor',
106 'PAYFLOWCOLOR' =>
'payflowcolor',
107 'LOCALECODE' =>
'locale_code',
109 'USERSELECTEDFUNDINGSOURCE' =>
'funding_source',
112 'TRANSACTIONID' =>
'transaction_id',
113 'AUTHORIZATIONID' =>
'authorization_id',
114 'REFUNDTRANSACTIONID' =>
'refund_transaction_id',
115 'COMPLETETYPE' =>
'complete_type',
117 'ITEMAMT' =>
'subtotal_amount',
118 'GROSSREFUNDAMT' =>
'refunded_amount',
121 'CURRENCYCODE' =>
'currency_code',
122 'PAYMENTSTATUS' =>
'payment_status',
123 'PENDINGREASON' =>
'pending_reason',
124 'PROTECTIONELIGIBILITY' =>
'protection_eligibility',
125 'PAYERID' =>
'payer_id',
126 'PAYERSTATUS' =>
'payer_status',
127 'ADDRESSID' =>
'address_id',
128 'ADDRESSSTATUS' =>
'address_status',
132 'FIRSTNAME' =>
'firstname',
133 'LASTNAME' =>
'lastname',
136 'SHIPPINGOPTIONNAME' =>
'shipping_rate_code',
137 'NOSHIPPING' =>
'suppress_shipping',
140 'CREDITCARDTYPE' =>
'credit_card_type',
141 'ACCT' =>
'credit_card_number',
142 'EXPDATE' =>
'credit_card_expiration_date',
143 'CVV2' =>
'credit_card_cvv2',
144 'STARTDATE' =>
'maestro_solo_issue_date',
145 'ISSUENUMBER' =>
'maestro_solo_issue_number',
146 'CVV2MATCH' =>
'cvv2_check_result',
147 'AVSCODE' =>
'avs_result',
149 'SHIPPINGAMT' =>
'shipping_amount',
150 'TAXAMT' =>
'tax_amount',
151 'INITAMT' =>
'init_amount',
152 'STATUS' =>
'status',
155 'TAXID' =>
'buyer_tax_id',
156 'TAXIDTYPE' =>
'buyer_tax_id_type',
158 'BILLINGAGREEMENTID' =>
'billing_agreement_id',
159 'REFERENCEID' =>
'reference_id',
160 'BILLINGAGREEMENTSTATUS' =>
'billing_agreement_status',
161 'BILLINGTYPE' =>
'billing_type',
165 'COUNTRYCODE' =>
'countrycode',
167 'PAYERBUSINESS' =>
'payer_business',
176 'AMT' =>
'formatPrice',
177 'ITEMAMT' =>
'formatPrice',
178 'TRIALAMT' =>
'formatPrice',
179 'SHIPPINGAMT' =>
'formatPrice',
180 'TAXAMT' =>
'formatPrice',
181 'INITAMT' =>
'formatPrice',
182 'CREDITCARDTYPE' =>
'_filterCcType',
183 'AUTOBILLAMT' =>
'_filterBillFailedLater',
184 'BILLINGPERIOD' =>
'_filterPeriodUnit',
185 'TRIALBILLINGPERIOD' =>
'_filterPeriodUnit',
186 'FAILEDINITAMTACTION' =>
'_filterInitialAmountMayFail',
187 'BILLINGAGREEMENTSTATUS' =>
'_filterBillingAgreementStatus',
188 'NOSHIPPING' =>
'_filterInt',
197 'REDIRECTREQUIRED' =>
'_filterToBool',
198 'SUCCESSPAGEREDIRECTREQUESTED' =>
'_filterToBool',
199 'PAYMENTSTATUS' =>
'_filterPaymentStatusFromNvpToInfo',
238 'USERSELECTEDFUNDINGSOURCE',
349 'PROTECTIONELIGIBILITY',
357 protected $_doCaptureRequest = [
'AUTHORIZATIONID',
'COMPLETETYPE',
'AMT',
'CURRENCYCODE',
'NOTE',
'INVNUM'];
364 protected $_doCaptureResponse = [
'TRANSACTIONID',
'CURRENCYCODE',
'AMT',
'PAYMENTSTATUS',
'PENDINGREASON'];
404 'PARENTTRANSACTIONID',
452 'BUSINESS' =>
'company',
453 'NOTETEXT' =>
'customer_notes',
455 'FIRSTNAME' =>
'firstname',
456 'LASTNAME' =>
'lastname',
457 'MIDDLENAME' =>
'middlename',
458 'SALUTATION' =>
'prefix',
459 'SUFFIX' =>
'suffix',
460 'COUNTRYCODE' =>
'country_id',
463 'STREET' =>
'street',
464 'STREET2' =>
'street2',
466 'PHONENUM' =>
'telephone',
482 'SHIPTOCOUNTRYCODE' =>
'country_id',
483 'SHIPTOSTATE' =>
'region',
484 'SHIPTOCITY' =>
'city',
485 'SHIPTOSTREET' =>
'street',
486 'SHIPTOSTREET2' =>
'street2',
487 'SHIPTOZIP' =>
'postcode',
488 'SHIPTOPHONENUM' =>
'telephone',
497 'SHIPTOCOUNTRY' =>
'country_id',
498 'SHIPTOSTATE' =>
'region',
499 'SHIPTOCITY' =>
'city',
500 'SHIPTOSTREET' =>
'street',
501 'SHIPTOSTREET2' =>
'street2',
502 'SHIPTOZIP' =>
'postcode',
517 'PROTECTIONELIGIBILITY',
519 'SHIPPINGOPTIONNAME',
539 'id' =>
'L_NUMBER%d',
540 'name' =>
'L_NAME%d',
542 'amount' =>
'L_AMT%d',
550 'is_default' =>
'L_SHIPPINGOPTIONISDEFAULT%d',
551 'amount' =>
'L_SHIPPINGOPTIONAMOUNT%d',
552 'code' =>
'L_SHIPPINGOPTIONNAME%d',
553 'name' =>
'L_SHIPPINGOPTIONLABEL%d',
554 'tax_amount' =>
'L_TAXAMT%d',
612 'BILLINGAGREEMENTDESCRIPTION',
613 'BILLINGAGREEMENTSTATUS',
614 'BILLINGAGREEMENTCUSTOM',
624 'BILLINGAGREEMENTDESCRIPTION',
625 'BILLINGAGREEMENTSTATUS',
626 'BILLINGAGREEMENTCUSTOM',
677 'MC' =>
'MasterCard',
757 \
Magento\Directory\Model\RegionFactory $regionFactory,
758 \
Magento\Directory\Model\CountryFactory $countryFactory,
759 \
Magento\Paypal\Model\Api\ProcessableExceptionFactory $processableExceptionFactory,
760 \
Magento\Framework\
Exception\LocalizedExceptionFactory $frameworkExceptionFactory,
761 \
Magento\Framework\HTTP\Adapter\CurlFactory $curlFactory,
765 $this->_countryFactory = $countryFactory;
766 $this->_processableExceptionFactory = $processableExceptionFactory;
767 $this->_frameworkExceptionFactory = $frameworkExceptionFactory;
768 $this->_curlFactory = $curlFactory;
779 return sprintf(
$url, $this->_config->getValue(
'sandboxFlag') ?
'.sandbox' :
'');
799 return 'MerchantInitiatedBilling';
817 $options = $this->getShippingOptions();
818 if ($this->getAddress()) {
823 $request[
'CALLBACK'] = $this->getShippingOptionsCallbackUrl();
862 if ($this->getAddress()) {
882 if ($this->getAddress()) {
911 return in_array(11610, $this->_callWarnings);
992 $request[
'AMT'] = $this->formatPrice($this->getAmount());
1076 if (in_array(10201, $this->_callErrors)) {
1077 $this->setIsBillingAgreementAlreadyCancelled(
true);
1092 $address = new \Magento\Framework\DataObject();
1093 \Magento\Framework\DataObject\Mapper::accumulateByMap(
$request,
$address, $this->_callbackRequestMap);
1094 $address->setExportedKeys(array_values($this->_callbackRequestMap));
1108 $response[
'NO_SHIPPING_OPTION_DETAILS'] =
'1';
1137 $pos = strpos($key,
'[');
1139 if (
$pos ===
false) {
1146 $modifiedKey = substr($key, 0,
$pos);
1168 $key = array_search(
'SIGNATURE', $eachCallRequest);
1170 unset($eachCallRequest[$key]);
1177 $http = $this->_curlFactory->create();
1178 $config = [
'timeout' => 60,
'verifypeer' => $this->_config->getValue(
'verifyPeer')];
1195 $debugData[
'http_error'] = [
'error' => $e->getMessage(),
'code' => $e->getCode()];
1196 $this->
_debug($debugData);
1205 $this->
_debug($debugData);
1210 if ($http->getErrno()) {
1211 $this->_logger->critical(
1213 sprintf(
'PayPal NVP CURL connection error #%s: %s', $http->getErrno(), $http->getError())
1218 throw new \Magento\Framework\Exception\LocalizedException(
1219 __(
'Payment Gateway is unreachable at the moment. Please use another payment option.')
1227 $this->_logger->critical(
new \
Exception(
__(
'PayPal response hasn\'t required fields.')));
1228 throw new \Magento\Framework\Exception\LocalizedException(
1229 __(
'Something went wrong while processing your order.')
1233 $this->_callErrors = [];
1235 if ($this->_rawResponseNeeded) {
1236 $this->setRawSuccessResponseData(
$response);
1252 $this->_rawResponseNeeded = $flag;
1264 protected function _handleCallErrors(
$response)
1271 $errorMessages = [];
1273 $errorMessages[] = $error[
'message'];
1274 $this->_callErrors[] = $error[
'code'];
1276 $errorMessages = implode(
' ', $errorMessages);
1278 $exceptionLogMessage = sprintf(
1279 'PayPal NVP gateway errors: %s Correlation ID: %s. Version: %s.',
1284 $this->_logger->critical($exceptionLogMessage);
1295 $exceptionPhrase =
__(
'PayPal gateway has rejected request. %1', $errorMessages);
1298 $firstError =
$errors[0][
'code'];
1300 ? $this->_processableExceptionFactory->create(
1301 [
'phrase' => $exceptionPhrase,
'code' => $firstError]
1303 : $this->_frameworkExceptionFactory->create(
1304 [
'phrase' => $exceptionPhrase]
1320 $longErrorMessage = preg_replace(
'/\.$/',
'', $longErrorMessage);
1321 $shortErrorMessage = preg_replace(
'/\.$/',
'', $shortErrorMessage);
1323 return $longErrorMessage ? sprintf(
'%s (#%s: %s).', $longErrorMessage, $errorCode, $shortErrorMessage)
1324 : sprintf(
'#%s: %s.', $errorCode, $shortErrorMessage);
1335 $processableErrorsList = $this->getProcessableErrors();
1337 if (!$processableErrorsList || !is_array($processableErrorsList)) {
1341 return in_array($errorCode, $processableErrorsList);
1355 $errorCode =
$response[
"L_ERRORCODE{$i}"];
1362 'code' => $errorCode,
1363 'message' => $errorMessage,
1383 $this->_callWarnings = [];
1384 if ($ack ==
'SUCCESS' || $ack ==
'SUCCESSWITHWARNING') {
1386 if ($ack ==
'SUCCESSWITHWARNING') {
1388 $this->_callWarnings[] =
$response[
"L_ERRORCODE{$i}"];
1405 if (isset($this->_requiredResponseParams[
$method])) {
1406 foreach ($this->_requiredResponseParams[
$method] as $param) {
1425 $nvpstr = strpos($nvpstr,
"\r\n\r\n") !==
false ? substr($nvpstr, strpos($nvpstr,
"\r\n\r\n") + 4) : $nvpstr;
1427 while (strlen($nvpstr)) {
1429 $keypos = strpos($nvpstr,
'=');
1431 $valuepos = strpos($nvpstr,
'&') ? strpos($nvpstr,
'&') : strlen($nvpstr);
1434 $keyval = substr($nvpstr, $intial, $keypos);
1435 $valval = substr($nvpstr, $keypos + 1, $valuepos - $keypos - 1);
1437 $nvpArray[urldecode($keyval)] = urldecode($valval);
1438 $nvpstr = substr($nvpstr, $valuepos + 1, strlen($nvpstr));
1452 if (!$this->_cart) {
1455 $this->_cart->setTransferDiscountAsItem();
1456 return parent::_exportLineItems(
$request,
$i);
1480 $address = new \Magento\Framework\DataObject();
1481 \Magento\Framework\DataObject\Mapper::accumulateByMap(
$data,
$address, $this->_billingAddressMap);
1482 $address->setExportedKeys(array_values($this->_billingAddressMap));
1484 $this->setExportedBillingAddress(
$address);
1486 if (isset(
$data[
'SHIPTONAME'])) {
1488 \Magento\Framework\DataObject\Mapper::accumulateByMap(
$data,
$shippingAddress, $this->_shippingAddressMap);
1505 if (
$address->getData(
'street2') !==
null) {
1511 $regions = $this->_countryFactory->create()->loadByCode(
1513 )->getRegionCollection()->addRegionCodeOrNameFilter(
1518 foreach ($regions as $region) {
1519 $address->setRegionId($region->getId());
1520 $address->setExportedKeys(array_merge(
$address->getExportedKeys(), [
'region_id']));
1534 $billingAddress = $this->getBillingAddress() ? $this->getBillingAddress() : $this->getAddress();
1537 $to = \Magento\Framework\DataObject\Mapper::accumulateByMap(
1540 array_merge(array_flip($this->_billingAddressMap), $this->_billingAddressMapRequest)
1544 $to[
'STATE'] = $regionCode;
1546 if (!$this->getSuppressShipping()) {
1547 $to = \Magento\Framework\DataObject\Mapper::accumulateByMap(
1550 array_flip($this->_shippingAddressMap)
1554 $to[
'SHIPTOSTATE'] = $regionCode;
1571 if (isset($this->_supportedCcTypes[
$value])) {
1572 return $this->_supportedCcTypes[
$value];
1601 return $value ?
'AddToNextBilling' :
'NoAutoBill';
1636 return $value ?
'ContinueOnFailure' :
'CancelOnFailure';
1668 return \Magento\Paypal\Model\Info::PAYMENTSTATUS_NONE;
1670 return \Magento\Paypal\Model\Info::PAYMENTSTATUS_COMPLETED;
1672 return \Magento\Paypal\Model\Info::PAYMENTSTATUS_DENIED;
1674 return \Magento\Paypal\Model\Info::PAYMENTSTATUS_EXPIRED;
1676 return \Magento\Paypal\Model\Info::PAYMENTSTATUS_FAILED;
1678 return \Magento\Paypal\Model\Info::PAYMENTSTATUS_INPROGRESS;
1680 return \Magento\Paypal\Model\Info::PAYMENTSTATUS_PENDING;
1682 return \Magento\Paypal\Model\Info::PAYMENTSTATUS_REFUNDED;
1683 case 'Partially-Refunded':
1684 return \Magento\Paypal\Model\Info::PAYMENTSTATUS_REFUNDEDPART;
1686 return \Magento\Paypal\Model\Info::PAYMENTSTATUS_REVERSED;
1687 case 'Canceled-Reversal':
1688 return \Magento\Paypal\Model\Info::PAYMENTSTATUS_UNREVERSED;
1690 return \Magento\Paypal\Model\Info::PAYMENTSTATUS_PROCESSED;
1692 return \Magento\Paypal\Model\Info::PAYMENTSTATUS_VOIDED;
1707 case \Magento\Paypal\Model\Pro::PAYMENT_REVIEW_ACCEPT:
1709 case \Magento\Paypal\Model\Pro::PAYMENT_REVIEW_DENY:
1734 $expressCheckoutMethods = [
1739 if (!in_array($methodName, $expressCheckoutMethods) || !$this->_config->shouldUseUnilateralPayments()) {
1742 return array_diff($this->_eachCallRequest, [
'USER',
'PWD',
'SIGNATURE']);
1753 if (!$this->_config->shouldUseUnilateralPayments()) {
1754 $key = array_search(
'SUBJECT', $requestFields);
1756 unset($requestFields[$key]);
_exportShippingOptions(array &$request, $i=0)
callDoExpressCheckoutPayment()
callUpdateBillingAgreement()
$_getExpressCheckoutDetailsRequest
$_refundTransactionResponse
$_createBillingAgreementRequest
prepareShippingOptionsCallbackAddress(array $request)
$_getTransactionDetailsResponse
_exportLineItems(array &$request, $i=0)
$_doExpressCheckoutPaymentRequest
elseif(isset( $params[ 'redirect_parent']))
$_managePendingTransactionStatusResponse
$_doReauthorizationResponse
_filterBillingAgreementStatus($value)
$_customerBillingAgreementRequest
_extractErrorsFromResponse($response)
_lookupRegionCodeFromAddress(\Magento\Framework\DataObject $address)
$_billingAddressMapRequest
_isProcessableError($errorCode)
& _exportToRequest(array $privateRequestMap, array $request=[])
const PENDING_TRANSACTION_ACCEPT
$_billingAgreementCustomerDetailsRequest
$_doReauthorizationRequest
const API_TRANSACTION_HAS_BEEN_COMPLETED
_prepareExpressCheckoutCallRequest(&$requestFields)
$_managePendingTransactionStatusRequest
_applyStreetAndRegionWorkarounds(\Magento\Framework\DataObject $address)
_importStreetFromAddress(\Magento\Framework\DataObject $address, array &$to)
_filterPaymentStatusFromNvpToInfo($value)
_validateResponse($method, $response)
$_doReferenceTransactionResponse
_postProcessResponse($response)
$_doDirectPaymentResponse
$_shippingOptionsExportItemsFormat
$_doAuthorizationResponse
callCreateBillingAgreement()
callGetTransactionDetails()
$_paymentInformationResponse
_formatErrorMessage($errorCode, $shortErrorMessage, $longErrorMessage)
$_updateBillingAgreementRequest
const DO_EXPRESS_CHECKOUT_PAYMENT
_prepareEachCallRequest($methodName)
_importAddresses(array $to)
_addMethodToRequest($methodName, $request)
$_setExpressCheckoutRequest
callManagePendingTransactionStatus()
$_frameworkExceptionFactory
$_updateBillingAgreementResponse
$_refundTransactionRequest
_filterPeriodUnit($value)
_importFromResponse(array $privateResponseMap, array $response)
callGetBillingAgreementCustomerDetails()
const GET_EXPRESS_CHECKOUT_DETAILS
const REFUND_TYPE_PARTIAL
_getCaptureCompleteType()
call($methodName, array $request)
$_customerBillingAgreementResponse
$_getTransactionDetailsRequest
$_processableExceptionFactory
_filterPaymentReviewAction($value)
callDoReferenceTransaction()
_filterInitialAmountMayFail($value)
$_billingAgreementCustomerDetailsResponse
$_doReferenceTransactionRequest
_isCallSuccessful($response)
callGetExpressCheckoutDetails()
getBillingAgreementType()
$_lineItemExportItemsFormat
formatShippingOptionsCallback()
const PENDING_TRANSACTION_DENY
__construct(\Magento\Customer\Helper\Address $customerAddress, \Psr\Log\LoggerInterface $logger, Logger $customLogger, \Magento\Framework\Locale\ResolverInterface $localeResolver, \Magento\Directory\Model\RegionFactory $regionFactory, \Magento\Directory\Model\CountryFactory $countryFactory, \Magento\Paypal\Model\Api\ProcessableExceptionFactory $processableExceptionFactory, \Magento\Framework\Exception\LocalizedExceptionFactory $frameworkExceptionFactory, \Magento\Framework\HTTP\Adapter\CurlFactory $curlFactory, array $data=[])
_filterBillFailedLater($value)
$_doExpressCheckoutPaymentResponse
callSetCustomerBillingAgreement()
const SET_EXPRESS_CHECKOUT
$_createBillingAgreementResponse
$_importFromRequestFilters
$_setExpressCheckoutResponse
setRawResponseNeeded($flag)
$_debugReplacePrivateDataKeys
getUseCertAuthentication()