Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions | Protected Attributes
Direct Class Reference
Inheritance diagram for Direct:
Hostedpro

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\Paypal\Model\ProFactory $proFactory, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Framework\UrlInterface $urlBuilder, \Magento\Framework\App\RequestInterface $requestHttp, \Magento\Paypal\Model\CartFactory $cartFactory, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[])
 
 setStore ($store)
 
 canUseForCurrency ($currencyCode)
 
 getConfigPaymentAction ()
 
 getAllowedCcTypes ()
 
 isAvailable (\Magento\Quote\Api\Data\CartInterface $quote=null)
 
 getConfigData ($field, $storeId=null)
 
 authorize (\Magento\Payment\Model\InfoInterface $payment, $amount)
 
 void (\Magento\Payment\Model\InfoInterface $payment)
 
 capture (\Magento\Payment\Model\InfoInterface $payment, $amount)
 
 refund (\Magento\Payment\Model\InfoInterface $payment, $amount)
 
 cancel (\Magento\Payment\Model\InfoInterface $payment)
 
 canReviewPayment ()
 
 acceptPayment (\Magento\Payment\Model\InfoInterface $payment)
 
 denyPayment (\Magento\Payment\Model\InfoInterface $payment)
 
 fetchTransactionInfo (\Magento\Payment\Model\InfoInterface $payment, $transactionId)
 
 canVoid ()
 

Protected Member Functions

 _placeOrder (Payment $payment, $amount)
 
 _getFormattedCcExpirationDate ($month, $year)
 
 _importResultToPayment ($api, $payment)
 

Protected Attributes

 $_code = \Magento\Paypal\Model\Config::METHOD_WPP_DIRECT
 
 $_infoBlockType = \Magento\Paypal\Block\Payment\Info::class
 
 $_isGateway = true
 
 $_canAuthorize = true
 
 $_canCapture = true
 
 $_canCapturePartial = true
 
 $_canRefund = true
 
 $_canRefundInvoicePartial = true
 
 $_canVoid = true
 
 $_canUseInternal = true
 
 $_canUseCheckout = true
 
 $_canSaveCc = false
 
 $_canFetchTransactionInfo = true
 
 $_canReviewPayment = true
 
 $_pro
 
 $_storeManager
 
 $_urlBuilder
 
 $_requestHttp
 
 $_cartFactory
 

Detailed Description

PayPal Direct Module @SuppressWarnings(PHPMD.TooManyFields) @SuppressWarnings(PHPMD.CouplingBetweenObjects)

Definition at line 16 of file Direct.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\Paypal\Model\ProFactory  $proFactory,
\Magento\Store\Model\StoreManagerInterface  $storeManager,
\Magento\Framework\UrlInterface  $urlBuilder,
\Magento\Framework\App\RequestInterface  $requestHttp,
\Magento\Paypal\Model\CartFactory  $cartFactory,
\Magento\Framework\Model\ResourceModel\AbstractResource  $resource = null,
\Magento\Framework\Data\Collection\AbstractDb  $resourceCollection = null,
array  $data = [] 
)
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
ProFactory$proFactory
\Magento\Store\Model\StoreManagerInterface$storeManager
\Magento\Framework\UrlInterface$urlBuilder
\Magento\Framework\App\RequestInterface$requestHttp
CartFactory$cartFactory
\Magento\Framework\Model\ResourceModel\AbstractResource$resource
\Magento\Framework\Data\Collection\AbstractDb$resourceCollection
array$data@SuppressWarnings(PHPMD.ExcessiveParameterList)

Definition at line 157 of file Direct.php.

175  {
176  parent::__construct(
177  $context,
178  $registry,
179  $extensionFactory,
180  $customAttributeFactory,
181  $paymentData,
182  $scopeConfig,
183  $logger,
184  $moduleList,
185  $localeDate,
186  $resource,
187  $resourceCollection,
188  $data
189  );
190  $this->_storeManager = $storeManager;
191  $this->_urlBuilder = $urlBuilder;
192  $this->_requestHttp = $requestHttp;
193  $this->_cartFactory = $cartFactory;
194 
195  $proInstance = array_shift($data);
196  if ($proInstance && $proInstance instanceof \Magento\Paypal\Model\Pro) {
197  $this->_pro = $proInstance;
198  } else {
199  $this->_pro = $proFactory->create();
200  }
201  $this->_pro->setMethod($this->_code);
202  }
$storeManager
$resource
Definition: bulk.php:12
$logger

