Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
PaymentToken.php
Go to the documentation of this file.
1 <?php
7 
8 use Magento\Vault\Setup\InstallSchema;
10 
14 class PaymentToken extends AbstractDb
15 {
21  protected function _construct()
22  {
23  $this->_init('vault_payment_token', 'entity_id');
24  }
25 
32  public function getByOrderPaymentId($paymentId)
33  {
34  $connection = $this->getConnection();
36  ->select()
37  ->from($this->getMainTable())
38  ->joinInner(
39  $this->getTable('vault_payment_token_order_payment_link'),
40  'payment_token_id = entity_id',
41  null
42  )
43  ->where('order_payment_id = ?', (int) $paymentId);
44  return $connection->fetchRow($select);
45  }
46 
56  public function getByGatewayToken($token, $paymentMethodCode, $customerId = 0)
57  {
58  $connection = $this->getConnection();
60  ->select()
61  ->from($this->getMainTable())
62  ->where('gateway_token = ?', $token)
63  ->where('payment_method_code = ?', $paymentMethodCode);
64  if ($customerId > 0) {
65  $select = $select->where('customer_id = ?', $customerId);
66  } else {
67  $select = $select->where('customer_id IS NULL');
68  }
69  return $connection->fetchRow($select);
70  }
71 
80  public function getByPublicHash($hash, $customerId = 0)
81  {
82  $connection = $this->getConnection();
84  ->select()
85  ->from($this->getMainTable())
86  ->where('public_hash = ?', $hash);
87  if ($customerId > 0) {
88  $select = $select->where('customer_id = ?', $customerId);
89  } else {
90  $select = $select->where('customer_id IS NULL');
91  }
92  return $connection->fetchRow($select);
93  }
94 
102  public function addLinkToOrderPayment($paymentTokenId, $orderPaymentId)
103  {
104  $connection = $this->getConnection();
105 
106  $select = $connection->select()
107  ->from($this->getTable('vault_payment_token_order_payment_link'))
108  ->where('order_payment_id = ?', (int) $orderPaymentId)
109  ->where('payment_token_id =?', (int) $paymentTokenId);
110 
111  if (!empty($connection->fetchRow($select))) {
112  return true;
113  }
114 
115  return 1 === $connection->insert(
116  $this->getTable('vault_payment_token_order_payment_link'),
117  ['order_payment_id' => (int) $orderPaymentId, 'payment_token_id' => (int) $paymentTokenId]
118  );
119  }
120 }
addLinkToOrderPayment($paymentTokenId, $orderPaymentId)
getByGatewayToken($token, $paymentMethodCode, $customerId=0)
$connection
Definition: bulk.php:13