Changeset 3138287
- Timestamp:
- 08/20/2024 03:08:31 PM (20 months ago)
- Location:
- yoco-payment-gateway
- Files:
-
- 62 added
- 14 edited
- 1 copied
-
tags/3.7.0 (copied) (copied from yoco-payment-gateway/trunk)
-
tags/3.7.0/.env-example (added)
-
tags/3.7.0/.nvmrc (added)
-
tags/3.7.0/.wp-env.json (added)
-
tags/3.7.0/README.md (modified) (1 diff)
-
tags/3.7.0/pnpm-lock.yaml (added)
-
tags/3.7.0/readme.txt (modified) (2 diffs)
-
tags/3.7.0/src/Gateway/PaymentStatusScheduler.php (modified) (10 diffs)
-
tags/3.7.0/src/Helpers/Admin/Notices.php (modified) (1 diff)
-
tags/3.7.0/src/Telemetry/Models/TelemetryObject.php (modified) (4 diffs)
-
tags/3.7.0/src/Telemetry/Telemetry.php (modified) (1 diff)
-
tags/3.7.0/tests (added)
-
tags/3.7.0/tests/e2e-pw (added)
-
tags/3.7.0/tests/e2e-pw/README.md (added)
-
tags/3.7.0/tests/e2e-pw/WSL_SETUP_INSTRUCTIONS.md (added)
-
tags/3.7.0/tests/e2e-pw/bin (added)
-
tags/3.7.0/tests/e2e-pw/bin/test-env-setup.sh (added)
-
tags/3.7.0/tests/e2e-pw/bin/update-wp-env.php (added)
-
tags/3.7.0/tests/e2e-pw/daily.playwright.config.js (added)
-
tags/3.7.0/tests/e2e-pw/global-setup.js (added)
-
tags/3.7.0/tests/e2e-pw/global-teardown.js (added)
-
tags/3.7.0/tests/e2e-pw/ignore-plugin-tests.playwright.config.js (added)
-
tags/3.7.0/tests/e2e-pw/playwright.config.js (added)
-
tags/3.7.0/tests/e2e-pw/test-data (added)
-
tags/3.7.0/tests/e2e-pw/test-data/data.js (added)
-
tags/3.7.0/tests/e2e-pw/test-data/sample_products.xml (added)
-
tags/3.7.0/tests/e2e-pw/tests (added)
-
tags/3.7.0/tests/e2e-pw/tests/1.basic.spec.js (added)
-
tags/3.7.0/tests/e2e-pw/tests/2.setup.spec.js (added)
-
tags/3.7.0/tests/e2e-pw/tests/3.checkout.spec.js (added)
-
tags/3.7.0/tests/e2e-pw/utils (added)
-
tags/3.7.0/tests/e2e-pw/utils/api.js (added)
-
tags/3.7.0/tests/e2e-pw/utils/index.js (added)
-
tags/3.7.0/tests/e2e-pw/utils/onboarding.js (added)
-
tags/3.7.0/tests/e2e-pw/utils/plugin-utils.js (added)
-
tags/3.7.0/tests/e2e-pw/utils/site.js (added)
-
tags/3.7.0/tests/e2e-pw/utils/wordpress.js (added)
-
tags/3.7.0/tests/wp-cli.yml (added)
-
tags/3.7.0/yoco_wc_payment_gateway.php (modified) (1 diff)
-
trunk/.env-example (added)
-
trunk/.nvmrc (added)
-
trunk/.wp-env.json (added)
-
trunk/README.md (modified) (1 diff)
-
trunk/pnpm-lock.yaml (added)
-
trunk/readme.txt (modified) (2 diffs)
-
trunk/src/Gateway/PaymentStatusScheduler.php (modified) (10 diffs)
-
trunk/src/Helpers/Admin/Notices.php (modified) (1 diff)
-
trunk/src/Telemetry/Models/TelemetryObject.php (modified) (4 diffs)
-
trunk/src/Telemetry/Telemetry.php (modified) (1 diff)
-
trunk/tests (added)
-
trunk/tests/e2e-pw (added)
-
trunk/tests/e2e-pw/README.md (added)
-
trunk/tests/e2e-pw/WSL_SETUP_INSTRUCTIONS.md (added)
-
trunk/tests/e2e-pw/bin (added)
-
trunk/tests/e2e-pw/bin/test-env-setup.sh (added)
-
trunk/tests/e2e-pw/bin/update-wp-env.php (added)
-
trunk/tests/e2e-pw/daily.playwright.config.js (added)
-
trunk/tests/e2e-pw/global-setup.js (added)
-
trunk/tests/e2e-pw/global-teardown.js (added)
-
trunk/tests/e2e-pw/ignore-plugin-tests.playwright.config.js (added)
-
trunk/tests/e2e-pw/playwright.config.js (added)
-
trunk/tests/e2e-pw/test-data (added)
-
trunk/tests/e2e-pw/test-data/data.js (added)
-
trunk/tests/e2e-pw/test-data/sample_products.xml (added)
-
trunk/tests/e2e-pw/tests (added)
-
trunk/tests/e2e-pw/tests/1.basic.spec.js (added)
-
trunk/tests/e2e-pw/tests/2.setup.spec.js (added)
-
trunk/tests/e2e-pw/tests/3.checkout.spec.js (added)
-
trunk/tests/e2e-pw/utils (added)
-
trunk/tests/e2e-pw/utils/api.js (added)
-
trunk/tests/e2e-pw/utils/index.js (added)
-
trunk/tests/e2e-pw/utils/onboarding.js (added)
-
trunk/tests/e2e-pw/utils/plugin-utils.js (added)
-
trunk/tests/e2e-pw/utils/site.js (added)
-
trunk/tests/e2e-pw/utils/wordpress.js (added)
-
trunk/tests/wp-cli.yml (added)
-
trunk/yoco_wc_payment_gateway.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
yoco-payment-gateway/tags/3.7.0/README.md
r3102357 r3138287 43 43 - [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html) 44 44 45 ### Note45 ### Updating the version 46 46 To update version, update it in the: 47 47 - [package.json](package.json) -
yoco-payment-gateway/tags/3.7.0/readme.txt
r3102357 r3138287 3 3 Tags: woocommerce,payment gateway 4 4 Requires at least: 5.0.0 5 Tested up to: 6. 55 Tested up to: 6.6 6 6 Requires PHP: 7.4.0 7 Stable tag: 3. 6.07 Stable tag: 3.7.0 8 8 License: GPLv2 or later 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 137 137 == Changelog == 138 138 139 = 3.7.0 = 140 141 * Update Payment Status Scheduler logic - Polling issue 142 * Add wp-env and e2e tests 143 * Telemetry webhook improvements 144 139 145 = 3.6.0 = 146 140 147 * Conditionally reset installation idempotency key. 141 148 * Extend the installation telemetry data. 142 149 143 150 = 3.5.0 = 151 144 152 * Add payment status polling as fallback method. 145 153 * Add simplify getting the logs to be shared with Yoco support. -
yoco-payment-gateway/tags/3.7.0/src/Gateway/PaymentStatusScheduler.php
r3067423 r3138287 18 18 private const SCHEDULE_INTERVAL = 60; // seconds. 19 19 20 private const NO_OF_RETRIES = 20;21 22 private const MAX_BACKOFF_TIME = 60; //minutes.20 private const NO_OF_RETRIES = 30; 21 22 private const MAX_BACKOFF_TIME = 7200; // 5 days in minutes. 23 23 24 24 private const WAIT_TIME_BEFORE_PROCESSING = 10; // minutes. … … 38 38 } 39 39 40 // Add order to processing list. 40 41 $this->add_order( $order->get_id() ); 41 42 } … … 43 44 public function process_list() { 44 45 $orders_to_process = get_option( 'yoco_orders_pending_payment', array() ); 45 $hold_stock_minutes = (int) get_option( 'woocommerce_hold_stock_minutes', 60 );46 $wait_before_processing = $hold_stock_minutes < self::WAIT_TIME_BEFORE_PROCESSING ? intval( $hold_stock_minutes / 2 ) : self::WAIT_TIME_BEFORE_PROCESSING;47 46 48 47 if ( empty( $orders_to_process ) || ! is_array( $orders_to_process ) ) { … … 62 61 // If order has payment ID saved in meta this means payment was successful and we remove order from the list. 63 62 if ( ! empty( $order->get_meta( 'yoco_order_payment_id', true ) ) ) { 64 $this->remove_order( $order ->get_id());63 $this->remove_order( $order_id ); 65 64 continue; 66 65 } 67 68 $backoff_time = min( self::MAX_BACKOFF_TIME, $order_data['i'] * $order_data['i'] );69 $now = new WC_DateTime( 'now' );70 $min_time_to_process = new WC_DateTime( 'now - ' . $wait_before_processing . ' min' );71 $next_time_to_process = new WC_DateTime( $order_data['t'] . ' + ' . $backoff_time . 'min' );72 66 73 67 // If number of retries exceeds maximum allowed number, log error and remove order from the list. 74 68 if ( $order_data['i'] > self::NO_OF_RETRIES ) { 75 yoco( Logger::class )->logError( sprintf( 'Failed to process payment for order: #%s', $order_id ) ); 76 $this->remove_order( $order->get_id() ); 69 // add order note. 70 $order->add_order_note( 71 sprintf( 72 // translators: 1: attempt number, 2: status. 73 __( 'Yoco: Failed to process payment after %d attempts', 'yoco_wc_payment_gateway' ), 74 $order_data['i'] 75 ) 76 ); 77 yoco( Logger::class )->logError( 78 sprintf( 79 'Failed to process payment for order: #%1$s after %2$d attempts', 80 $order_id, 81 $order_data['i'] 82 ) 83 ); 84 $this->remove_order( $order_id ); 77 85 continue; 78 86 } 79 87 80 // Check against time to process range.81 if (82 $min_time_to_process < $order->get_date_created() || 83 $next_time_to_process > $now84 ) {88 $now = new WC_DateTime( 'now' ); 89 $next_time_to_process = new WC_DateTime( $order_data['t'] ); 90 91 // If time to process is greater than now skip update. 92 if ( $next_time_to_process > $now ) { 85 93 continue; 86 94 } … … 96 104 $payment_status = $data['body']['status']; 97 105 $payment_id = $data['body']['paymentId']; 106 107 // add order note. 108 $order->add_order_note( 109 sprintf( 110 // translators: 1: attempt number, 2: status. 111 __( 'Yoco: Payment status update attempt #%1$d -- obtained status: %2$s', 'yoco_wc_payment_gateway' ), 112 $order_data['i'], 113 $payment_status 114 ) 115 ); 98 116 99 117 if ( 'completed' === $payment_status && true === $order->update_status( 'processing' ) ) { … … 123 141 return; 124 142 } 125 126 // If payment failed. Add MAX_BACKOFF_TIME to next process time and increase iteration counter. 143 // When payment capturing process fail. 127 144 if ( isset( $_GET['yoco_checkout_status'] ) && 'failed' === sanitize_key( $_GET['yoco_checkout_status'] ) ) { 128 145 $this->update_order( 129 146 $order_id, 130 147 'failed', 131 array( 132 't' => self::MAX_BACKOFF_TIME, 133 'i' => 9, 134 ) 148 false 135 149 ); 150 151 // Add order note. 152 $order = wc_get_order( $order_id ); 153 if ( $order instanceof WC_Order ) { 154 $order->add_order_note( __( 'Yoco: Payment capture failed.', 'yoco_wc_payment_gateway' ) ); 155 } 156 136 157 return; 137 158 } … … 140 161 } 141 162 142 // If payment is canceled. Add MAX_BACKOFF_TIME to next process time and increase iteration counter.163 // When payment is canceled. 143 164 if ( 144 165 isset( $_GET['key'] ) … … 156 177 $order_id, 157 178 'canceled', 158 array( 159 't' => self::MAX_BACKOFF_TIME, 160 'i' => 9, 161 ) 179 false 162 180 ); 181 182 // Add order note. 183 $order = wc_get_order( $order_id ); 184 if ( $order instanceof WC_Order ) { 185 $order->add_order_note( __( 'Yoco: Payment canceled by the customer.', 'yoco_wc_payment_gateway' ) ); 186 } 187 188 // Empty cart when user cancel payment, order is already created. 189 // Order can be accessed and paid from My Account page. 190 WC()->cart->empty_cart(); 163 191 } 164 192 } … … 216 244 */ 217 245 private function add_order( $order_id ) { 218 $orders = get_option( 'yoco_orders_pending_payment', array() ); 219 $orders = is_array( $orders ) ? $orders : array(); 220 $now = new WC_DateTime( 'now' ); 246 $orders = get_option( 'yoco_orders_pending_payment', array() ); 247 $orders = is_array( $orders ) ? $orders : array(); 248 $hold_stock_minutes = (int) get_option( 'woocommerce_hold_stock_minutes', 60 ); 249 $wait_before_processing = $hold_stock_minutes < self::WAIT_TIME_BEFORE_PROCESSING ? intval( $hold_stock_minutes / 2 ) : self::WAIT_TIME_BEFORE_PROCESSING; 250 $process_at = ( new WC_DateTime( 'now + ' . $wait_before_processing . ' min' ) )->__toString(); 221 251 222 252 if ( ! isset( $orders[ $order_id ] ) ) { 223 253 $orders[ $order_id ] = array( 224 't' => $ now->__toString(),254 't' => $process_at, 225 255 'i' => 1, 226 256 's' => 'init', … … 240 270 } 241 271 242 private function update_order( $order_id, $status = '', $args = array() ) { 272 /** 273 * Update order data in order processing list. 274 * 275 * @param int $order_id Order payment data. 276 * @param string $status Payment status. 277 * @param bool $increase_counter Counter flag, increase counter by default, prevent increase by passing false. 278 * 279 * @return void 280 */ 281 private function update_order( $order_id, $status, $increase_counter = true ) { 243 282 $orders = get_option( 'yoco_orders_pending_payment', array() ); 244 283 245 284 if ( isset( $orders[ $order_id ] ) ) { 246 $iteration = isset( $args['i'] ) ? $args['i'] : $orders[ $order_id ]['i']; 247 $status = $status ? $status : $orders[ $order_id ]['s']; 248 $next_process_time = isset( $args['t'] ) ? new WC_DateTime( 'now +' . $args['t'] . ' min' ) : new WC_DateTime( 'now' ); 285 $iteration = (int) $orders[ $order_id ]['i']; 286 $status = $status ? $status : $orders[ $order_id ]['s']; 287 $backoff_time = min( self::MAX_BACKOFF_TIME, $iteration * $iteration * $iteration ); 288 // In case status is failed|canceled set backoff_time to at least 1440 min (1 day). 289 if ( 'failed' === $status || 'canceled' === $status ) { 290 $backoff_time = max( $backoff_time, 1440 ); 291 } 249 292 $orders[ $order_id ] = array( 250 't' => $next_process_time->__toString(),251 'i' => ++$iteration,293 't' => ( new WC_DateTime( 'now + ' . $backoff_time . ' min' ) )->__toString(), 294 'i' => $increase_counter ? ++$iteration : $iteration, 252 295 's' => $status, 253 296 ); -
yoco-payment-gateway/tags/3.7.0/src/Helpers/Admin/Notices.php
r3005796 r3138287 56 56 function () use ( $type, $prefix, $message ) { 57 57 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped 58 echo '<div class=" notice ', esc_html( $type ), ' is-dismissible"><p><b>', esc_html( $prefix ), ':</b> ', force_balance_tags( $message ), '</p></div>';58 echo '<div class="yoco-notice notice ', esc_html( $type ), ' is-dismissible"><p><b>', esc_html( $prefix ), ':</b> ', force_balance_tags( $message ), '</p></div>'; 59 59 } 60 60 ); -
yoco-payment-gateway/tags/3.7.0/src/Telemetry/Models/TelemetryObject.php
r3102357 r3138287 14 14 private ?string $host = null; 15 15 16 private ?array $webhook = null;16 private ?array $webhooks = null; 17 17 18 18 private ?string $url = null; … … 52 52 } 53 53 54 public function getWebhook (): array {55 if ( null === $this->webhook ) {54 public function getWebhooks(): array { 55 if ( null === $this->webhooks ) { 56 56 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- only comparing the value. 57 57 $cache = isset( $_GET['section'] ) && 'class_yoco_wc_payment_gateway' === $_GET['section'] ? false : get_transient( 'yoco_available_webhooks' ); 58 $webhook = array();58 $webhooks = array(); 59 59 60 60 if ( is_array( $cache ) ) { 61 $this->webhook = $cache;62 63 return $this->webhook ;61 $this->webhooks = $cache; 62 63 return $this->webhooks; 64 64 } 65 65 … … 80 80 foreach ( $endpoints as $endpoint ) { 81 81 $result = wp_remote_post( $this->getHostUrl() . $endpoint, $args ); 82 $webhook [] = array(82 $webhooks[] = array( 83 83 'endpoint' => $endpoint, 84 84 'status' => 200 === wp_remote_retrieve_response_code( $result ), … … 86 86 } 87 87 88 $this->webhook = $webhook; 89 90 set_transient( 'yoco_available_webhooks', $this->webhook ); 91 } 92 93 return $this->webhook; 88 $this->webhooks = $webhooks; 89 90 set_transient( 'yoco_available_webhooks', $this->webhooks ); 91 } 92 93 return $this->webhooks; 94 } 95 96 97 public function getPreferredWebhook(): string { 98 if ( null === $this->webhooks ) { 99 $this->getWebhooks(); 100 } 101 102 foreach ( $this->webhooks as $webhook ) { 103 if ( isset( $webhook['status'] ) && true === $webhook['status'] ) { 104 return $webhook['endpoint']; 105 } 106 } 107 108 return ''; 94 109 } 95 110 -
yoco-payment-gateway/tags/3.7.0/src/Telemetry/Telemetry.php
r3102357 r3138287 18 18 array( 19 19 'domain' => $object->getHostUrl(), 20 'webhook' => $object->getWebhook(), 20 'webhooks' => $object->getWebhooks(), 21 'preferredWebhook' => $object->getPreferredWebhook(), 21 22 'installationName' => $object->getSiteName(), 22 23 'phpVersion' => $object->getPhpVersion(), -
yoco-payment-gateway/tags/3.7.0/yoco_wc_payment_gateway.php
r3102357 r3138287 6 6 * Author: Yoco 7 7 * Author URI: https://www.yoco.com 8 * Version: 3. 6.08 * Version: 3.7.0 9 9 * Requires at least: 5.0.0 10 * Tested up to: 6. 510 * Tested up to: 6.6 11 11 * WC requires at least: 4.0.0 12 * WC tested up to: 8.712 * WC tested up to: 9.1 13 13 * Requires Plugins: woocommerce 14 14 * Text Domain: yoco_wc_payment_gateway -
yoco-payment-gateway/trunk/README.md
r3102357 r3138287 43 43 - [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html) 44 44 45 ### Note45 ### Updating the version 46 46 To update version, update it in the: 47 47 - [package.json](package.json) -
yoco-payment-gateway/trunk/readme.txt
r3102357 r3138287 3 3 Tags: woocommerce,payment gateway 4 4 Requires at least: 5.0.0 5 Tested up to: 6. 55 Tested up to: 6.6 6 6 Requires PHP: 7.4.0 7 Stable tag: 3. 6.07 Stable tag: 3.7.0 8 8 License: GPLv2 or later 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 137 137 == Changelog == 138 138 139 = 3.7.0 = 140 141 * Update Payment Status Scheduler logic - Polling issue 142 * Add wp-env and e2e tests 143 * Telemetry webhook improvements 144 139 145 = 3.6.0 = 146 140 147 * Conditionally reset installation idempotency key. 141 148 * Extend the installation telemetry data. 142 149 143 150 = 3.5.0 = 151 144 152 * Add payment status polling as fallback method. 145 153 * Add simplify getting the logs to be shared with Yoco support. -
yoco-payment-gateway/trunk/src/Gateway/PaymentStatusScheduler.php
r3067423 r3138287 18 18 private const SCHEDULE_INTERVAL = 60; // seconds. 19 19 20 private const NO_OF_RETRIES = 20;21 22 private const MAX_BACKOFF_TIME = 60; //minutes.20 private const NO_OF_RETRIES = 30; 21 22 private const MAX_BACKOFF_TIME = 7200; // 5 days in minutes. 23 23 24 24 private const WAIT_TIME_BEFORE_PROCESSING = 10; // minutes. … … 38 38 } 39 39 40 // Add order to processing list. 40 41 $this->add_order( $order->get_id() ); 41 42 } … … 43 44 public function process_list() { 44 45 $orders_to_process = get_option( 'yoco_orders_pending_payment', array() ); 45 $hold_stock_minutes = (int) get_option( 'woocommerce_hold_stock_minutes', 60 );46 $wait_before_processing = $hold_stock_minutes < self::WAIT_TIME_BEFORE_PROCESSING ? intval( $hold_stock_minutes / 2 ) : self::WAIT_TIME_BEFORE_PROCESSING;47 46 48 47 if ( empty( $orders_to_process ) || ! is_array( $orders_to_process ) ) { … … 62 61 // If order has payment ID saved in meta this means payment was successful and we remove order from the list. 63 62 if ( ! empty( $order->get_meta( 'yoco_order_payment_id', true ) ) ) { 64 $this->remove_order( $order ->get_id());63 $this->remove_order( $order_id ); 65 64 continue; 66 65 } 67 68 $backoff_time = min( self::MAX_BACKOFF_TIME, $order_data['i'] * $order_data['i'] );69 $now = new WC_DateTime( 'now' );70 $min_time_to_process = new WC_DateTime( 'now - ' . $wait_before_processing . ' min' );71 $next_time_to_process = new WC_DateTime( $order_data['t'] . ' + ' . $backoff_time . 'min' );72 66 73 67 // If number of retries exceeds maximum allowed number, log error and remove order from the list. 74 68 if ( $order_data['i'] > self::NO_OF_RETRIES ) { 75 yoco( Logger::class )->logError( sprintf( 'Failed to process payment for order: #%s', $order_id ) ); 76 $this->remove_order( $order->get_id() ); 69 // add order note. 70 $order->add_order_note( 71 sprintf( 72 // translators: 1: attempt number, 2: status. 73 __( 'Yoco: Failed to process payment after %d attempts', 'yoco_wc_payment_gateway' ), 74 $order_data['i'] 75 ) 76 ); 77 yoco( Logger::class )->logError( 78 sprintf( 79 'Failed to process payment for order: #%1$s after %2$d attempts', 80 $order_id, 81 $order_data['i'] 82 ) 83 ); 84 $this->remove_order( $order_id ); 77 85 continue; 78 86 } 79 87 80 // Check against time to process range.81 if (82 $min_time_to_process < $order->get_date_created() || 83 $next_time_to_process > $now84 ) {88 $now = new WC_DateTime( 'now' ); 89 $next_time_to_process = new WC_DateTime( $order_data['t'] ); 90 91 // If time to process is greater than now skip update. 92 if ( $next_time_to_process > $now ) { 85 93 continue; 86 94 } … … 96 104 $payment_status = $data['body']['status']; 97 105 $payment_id = $data['body']['paymentId']; 106 107 // add order note. 108 $order->add_order_note( 109 sprintf( 110 // translators: 1: attempt number, 2: status. 111 __( 'Yoco: Payment status update attempt #%1$d -- obtained status: %2$s', 'yoco_wc_payment_gateway' ), 112 $order_data['i'], 113 $payment_status 114 ) 115 ); 98 116 99 117 if ( 'completed' === $payment_status && true === $order->update_status( 'processing' ) ) { … … 123 141 return; 124 142 } 125 126 // If payment failed. Add MAX_BACKOFF_TIME to next process time and increase iteration counter. 143 // When payment capturing process fail. 127 144 if ( isset( $_GET['yoco_checkout_status'] ) && 'failed' === sanitize_key( $_GET['yoco_checkout_status'] ) ) { 128 145 $this->update_order( 129 146 $order_id, 130 147 'failed', 131 array( 132 't' => self::MAX_BACKOFF_TIME, 133 'i' => 9, 134 ) 148 false 135 149 ); 150 151 // Add order note. 152 $order = wc_get_order( $order_id ); 153 if ( $order instanceof WC_Order ) { 154 $order->add_order_note( __( 'Yoco: Payment capture failed.', 'yoco_wc_payment_gateway' ) ); 155 } 156 136 157 return; 137 158 } … … 140 161 } 141 162 142 // If payment is canceled. Add MAX_BACKOFF_TIME to next process time and increase iteration counter.163 // When payment is canceled. 143 164 if ( 144 165 isset( $_GET['key'] ) … … 156 177 $order_id, 157 178 'canceled', 158 array( 159 't' => self::MAX_BACKOFF_TIME, 160 'i' => 9, 161 ) 179 false 162 180 ); 181 182 // Add order note. 183 $order = wc_get_order( $order_id ); 184 if ( $order instanceof WC_Order ) { 185 $order->add_order_note( __( 'Yoco: Payment canceled by the customer.', 'yoco_wc_payment_gateway' ) ); 186 } 187 188 // Empty cart when user cancel payment, order is already created. 189 // Order can be accessed and paid from My Account page. 190 WC()->cart->empty_cart(); 163 191 } 164 192 } … … 216 244 */ 217 245 private function add_order( $order_id ) { 218 $orders = get_option( 'yoco_orders_pending_payment', array() ); 219 $orders = is_array( $orders ) ? $orders : array(); 220 $now = new WC_DateTime( 'now' ); 246 $orders = get_option( 'yoco_orders_pending_payment', array() ); 247 $orders = is_array( $orders ) ? $orders : array(); 248 $hold_stock_minutes = (int) get_option( 'woocommerce_hold_stock_minutes', 60 ); 249 $wait_before_processing = $hold_stock_minutes < self::WAIT_TIME_BEFORE_PROCESSING ? intval( $hold_stock_minutes / 2 ) : self::WAIT_TIME_BEFORE_PROCESSING; 250 $process_at = ( new WC_DateTime( 'now + ' . $wait_before_processing . ' min' ) )->__toString(); 221 251 222 252 if ( ! isset( $orders[ $order_id ] ) ) { 223 253 $orders[ $order_id ] = array( 224 't' => $ now->__toString(),254 't' => $process_at, 225 255 'i' => 1, 226 256 's' => 'init', … … 240 270 } 241 271 242 private function update_order( $order_id, $status = '', $args = array() ) { 272 /** 273 * Update order data in order processing list. 274 * 275 * @param int $order_id Order payment data. 276 * @param string $status Payment status. 277 * @param bool $increase_counter Counter flag, increase counter by default, prevent increase by passing false. 278 * 279 * @return void 280 */ 281 private function update_order( $order_id, $status, $increase_counter = true ) { 243 282 $orders = get_option( 'yoco_orders_pending_payment', array() ); 244 283 245 284 if ( isset( $orders[ $order_id ] ) ) { 246 $iteration = isset( $args['i'] ) ? $args['i'] : $orders[ $order_id ]['i']; 247 $status = $status ? $status : $orders[ $order_id ]['s']; 248 $next_process_time = isset( $args['t'] ) ? new WC_DateTime( 'now +' . $args['t'] . ' min' ) : new WC_DateTime( 'now' ); 285 $iteration = (int) $orders[ $order_id ]['i']; 286 $status = $status ? $status : $orders[ $order_id ]['s']; 287 $backoff_time = min( self::MAX_BACKOFF_TIME, $iteration * $iteration * $iteration ); 288 // In case status is failed|canceled set backoff_time to at least 1440 min (1 day). 289 if ( 'failed' === $status || 'canceled' === $status ) { 290 $backoff_time = max( $backoff_time, 1440 ); 291 } 249 292 $orders[ $order_id ] = array( 250 't' => $next_process_time->__toString(),251 'i' => ++$iteration,293 't' => ( new WC_DateTime( 'now + ' . $backoff_time . ' min' ) )->__toString(), 294 'i' => $increase_counter ? ++$iteration : $iteration, 252 295 's' => $status, 253 296 ); -
yoco-payment-gateway/trunk/src/Helpers/Admin/Notices.php
r3005796 r3138287 56 56 function () use ( $type, $prefix, $message ) { 57 57 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped 58 echo '<div class=" notice ', esc_html( $type ), ' is-dismissible"><p><b>', esc_html( $prefix ), ':</b> ', force_balance_tags( $message ), '</p></div>';58 echo '<div class="yoco-notice notice ', esc_html( $type ), ' is-dismissible"><p><b>', esc_html( $prefix ), ':</b> ', force_balance_tags( $message ), '</p></div>'; 59 59 } 60 60 ); -
yoco-payment-gateway/trunk/src/Telemetry/Models/TelemetryObject.php
r3102357 r3138287 14 14 private ?string $host = null; 15 15 16 private ?array $webhook = null;16 private ?array $webhooks = null; 17 17 18 18 private ?string $url = null; … … 52 52 } 53 53 54 public function getWebhook (): array {55 if ( null === $this->webhook ) {54 public function getWebhooks(): array { 55 if ( null === $this->webhooks ) { 56 56 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- only comparing the value. 57 57 $cache = isset( $_GET['section'] ) && 'class_yoco_wc_payment_gateway' === $_GET['section'] ? false : get_transient( 'yoco_available_webhooks' ); 58 $webhook = array();58 $webhooks = array(); 59 59 60 60 if ( is_array( $cache ) ) { 61 $this->webhook = $cache;62 63 return $this->webhook ;61 $this->webhooks = $cache; 62 63 return $this->webhooks; 64 64 } 65 65 … … 80 80 foreach ( $endpoints as $endpoint ) { 81 81 $result = wp_remote_post( $this->getHostUrl() . $endpoint, $args ); 82 $webhook [] = array(82 $webhooks[] = array( 83 83 'endpoint' => $endpoint, 84 84 'status' => 200 === wp_remote_retrieve_response_code( $result ), … … 86 86 } 87 87 88 $this->webhook = $webhook; 89 90 set_transient( 'yoco_available_webhooks', $this->webhook ); 91 } 92 93 return $this->webhook; 88 $this->webhooks = $webhooks; 89 90 set_transient( 'yoco_available_webhooks', $this->webhooks ); 91 } 92 93 return $this->webhooks; 94 } 95 96 97 public function getPreferredWebhook(): string { 98 if ( null === $this->webhooks ) { 99 $this->getWebhooks(); 100 } 101 102 foreach ( $this->webhooks as $webhook ) { 103 if ( isset( $webhook['status'] ) && true === $webhook['status'] ) { 104 return $webhook['endpoint']; 105 } 106 } 107 108 return ''; 94 109 } 95 110 -
yoco-payment-gateway/trunk/src/Telemetry/Telemetry.php
r3102357 r3138287 18 18 array( 19 19 'domain' => $object->getHostUrl(), 20 'webhook' => $object->getWebhook(), 20 'webhooks' => $object->getWebhooks(), 21 'preferredWebhook' => $object->getPreferredWebhook(), 21 22 'installationName' => $object->getSiteName(), 22 23 'phpVersion' => $object->getPhpVersion(), -
yoco-payment-gateway/trunk/yoco_wc_payment_gateway.php
r3102357 r3138287 6 6 * Author: Yoco 7 7 * Author URI: https://www.yoco.com 8 * Version: 3. 6.08 * Version: 3.7.0 9 9 * Requires at least: 5.0.0 10 * Tested up to: 6. 510 * Tested up to: 6.6 11 11 * WC requires at least: 4.0.0 12 * WC tested up to: 8.712 * WC tested up to: 9.1 13 13 * Requires Plugins: woocommerce 14 14 * Text Domain: yoco_wc_payment_gateway
Note: See TracChangeset
for help on using the changeset viewer.