Plugin Directory

Changeset 3102357


Ignore:
Timestamp:
06/13/2024 01:57:56 PM (22 months ago)
Author:
yocoadmin
Message:

Update to version 3.6.0 from Gitlab

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

Legend:

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

    r2953749 r3102357  
    4242- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
    4343- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
     44
     45### Note
     46To update version, update it in the:
     47- [package.json](package.json)
     48- [readme.txt](readme.txt)
     49- [yoco_wc_payment_gateway.php](yoco_wc_payment_gateway.php)
    4450
    4551***
  • yoco-payment-gateway/tags/3.6.0/readme.txt

    r3067451 r3102357  
    55Tested up to: 6.5
    66Requires PHP: 7.4.0
    7 Stable tag: 3.5.0
     7Stable tag: 3.6.0
    88License: GPLv2 or later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    137137== Changelog ==
    138138
     139= 3.6.0 =
     140* Conditionally reset installation idempotency key.
     141* Extend the installation telemetry data.
     142
    139143= 3.5.0 =
    140144* Add payment status polling as fallback method.
  • yoco-payment-gateway/tags/3.6.0/src/Gateway/Processors/OptionsProcessor.php

    r3067423 r3102357  
    3434
    3535            $response = $installationRequest->send();
     36
     37            // If we get 500 error, reset Idempotence Key and retry the request.
     38            if ( 500 === (int) $response['code'] ) {
     39                add_filter( 'yoco_payment_gateway/installation/request/headers', array( $this, 'resetIdempotenceKey' ) );
     40
     41                $response = $installationRequest->send();
     42            }
    3643
    3744            if ( ! in_array( $response['code'], array( 200, 201, 202 ) ) ) {
     
    100107        }
    101108    }
     109
     110    public function resetIdempotenceKey( $headers ) {
     111        if ( ! isset( $headers['Idempotency-Key'] ) || ! is_scalar( $headers['Idempotency-Key'] ) ) {
     112            return $headers;
     113        }
     114
     115        $headers['Idempotency-Key'] = hash( 'SHA256', $headers['Idempotency-Key'] . time() );
     116
     117        return $headers;
     118    }
    102119}
  • yoco-payment-gateway/tags/3.6.0/src/Integrations/Yoco/Webhooks/REST/Routes/Webhook.php

    r2972271 r3102357  
    2828
    2929    public function callback( WP_REST_Request $request ): WP_REST_Response {
    30         return ( new WebhookController( $request ) )->handleRequest();
     30        return wp_salt() === json_decode( $request->get_body() )
     31            ? new WP_REST_Response( 'OK', 200 )
     32            : ( new WebhookController( $request ) )->handleRequest();
    3133    }
    3234
    3335    public function permit( WP_REST_Request $request ): bool {
    34         return yoco( Guard::class )->verifySignature( $request );
     36        return wp_salt() === json_decode( $request->get_body() ) ? true : yoco( Guard::class )->verifySignature( $request );
    3537    }
    3638}
  • yoco-payment-gateway/tags/3.6.0/src/Telemetry/Models/TelemetryObject.php

    r3067423 r3102357  
    1313
    1414    private ?string $host = null;
     15
     16    private ?array $webhook = null;
    1517
    1618    private ?string $url = null;
     
    4850
    4951        return $this->host;
     52    }
     53
     54    public function getWebhook(): array {
     55        if ( null === $this->webhook ) {
     56            // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- only comparing the value.
     57            $cache   = isset( $_GET['section'] ) && 'class_yoco_wc_payment_gateway' === $_GET['section'] ? false : get_transient( 'yoco_available_webhooks' );
     58            $webhook = array();
     59
     60            if ( is_array( $cache ) ) {
     61                $this->webhook = $cache;
     62
     63                return $this->webhook;
     64            }
     65
     66            $args = array(
     67                'headers' => array(
     68                    'Content-Type' => 'application/json',
     69                ),
     70                'body'    => wp_json_encode( wp_salt() ),
     71                'timeout' => 10,
     72            );
     73
     74            $endpoints = array(
     75                '/index.php?rest_route=/yoco/webhook',
     76                '/yoco/webhook',
     77                '/wp-json/yoco/webhook',
     78            );
     79
     80            foreach ( $endpoints as $endpoint ) {
     81                $result    = wp_remote_post( $this->getHostUrl() . $endpoint, $args );
     82                $webhook[] = array(
     83                    'endpoint' => $endpoint,
     84                    'status'   => 200 === wp_remote_retrieve_response_code( $result ),
     85                );
     86            }
     87
     88            $this->webhook = $webhook;
     89
     90            set_transient( 'yoco_available_webhooks', $this->webhook );
     91        }
     92
     93        return $this->webhook;
    5094    }
    5195
  • yoco-payment-gateway/tags/3.6.0/src/Telemetry/Telemetry.php

    r3005796 r3102357  
    1818            array(
    1919                'domain'                   => $object->getHostUrl(),
     20                'webhook'                  => $object->getWebhook(),
    2021                'installationName'         => $object->getSiteName(),
    2122                'phpVersion'               => $object->getPhpVersion(),
  • yoco-payment-gateway/tags/3.6.0/yoco_wc_payment_gateway.php

    r3067423 r3102357  
    66 * Author: Yoco
    77 * Author URI: https://www.yoco.com
    8  * Version: 3.5.0
     8 * Version: 3.6.0
    99 * Requires at least: 5.0.0
    1010 * Tested up to: 6.5
  • yoco-payment-gateway/trunk/README.md

    r2953749 r3102357  
    4242- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
    4343- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
     44
     45### Note
     46To update version, update it in the:
     47- [package.json](package.json)
     48- [readme.txt](readme.txt)
     49- [yoco_wc_payment_gateway.php](yoco_wc_payment_gateway.php)
    4450
    4551***
  • yoco-payment-gateway/trunk/readme.txt

    r3067451 r3102357  
    55Tested up to: 6.5
    66Requires PHP: 7.4.0
    7 Stable tag: 3.5.0
     7Stable tag: 3.6.0
    88License: GPLv2 or later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    137137== Changelog ==
    138138
     139= 3.6.0 =
     140* Conditionally reset installation idempotency key.
     141* Extend the installation telemetry data.
     142
    139143= 3.5.0 =
    140144* Add payment status polling as fallback method.
  • yoco-payment-gateway/trunk/src/Gateway/Processors/OptionsProcessor.php

    r3067423 r3102357  
    3434
    3535            $response = $installationRequest->send();
     36
     37            // If we get 500 error, reset Idempotence Key and retry the request.
     38            if ( 500 === (int) $response['code'] ) {
     39                add_filter( 'yoco_payment_gateway/installation/request/headers', array( $this, 'resetIdempotenceKey' ) );
     40
     41                $response = $installationRequest->send();
     42            }
    3643
    3744            if ( ! in_array( $response['code'], array( 200, 201, 202 ) ) ) {
     
    100107        }
    101108    }
     109
     110    public function resetIdempotenceKey( $headers ) {
     111        if ( ! isset( $headers['Idempotency-Key'] ) || ! is_scalar( $headers['Idempotency-Key'] ) ) {
     112            return $headers;
     113        }
     114
     115        $headers['Idempotency-Key'] = hash( 'SHA256', $headers['Idempotency-Key'] . time() );
     116
     117        return $headers;
     118    }
    102119}
  • yoco-payment-gateway/trunk/src/Integrations/Yoco/Webhooks/REST/Routes/Webhook.php

    r2972271 r3102357  
    2828
    2929    public function callback( WP_REST_Request $request ): WP_REST_Response {
    30         return ( new WebhookController( $request ) )->handleRequest();
     30        return wp_salt() === json_decode( $request->get_body() )
     31            ? new WP_REST_Response( 'OK', 200 )
     32            : ( new WebhookController( $request ) )->handleRequest();
    3133    }
    3234
    3335    public function permit( WP_REST_Request $request ): bool {
    34         return yoco( Guard::class )->verifySignature( $request );
     36        return wp_salt() === json_decode( $request->get_body() ) ? true : yoco( Guard::class )->verifySignature( $request );
    3537    }
    3638}
  • yoco-payment-gateway/trunk/src/Telemetry/Models/TelemetryObject.php

    r3067423 r3102357  
    1313
    1414    private ?string $host = null;
     15
     16    private ?array $webhook = null;
    1517
    1618    private ?string $url = null;
     
    4850
    4951        return $this->host;
     52    }
     53
     54    public function getWebhook(): array {
     55        if ( null === $this->webhook ) {
     56            // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- only comparing the value.
     57            $cache   = isset( $_GET['section'] ) && 'class_yoco_wc_payment_gateway' === $_GET['section'] ? false : get_transient( 'yoco_available_webhooks' );
     58            $webhook = array();
     59
     60            if ( is_array( $cache ) ) {
     61                $this->webhook = $cache;
     62
     63                return $this->webhook;
     64            }
     65
     66            $args = array(
     67                'headers' => array(
     68                    'Content-Type' => 'application/json',
     69                ),
     70                'body'    => wp_json_encode( wp_salt() ),
     71                'timeout' => 10,
     72            );
     73
     74            $endpoints = array(
     75                '/index.php?rest_route=/yoco/webhook',
     76                '/yoco/webhook',
     77                '/wp-json/yoco/webhook',
     78            );
     79
     80            foreach ( $endpoints as $endpoint ) {
     81                $result    = wp_remote_post( $this->getHostUrl() . $endpoint, $args );
     82                $webhook[] = array(
     83                    'endpoint' => $endpoint,
     84                    'status'   => 200 === wp_remote_retrieve_response_code( $result ),
     85                );
     86            }
     87
     88            $this->webhook = $webhook;
     89
     90            set_transient( 'yoco_available_webhooks', $this->webhook );
     91        }
     92
     93        return $this->webhook;
    5094    }
    5195
  • yoco-payment-gateway/trunk/src/Telemetry/Telemetry.php

    r3005796 r3102357  
    1818            array(
    1919                'domain'                   => $object->getHostUrl(),
     20                'webhook'                  => $object->getWebhook(),
    2021                'installationName'         => $object->getSiteName(),
    2122                'phpVersion'               => $object->getPhpVersion(),
  • yoco-payment-gateway/trunk/yoco_wc_payment_gateway.php

    r3067423 r3102357  
    66 * Author: Yoco
    77 * Author URI: https://www.yoco.com
    8  * Version: 3.5.0
     8 * Version: 3.6.0
    99 * Requires at least: 5.0.0
    1010 * Tested up to: 6.5
Note: See TracChangeset for help on using the changeset viewer.