@@ -151,8 +151,8 @@ discard block |
||
| 151 | 151 | * @param Money $amount Amount. |
| 152 | 152 | * @param string $merchant_return_url Merchant return URL. |
| 153 | 153 | */ |
| 154 | - public function __construct( $merchant_order_id, $amount, $merchant_return_url ) { |
|
| 155 | - $this->timestamp = date( DATE_ATOM ); |
|
| 154 | + public function __construct($merchant_order_id, $amount, $merchant_return_url) { |
|
| 155 | + $this->timestamp = date(DATE_ATOM); |
|
| 156 | 156 | $this->merchant_order_id = $merchant_order_id; |
| 157 | 157 | $this->amount = $amount; |
| 158 | 158 | $this->merchant_return_url = $merchant_return_url; |
@@ -163,7 +163,7 @@ discard block |
||
| 163 | 163 | * |
| 164 | 164 | * @param string $description Description. |
| 165 | 165 | */ |
| 166 | - public function set_description( $description ) { |
|
| 166 | + public function set_description($description) { |
|
| 167 | 167 | $this->description = $description; |
| 168 | 168 | } |
| 169 | 169 | |
@@ -172,7 +172,7 @@ discard block |
||
| 172 | 172 | * |
| 173 | 173 | * @param string $language Language. |
| 174 | 174 | */ |
| 175 | - public function set_language( $language ) { |
|
| 175 | + public function set_language($language) { |
|
| 176 | 176 | $this->language = $language; |
| 177 | 177 | } |
| 178 | 178 | |
@@ -181,7 +181,7 @@ discard block |
||
| 181 | 181 | * |
| 182 | 182 | * @param string $payment_brand Payment brand. |
| 183 | 183 | */ |
| 184 | - public function set_payment_brand( $payment_brand ) { |
|
| 184 | + public function set_payment_brand($payment_brand) { |
|
| 185 | 185 | $this->payment_brand = $payment_brand; |
| 186 | 186 | } |
| 187 | 187 | |
@@ -190,7 +190,7 @@ discard block |
||
| 190 | 190 | * |
| 191 | 191 | * @param string $payment_brand_force Payment brand force. |
| 192 | 192 | */ |
| 193 | - public function set_payment_brand_force( $payment_brand_force ) { |
|
| 193 | + public function set_payment_brand_force($payment_brand_force) { |
|
| 194 | 194 | $this->payment_brand_force = $payment_brand_force; |
| 195 | 195 | } |
| 196 | 196 | |
@@ -237,8 +237,8 @@ discard block |
||
| 237 | 237 | ); |
| 238 | 238 | |
| 239 | 239 | // Remove empty optional fields. |
| 240 | - $optional = array_filter( $optional ); |
|
| 240 | + $optional = array_filter($optional); |
|
| 241 | 241 | |
| 242 | - return array_merge( $fields, $optional ); |
|
| 242 | + return array_merge($fields, $optional); |
|
| 243 | 243 | } |
| 244 | 244 | } |
@@ -54,8 +54,8 @@ |
||
| 54 | 54 | * @param string $status OmniKassa 2.0 status. |
| 55 | 55 | * @return string|null |
| 56 | 56 | */ |
| 57 | - public static function transform( $status ) { |
|
| 58 | - switch ( $status ) { |
|
| 57 | + public static function transform($status) { |
|
| 58 | + switch ($status) { |
|
| 59 | 59 | case self::CANCELLED: |
| 60 | 60 | return Core_Statuses::CANCELLED; |
| 61 | 61 | case self::COMPLETED: |
@@ -25,21 +25,21 @@ discard block |
||
| 25 | 25 | * @param string $signing_key Signing Key. |
| 26 | 26 | * @return string|null |
| 27 | 27 | */ |
| 28 | - public static function get_signature( Signable $signable, $signing_key ) { |
|
| 28 | + public static function get_signature(Signable $signable, $signing_key) { |
|
| 29 | 29 | $data = $signable->get_signature_data(); |
| 30 | 30 | |
| 31 | - if ( empty( $data ) ) { |
|
| 31 | + if (empty($data)) { |
|
| 32 | 32 | return; |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | - if ( empty( $signing_key ) ) { |
|
| 35 | + if (empty($signing_key)) { |
|
| 36 | 36 | return; |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | $signature = hash_hmac( |
| 40 | 40 | 'sha512', |
| 41 | - implode( ',', $data ), |
|
| 42 | - base64_decode( $signing_key ) |
|
| 41 | + implode(',', $data), |
|
| 42 | + base64_decode($signing_key) |
|
| 43 | 43 | ); |
| 44 | 44 | |
| 45 | 45 | return $signature; |
@@ -52,12 +52,12 @@ discard block |
||
| 52 | 52 | * @param string $signature_b Signature B. |
| 53 | 53 | * @return bool True if valid, false otherwise. |
| 54 | 54 | */ |
| 55 | - public static function validate_signature( $signature_a, $signature_b ) { |
|
| 56 | - if ( empty( $signature_a ) || empty( $signature_b ) ) { |
|
| 55 | + public static function validate_signature($signature_a, $signature_b) { |
|
| 56 | + if (empty($signature_a) || empty($signature_b)) { |
|
| 57 | 57 | // Empty signature string or null from calculation. |
| 58 | 58 | return false; |
| 59 | 59 | } |
| 60 | 60 | |
| 61 | - return ( 0 === strcasecmp( $signature_a, $signature_b ) ); |
|
| 61 | + return (0 === strcasecmp($signature_a, $signature_b)); |
|
| 62 | 62 | } |
| 63 | 63 | } |
@@ -61,8 +61,8 @@ discard block |
||
| 61 | 61 | * @param int|string $poi_id POI ID. |
| 62 | 62 | * @param string $signature Signature. |
| 63 | 63 | */ |
| 64 | - public function __construct( $authentication, $expiry, $event_name, $poi_id, $signature ) { |
|
| 65 | - parent::__construct( $signature ); |
|
| 64 | + public function __construct($authentication, $expiry, $event_name, $poi_id, $signature) { |
|
| 65 | + parent::__construct($signature); |
|
| 66 | 66 | |
| 67 | 67 | $this->authentication = $authentication; |
| 68 | 68 | $this->expiry = $expiry; |
@@ -94,9 +94,9 @@ discard block |
||
| 94 | 94 | * @return bool True if notice authentication token is epxired, false otherwise. |
| 95 | 95 | */ |
| 96 | 96 | public function is_expired() { |
| 97 | - $timestamp = strtotime( $this->get_expiry() ); |
|
| 97 | + $timestamp = strtotime($this->get_expiry()); |
|
| 98 | 98 | |
| 99 | - if ( false === $timestamp ) { |
|
| 99 | + if (false === $timestamp) { |
|
| 100 | 100 | return true; |
| 101 | 101 | } |
| 102 | 102 | |
@@ -142,25 +142,25 @@ discard block |
||
| 142 | 142 | * @return Notification |
| 143 | 143 | * @throws InvalidArgumentException Throws invalid argument exception when object does not contains the required properties. |
| 144 | 144 | */ |
| 145 | - public static function from_object( stdClass $object ) { |
|
| 146 | - if ( ! isset( $object->signature ) ) { |
|
| 147 | - throw new InvalidArgumentException( 'Object must contain `signature` property.' ); |
|
| 145 | + public static function from_object(stdClass $object) { |
|
| 146 | + if ( ! isset($object->signature)) { |
|
| 147 | + throw new InvalidArgumentException('Object must contain `signature` property.'); |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | - if ( ! isset( $object->authentication ) ) { |
|
| 151 | - throw new InvalidArgumentException( 'Object must contain `authentication` property.' ); |
|
| 150 | + if ( ! isset($object->authentication)) { |
|
| 151 | + throw new InvalidArgumentException('Object must contain `authentication` property.'); |
|
| 152 | 152 | } |
| 153 | 153 | |
| 154 | - if ( ! isset( $object->expiry ) ) { |
|
| 155 | - throw new InvalidArgumentException( 'Object must contain `expiry` property.' ); |
|
| 154 | + if ( ! isset($object->expiry)) { |
|
| 155 | + throw new InvalidArgumentException('Object must contain `expiry` property.'); |
|
| 156 | 156 | } |
| 157 | 157 | |
| 158 | - if ( ! isset( $object->eventName ) ) { |
|
| 159 | - throw new InvalidArgumentException( 'Object must contain `eventName` property.' ); |
|
| 158 | + if ( ! isset($object->eventName)) { |
|
| 159 | + throw new InvalidArgumentException('Object must contain `eventName` property.'); |
|
| 160 | 160 | } |
| 161 | 161 | |
| 162 | - if ( ! isset( $object->poiId ) ) { |
|
| 163 | - throw new InvalidArgumentException( 'Object must contain `poiId` property.' ); |
|
| 162 | + if ( ! isset($object->poiId)) { |
|
| 163 | + throw new InvalidArgumentException('Object must contain `poiId` property.'); |
|
| 164 | 164 | } |
| 165 | 165 | |
| 166 | 166 | return new self( |
@@ -179,15 +179,15 @@ discard block |
||
| 179 | 179 | * @return Notification |
| 180 | 180 | * @throws \JsonSchema\Exception\ValidationException Throws JSON schema validation exception when JSON is invalid. |
| 181 | 181 | */ |
| 182 | - public static function from_json( $json ) { |
|
| 183 | - $data = json_decode( $json ); |
|
| 182 | + public static function from_json($json) { |
|
| 183 | + $data = json_decode($json); |
|
| 184 | 184 | |
| 185 | 185 | $validator = new Validator(); |
| 186 | 186 | |
| 187 | - $validator->validate( $data, (object) array( |
|
| 188 | - '$ref' => 'file://' . realpath( __DIR__ . '/../json-schemas/notification.json' ), |
|
| 189 | - ), Constraint::CHECK_MODE_EXCEPTIONS ); |
|
| 187 | + $validator->validate($data, (object) array( |
|
| 188 | + '$ref' => 'file://' . realpath(__DIR__ . '/../json-schemas/notification.json'), |
|
| 189 | + ), Constraint::CHECK_MODE_EXCEPTIONS); |
|
| 190 | 190 | |
| 191 | - return self::from_object( $data ); |
|
| 191 | + return self::from_object($data); |
|
| 192 | 192 | } |
| 193 | 193 | } |
@@ -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 | } |