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

Public Member Functions

 __construct (PaymentTokenRepositoryInterface $repository, PaymentTokenResourceModel $paymentTokenResourceModel, PaymentTokenFactory $paymentTokenFactory, FilterBuilder $filterBuilder, SearchCriteriaBuilder $searchCriteriaBuilder, PaymentTokenSearchResultsInterfaceFactory $searchResultsFactory, EncryptorInterface $encryptor, DateTimeFactory $dateTimeFactory)
 
 getListByCustomerId ($customerId)
 
 getVisibleAvailableTokens ($customerId)
 
 getByPaymentId ($paymentId)
 
 getByGatewayToken ($token, $paymentMethodCode, $customerId)
 
 getByPublicHash ($hash, $customerId)
 
 saveTokenWithPaymentLink (PaymentTokenInterface $token, OrderPaymentInterface $payment)
 
 addLinkToOrderPayment ($paymentTokenId, $orderPaymentId)
 

Protected Attributes

 $paymentTokenRepository
 
 $paymentTokenResourceModel
 
 $resourceModel
 
 $paymentTokenFactory
 
 $searchResultsFactory
 
 $filterBuilder
 
 $searchCriteriaBuilder
 

Detailed Description

Vault payment token repository @SuppressWarnings(PHPMD.CouplingBetweenObjects)

Definition at line 25 of file PaymentTokenManagement.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( PaymentTokenRepositoryInterface  $repository,
PaymentTokenResourceModel  $paymentTokenResourceModel,
PaymentTokenFactory  $paymentTokenFactory,
FilterBuilder  $filterBuilder,
SearchCriteriaBuilder  $searchCriteriaBuilder,
PaymentTokenSearchResultsInterfaceFactory  $searchResultsFactory,
EncryptorInterface  $encryptor,
DateTimeFactory  $dateTimeFactory 
)
Parameters
PaymentTokenRepositoryInterface$repository
PaymentTokenResourceModel$paymentTokenResourceModel
PaymentTokenFactory$paymentTokenFactory
FilterBuilder$filterBuilder
SearchCriteriaBuilder$searchCriteriaBuilder
PaymentTokenSearchResultsInterfaceFactory$searchResultsFactory
EncryptorInterface$encryptor
DateTimeFactory$dateTimeFactory

Definition at line 82 of file PaymentTokenManagement.php.

91  {
92  $this->paymentTokenRepository = $repository;
93  $this->paymentTokenResourceModel = $paymentTokenResourceModel;
94  $this->paymentTokenFactory = $paymentTokenFactory;
95  $this->filterBuilder = $filterBuilder;
96  $this->searchCriteriaBuilder = $searchCriteriaBuilder;
97  $this->searchResultsFactory = $searchResultsFactory;
98  $this->encryptor = $encryptor;
99  $this->dateTimeFactory = $dateTimeFactory;
100  }

Member Function Documentation

◆ addLinkToOrderPayment()

addLinkToOrderPayment (   $paymentTokenId,
  $orderPaymentId 
)

Add link between payment token and order payment.

Parameters
int$paymentTokenIdPayment token ID.
int$orderPaymentIdOrder payment ID.
Returns
bool

Implements PaymentTokenManagementInterface.

Definition at line 249 of file PaymentTokenManagement.php.

250  {
251  return $this->paymentTokenResourceModel->addLinkToOrderPayment($paymentTokenId, $orderPaymentId);
252  }

◆ getByGatewayToken()

getByGatewayToken (   $token,
  $paymentMethodCode,
  $customerId 
)

Get payment token by gateway token.

Parameters
string$tokenThe gateway token.
string$paymentMethodCode
int$customerIdCustomer ID.
Returns
PaymentTokenInterface|null Payment token interface.

Implements PaymentTokenManagementInterface.

Definition at line 187 of file PaymentTokenManagement.php.

188  {
189  $tokenData = $this->paymentTokenResourceModel->getByGatewayToken($token, $paymentMethodCode, $customerId);
190  $tokenModel = !empty($tokenData) ? $this->paymentTokenFactory->create(['data' => $tokenData]) : null;
191  return $tokenModel;
192  }

◆ getByPaymentId()

getByPaymentId (   $paymentId)

Get payment token by token Id.

Parameters
int$paymentIdThe payment token ID.
Returns
PaymentTokenInterface|null Payment token interface.

Implements PaymentTokenManagementInterface.

Definition at line 172 of file PaymentTokenManagement.php.

173  {
174  $tokenData = $this->paymentTokenResourceModel->getByOrderPaymentId($paymentId);
175  $tokenModel = !empty($tokenData) ? $this->paymentTokenFactory->create(['data' => $tokenData]) : null;
176  return $tokenModel;
177  }

◆ getByPublicHash()

getByPublicHash (   $hash,
  $customerId 
)

Get payment token by public hash.

Parameters
string$hashPublic hash.
int$customerIdCustomer ID.
Returns
PaymentTokenInterface|null Payment token interface.

Implements PaymentTokenManagementInterface.

Definition at line 201 of file PaymentTokenManagement.php.

