Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions
SubjectReader Class Reference

Public Member Functions

 readResponseObject (array $subject)
 
 readPayment (array $subject)
 
 readTransaction (array $subject)
 
 readAmount (array $subject)
 
 readCustomerId (array $subject)
 
 readPublicHash (array $subject)
 
 readPayPal (Transaction $transaction)
 
 readStoreId (array $subject)
 

Detailed Description

Class SubjectReader

Definition at line 16 of file SubjectReader.php.

Member Function Documentation

◆ readAmount()

readAmount ( array  $subject)

Reads amount from subject

Parameters
array$subject
Returns
mixed

Definition at line 73 of file SubjectReader.php.

74  {
75  return Helper\SubjectReader::readAmount($subject);
76  }

◆ readCustomerId()

readCustomerId ( array  $subject)

Reads customer id from subject

Parameters
array$subject
Returns
int

Definition at line 84 of file SubjectReader.php.

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  }

◆ readPayment()

readPayment ( array  $subject)

Reads payment from subject

Parameters
array$subject
Returns
PaymentDataObjectInterface

Definition at line 40 of file SubjectReader.php.

41  {
42  return Helper\SubjectReader::readPayment($subject);
43  }

◆ readPayPal()

readPayPal ( Transaction  $transaction)

Reads PayPal details from transaction object

Parameters
Transaction$transaction
Returns
array

Definition at line 114 of file SubjectReader.php.

115  {
116  if (!isset($transaction->paypal)) {
117  throw new \InvalidArgumentException('Transaction has\'t paypal attribute');
118  }
119 
120  return $transaction->paypal;
121  }
$transaction

◆ readPublicHash()

readPublicHash ( array  $subject)

Reads public hash from subject

Parameters
array$subject
Returns
string

Definition at line 99 of file SubjectReader.php.

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  }

◆ readResponseObject()

readResponseObject ( array  $subject)

Reads response object from subject

Parameters
array$subject
Returns
object

Definition at line 24 of file SubjectReader.php.

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  }
$response
Definition: 404.php:11

◆ readStoreId()

readStoreId ( array  $subject)

Reads store's ID, otherwise returns null.

Parameters
array$subject
Returns
int|null

Definition at line 129 of file SubjectReader.php.

130  {
131  return $subject['store_id'] ?? null;
132  }

◆ readTransaction()

readTransaction ( array  $subject)

Reads transaction from the subject.

Parameters
array$subject
Returns
Transaction
Exceptions

Definition at line 52 of file SubjectReader.php.

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  }

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