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

Public Member Functions

 __construct (\Magento\Paypal\Model\Config\Factory $configFactory, \Magento\Paypal\Model\Api\Type\Factory $apiFactory, \Magento\Paypal\Model\InfoFactory $infoFactory, TransactionRepositoryInterface $transactionRepository)
 
 setMethod ($code, $storeId=null)
 
 setConfig (\Magento\Paypal\Model\Config $instance, $storeId=null)
 
 getConfig ()
 
 getApi ()
 
 resetApi ()
 
 getInfo ()
 
 importPaymentInfo (\Magento\Framework\DataObject $from, \Magento\Payment\Model\InfoInterface $to)
 
 void (\Magento\Framework\DataObject $payment)
 
 capture (\Magento\Framework\DataObject $payment, $amount)
 
 refund (\Magento\Framework\DataObject $payment, $amount)
 
 cancel (\Magento\Framework\DataObject $payment)
 
 canReviewPayment (\Magento\Payment\Model\InfoInterface $payment)
 
 reviewPayment (\Magento\Payment\Model\InfoInterface $payment, $action)
 
 fetchTransactionInfo (\Magento\Payment\Model\InfoInterface $payment, $transactionId)
 

Data Fields

const PAYMENT_REVIEW_ACCEPT = 'accept'
 
const PAYMENT_REVIEW_DENY = 'deny'
 

Protected Member Functions

 _isPaymentReviewRequired (\Magento\Payment\Model\InfoInterface $payment)
 
 _importCaptureResultToPayment ($api, $payment)
 
 _importRefundResultToPayment ($api, $payment, $canRefundMore)
 
 _getParentTransactionId (\Magento\Framework\DataObject $payment)
 

Protected Attributes

 $_config
 
 $_api
 
 $_infoInstance
 
 $_apiType = \Magento\Paypal\Model\Api\Nvp::class
 
 $_configType = \Magento\Paypal\Model\Config::class
 
 $_configFactory
 
 $_apiFactory
 
 $_infoFactory
 
 $transactionRepository
 

Detailed Description

PayPal Website Payments Pro implementation for payment method instances This model was created because right now PayPal Direct and PayPal Express payment methods cannot have same abstract

Definition at line 17 of file Pro.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Magento\Paypal\Model\Config\Factory  $configFactory,
\Magento\Paypal\Model\Api\Type\Factory  $apiFactory,
\Magento\Paypal\Model\InfoFactory  $infoFactory,
TransactionRepositoryInterface  $transactionRepository 
)
Parameters
\Magento\Paypal\Model\Config\Factory$configFactory
\Magento\Paypal\Model\Api\Type\Factory$apiFactory
\Magento\Paypal\Model\InfoFactory$infoFactory
TransactionRepositoryInterface$transactionRepository

Definition at line 87 of file Pro.php.

92  {
93  $this->_configFactory = $configFactory;
94  $this->_apiFactory = $apiFactory;
95  $this->_infoFactory = $infoFactory;
96  $this->transactionRepository = $transactionRepository;
97  }
$configFactory
Definition: config_data.php:43

Member Function Documentation

◆ _getParentTransactionId()

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

Parent transaction id getter

Parameters
\Magento\Framework\DataObject$payment
Returns
string

Definition at line 432 of file Pro.php.

433  {
434  return $payment->getParentTransactionId();
435  }
$payment
Definition: order.php:17

◆ _importCaptureResultToPayment()

_importCaptureResultToPayment (   $api,
  $payment 
)
protected

Import capture results to payment

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

Definition at line 400 of file Pro.php.

401  {
402  $payment->setTransactionId($api->getTransactionId())->setIsTransactionClosed(false);
403  $this->importPaymentInfo($api, $payment);
404  }
$payment
Definition: order.php:17
importPaymentInfo(\Magento\Framework\DataObject $from, \Magento\Payment\Model\InfoInterface $to)
Definition: Pro.php:196

◆ _importRefundResultToPayment()

_importRefundResultToPayment (   $api,
  $payment,
  $canRefundMore 
)
protected

Import refund results to payment

Parameters
\Magento\Paypal\Model\Api\Nvp$api
\Magento\Sales\Model\Order\Payment$payment
bool$canRefundMore
Returns
void

Definition at line 414 of file Pro.php.

