Plugin Directory

Changeset 3138287


Ignore:
Timestamp:
08/20/2024 03:08:31 PM (20 months ago)
Author:
yocoadmin
Message:

Update to version 3.7.0 from Gitlab

Location:
yoco-payment-gateway
Files:
62 added
14 edited
1 copied

Legend:

Unmodified
Added
Removed
  • yoco-payment-gateway/tags/3.7.0/README.md

    r3102357 r3138287  
    4343- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
    4444
    45 ### Note
     45### Updating the version
    4646To update version, update it in the:
    4747- [package.json](package.json)
  • yoco-payment-gateway/tags/3.7.0/readme.txt

    r3102357 r3138287  
    33Tags: woocommerce,payment gateway
    44Requires at least: 5.0.0
    5 Tested up to: 6.5
     5Tested up to: 6.6
    66Requires PHP: 7.4.0
    7 Stable tag: 3.6.0
     7Stable tag: 3.7.0
    88License: GPLv2 or later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    137137== Changelog ==
    138138
     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
    139145= 3.6.0 =
     146
    140147* Conditionally reset installation idempotency key.
    141148* Extend the installation telemetry data.
    142149
    143150= 3.5.0 =
     151
    144152* Add payment status polling as fallback method.
    145153* Add simplify getting the logs to be shared with Yoco support.
  • yoco-payment-gateway/tags/3.7.0/src/Gateway/PaymentStatusScheduler.php

    r3067423 r3138287  
    1818    private const SCHEDULE_INTERVAL = 60;  // seconds.
    1919
    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.
    2323
    2424    private const WAIT_TIME_BEFORE_PROCESSING = 10; // minutes.
     
    3838        }
    3939
     40        // Add order to processing list.
    4041        $this->add_order( $order->get_id() );
    4142    }
     
    4344    public function process_list() {
    4445        $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;
    4746
    4847        if ( empty( $orders_to_process ) || ! is_array( $orders_to_process ) ) {
     
    6261            // If order has payment ID saved in meta this means payment was successful and we remove order from the list.
    6362            if ( ! empty( $order->get_meta( 'yoco_order_payment_id', true ) ) ) {
    64                 $this->remove_order( $order->get_id() );
     63                $this->remove_order( $order_id );
    6564                continue;
    6665            }
    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' );
    7266
    7367            // If number of retries exceeds maximum allowed number, log error and remove order from the list.
    7468            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 );
    7785                continue;
    7886            }
    7987
    80             // Check against time to process range.
    81             if (
    82                 $min_time_to_process < $order->get_date_created() ||
    83                 $next_time_to_process > $now
    84             ) {
     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 ) {
    8593                continue;
    8694            }
     
    96104                $payment_status = $data['body']['status'];
    97105                $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                );
    98116
    99117                if ( 'completed' === $payment_status && true === $order->update_status( 'processing' ) ) {
     
    123141                return;
    124142            }
    125 
    126             // If payment failed. Add MAX_BACKOFF_TIME to next process time and increase iteration counter.
     143            // When payment capturing process fail.
    127144            if ( isset( $_GET['yoco_checkout_status'] ) && 'failed' === sanitize_key( $_GET['yoco_checkout_status'] ) ) {
    128145                $this->update_order(
    129146                    $order_id,
    130147                    'failed',
    131                     array(
    132                         't' => self::MAX_BACKOFF_TIME,
    133                         'i' => 9,
    134                     )
     148                    false
    135149                );
     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
    136157                return;
    137158            }
     
    140161        }
    141162
    142         // If payment is canceled. Add MAX_BACKOFF_TIME to next process time and increase iteration counter.
     163        // When payment is canceled.
    143164        if (
    144165            isset( $_GET['key'] )
     
    156177                $order_id,
    157178                'canceled',
    158                 array(
    159                     't' => self::MAX_BACKOFF_TIME,
    160                     'i' => 9,
    161                 )
     179                false
    162180            );
     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();
    163191        }
    164192    }
     
    216244     */
    217245    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();
    221251
    222252        if ( ! isset( $orders[ $order_id ] ) ) {
    223253            $orders[ $order_id ] = array(
    224                 't' => $now->__toString(),
     254                't' => $process_at,
    225255                'i' => 1,
    226256                's' => 'init',
     
    240270    }
    241271
    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 ) {
    243282        $orders = get_option( 'yoco_orders_pending_payment', array() );
    244283
    245284        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            }
    249292            $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,
    252295                's' => $status,
    253296            );
  • yoco-payment-gateway/tags/3.7.0/src/Helpers/Admin/Notices.php

    r3005796 r3138287  
    5656            function () use ( $type, $prefix, $message ) {
    5757                // 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>';
    5959            }
    6060        );
  • yoco-payment-gateway/tags/3.7.0/src/Telemetry/Models/TelemetryObject.php

    r3102357 r3138287  
    1414    private ?string $host = null;
    1515
    16     private ?array $webhook = null;
     16    private ?array $webhooks = null;
    1717
    1818    private ?string $url = null;
     
    5252    }
    5353
    54     public function getWebhook(): array {
    55         if ( null === $this->webhook ) {
     54    public function getWebhooks(): array {
     55        if ( null === $this->webhooks ) {
    5656            // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- only comparing the value.
    5757            $cache   = isset( $_GET['section'] ) && 'class_yoco_wc_payment_gateway' === $_GET['section'] ? false : get_transient( 'yoco_available_webhooks' );
    58             $webhook = array();
     58            $webhooks = array();
    5959
    6060            if ( is_array( $cache ) ) {
    61                 $this->webhook = $cache;
    62 
    63                 return $this->webhook;
     61                $this->webhooks = $cache;
     62
     63                return $this->webhooks;
    6464            }
    6565
     
    8080            foreach ( $endpoints as $endpoint ) {
    8181                $result    = wp_remote_post( $this->getHostUrl() . $endpoint, $args );
    82                 $webhook[] = array(
     82                $webhooks[] = array(
    8383                    'endpoint' => $endpoint,
    8484                    'status'   => 200 === wp_remote_retrieve_response_code( $result ),
     
    8686            }
    8787
    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 '';
    94109    }
    95110
  • yoco-payment-gateway/tags/3.7.0/src/Telemetry/Telemetry.php

    r3102357 r3138287  
    1818            array(
    1919                'domain'                   => $object->getHostUrl(),
    20                 'webhook'                  => $object->getWebhook(),
     20                'webhooks'                 => $object->getWebhooks(),
     21                'preferredWebhook'         => $object->getPreferredWebhook(),
    2122                'installationName'         => $object->getSiteName(),
    2223                'phpVersion'               => $object->getPhpVersion(),
  • yoco-payment-gateway/tags/3.7.0/yoco_wc_payment_gateway.php

    r3102357 r3138287  
    66 * Author: Yoco
    77 * Author URI: https://www.yoco.com
    8  * Version: 3.6.0
     8 * Version: 3.7.0
    99 * Requires at least: 5.0.0
    10  * Tested up to: 6.5
     10 * Tested up to: 6.6
    1111 * WC requires at least: 4.0.0
    12  * WC tested up to: 8.7
     12 * WC tested up to: 9.1
    1313 * Requires Plugins: woocommerce
    1414 * Text Domain: yoco_wc_payment_gateway
  • yoco-payment-gateway/trunk/README.md

    r3102357 r3138287  
    4343- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
    4444
    45 ### Note
     45### Updating the version
    4646To update version, update it in the:
    4747- [package.json](package.json)
  • yoco-payment-gateway/trunk/readme.txt

    r3102357 r3138287  
    33Tags: woocommerce,payment gateway
    44Requires at least: 5.0.0
    5 Tested up to: 6.5
     5Tested up to: 6.6
    66Requires PHP: 7.4.0
    7 Stable tag: 3.6.0
     7Stable tag: 3.7.0
    88License: GPLv2 or later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    137137== Changelog ==
    138138
     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
    139145= 3.6.0 =
     146
    140147* Conditionally reset installation idempotency key.
    141148* Extend the installation telemetry data.
    142149
    143150= 3.5.0 =
     151
    144152* Add payment status polling as fallback method.
    145153* Add simplify getting the logs to be shared with Yoco support.
  • yoco-payment-gateway/trunk/src/Gateway/PaymentStatusScheduler.php

    r3067423 r3138287  
    1818    private const SCHEDULE_INTERVAL = 60;  // seconds.
    1919
    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.
    2323
    2424    private const WAIT_TIME_BEFORE_PROCESSING = 10; // minutes.
     
    3838        }
    3939
     40        // Add order to processing list.
    4041        $this->add_order( $order->get_id() );
    4142    }
     
    4344    public function process_list() {
    4445        $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;
    4746
    4847        if ( empty( $orders_to_process ) || ! is_array( $orders_to_process ) ) {
     
    6261            // If order has payment ID saved in meta this means payment was successful and we remove order from the list.
    6362            if ( ! empty( $order->get_meta( 'yoco_order_payment_id', true ) ) ) {
    64                 $this->remove_order( $order->get_id() );
     63                $this->remove_order( $order_id );
    6564                continue;
    6665            }
    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' );
    7266
    7367            // If number of retries exceeds maximum allowed number, log error and remove order from the list.
    7468            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 );
    7785                continue;
    7886            }
    7987
    80             // Check against time to process range.
    81             if (
    82                 $min_time_to_process < $order->get_date_created() ||
    83                 $next_time_to_process > $now
    84             ) {
     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 ) {
    8593                continue;
    8694            }
     
    96104                $payment_status = $data['body']['status'];
    97105                $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                );
    98116
    99117                if ( 'completed' === $payment_status && true === $order->update_status( 'processing' ) ) {
     
    123141                return;
    124142            }
    125 
    126             // If payment failed. Add MAX_BACKOFF_TIME to next process time and increase iteration counter.
     143            // When payment capturing process fail.
    127144            if ( isset( $_GET['yoco_checkout_status'] ) && 'failed' === sanitize_key( $_GET['yoco_checkout_status'] ) ) {
    128145                $this->update_order(
    129146                    $order_id,
    130147                    'failed',
    131                     array(
    132                         't' => self::MAX_BACKOFF_TIME,
    133                         'i' => 9,
    134                     )
     148                    false
    135149                );
     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
    136157                return;
    137158            }
     
    140161        }
    141162
    142         // If payment is canceled. Add MAX_BACKOFF_TIME to next process time and increase iteration counter.
     163        // When payment is canceled.
    143164        if (
    144165            isset( $_GET['key'] )
     
    156177                $order_id,
    157178                'canceled',
    158                 array(
    159                     't' => self::MAX_BACKOFF_TIME,
    160                     'i' => 9,
    161                 )
     179                false
    162180            );
     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();
    163191        }
    164192    }
     
    216244     */
    217245    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();
    221251
    222252        if ( ! isset( $orders[ $order_id ] ) ) {
    223253            $orders[ $order_id ] = array(
    224                 't' => $now->__toString(),
     254                't' => $process_at,
    225255                'i' => 1,
    226256                's' => 'init',
     
    240270    }
    241271
    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 ) {
    243282        $orders = get_option( 'yoco_orders_pending_payment', array() );
    244283
    245284        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            }
    249292            $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,
    252295                's' => $status,
    253296            );
  • yoco-payment-gateway/trunk/src/Helpers/Admin/Notices.php

    r3005796 r3138287  
    5656            function () use ( $type, $prefix, $message ) {
    5757                // 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>';
    5959            }
    6060        );
  • yoco-payment-gateway/trunk/src/Telemetry/Models/TelemetryObject.php

    r3102357 r3138287  
    1414    private ?string $host = null;
    1515
    16     private ?array $webhook = null;
     16    private ?array $webhooks = null;
    1717
    1818    private ?string $url = null;
     
    5252    }
    5353
    54     public function getWebhook(): array {
    55         if ( null === $this->webhook ) {
     54    public function getWebhooks(): array {
     55        if ( null === $this->webhooks ) {
    5656            // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- only comparing the value.
    5757            $cache   = isset( $_GET['section'] ) && 'class_yoco_wc_payment_gateway' === $_GET['section'] ? false : get_transient( 'yoco_available_webhooks' );
    58             $webhook = array();
     58            $webhooks = array();
    5959
    6060            if ( is_array( $cache ) ) {
    61                 $this->webhook = $cache;
    62 
    63                 return $this->webhook;
     61                $this->webhooks = $cache;
     62
     63                return $this->webhooks;
    6464            }
    6565
     
    8080            foreach ( $endpoints as $endpoint ) {
    8181                $result    = wp_remote_post( $this->getHostUrl() . $endpoint, $args );
    82                 $webhook[] = array(
     82                $webhooks[] = array(
    8383                    'endpoint' => $endpoint,
    8484                    'status'   => 200 === wp_remote_retrieve_response_code( $result ),
     
    8686            }
    8787
    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 '';
    94109    }
    95110
  • yoco-payment-gateway/trunk/src/Telemetry/Telemetry.php

    r3102357 r3138287  
    1818            array(
    1919                'domain'                   => $object->getHostUrl(),
    20                 'webhook'                  => $object->getWebhook(),
     20                'webhooks'                 => $object->getWebhooks(),
     21                'preferredWebhook'         => $object->getPreferredWebhook(),
    2122                'installationName'         => $object->getSiteName(),
    2223                'phpVersion'               => $object->getPhpVersion(),
  • yoco-payment-gateway/trunk/yoco_wc_payment_gateway.php

    r3102357 r3138287  
    66 * Author: Yoco
    77 * Author URI: https://www.yoco.com
    8  * Version: 3.6.0
     8 * Version: 3.7.0
    99 * Requires at least: 5.0.0
    10  * Tested up to: 6.5
     10 * Tested up to: 6.6
    1111 * WC requires at least: 4.0.0
    12  * WC tested up to: 8.7
     12 * WC tested up to: 9.1
    1313 * Requires Plugins: woocommerce
    1414 * Text Domain: yoco_wc_payment_gateway
Note: See TracChangeset for help on using the changeset viewer.