Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
SubjectReader.php
Go to the documentation of this file.
1 <?php
7 
8 use Braintree\Transaction;
12 
17 {
24  public function readResponseObject(array $subject)
25  {
26  $response = Helper\SubjectReader::readResponse($subject);
27  if (!isset($response['object']) || !is_object($response['object'])) {
28  throw new \InvalidArgumentException('Response object does not exist');
29  }
30 
31  return $response['object'];
32  }
33 
40  public function readPayment(array $subject)
41  {
42  return Helper\SubjectReader::readPayment($subject);
43  }
44 
52  public function readTransaction(array $subject)
53  {
54  if (!isset($subject['object']) || !is_object($subject['object'])) {
55  throw new \InvalidArgumentException('Response object does not exist.');
56  }
57 
58  if (!isset($subject['object']->transaction)
59  || !$subject['object']->transaction instanceof Transaction
60  ) {
61  throw new \InvalidArgumentException('The object is not a class \Braintree\Transaction.');
62  }
63 
64  return $subject['object']->transaction;
65  }
66 
73  public function readAmount(array $subject)
74  {
75  return Helper\SubjectReader::readAmount($subject);
76  }
77 
84  public function readCustomerId(array $subject)
85  {
86  if (!isset($subject['customer_id'])) {
87  throw new \InvalidArgumentException('The "customerId" field does not exists');
88  }
89 
90  return (int) $subject['customer_id'];
91  }
92 
99  public function readPublicHash(array $subject)
100  {
101  if (empty($subject[PaymentTokenInterface::PUBLIC_HASH])) {
102  throw new \InvalidArgumentException('The "public_hash" field does not exists');
103  }
104 
105  return $subject[PaymentTokenInterface::PUBLIC_HASH];
106  }
107 
114  public function readPayPal(Transaction $transaction)
115  {
116  if (!isset($transaction->paypal)) {
117  throw new \InvalidArgumentException('Transaction has\'t paypal attribute');
118  }
119 
120  return $transaction->paypal;
121  }
122 
129  public function readStoreId(array $subject)
130  {
131  return $subject['store_id'] ?? null;
132  }
133 }
$transaction
$response
Definition: 404.php:11
readPayPal(Transaction $transaction)