Member Function Documentation

◆ _getFormattedCcExpirationDate()

_getFormattedCcExpirationDate (   $month,
  $year 
)
protected

Format credit card expiration date based on month and year values Format: mmyyyy

Parameters
string | int$month
string | int$year
Returns
string

Definition at line 477 of file Direct.php.

478  {
479  return sprintf('%02d%02d', $month, $year);
480  }

◆ _importResultToPayment()

_importResultToPayment (   $api,
  $payment 
)
protected

Import direct payment results to payment

Parameters
\Magento\Paypal\Model\Api\Nvp$api
Payment$payment
Returns
void

Definition at line 489 of file Direct.php.

490  {
491  $payment->setTransactionId($api->getTransactionId())->setIsTransactionClosed(0);
492  $this->_pro->importPaymentInfo($api, $payment);
493  }
$payment
Definition: order.php:17

◆ _placeOrder()

_placeOrder ( Payment  $payment,
  $amount 
)
protected

Place an order with authorization or capture action

Parameters
Payment$payment
float$amount
Returns
$this

Definition at line 415 of file Direct.php.

416  {
417  $order = $payment->getOrder();
418  $api = $this->_pro->getApi()->setPaymentAction(
419  $this->_pro->getConfig()->getValue('paymentAction')
420  )->setIpAddress(
421  $this->_requestHttp->getClientIp(false)
422  )->setAmount(
423  $amount
424  )->setCurrencyCode(
425  $order->getBaseCurrencyCode()
426  )->setInvNum(
427  $order->getIncrementId()
428  )->setEmail(
429  $order->getCustomerEmail()
430  )->setNotifyUrl(
431  $this->_urlBuilder->getUrl('paypal/ipn/')
432  )->setCreditCardType(
433  $payment->getCcType()
434  )->setCreditCardNumber(
435  $payment->getCcNumber()
436  )->setCreditCardExpirationDate(
437  $this->_getFormattedCcExpirationDate($payment->getCcExpMonth(), $payment->getCcExpYear())
438  )->setCreditCardCvv2(
439  $payment->getCcCid()
440  );
441 
442  // add shipping and billing addresses
443  if ($order->getIsVirtual()) {
444  $api->setAddress($order->getBillingAddress())->setSuppressShipping(true);
445  } else {
446  $api->setAddress($order->getShippingAddress());
447  $api->setBillingAddress($order->getBillingAddress());
448  }
449 
450  // add line items
451  $cart = $this->_cartFactory->create(['salesModel' => $order]);
452 
453  $api->setPaypalCart($cart)->setIsLineItemsEnabled($this->_pro->getConfig()->getValue('lineItemsEnabled'));
454 
455  // call api and import transaction and other payment information
456  $api->callDoDirectPayment();
457  $this->_importResultToPayment($api, $payment);
458 
459  try {
460  $api->callGetTransactionDetails();
461  } catch (\Magento\Framework\Exception\LocalizedException $e) {
462  // if we receive errors, but DoDirectPayment response is Success, then set Pending status for transaction
463  $payment->setIsTransactionPending(true);
464  }
465  $this->_importResultToPayment($api, $payment);
466  return $this;
467  }
$order
Definition: order.php:55
_importResultToPayment($api, $payment)
Definition: Direct.php:489
$amount
Definition: order.php:14
$payment
Definition: order.php:17
_getFormattedCcExpirationDate($month, $year)
Definition: Direct.php:477

◆ acceptPayment()

acceptPayment ( \Magento\Payment\Model\InfoInterface  $payment)

Attempt to accept a pending payment

Parameters
\Magento\Payment\Model\Info | Payment$payment
Returns
bool

