PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.18.0
GiveWP – Donation Plugin and Fundraising Platform v4.18.0
4.18.0 4.17.0 4.16.9 4.16.8.1 4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 All 257 releases
give / src / PaymentGateways / PayPalCommerce / Models / PayPalPayment.php

PayPalPayment.php in GiveWP – Donation Plugin and Fundraising Platform 4.18.0, at src/PaymentGateways/PayPalCommerce/Models/PayPalPayment.php

122 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Give\PaymentGateways\PayPalCommerce\Models;
4
5 use Give\Framework\Exceptions\Primitives\InvalidArgumentException;
6 use Give\Helpers\ArrayDataSet;
7
8 /**
9 * Class PayPalPayment
10 * @package Give\PaymentGateways\PayPalCommerce
11 *
12 * @since 2.9.0
13 */
14 class PayPalPayment
15 {
16 /**
17 * Payment Id.
18 *
19 * @since 2.9.0
20 *
21 * @var string
22 */
23 public $id;
24
25 /**
26 * Payment Amount.
27 *
28 * @since 2.9.0
29 *
30 * @var string
31 */
32 public $amount;
33
34 /**
35 * Payment status.
36 *
37 * @since 2.9.0
38 *
39 * @var string
40 */
41 public $status;
42
43 /**
44 * Payment creation time.
45 *
46 * @since 2.9.0
47 *
48 * @var string
49 */
50 public $createTime;
51
52 /**
53 * Payment update time.
54 *
55 * @since 2.9.0
56 *
57 * @var string
58 */
59 public $updateTime;
60
61 /**
62 * PayPal Payment action links.
63 *
64 * @since 2.9.0
65 *
66 * @var string
67 */
68 public $links;
69
70 /**
71 *
72 */
73 /**
74 * Create PayPalPayment object from given array.
75 *
76 * @since 2.9.0
77 *
78 * @param $array
79 *
80 * @return PayPalPayment
81 */
82 public static function fromArray($array)
83 {
84 /* @var PayPalPayment $payment */
85 $payment = give(__CLASS__);
86
87 $payment->validate($array);
88
89 $array = ArrayDataSet::camelCaseKeys($array);
90
91 foreach ($array as $itemName => $value) {
92 $payment->{$itemName} = $value;
93 }
94
95 return $payment;
96 }
97
98 /**
99 * Validate order given in array format.
100 *
101 * @since 2.9.0
102 *
103 * @param array $array
104 *
105 * @throws InvalidArgumentException
106 */
107 private function validate($array)
108 {
109 $required = ['id', 'amount', 'status', 'create_time', 'update_time', 'links'];
110 $array = array_filter($array); // Remove empty values.
111
112 if (array_diff($required, array_keys($array))) {
113 throw new InvalidArgumentException(
114 __(
115 'To create a PayPalPayment object, please provide valid id, amount, status, create_time, update_time and links',
116 'give'
117 )
118 );
119 }
120 }
121 }
122