415  {
416  $payment->setTransactionId(
417  $api->getRefundTransactionId()
418  )->setIsTransactionClosed(
419  1 // refund initiated by merchant
420  )->setShouldCloseParentTransaction(
421  !$canRefundMore
422  );
423  $this->importPaymentInfo($api, $payment);
424  }
$payment
Definition: order.php:17
importPaymentInfo(\Magento\Framework\DataObject $from, \Magento\Payment\Model\InfoInterface $to)
Definition: Pro.php:196

◆ _isPaymentReviewRequired()

_isPaymentReviewRequired ( \Magento\Payment\Model\InfoInterface  $payment)
protected

Check whether payment review is required

Parameters
\Magento\Payment\Model\InfoInterface$payment
Returns
bool

Definition at line 347 of file Pro.php.

348  {
350  }
static isPaymentReviewRequired(\Magento\Payment\Model\InfoInterface $payment)
Definition: Info.php:338
$payment
Definition: order.php:17

◆ cancel()

cancel ( \Magento\Framework\DataObject  $payment)

Cancel payment

Parameters
\Magento\Framework\DataObject$payment
Returns
void

Definition at line 320 of file Pro.php.

321  {
322  if (!$payment->getOrder()->getInvoiceCollection()->count()) {
323  $this->void($payment);
324  }
325  }
void(\Magento\Framework\DataObject $payment)
Definition: Pro.php:229
$payment
Definition: order.php:17

◆ canReviewPayment()

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

Check whether can do payment review

Parameters
\Magento\Payment\Model\InfoInterface$payment
Returns
bool

Definition at line 333 of file Pro.php.