202  {
203  $tokenData = $this->paymentTokenResourceModel->getByPublicHash($hash, $customerId);
204  $tokenModel = !empty($tokenData) ? $this->paymentTokenFactory->create(['data' => $tokenData]) : null;
205  return $tokenModel;
206  }

◆ getListByCustomerId()

getListByCustomerId (   $customerId)

Lists payment tokens that match specified search criteria.

Parameters
int$customerIdCustomer ID.
Returns
\Magento\Vault\Api\Data\PaymentTokenSearchResultsInterface[] Payment tokens search result interface.

Implements PaymentTokenManagementInterface.

Definition at line 108 of file PaymentTokenManagement.php.

109  {
110  $filters[] = $this->filterBuilder
112  ->setValue($customerId)
113  ->create();
114  $entities = $this->paymentTokenRepository->getList(
115  $this->searchCriteriaBuilder
116  ->addFilters($filters)
117  ->create()
118  )->getItems();
119 
120  return $entities;
121  }
$filters
Definition: uploader.phtml:11

◆ getVisibleAvailableTokens()

getVisibleAvailableTokens (   $customerId)

Searches for all visible, non-expired tokens

Parameters
int$customerId
Returns
Data\PaymentTokenInterface[]

Definition at line 129 of file PaymentTokenManagement.php.

130  {
131  $customerFilter = [
132  $this->filterBuilder->setField(PaymentTokenInterface::CUSTOMER_ID)
133  ->setValue($customerId)
134  ->create()
135  ];
136  $visibleFilter = [
137  $this->filterBuilder->setField(PaymentTokenInterface::IS_VISIBLE)
138  ->setValue(1)
139  ->create()
140  ];
141  $isActiveFilter = [
142  $this->filterBuilder->setField(PaymentTokenInterface::IS_ACTIVE)
143  ->setValue(1)
144  ->create()
145  ];
146  $expiresAtFilter = [
147  $this->filterBuilder->setField(PaymentTokenInterface::EXPIRES_AT)
148  ->setConditionType('gt')
149  ->setValue(
150  $this->dateTimeFactory->create(
151  'now',
152  new \DateTimeZone('UTC')
153  )->format('Y-m-d 00:00:00')
154  )
155  ->create()
156  ];
157  $this->searchCriteriaBuilder->addFilters($customerFilter);
158  $this->searchCriteriaBuilder->addFilters($visibleFilter);
159  $this->searchCriteriaBuilder->addFilters($isActiveFilter);
160  // add filters to different filter groups in order to filter by AND expression
161  $searchCriteria = $this->searchCriteriaBuilder->addFilters($expiresAtFilter)->create();
162 
163  return $this->paymentTokenRepository->getList($searchCriteria)->getItems();
164  }
$searchCriteria

◆ saveTokenWithPaymentLink()

saveTokenWithPaymentLink ( PaymentTokenInterface  $token,
OrderPaymentInterface  $payment 
)
Parameters
PaymentTokenInterface$token
OrderPaymentInterface$payment
Returns
bool

Implements PaymentTokenManagementInterface.

Definition at line 213 of file PaymentTokenManagement.php.

214  {
215  $tokenDuplicate = $this->getByPublicHash(
216  $token->getPublicHash(),
217  $token->getCustomerId()
218  );
219 
220  if (!empty($tokenDuplicate)) {
221  if ($token->getIsVisible() || $tokenDuplicate->getIsVisible()) {
222  $token->setEntityId($tokenDuplicate->getEntityId());
223  $token->setIsVisible(true);
224  } elseif ($token->getIsVisible() === $tokenDuplicate->getIsVisible()) {
225  $token->setEntityId($tokenDuplicate->getEntityId());
226  } else {
227  $token->setPublicHash(
228  $this->encryptor->getHash(
229  $token->getPublicHash() . $token->getGatewayToken()
230  )
231  );
232  }
233  }
234 
235  $this->paymentTokenRepository->save($token);
236 
237  $result = $this->addLinkToOrderPayment($token->getEntityId(), $payment->getEntityId());
238 
239  return $result;
240  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$payment
Definition: order.php:17
addLinkToOrderPayment($paymentTokenId, $orderPaymentId)

Field Documentation

◆ $filterBuilder

$filterBuilder
protected

Definition at line 55 of file PaymentTokenManagement.php.

◆ $paymentTokenFactory

$paymentTokenFactory
protected

Definition at line 45 of file PaymentTokenManagement.php.

◆ $paymentTokenRepository

$paymentTokenRepository
protected

Definition at line 30 of file PaymentTokenManagement.php.

◆ $paymentTokenResourceModel

$paymentTokenResourceModel
protected

Definition at line 35 of file PaymentTokenManagement.php.

◆ $resourceModel

$resourceModel
protected

Definition at line 40 of file PaymentTokenManagement.php.

◆ $searchCriteriaBuilder

$searchCriteriaBuilder
protected

Definition at line 60 of file PaymentTokenManagement.php.

◆ $searchResultsFactory

$searchResultsFactory
protected

Definition at line 50 of file PaymentTokenManagement.php.


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