@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | * |
65 | 65 | * @param string $email_address E-mailadress of the consumer. |
66 | 66 | */ |
67 | - public function set_email_address( $email_address ) { |
|
67 | + public function set_email_address($email_address) { |
|
68 | 68 | $this->email_address = $email_address; |
69 | 69 | } |
70 | 70 | |
@@ -82,9 +82,9 @@ discard block |
||
82 | 82 | 'telephoneNumber' => $this->telephone_number, |
83 | 83 | ); |
84 | 84 | |
85 | - $data = array_filter( $data ); |
|
85 | + $data = array_filter($data); |
|
86 | 86 | |
87 | - if ( empty( $data ) ) { |
|
87 | + if (empty($data)) { |
|
88 | 88 | return null; |
89 | 89 | } |
90 | 90 |
@@ -47,8 +47,8 @@ discard block |
||
47 | 47 | * @param array $order_results Order results. |
48 | 48 | * @param string $signature Signature. |
49 | 49 | */ |
50 | - public function __construct( $more_available, array $order_results, $signature ) { |
|
51 | - parent::__construct( $signature ); |
|
50 | + public function __construct($more_available, array $order_results, $signature) { |
|
51 | + parent::__construct($signature); |
|
52 | 52 | |
53 | 53 | $this->more_available = $more_available; |
54 | 54 | $this->order_results = $order_results; |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | |
74 | 74 | $data[] = $this->more_available() ? 'true' : 'false'; |
75 | 75 | |
76 | - foreach ( $this->order_results as $order_result ) { |
|
76 | + foreach ($this->order_results as $order_result) { |
|
77 | 77 | $data[] = $order_result->get_merchant_order_id(); |
78 | 78 | $data[] = $order_result->get_omnikassa_order_id(); |
79 | 79 | $data[] = $order_result->get_poi_id(); |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | * @return ArrayIterator |
96 | 96 | */ |
97 | 97 | public function getIterator() { |
98 | - return new ArrayIterator( $this->order_results ); |
|
98 | + return new ArrayIterator($this->order_results); |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | /** |
@@ -105,27 +105,27 @@ discard block |
||
105 | 105 | * @return OrderResults |
106 | 106 | * @throws InvalidArgumentException Throws invalid argument exception when object does not contains the required properties. |
107 | 107 | */ |
108 | - public static function from_object( stdClass $object ) { |
|
109 | - if ( ! isset( $object->signature ) ) { |
|
110 | - throw new InvalidArgumentException( 'Object must contain `signature` property.' ); |
|
108 | + public static function from_object(stdClass $object) { |
|
109 | + if ( ! isset($object->signature)) { |
|
110 | + throw new InvalidArgumentException('Object must contain `signature` property.'); |
|
111 | 111 | } |
112 | 112 | |
113 | - if ( ! isset( $object->moreOrderResultsAvailable ) ) { |
|
114 | - throw new InvalidArgumentException( 'Object must contain `moreOrderResultsAvailable` property.' ); |
|
113 | + if ( ! isset($object->moreOrderResultsAvailable)) { |
|
114 | + throw new InvalidArgumentException('Object must contain `moreOrderResultsAvailable` property.'); |
|
115 | 115 | } |
116 | 116 | |
117 | - if ( ! isset( $object->orderResults ) ) { |
|
118 | - throw new InvalidArgumentException( 'Object must contain `orderResults` property.' ); |
|
117 | + if ( ! isset($object->orderResults)) { |
|
118 | + throw new InvalidArgumentException('Object must contain `orderResults` property.'); |
|
119 | 119 | } |
120 | 120 | |
121 | - if ( ! is_array( $object->orderResults ) ) { |
|
122 | - throw new InvalidArgumentException( 'The `orderResults` property must be an array.' ); |
|
121 | + if ( ! is_array($object->orderResults)) { |
|
122 | + throw new InvalidArgumentException('The `orderResults` property must be an array.'); |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | $order_results = array(); |
126 | 126 | |
127 | - foreach ( $object->orderResults as $o ) { |
|
128 | - $order_results[] = OrderResult::from_object( $o ); |
|
127 | + foreach ($object->orderResults as $o) { |
|
128 | + $order_results[] = OrderResult::from_object($o); |
|
129 | 129 | } |
130 | 130 | |
131 | 131 | return new self( |
@@ -142,19 +142,19 @@ discard block |
||
142 | 142 | * @return OrderResults |
143 | 143 | * @throws \JsonSchema\Exception\ValidationException Throws JSON schema validation exception when JSON is invalid. |
144 | 144 | */ |
145 | - public static function from_json( $json ) { |
|
146 | - $data = json_decode( $json ); |
|
145 | + public static function from_json($json) { |
|
146 | + $data = json_decode($json); |
|
147 | 147 | |
148 | 148 | $validator = new Validator(); |
149 | 149 | |
150 | 150 | $validator->validate( |
151 | 151 | $data, |
152 | 152 | (object) array( |
153 | - '$ref' => 'file://' . realpath( __DIR__ . '/../json-schemas/order-results.json' ), |
|
153 | + '$ref' => 'file://' . realpath(__DIR__ . '/../json-schemas/order-results.json'), |
|
154 | 154 | ), |
155 | 155 | Constraint::CHECK_MODE_EXCEPTIONS |
156 | 156 | ); |
157 | 157 | |
158 | - return self::from_object( $data ); |
|
158 | + return self::from_object($data); |
|
159 | 159 | } |
160 | 160 | } |
@@ -26,16 +26,16 @@ discard block |
||
26 | 26 | * @param string $post_id Post ID. |
27 | 27 | * @return Config |
28 | 28 | */ |
29 | - public function get_config( $post_id ) { |
|
29 | + public function get_config($post_id) { |
|
30 | 30 | $config = new Config(); |
31 | 31 | |
32 | 32 | $config->post_id = $post_id; |
33 | - $config->mode = $this->get_meta( $post_id, 'mode' ); |
|
34 | - $config->refresh_token = $this->get_meta( $post_id, 'omnikassa_2_refresh_token' ); |
|
35 | - $config->signing_key = $this->get_meta( $post_id, 'omnikassa_2_signing_key' ); |
|
36 | - $config->access_token = $this->get_meta( $post_id, 'omnikassa_2_access_token' ); |
|
37 | - $config->access_token_valid_until = $this->get_meta( $post_id, 'omnikassa_2_access_token_valid_until' ); |
|
38 | - $config->order_id = $this->get_meta( $post_id, 'omnikassa_2_order_id' ); |
|
33 | + $config->mode = $this->get_meta($post_id, 'mode'); |
|
34 | + $config->refresh_token = $this->get_meta($post_id, 'omnikassa_2_refresh_token'); |
|
35 | + $config->signing_key = $this->get_meta($post_id, 'omnikassa_2_signing_key'); |
|
36 | + $config->access_token = $this->get_meta($post_id, 'omnikassa_2_access_token'); |
|
37 | + $config->access_token_valid_until = $this->get_meta($post_id, 'omnikassa_2_access_token_valid_until'); |
|
38 | + $config->order_id = $this->get_meta($post_id, 'omnikassa_2_order_id'); |
|
39 | 39 | |
40 | 40 | return $config; |
41 | 41 | } |
@@ -48,19 +48,19 @@ discard block |
||
48 | 48 | * |
49 | 49 | * @return string |
50 | 50 | */ |
51 | - private function get_meta( $post_id, $key ) { |
|
52 | - if ( empty( $post_id ) ) { |
|
51 | + private function get_meta($post_id, $key) { |
|
52 | + if (empty($post_id)) { |
|
53 | 53 | return ''; |
54 | 54 | } |
55 | 55 | |
56 | - $post_id = intval( $post_id ); |
|
56 | + $post_id = intval($post_id); |
|
57 | 57 | |
58 | - $meta_key = sprintf( '_pronamic_gateway_%s', $key ); |
|
58 | + $meta_key = sprintf('_pronamic_gateway_%s', $key); |
|
59 | 59 | |
60 | 60 | // Get post meta. |
61 | - $meta_value = get_post_meta( $post_id, $meta_key, true ); |
|
61 | + $meta_value = get_post_meta($post_id, $meta_key, true); |
|
62 | 62 | |
63 | - if ( false === $meta_value ) { |
|
63 | + if (false === $meta_value) { |
|
64 | 64 | $meta_value = ''; |
65 | 65 | } |
66 | 66 |
@@ -28,23 +28,23 @@ discard block |
||
28 | 28 | * |
29 | 29 | * @param Config $config Config. |
30 | 30 | */ |
31 | - public function __construct( Config $config ) { |
|
32 | - parent::__construct( $config ); |
|
31 | + public function __construct(Config $config) { |
|
32 | + parent::__construct($config); |
|
33 | 33 | |
34 | - $this->set_method( self::METHOD_HTTP_REDIRECT ); |
|
34 | + $this->set_method(self::METHOD_HTTP_REDIRECT); |
|
35 | 35 | |
36 | 36 | // Client. |
37 | 37 | $this->client = new Client(); |
38 | 38 | |
39 | 39 | $url = Client::URL_PRODUCTION; |
40 | 40 | |
41 | - if ( self::MODE_TEST === $config->mode ) { |
|
41 | + if (self::MODE_TEST === $config->mode) { |
|
42 | 42 | $url = Client::URL_SANDBOX; |
43 | 43 | } |
44 | 44 | |
45 | - $this->client->set_url( $url ); |
|
46 | - $this->client->set_refresh_token( $config->refresh_token ); |
|
47 | - $this->client->set_signing_key( $config->signing_key ); |
|
45 | + $this->client->set_url($url); |
|
46 | + $this->client->set_refresh_token($config->refresh_token); |
|
47 | + $this->client->set_signing_key($config->signing_key); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | /** |
@@ -69,39 +69,39 @@ discard block |
||
69 | 69 | * |
70 | 70 | * @param Payment $payment Payment. |
71 | 71 | */ |
72 | - public function start( Payment $payment ) { |
|
73 | - $merchant_order_id = $payment->format_string( $this->config->order_id ); |
|
72 | + public function start(Payment $payment) { |
|
73 | + $merchant_order_id = $payment->format_string($this->config->order_id); |
|
74 | 74 | |
75 | - $payment->set_meta( 'omnikassa_2_merchant_order_id', $merchant_order_id ); |
|
75 | + $payment->set_meta('omnikassa_2_merchant_order_id', $merchant_order_id); |
|
76 | 76 | |
77 | 77 | $amount = new Money( |
78 | 78 | $payment->get_currency(), |
79 | - Core_Util::amount_to_cents( $payment->get_amount()->get_amount() ) |
|
79 | + Core_Util::amount_to_cents($payment->get_amount()->get_amount()) |
|
80 | 80 | ); |
81 | 81 | |
82 | - $merchant_return_url = str_replace( '.test', '.nl', $payment->get_return_url() ); |
|
82 | + $merchant_return_url = str_replace('.test', '.nl', $payment->get_return_url()); |
|
83 | 83 | |
84 | - $order = new Order( $merchant_order_id, $amount, $merchant_return_url ); |
|
84 | + $order = new Order($merchant_order_id, $amount, $merchant_return_url); |
|
85 | 85 | |
86 | - $order->set_description( $payment->get_description() ); |
|
87 | - $order->set_language( $payment->get_language() ); |
|
86 | + $order->set_description($payment->get_description()); |
|
87 | + $order->set_language($payment->get_language()); |
|
88 | 88 | |
89 | 89 | // Payment brand. |
90 | - $payment_brand = PaymentBrands::transform( $payment->get_method() ); |
|
90 | + $payment_brand = PaymentBrands::transform($payment->get_method()); |
|
91 | 91 | |
92 | - $order->set_payment_brand( $payment_brand ); |
|
92 | + $order->set_payment_brand($payment_brand); |
|
93 | 93 | |
94 | - if ( null !== $payment_brand ) { |
|
94 | + if (null !== $payment_brand) { |
|
95 | 95 | // Payment brand force should only be set if payment brand is not empty. |
96 | - $order->set_payment_brand_force( PaymentBrandForce::FORCE_ONCE ); |
|
96 | + $order->set_payment_brand_force(PaymentBrandForce::FORCE_ONCE); |
|
97 | 97 | } |
98 | 98 | |
99 | - if ( ! $this->config->is_access_token_valid() ) { |
|
99 | + if ( ! $this->config->is_access_token_valid()) { |
|
100 | 100 | $data = $this->client->get_access_token_data(); |
101 | 101 | |
102 | 102 | $error = $this->client->get_error(); |
103 | 103 | |
104 | - if ( is_wp_error( $error ) ) { |
|
104 | + if (is_wp_error($error)) { |
|
105 | 105 | $this->error = $error; |
106 | 106 | |
107 | 107 | return; |
@@ -110,22 +110,22 @@ discard block |
||
110 | 110 | $this->config->access_token = $data->token; |
111 | 111 | $this->config->access_token_valid_until = $data->validUntil; |
112 | 112 | |
113 | - update_post_meta( $this->config->post_id, '_pronamic_gateway_omnikassa_2_access_token', $data->token ); |
|
114 | - update_post_meta( $this->config->post_id, '_pronamic_gateway_omnikassa_2_access_token_valid_until', $data->validUntil ); |
|
113 | + update_post_meta($this->config->post_id, '_pronamic_gateway_omnikassa_2_access_token', $data->token); |
|
114 | + update_post_meta($this->config->post_id, '_pronamic_gateway_omnikassa_2_access_token_valid_until', $data->validUntil); |
|
115 | 115 | } |
116 | 116 | |
117 | - $result = $this->client->order_announce( $this->config, $order ); |
|
117 | + $result = $this->client->order_announce($this->config, $order); |
|
118 | 118 | |
119 | 119 | $error = $this->client->get_error(); |
120 | 120 | |
121 | - if ( is_wp_error( $error ) ) { |
|
121 | + if (is_wp_error($error)) { |
|
122 | 122 | $this->error = $error; |
123 | 123 | |
124 | 124 | return; |
125 | 125 | } |
126 | 126 | |
127 | - if ( $result ) { |
|
128 | - $payment->set_action_url( $result->redirectUrl ); |
|
127 | + if ($result) { |
|
128 | + $payment->set_action_url($result->redirectUrl); |
|
129 | 129 | } |
130 | 130 | } |
131 | 131 | |
@@ -134,45 +134,45 @@ discard block |
||
134 | 134 | * |
135 | 135 | * @param Payment $payment Payment. |
136 | 136 | */ |
137 | - public function update_status( Payment $payment ) { |
|
138 | - if ( ! ReturnParameters::contains( $_GET ) ) { // WPCS: CSRF ok. |
|
137 | + public function update_status(Payment $payment) { |
|
138 | + if ( ! ReturnParameters::contains($_GET)) { // WPCS: CSRF ok. |
|
139 | 139 | return; |
140 | 140 | } |
141 | 141 | |
142 | - $parameters = ReturnParameters::from_array( $_GET ); // WPCS: CSRF ok. |
|
142 | + $parameters = ReturnParameters::from_array($_GET); // WPCS: CSRF ok. |
|
143 | 143 | |
144 | 144 | // Note. |
145 | 145 | $note_values = array( |
146 | 146 | 'order_id' => $parameters->get_order_id(), |
147 | 147 | 'status' => $parameters->get_status(), |
148 | 148 | 'signature' => $parameters->get_signature(), |
149 | - 'valid' => $parameters->is_valid( $this->config->signing_key ) ? 'true' : 'false', |
|
149 | + 'valid' => $parameters->is_valid($this->config->signing_key) ? 'true' : 'false', |
|
150 | 150 | ); |
151 | 151 | |
152 | 152 | $note = ''; |
153 | 153 | |
154 | 154 | $note .= '<p>'; |
155 | - $note .= __( 'OmniKassa 2.0 return URL requested:', 'pronamic_ideal' ); |
|
155 | + $note .= __('OmniKassa 2.0 return URL requested:', 'pronamic_ideal'); |
|
156 | 156 | $note .= '</p>'; |
157 | 157 | |
158 | 158 | $note .= '<dl>'; |
159 | 159 | |
160 | - foreach ( $note_values as $key => $value ) { |
|
161 | - $note .= sprintf( '<dt>%s</dt>', esc_html( $key ) ); |
|
162 | - $note .= sprintf( '<dd>%s</dd>', esc_html( $value ) ); |
|
160 | + foreach ($note_values as $key => $value) { |
|
161 | + $note .= sprintf('<dt>%s</dt>', esc_html($key)); |
|
162 | + $note .= sprintf('<dd>%s</dd>', esc_html($value)); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | $note .= '</dl>'; |
166 | 166 | |
167 | - $payment->add_note( $note ); |
|
167 | + $payment->add_note($note); |
|
168 | 168 | |
169 | 169 | // Validate. |
170 | - if ( ! $parameters->is_valid( $this->config->signing_key ) ) { |
|
170 | + if ( ! $parameters->is_valid($this->config->signing_key)) { |
|
171 | 171 | return; |
172 | 172 | } |
173 | 173 | |
174 | 174 | // Status. |
175 | - $payment->set_status( Statuses::transform( $parameters->get_status() ) ); |
|
175 | + $payment->set_status(Statuses::transform($parameters->get_status())); |
|
176 | 176 | } |
177 | 177 | |
178 | 178 | /** |
@@ -182,14 +182,14 @@ discard block |
||
182 | 182 | * |
183 | 183 | * @return void |
184 | 184 | */ |
185 | - public function handle_notification( Notification $notification ) { |
|
186 | - if ( ! $notification->is_valid( $this->config->signing_key ) ) { |
|
185 | + public function handle_notification(Notification $notification) { |
|
186 | + if ( ! $notification->is_valid($this->config->signing_key)) { |
|
187 | 187 | return; |
188 | 188 | } |
189 | 189 | |
190 | - switch ( $notification->get_event_name() ) { |
|
190 | + switch ($notification->get_event_name()) { |
|
191 | 191 | case 'merchant.order.status.changed': |
192 | - $this->handle_merchant_order_status_changed( $notification ); |
|
192 | + $this->handle_merchant_order_status_changed($notification); |
|
193 | 193 | } |
194 | 194 | } |
195 | 195 | |
@@ -200,38 +200,38 @@ discard block |
||
200 | 200 | * |
201 | 201 | * @return void |
202 | 202 | */ |
203 | - private function handle_merchant_order_status_changed( Notification $notification ) { |
|
203 | + private function handle_merchant_order_status_changed(Notification $notification) { |
|
204 | 204 | do { |
205 | - $order_results = $this->client->get_order_results( $notification->get_authentication() ); |
|
205 | + $order_results = $this->client->get_order_results($notification->get_authentication()); |
|
206 | 206 | |
207 | - if ( ! $order_results || $order_results->is_valid( $this->config->signing_key ) ) { |
|
207 | + if ( ! $order_results || $order_results->is_valid($this->config->signing_key)) { |
|
208 | 208 | return; |
209 | 209 | } |
210 | 210 | |
211 | - foreach ( $order_results as $order_result ) { |
|
212 | - $payment = get_pronamic_payment_by_meta( '_pronamic_payment_omnikassa_2_merchant_order_id', $order_result->get_merchant_order_id() ); |
|
211 | + foreach ($order_results as $order_result) { |
|
212 | + $payment = get_pronamic_payment_by_meta('_pronamic_payment_omnikassa_2_merchant_order_id', $order_result->get_merchant_order_id()); |
|
213 | 213 | |
214 | - if ( empty( $payment ) ) { |
|
214 | + if (empty($payment)) { |
|
215 | 215 | continue; |
216 | 216 | } |
217 | 217 | |
218 | - $payment->set_transaction_id( $order_result->get_omnikassa_order_id() ); |
|
219 | - $payment->set_status( Statuses::transform( $order_result->get_order_status() ) ); |
|
218 | + $payment->set_transaction_id($order_result->get_omnikassa_order_id()); |
|
219 | + $payment->set_status(Statuses::transform($order_result->get_order_status())); |
|
220 | 220 | |
221 | 221 | // Note. |
222 | 222 | $note = ''; |
223 | 223 | |
224 | 224 | $note .= '<p>'; |
225 | - $note .= __( 'OmniKassa 2.0 webhook URL requested:', 'pronamic_ideal' ); |
|
225 | + $note .= __('OmniKassa 2.0 webhook URL requested:', 'pronamic_ideal'); |
|
226 | 226 | $note .= '</p>'; |
227 | 227 | $note .= '<pre>'; |
228 | - $note .= wp_json_encode( $order_result->get_json(), JSON_PRETTY_PRINT ); |
|
228 | + $note .= wp_json_encode($order_result->get_json(), JSON_PRETTY_PRINT); |
|
229 | 229 | $note .= '</pre>'; |
230 | 230 | |
231 | - $payment->add_note( $note ); |
|
231 | + $payment->add_note($note); |
|
232 | 232 | |
233 | 233 | $payment->save(); |
234 | 234 | } |
235 | - } while ( $order_results->more_available() ); |
|
235 | + } while ($order_results->more_available()); |
|
236 | 236 | } |
237 | 237 | } |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | * @param Money $paid_amount Paid amount. |
96 | 96 | * @param Money $total_amount Total amount. |
97 | 97 | */ |
98 | - public function __construct( $merchant_order_id, $omnikassa_order_id, $poi_id, $order_status, $order_status_datetime, $error_code, Money $paid_amount, Money $total_amount ) { |
|
98 | + public function __construct($merchant_order_id, $omnikassa_order_id, $poi_id, $order_status, $order_status_datetime, $error_code, Money $paid_amount, Money $total_amount) { |
|
99 | 99 | $this->merchant_order_id = $merchant_order_id; |
100 | 100 | $this->omnikassa_order_id = $omnikassa_order_id; |
101 | 101 | $this->poi_id = $poi_id; |
@@ -203,37 +203,37 @@ discard block |
||
203 | 203 | * @return OrderResult |
204 | 204 | * @throws InvalidArgumentException Throws invalid argument exception when object does not contains the required properties. |
205 | 205 | */ |
206 | - public static function from_object( stdClass $object ) { |
|
207 | - if ( ! isset( $object->merchantOrderId ) ) { |
|
208 | - throw new InvalidArgumentException( 'Object must contain `merchantOrderId` property.' ); |
|
206 | + public static function from_object(stdClass $object) { |
|
207 | + if ( ! isset($object->merchantOrderId)) { |
|
208 | + throw new InvalidArgumentException('Object must contain `merchantOrderId` property.'); |
|
209 | 209 | } |
210 | 210 | |
211 | - if ( ! isset( $object->omnikassaOrderId ) ) { |
|
212 | - throw new InvalidArgumentException( 'Object must contain `omnikassaOrderId` property.' ); |
|
211 | + if ( ! isset($object->omnikassaOrderId)) { |
|
212 | + throw new InvalidArgumentException('Object must contain `omnikassaOrderId` property.'); |
|
213 | 213 | } |
214 | 214 | |
215 | - if ( ! isset( $object->poiId ) ) { |
|
216 | - throw new InvalidArgumentException( 'Object must contain `poiId` property.' ); |
|
215 | + if ( ! isset($object->poiId)) { |
|
216 | + throw new InvalidArgumentException('Object must contain `poiId` property.'); |
|
217 | 217 | } |
218 | 218 | |
219 | - if ( ! isset( $object->orderStatus ) ) { |
|
220 | - throw new InvalidArgumentException( 'Object must contain `orderStatus` property.' ); |
|
219 | + if ( ! isset($object->orderStatus)) { |
|
220 | + throw new InvalidArgumentException('Object must contain `orderStatus` property.'); |
|
221 | 221 | } |
222 | 222 | |
223 | - if ( ! isset( $object->orderStatusDateTime ) ) { |
|
224 | - throw new InvalidArgumentException( 'Object must contain `orderStatusDateTime` property.' ); |
|
223 | + if ( ! isset($object->orderStatusDateTime)) { |
|
224 | + throw new InvalidArgumentException('Object must contain `orderStatusDateTime` property.'); |
|
225 | 225 | } |
226 | 226 | |
227 | - if ( ! isset( $object->errorCode ) ) { |
|
228 | - throw new InvalidArgumentException( 'Object must contain `errorCode` property.' ); |
|
227 | + if ( ! isset($object->errorCode)) { |
|
228 | + throw new InvalidArgumentException('Object must contain `errorCode` property.'); |
|
229 | 229 | } |
230 | 230 | |
231 | - if ( ! isset( $object->paidAmount ) ) { |
|
232 | - throw new InvalidArgumentException( 'Object must contain `paidAmount` property.' ); |
|
231 | + if ( ! isset($object->paidAmount)) { |
|
232 | + throw new InvalidArgumentException('Object must contain `paidAmount` property.'); |
|
233 | 233 | } |
234 | 234 | |
235 | - if ( ! isset( $object->totalAmount ) ) { |
|
236 | - throw new InvalidArgumentException( 'Object must contain `totalAmount` property.' ); |
|
235 | + if ( ! isset($object->totalAmount)) { |
|
236 | + throw new InvalidArgumentException('Object must contain `totalAmount` property.'); |
|
237 | 237 | } |
238 | 238 | |
239 | 239 | return new self( |
@@ -243,8 +243,8 @@ discard block |
||
243 | 243 | $object->orderStatus, |
244 | 244 | $object->orderStatusDateTime, |
245 | 245 | $object->errorCode, |
246 | - Money::from_object( $object->paidAmount ), |
|
247 | - Money::from_object( $object->totalAmount ) |
|
246 | + Money::from_object($object->paidAmount), |
|
247 | + Money::from_object($object->totalAmount) |
|
248 | 248 | ); |
249 | 249 | } |
250 | 250 | |
@@ -255,15 +255,15 @@ discard block |
||
255 | 255 | * @return OrderResult |
256 | 256 | * @throws \JsonSchema\Exception\ValidationException Throws JSON schema validation exception when JSON is invalid. |
257 | 257 | */ |
258 | - public static function from_json( $json ) { |
|
259 | - $data = json_decode( $json ); |
|
258 | + public static function from_json($json) { |
|
259 | + $data = json_decode($json); |
|
260 | 260 | |
261 | 261 | $validator = new Validator(); |
262 | 262 | |
263 | - $validator->validate( $data, (object) array( |
|
264 | - '$ref' => 'file://' . realpath( __DIR__ . '/../json-schemas/json-schema-order-result.json' ), |
|
265 | - ), Constraint::CHECK_MODE_EXCEPTIONS ); |
|
263 | + $validator->validate($data, (object) array( |
|
264 | + '$ref' => 'file://' . realpath(__DIR__ . '/../json-schemas/json-schema-order-result.json'), |
|
265 | + ), Constraint::CHECK_MODE_EXCEPTIONS); |
|
266 | 266 | |
267 | - return self::from_object( $data ); |
|
267 | + return self::from_object($data); |
|
268 | 268 | } |
269 | 269 | } |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | * |
86 | 86 | * @param string $url URL. |
87 | 87 | */ |
88 | - public function set_url( $url ) { |
|
88 | + public function set_url($url) { |
|
89 | 89 | $this->url = $url; |
90 | 90 | } |
91 | 91 | |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | * |
104 | 104 | * @param string $refresh_token Refresh token. |
105 | 105 | */ |
106 | - public function set_refresh_token( $refresh_token ) { |
|
106 | + public function set_refresh_token($refresh_token) { |
|
107 | 107 | $this->refresh_token = $refresh_token; |
108 | 108 | } |
109 | 109 | |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | * |
122 | 122 | * @param string $signing_key Signing key. |
123 | 123 | */ |
124 | - public function set_signing_key( $signing_key ) { |
|
124 | + public function set_signing_key($signing_key) { |
|
125 | 125 | $this->signing_key = $signing_key; |
126 | 126 | } |
127 | 127 | |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | * @param string $token Authorization token. |
134 | 134 | * @param object|null $object Object. |
135 | 135 | */ |
136 | - private function request( $method, $endpoint, $token, $object = null ) { |
|
136 | + private function request($method, $endpoint, $token, $object = null) { |
|
137 | 137 | // URL. |
138 | 138 | $url = $this->get_url() . $endpoint; |
139 | 139 | |
@@ -145,45 +145,45 @@ discard block |
||
145 | 145 | ), |
146 | 146 | ); |
147 | 147 | |
148 | - if ( null !== $object ) { |
|
148 | + if (null !== $object) { |
|
149 | 149 | $args['headers']['Content-Type'] = 'application/json'; |
150 | 150 | |
151 | - $args['body'] = wp_json_encode( $object ); |
|
151 | + $args['body'] = wp_json_encode($object); |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | // Request. |
155 | - $response = wp_remote_request( $url, $args ); |
|
155 | + $response = wp_remote_request($url, $args); |
|
156 | 156 | |
157 | - if ( is_wp_error( $response ) ) { |
|
157 | + if (is_wp_error($response)) { |
|
158 | 158 | $this->error = $response; |
159 | 159 | |
160 | - $this->error->add( 'omnikassa_2_error', 'HTTP Request Failed' ); |
|
160 | + $this->error->add('omnikassa_2_error', 'HTTP Request Failed'); |
|
161 | 161 | |
162 | 162 | return false; |
163 | 163 | } |
164 | 164 | |
165 | 165 | // Body. |
166 | - $body = wp_remote_retrieve_body( $response ); |
|
166 | + $body = wp_remote_retrieve_body($response); |
|
167 | 167 | |
168 | - $data = json_decode( $body ); |
|
168 | + $data = json_decode($body); |
|
169 | 169 | |
170 | - if ( ! is_object( $data ) ) { |
|
171 | - $this->error = new \WP_Error( 'omnikassa_2_error', 'Could not parse response.', $data ); |
|
170 | + if ( ! is_object($data)) { |
|
171 | + $this->error = new \WP_Error('omnikassa_2_error', 'Could not parse response.', $data); |
|
172 | 172 | |
173 | 173 | return false; |
174 | 174 | } |
175 | 175 | |
176 | 176 | // Error. |
177 | - if ( isset( $data->errorCode ) ) { |
|
177 | + if (isset($data->errorCode)) { |
|
178 | 178 | $message = 'Unknown error.'; |
179 | 179 | |
180 | - if ( isset( $data->consumerMessage ) ) { |
|
180 | + if (isset($data->consumerMessage)) { |
|
181 | 181 | $message = $data->consumerMessage; |
182 | - } elseif ( isset( $data->errorMessage ) ) { |
|
182 | + } elseif (isset($data->errorMessage)) { |
|
183 | 183 | $message = $data->errorMessage; |
184 | 184 | } |
185 | 185 | |
186 | - $this->error = new \WP_Error( 'omnikassa_2_error', $message, $data ); |
|
186 | + $this->error = new \WP_Error('omnikassa_2_error', $message, $data); |
|
187 | 187 | |
188 | 188 | return false; |
189 | 189 | } |
@@ -198,7 +198,7 @@ discard block |
||
198 | 198 | * @return object|false |
199 | 199 | */ |
200 | 200 | public function get_access_token_data() { |
201 | - return $this->request( 'GET', 'gatekeeper/refresh', $this->get_refresh_token() ); |
|
201 | + return $this->request('GET', 'gatekeeper/refresh', $this->get_refresh_token()); |
|
202 | 202 | } |
203 | 203 | |
204 | 204 | /** |
@@ -208,12 +208,12 @@ discard block |
||
208 | 208 | * @param Order $order Order. |
209 | 209 | * @return object|bool |
210 | 210 | */ |
211 | - public function order_announce( $config, Order $order ) { |
|
211 | + public function order_announce($config, Order $order) { |
|
212 | 212 | $object = $order->get_json(); |
213 | 213 | |
214 | - $object->signature = Security::get_signature( $order, $config->signing_key ); |
|
214 | + $object->signature = Security::get_signature($order, $config->signing_key); |
|
215 | 215 | |
216 | - return $this->request( 'POST', 'order/server/api/order', $config->access_token, $object ); |
|
216 | + return $this->request('POST', 'order/server/api/order', $config->access_token, $object); |
|
217 | 217 | } |
218 | 218 | |
219 | 219 | /** |
@@ -223,13 +223,13 @@ discard block |
||
223 | 223 | * |
224 | 224 | * @return OrderResults|false |
225 | 225 | */ |
226 | - public function get_order_results( $notification_token ) { |
|
227 | - $result = $this->request( 'GET', 'order/server/api/events/results/merchant.order.status.changed', $notification_token ); |
|
226 | + public function get_order_results($notification_token) { |
|
227 | + $result = $this->request('GET', 'order/server/api/events/results/merchant.order.status.changed', $notification_token); |
|
228 | 228 | |
229 | - if ( ! is_object( $result ) ) { |
|
229 | + if ( ! is_object($result)) { |
|
230 | 230 | return false; |
231 | 231 | } |
232 | 232 | |
233 | - return OrderResults::from_object( $result ); |
|
233 | + return OrderResults::from_object($result); |
|
234 | 234 | } |
235 | 235 | } |