334  {
335  $pendingReason = $payment->getAdditionalInformation(\Magento\Paypal\Model\Info::PENDING_REASON_GLOBAL);
336  return $this->_isPaymentReviewRequired(
337  $payment
339  }
$payment
Definition: order.php:17
const PENDING_REASON_GLOBAL
Definition: Info.php:64
_isPaymentReviewRequired(\Magento\Payment\Model\InfoInterface $payment)
Definition: Pro.php:347

◆ capture()

capture ( \Magento\Framework\DataObject  $payment,
  $amount 
)

Attempt to capture payment Will return false if the payment is not supposed to be captured

Parameters
\Magento\Framework\DataObject$payment
float$amount
Returns
false|null

Definition at line 251 of file Pro.php.

252  {
253  $authTransactionId = $this->_getParentTransactionId($payment);
254  if (!$authTransactionId) {
255  return false;
256  }
257  $api = $this->getApi()
258  ->setAuthorizationId($authTransactionId)
259  ->setIsCaptureComplete($payment->isCaptureFinal($amount))
260  ->setAmount($amount);
261 
262  $order = $payment->getOrder();
263  $orderIncrementId = $order->getIncrementId();
264  $api->setCurrencyCode($order->getBaseCurrencyCode())
265  ->setInvNum($orderIncrementId)
266  ->setCustref($orderIncrementId)
267  ->setPonum($order->getId());
268  // TODO: pass 'NOTE' to API
269 
270  $api->callDoCapture();
272  }
$order
Definition: order.php:55
$amount
Definition: order.php:14
$payment
Definition: order.php:17
_getParentTransactionId(\Magento\Framework\DataObject $payment)
Definition: Pro.php:432
_importCaptureResultToPayment($api, $payment)
Definition: Pro.php:400

◆ 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 384 of file Pro.php.

385  {
386  $api = $this->getApi()->setTransactionId($transactionId)->setRawResponseNeeded(true);
387  $api->callGetTransactionDetails();
388  $this->importPaymentInfo($api, $payment);
389  $data = $api->getRawSuccessResponseData();
390  return $data ? $data : [];
391  }
$payment
Definition: order.php:17
importPaymentInfo(\Magento\Framework\DataObject $from, \Magento\Payment\Model\InfoInterface $to)
Definition: Pro.php:196

◆ getApi()

getApi ( )

API instance getter Sets current store id to current config instance and passes it to API

Returns
\Magento\Paypal\Model\Api\Nvp

Definition at line 155 of file Pro.php.

156  {
157  if (null === $this->_api) {
158  $this->_api = $this->_apiFactory->create($this->_apiType);
159  }
160  $this->_api->setConfigObject($this->_config);
161  return $this->_api;
162  }

◆ getConfig()

getConfig ( )

Config instance getter

Returns
\Magento\Paypal\Model\Config

Definition at line 144 of file Pro.php.

145  {
146  return $this->_config;
147  }

◆ getInfo()

getInfo ( )

Instantiate and return info model

Returns
\Magento\Paypal\Model\Info

Definition at line 181 of file Pro.php.

182  {
183  if (null === $this->_infoInstance) {
184  $this->_infoInstance = $this->_infoFactory->create();
185  }
186  return $this->_infoInstance;
187  }

◆ importPaymentInfo()

importPaymentInfo ( \Magento\Framework\DataObject  $from,
\Magento\Payment\Model\InfoInterface  $to 
)

Transfer transaction/payment information from API instance to order payment

Parameters
\Magento\Framework\DataObject | AbstractApi$from
\Magento\Payment\Model\InfoInterface$to
Returns
$this

Detect payment review and/or frauds PayPal pro API returns fraud results only in the payment call response

Definition at line 196 of file Pro.php.

197  {
198  // update PayPal-specific payment information in the payment object
199  $this->getInfo()->importToPayment($from, $to);
200 
205  if ($from->getDataUsingMethod(\Magento\Paypal\Model\Info::IS_FRAUD)) {
206  $to->setIsTransactionPending(true);
207  $to->setIsFraudDetected(true);
209  $to->setIsTransactionPending(true);
210  }
211 
212  // give generic info about transaction state
213  if (Info::isPaymentSuccessful($to)) {
214  $to->setIsTransactionApproved(true);
215  } elseif (Info::isPaymentFailed($to)) {
216  $to->setIsTransactionDenied(true);
217  }
218 
219  return $this;
220  }
static isPaymentReviewRequired(\Magento\Payment\Model\InfoInterface $payment)
Definition: Info.php:338
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
static isPaymentFailed(\Magento\Payment\Model\InfoInterface $payment)
Definition: Info.php:411
static isPaymentSuccessful(\Magento\Payment\Model\InfoInterface $payment)
Definition: Info.php:381

◆ refund()

refund ( \Magento\Framework\DataObject  $payment,
  $amount 
)

Refund a capture transaction

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

Definition at line 282 of file Pro.php.

283  {
284  $captureTxnId = $this->_getParentTransactionId($payment);
285  if ($captureTxnId) {
286  $api = $this->getApi();
287  $order = $payment->getOrder();
288  $api->setPayment(
289  $payment
290  )->setTransactionId(
291  $captureTxnId
292  )->setAmount(
293  $amount
294  )->setCurrencyCode(
295  $order->getBaseCurrencyCode()
296  );
297  $canRefundMore = $payment->getCreditmemo()->getInvoice()->canRefund();
298  $isFullRefund = !$canRefundMore &&
299  0 == (double)$order->getBaseTotalOnlineRefunded() + (double)$order->getBaseTotalOfflineRefunded();
300  $api->setRefundType(
301  $isFullRefund
302  ? \Magento\Paypal\Model\Config::REFUND_TYPE_FULL
303  : \Magento\Paypal\Model\Config::REFUND_TYPE_PARTIAL
304  );
305  $api->callRefundTransaction();
306  $this->_importRefundResultToPayment($api, $payment, $canRefundMore);
307  } else {
308  throw new \Magento\Framework\Exception\LocalizedException(
309  __('We can\'t issue a refund transaction because there is no capture transaction.')
310  );
311  }
312  }
$order
Definition: order.php:55
__()
Definition: __.php:13
$amount
Definition: order.php:14
$payment
Definition: order.php:17
_importRefundResultToPayment($api, $payment, $canRefundMore)
Definition: Pro.php:414
_getParentTransactionId(\Magento\Framework\DataObject $payment)
Definition: Pro.php:432

◆ resetApi()

resetApi ( )

Destroy existing NVP Api object

Returns
$this

Definition at line 169 of file Pro.php.

170  {
171  $this->_api = null;
172 
173  return $this;
174  }

◆ reviewPayment()

reviewPayment ( \Magento\Payment\Model\InfoInterface  $payment,
  $action 
)

Perform the payment review

Parameters
\Magento\Payment\Model\InfoInterface$payment
string$action
Returns
bool

Definition at line 359 of file Pro.php.

360  {
361  $api = $this->getApi()->setTransactionId($payment->getLastTransId());
362 
363  // check whether the review is still needed
364  $api->callGetTransactionDetails();
365  $this->importPaymentInfo($api, $payment);
367  return false;
368  }
369 
370  // perform the review action
371  $api->setAction($action)->callManagePendingTransactionStatus();
372  $api->callGetTransactionDetails();
373  $this->importPaymentInfo($api, $payment);
374  return true;
375  }
static isPaymentReviewRequired(\Magento\Payment\Model\InfoInterface $payment)
Definition: Info.php:338
$payment
Definition: order.php:17
importPaymentInfo(\Magento\Framework\DataObject $from, \Magento\Payment\Model\InfoInterface $to)
Definition: Pro.php:196