Definition at line 378 of file Direct.php.

379  {
380  parent::acceptPayment($payment);
381  return $this->_pro->reviewPayment($payment, \Magento\Paypal\Model\Pro::PAYMENT_REVIEW_ACCEPT);
382  }
const PAYMENT_REVIEW_ACCEPT
Definition: Pro.php:22
$payment
Definition: order.php:17

◆ authorize()

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

Authorize payment

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

Definition at line 303 of file Direct.php.

304  {
305  return $this->_placeOrder($payment, $amount);
306  }
$amount
Definition: order.php:14
$payment
Definition: order.php:17
_placeOrder(Payment $payment, $amount)
Definition: Direct.php:415

◆ cancel()

cancel ( \Magento\Payment\Model\InfoInterface  $payment)

Cancel payment

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

Definition at line 356 of file Direct.php.

357  {
358  $this->void($payment);
359 
360  return $this;
361  }
void(\Magento\Payment\Model\InfoInterface $payment)
Definition: Direct.php:315
$payment
Definition: order.php:17

◆ canReviewPayment()

canReviewPayment ( )

Whether payment can be reviewed

Returns
bool

Definition at line 367 of file Direct.php.

368  {
369  return parent::canReviewPayment() && $this->_pro->canReviewPayment($this->getInfoInstance());
370  }

◆ canUseForCurrency()

canUseForCurrency (   $currencyCode)

Whether method is available for specified currency

Parameters
string$currencyCode
Returns
bool

Definition at line 227 of file Direct.php.

228  {
229  return $this->_pro->getConfig()->isCurrencyCodeSupported($currencyCode);
230  }

◆ canVoid()

canVoid ( )

Check void availability

Returns
bool

Definition at line 500 of file Direct.php.

501  {
502  return $this->_canVoid;
503  }

◆ capture()

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

Capture payment

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

Definition at line 328 of file Direct.php.

329  {
330  if (false === $this->_pro->capture($payment, $amount)) {
331  $this->_placeOrder($payment, $amount);
332  }
333  return $this;
334  }
$amount
Definition: order.php:14
$payment
Definition: order.php:17
_placeOrder(Payment $payment, $amount)
Definition: Direct.php:415

◆ denyPayment()

denyPayment ( \Magento\Payment\Model\InfoInterface  $payment)

Attempt to deny a pending payment

Parameters
\Magento\Payment\Model\Info | PaymentInterface$payment
Returns
bool

Definition at line 390 of file Direct.php.

391  {
392  parent::denyPayment($payment);
393  return $this->_pro->reviewPayment($payment, \Magento\Paypal\Model\Pro::PAYMENT_REVIEW_DENY);
394  }
const PAYMENT_REVIEW_DENY
Definition: Pro.php:24
$payment
Definition: order.php:17

◆ fetchTransactionInfo()

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

Fetch transaction details info

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

Definition at line 403 of file Direct.php.

404  {
405  return $this->_pro->fetchTransactionInfo($payment, $transactionId);
406  }
$payment
Definition: order.php:17

◆ getAllowedCcTypes()

getAllowedCcTypes ( )

Return available CC types for gateway based on merchant country

Returns
string

Definition at line 248 of file Direct.php.

