211 ProFactory $proFactory,
214 \
Magento\Paypal\Model\CartFactory $cartFactory,
215 \
Magento\Checkout\Model\Session $checkoutSession,
236 $this->_urlBuilder = $urlBuilder;
237 $this->_cartFactory = $cartFactory;
238 $this->_checkoutSession = $checkoutSession;
239 $this->_exception = $exception;
243 $proInstance = array_shift(
$data);
244 if ($proInstance && $proInstance instanceof \
Magento\Paypal\Model\
Pro) {
245 $this->_pro = $proInstance;
247 $this->_pro = $proFactory->create();
249 $this->_pro->setMethod($this->_code);
260 return $this->_pro->getApi()->setProcessableErrors(
262 ApiProcessableException::API_INTERNAL_ERROR,
263 ApiProcessableException::API_UNABLE_PROCESS_PAYMENT_ERROR_CODE,
264 ApiProcessableException::API_DO_EXPRESS_CHECKOUT_FAIL,
265 ApiProcessableException::API_UNABLE_TRANSACTION_COMPLETE,
266 ApiProcessableException::API_TRANSACTION_EXPIRED,
267 ApiProcessableException::API_MAX_PAYMENT_ATTEMPTS_EXCEEDED,
268 ApiProcessableException::API_COUNTRY_FILTER_DECLINE,
269 ApiProcessableException::API_MAXIMUM_AMOUNT_FILTER_DECLINE,
270 ApiProcessableException::API_OTHER_FILTER_DECLINE,
271 ApiProcessableException::API_ADDRESS_MATCH_FAIL,
287 $store = $this->_storeManager->getStore()->getId();
300 if ($this->_scopeConfig->isSetFlag(
301 'payment/hosted_pro/active',
303 ) && !$this->_scopeConfig->isSetFlag(
304 'payment/hosted_pro/display_ec',
310 return parent::canUseCheckout();
321 return $this->_pro->getConfig()->isCurrencyCodeSupported($currencyCode);
332 return $this->_pro->getConfig()->getPaymentAction();
342 return parent::isAvailable(
$quote) && $this->_pro->getConfig()->isMethodAvailable();
355 if (
'order_place_redirect_url' === $field) {
356 return $this->getOrderPlaceRedirectUrl();
358 return $this->_pro->getConfig()->getValue($field);
370 $paypalTransactionData = $this->_checkoutSession->getPaypalTransactionData();
371 if (!is_array($paypalTransactionData)) {
377 $payment->setAdditionalInformation($this->_isOrderPaymentActionKey,
true);
378 if (
$payment->getIsFraudDetected()) {
409 if (
$payment->getAdditionalInformation(
410 $this->_isOrderPaymentActionKey
411 ) && !
$payment->getVoidOnlyAuthorization()
414 if ($orderTransaction) {
415 $payment->setParentTransactionId($orderTransaction->getTxnId());
416 $payment->setTransactionId($orderTransaction->getTxnId() .
'-void');
434 $authorizationTransaction =
$payment->getAuthorizationTransaction();
435 $authorizationPeriod = abs(intval($this->
getConfigData(
'authorization_honor_period')));
436 $maxAuthorizationNumber = abs(intval($this->
getConfigData(
'child_authorization_number')));
437 $order = $payment->getOrder();
438 $isAuthorizationCreated =
false;
440 if (
$payment->getAdditionalInformation($this->_isOrderPaymentActionKey)) {
443 $authorizationTransaction,
448 $isCaptureFinal =
$payment->getShouldCloseParentTransaction();
449 $payment->setShouldCloseParentTransaction(
false);
450 $payment->setParentTransactionId($authorizationTransaction->getTxnId());
452 $payment->setVoidOnlyAuthorization(
true);
456 $payment->unsAuthorizationTransaction();
458 $payment->setShouldCloseParentTransaction($isCaptureFinal);
462 if ($authorizationTransaction->getIsClosed() || $voided) {
463 if (
$payment->getAdditionalInformation($this->_authorizationCountKey) > $maxAuthorizationNumber - 1) {
464 $this->_exception->create(
465 [
'phrase' =>
__(
'The maximum number of child authorizations is reached.')]
471 $this->_pro->importPaymentInfo($api,
$payment);
472 $payment->setTransactionId($api->getTransactionId());
473 $payment->setParentTransactionId($authorizationTransaction->getParentTxnId());
474 $payment->setIsTransactionClosed(
false);
476 $formatedPrice =
$order->getBaseCurrency()->formatTxt(
$amount);
478 if (
$payment->getIsTransactionPending()) {
480 'We\'ll authorize the amount of %1 as soon as the payment gateway approves it.',
484 $message =
__(
'The authorized amount is %1.', $formatedPrice);
489 ->setTransactionId(
$payment->getTransactionId())
494 $payment->setParentTransactionId($api->getTransactionId());
495 $isAuthorizationCreated =
true;
498 if (
$payment->getShouldCloseParentTransaction()) {
501 if ($orderTransaction) {
502 $orderTransaction->setIsClosed(
true);
503 $order->addRelatedObject($orderTransaction);
541 $this->
void($payment);
552 return parent::canReviewPayment() && $this->_pro->canReviewPayment($this->
getInfoInstance());
588 return $this->_urlBuilder->getUrl(
'paypal/express/start');
600 return $this->_pro->fetchTransactionInfo(
$payment, $transactionId);
608 return $this->_pro->getApi();
620 parent::assignData(
$data);
624 if (!is_array($additionalData)) {
628 foreach ($additionalData as $key =>
$value) {
630 if ($key === \
Magento\Framework\Api\ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY) {
651 $token =
$payment->getAdditionalInformation(ExpressCheckout::PAYMENT_INFO_TRANSPORT_TOKEN);
653 $cart = $this->_cartFactory->create([
'salesModel' =>
$order]);
655 $api = $this->
getApi()->setToken(
662 $this->_pro->getConfig()->getValue(
'paymentAction')
664 $this->_urlBuilder->getUrl(
'paypal/ipn/')
668 $order->getBaseCurrencyCode()
671 )->setIsLineItemsEnabled(
672 $this->_pro->getConfig()->getValue(
'lineItemsEnabled')
674 if (
$order->getIsVirtual()) {
675 $api->setAddress(
$order->getBillingAddress())->setSuppressShipping(
true);
677 $api->setAddress(
$order->getShippingAddress());
678 $api->setBillingAddress(
$order->getBillingAddress());
682 $api->callDoExpressCheckoutPayment();
698 $api->getTransactionId()
699 )->setIsTransactionClosed(
701 )->setAdditionalInformation(
702 ExpressCheckout::PAYMENT_INFO_TRANSPORT_REDIRECT,
703 $api->getRedirectRequired()
706 if ($api->getBillingAgreementId()) {
709 'billing_agreement_id' => $api->getBillingAgreementId(),
715 $this->_pro->importPaymentInfo($api,
$payment);
727 if (
$info->getAdditionalInformation($this->_isOrderPaymentActionKey)) {
729 if ($orderTransaction) {
730 $info->setParentTransactionId($orderTransaction->getTxnId());
745 $this->_pro->getConfig()->setStoreId(
$payment->getOrder()->getStore()->getId());
747 if (
$payment->getAdditionalInformation($this->_isOrderPaymentActionKey)) {
749 if ($orderTransaction->getIsClosed()) {
753 $orderValidPeriod = abs(intval($this->
getConfigData(
'order_valid_period')));
755 $dateCompass = new \DateTime($orderTransaction->getCreatedAt());
756 $dateCompass->modify(
'+' . $orderValidPeriod .
' days');
757 $currentDate = new \DateTime();
759 if ($currentDate > $dateCompass || $orderValidPeriod == 0) {
777 $apiData = $this->_pro->getApi()->getData();
778 foreach ($apiData as $k => $v) {
783 $this->_checkoutSession->setPaypalTransactionData($apiData);
784 $this->_pro->resetApi();
787 ->setCurrencyCode(
$payment->getOrder()->getBaseCurrencyCode())
788 ->setTransactionId($parentTransactionId)
789 ->callDoAuthorization();
792 $this->_authorizationCountKey,
793 $payment->getAdditionalInformation($this->_authorizationCountKey) + 1
808 $period = intval($period);
813 $transactionClosingDate = new \DateTime(
$transaction->getCreatedAt(), new \DateTimeZone(
'GMT'));
814 $transactionClosingDate->setTimezone(
new \DateTimeZone(
'US/Pacific'));
818 $transactionClosingDate->setTime(11, 49, 00);
819 $transactionClosingDate->modify(
'+' . $period .
' days');
821 $currentTime = new \DateTime(
null,
new \DateTimeZone(
'US/Pacific'));
823 if ($currentTime > $transactionClosingDate) {
854 return $this->transactionRepository->getByTransactionType(
cancel(\Magento\Payment\Model\InfoInterface $payment)
acceptPayment(\Magento\Payment\Model\InfoInterface $payment)
denyPayment(\Magento\Payment\Model\InfoInterface $payment)
order(\Magento\Payment\Model\InfoInterface $payment, $amount)
getOrderTransaction($payment)
_setApiProcessableErrors()
$_canFetchTransactionInfo
const PAYMENT_REVIEW_DENY
const KEY_ADDITIONAL_DATA
capture(\Magento\Payment\Model\InfoInterface $payment, $amount)
fetchTransactionInfo(\Magento\Payment\Model\InfoInterface $payment, $transactionId)
const PAYMENT_REVIEW_ACCEPT
_callDoAuthorize($amount, $payment, $parentTransactionId)
refund(\Magento\Payment\Model\InfoInterface $payment, $amount)
assignData(\Magento\Framework\DataObject $data)
authorize(\Magento\Payment\Model\InfoInterface $payment, $amount)
_placeOrder(Payment $payment, $amount)
isAvailable(\Magento\Quote\Api\Data\CartInterface $quote=null)
const ACTION_FLAG_INVOICE
void(\Magento\Payment\Model\InfoInterface $payment)
_importToPayment($api, $payment)
$_isOrderPaymentActionKey
setData($key, $value=null)
$_canRefundInvoicePartial
canUseForCurrency($currencyCode)
foreach( $_productCollection as $_product)() ?>" class $info
__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, ProFactory $proFactory, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Framework\UrlInterface $urlBuilder, \Magento\Paypal\Model\CartFactory $cartFactory, \Magento\Checkout\Model\Session $checkoutSession, \Magento\Framework\Exception\LocalizedExceptionFactory $exception, \Magento\Sales\Api\TransactionRepositoryInterface $transactionRepository, \Magento\Sales\Model\Order\Payment\Transaction\BuilderInterface $transactionBuilder, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[])
_isTransactionExpired(Transaction $transaction, $period)
getAdditionalInformation($key=null)
const METHOD_BILLING_AGREEMENT
getConfigData($field, $storeId=null)