◆ setConfig()

setConfig ( \Magento\Paypal\Model\Config  $instance,
  $storeId = null 
)

Config instance setter

Parameters
\Magento\Paypal\Model\Config$instance
int | null$storeId
Returns
$this

Definition at line 130 of file Pro.php.

131  {
132  $this->_config = $instance;
133  if (null !== $storeId) {
134  $this->_config->setStoreId($storeId);
135  }
136  return $this;
137  }

◆ setMethod()

setMethod (   $code,
  $storeId = null 
)

Payment method code setter. Also instantiates/updates config

Parameters
string$code
int | null$storeId
Returns
$this

Definition at line 106 of file Pro.php.

107  {
108  if (null === $this->_config) {
109  $params = [$code];
110  if (null !== $storeId) {
111  $params[] = $storeId;
112  }
113  $this->_config = $this->_configFactory->create($this->_configType, ['params' => $params]);
114  } else {
115  $this->_config->setMethod($code);
116  if (null !== $storeId) {
117  $this->_config->setStoreId($storeId);
118  }
119  }
120  return $this;
121  }
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18
$code
Definition: info.phtml:12

◆ void()

void ( \Magento\Framework\DataObject  $payment)

Void transaction

Parameters
\Magento\Framework\DataObject$payment
Returns
void
Exceptions

Definition at line 229 of file Pro.php.

230  {
231  $authTransactionId = $this->_getParentTransactionId($payment);
232  if ($authTransactionId) {
233  $api = $this->getApi();
234  $api->setPayment($payment)->setAuthorizationId($authTransactionId)->callDoVoid();
235  $this->importPaymentInfo($api, $payment);
236  } else {
237  throw new \Magento\Framework\Exception\LocalizedException(
238  __('You need an authorization transaction to void.')
239  );
240  }
241  }
__()
Definition: __.php:13
$payment
Definition: order.php:17
_getParentTransactionId(\Magento\Framework\DataObject $payment)
Definition: Pro.php:432
importPaymentInfo(\Magento\Framework\DataObject $from, \Magento\Payment\Model\InfoInterface $to)
Definition: Pro.php:196

Field Documentation

◆ $_api

$_api
protected

Definition at line 38 of file Pro.php.

◆ $_apiFactory

$_apiFactory
protected

Definition at line 69 of file Pro.php.

◆ $_apiType

$_apiType = \Magento\Paypal\Model\Api\Nvp::class
protected

Definition at line 52 of file Pro.php.

◆ $_config

$_config
protected

Definition at line 31 of file Pro.php.

◆ $_configFactory

$_configFactory
protected

Definition at line 64 of file Pro.php.

◆ $_configType

$_configType = \Magento\Paypal\Model\Config::class
protected

Definition at line 59 of file Pro.php.

◆ $_infoFactory

$_infoFactory
protected

Definition at line 74 of file Pro.php.

◆ $_infoInstance

$_infoInstance
protected

Definition at line 45 of file Pro.php.

◆ $transactionRepository

$transactionRepository
protected

Definition at line 79 of file Pro.php.

◆ PAYMENT_REVIEW_ACCEPT

const PAYMENT_REVIEW_ACCEPT = 'accept'

Possible payment review actions (for FMF only)

Definition at line 22 of file Pro.php.

◆ PAYMENT_REVIEW_DENY

const PAYMENT_REVIEW_DENY = 'deny'

Definition at line 24 of file Pro.php.


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