249  {
250  $ccTypes = explode(',', $this->_pro->getConfig()->getValue('cctypes'));
251  $country = $this->_pro->getConfig()->getMerchantCountry();
252 
253  if ($country == 'GB') {
254  $ccTypes = array_intersect(['SM', 'SO', 'MC', 'DI', 'VI'], $ccTypes);
255  } elseif ($country == 'CA') {
256  $ccTypes = array_intersect(['MC', 'VI'], $ccTypes);
257  }
258  return implode(',', $ccTypes);
259  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17

◆ getConfigData()

getConfigData (   $field,
  $storeId = null 
)

Custom getter for payment configuration

Parameters
string$field
int | null$storeId
Returns
null|string @SuppressWarnings(PHPMD.UnusedFormalParameter)

Definition at line 280 of file Direct.php.

281  {
282  $value = null;
283  switch ($field) {
284  case 'cctypes':
285  $value = $this->getAllowedCcTypes();
286  break;
287  case 'order_place_redirect_url':
288  $value = $this->getOrderPlaceRedirectUrl();
289  break;
290  default:
291  $value = $this->_pro->getConfig()->getValue($field);
292  }
293  return $value;
294  }
$value
Definition: gender.phtml:16

◆ getConfigPaymentAction()

getConfigPaymentAction ( )

Payment action getter compatible with payment model

See also
\Magento\Sales\Model\Payment::place()
Returns
string

Definition at line 238 of file Direct.php.

239  {
240  return $this->_pro->getConfig()->getPaymentAction();
241  }

◆ isAvailable()

isAvailable ( \Magento\Quote\Api\Data\CartInterface  $quote = null)

Check whether payment method can be used

Parameters
\Magento\Quote\Api\Data\CartInterface | \Magento\Quote\Model\Quote | null$quote
Returns
bool

Definition at line 267 of file Direct.php.

268  {
269  return parent::isAvailable($quote) && $this->_pro->getConfig()->isMethodAvailable();
270  }
$quote

◆ refund()

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

Refund capture

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

Definition at line 344 of file Direct.php.

345  {
346  $this->_pro->refund($payment, $amount);
347  return $this;
348  }
$amount
Definition: order.php:14
$payment
Definition: order.php:17

◆ setStore()

setStore (   $store)

Store setter Also updates store ID in config object

Parameters
\Magento\Store\Model\Store | int$store
Returns
$this

Definition at line 211 of file Direct.php.

212  {
213  $this->setData('store', $store);
214  if (null === $store) {
215  $store = $this->_storeManager->getStore()->getId();
216  }
217  $this->_pro->getConfig()->setStoreId(is_object($store) ? $store->getId() : $store);
218  return $this;
219  }

◆ void()

Void payment

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

Definition at line 315 of file Direct.php.

316  {
317  $this->_pro->void($payment);
318  return $this;
319  }
$payment
Definition: order.php:17

Field Documentation

◆ $_canAuthorize

$_canAuthorize = true
protected

Definition at line 40 of file Direct.php.

◆ $_canCapture

$_canCapture = true
protected

Definition at line 47 of file Direct.php.

◆ $_canCapturePartial

$_canCapturePartial = true
protected

Definition at line 54 of file Direct.php.

◆ $_canFetchTransactionInfo

$_canFetchTransactionInfo = true
protected

Definition at line 101 of file Direct.php.

◆ $_canRefund

$_canRefund = true
protected

Definition at line 61 of file Direct.php.

◆ $_canRefundInvoicePartial

$_canRefundInvoicePartial = true
protected

Definition at line 68 of file Direct.php.

◆ $_canReviewPayment

$_canReviewPayment = true
protected

Definition at line 108 of file Direct.php.

◆ $_canSaveCc

$_canSaveCc = false
protected

Definition at line 96 of file Direct.php.

◆ $_canUseCheckout

$_canUseCheckout = true
protected

Definition at line 89 of file Direct.php.

◆ $_canUseInternal

$_canUseInternal = true
protected

Definition at line 82 of file Direct.php.

◆ $_canVoid

$_canVoid = true
protected

Definition at line 75 of file Direct.php.

◆ $_cartFactory

$_cartFactory
protected

Definition at line 135 of file Direct.php.

◆ $_code

Definition at line 21 of file Direct.php.

◆ $_infoBlockType

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

Definition at line 26 of file Direct.php.

◆ $_isGateway

$_isGateway = true
protected

Definition at line 33 of file Direct.php.

◆ $_pro

$_pro
protected

Definition at line 115 of file Direct.php.

◆ $_requestHttp

$_requestHttp
protected

Definition at line 130 of file Direct.php.

◆ $_storeManager

$_storeManager
protected

Definition at line 120 of file Direct.php.

◆ $_urlBuilder

$_urlBuilder
protected

Definition at line 125 of file Direct.php.


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