Skip to content

Commit 14e99dd

Browse files
committed
Merge branch 'develop' into trunk
2 parents c452fc2 + 0022ec8 commit 14e99dd

File tree

15 files changed

+1056
-190
lines changed

15 files changed

+1056
-190
lines changed

.github/workflows/e2e.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ jobs:
3030
uses: actions/download-artifact@b14cf4c92620c250e1c074ab0a5800e37df86765 # v4.2.0
3131
with:
3232
name: ${{ github.event.repository.name }}
33+
path: ${{ github.event.repository.name }}
3334

3435
- name: Display structure of downloaded files
3536
run: ls -R

.github/workflows/generate-zip.yml

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Generate ZIP file
1+
name: Build release zip
22

33
on:
44
workflow_dispatch:
@@ -9,7 +9,7 @@ on:
99

1010
jobs:
1111
generate-zip-file:
12-
name: Generate ZIP file
12+
name: Build release zip
1313
runs-on: ubuntu-latest
1414

1515
steps:
@@ -35,11 +35,8 @@ jobs:
3535
if: steps.cache-node-modules.outputs.cache-hit != 'true'
3636
run: npm ci --no-optional
3737

38-
- name: Generate ZIP file
39-
run: npm run build && rm -rf ./woocommerce-gateway-gocardless && unzip woocommerce-gateway-gocardless.zip -d ./woocommerce-gateway-gocardless
38+
- name: Build plugin
39+
run: npm run build
4040

41-
- name: Use the Upload Artifact GitHub Action
42-
uses: actions/upload-artifact@4cec3d8aa04e39d1a68397de0c4cd6fb9dce8ec1 # v4.6.1
43-
with:
44-
name: woocommerce-gateway-gocardless
45-
path: woocommerce-gateway-gocardless/
41+
- name: Generate ZIP file
42+
uses: 10up/action-wordpress-plugin-build-zip@b9e621e1261ccf51592b6f3943e4dc4518fca0d1 # v1.0.2

.github/workflows/qit.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ jobs:
127127
path: phpcompat-result.txt
128128

129129
- name: Run security test
130-
if: "${{ inputs.tests == 'security' || contains(github.event.pull_request.labels.*.name, 'needs: qit security test') && ( success() || failure() ) }}"
130+
if: "${{ ( ( inputs.tests == 'default' || inputs.tests == 'security' ) || contains(github.event.pull_request.labels.*.name, 'needs: qit default tests') || contains(github.event.pull_request.labels.*.name, 'needs: qit security test') ) && ( success() || failure() ) }}"
131131
id: run-security-test
132132
run: ./vendor/bin/qit run:security ${{ github.event.repository.name }} --zip=${{ github.event.repository.name }}.zip --wait > security-result.txt
133133

@@ -139,7 +139,7 @@ jobs:
139139
path: security-result.txt
140140

141141
- name: Run malware test
142-
if: "${{ inputs.tests == 'malware' || contains(github.event.pull_request.labels.*.name, 'needs: qit malware test') && ( success() || failure() ) }}"
142+
if: "${{ ( ( inputs.tests == 'default' || inputs.tests == 'malware' ) || contains(github.event.pull_request.labels.*.name, 'needs: qit default tests') || contains(github.event.pull_request.labels.*.name, 'needs: qit malware test') ) && ( success() || failure() ) }}"
143143
id: run-malware-test
144144
run: ./vendor/bin/qit run:malware ${{ github.event.repository.name }} --zip=${{ github.event.repository.name }}.zip --wait > malware-result.txt
145145

changelog.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
*** GoCardless for WooCommerce Changelog ***
22

3+
2025-10-07 - version 2.9.8
4+
* Fix - Automatically disconnect the GoCardless account and display a reconnect notice when the token becomes invalid or inactive.
5+
* Dev - Bump WooCommerce "tested up to" version 10.2.
6+
* Dev - Bump WooCommerce minimum supported version to 10.0.
7+
38
2025-08-05 - version 2.9.7
49
* Add - Improved subscription cancellation by cancelling "Pending Submission" payments and preventing retries on non-cancellable payments.
510
* Fix - Ensure webhook events are handled properly without any issues.

includes/class-wc-gocardless-api.php

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,8 @@ protected static function _request( $endpoint, $args = array() ) {
174174
return $resp;
175175
}
176176

177-
$parsed_resp = json_decode( wp_remote_retrieve_body( $resp ), true );
177+
$response_code = wp_remote_retrieve_response_code( $resp );
178+
$parsed_resp = json_decode( wp_remote_retrieve_body( $resp ), true );
178179
if ( is_null( $parsed_resp ) ) {
179180
wc_gocardless()->log( sprintf( '%s - Failed to decode JSON resp %s', __METHOD__, print_r( wp_remote_retrieve_body( $resp ), true ) ) ); //phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_print_r
180181
return new WP_Error( 'error_json_decode', esc_html__( 'Error decoding JSON response', 'woocommerce-gateway-gocardless' ) );
@@ -198,6 +199,33 @@ protected static function _request( $endpoint, $args = array() ) {
198199
return new WP_Error( 'error_gocardless_create_refund', esc_html__( 'GoCardless refund endpoint is disabled by default. Please contact [email protected] to enable it for you.', 'woocommerce-gateway-gocardless' ) );
199200
}
200201

202+
/*
203+
* Error Handling for 401 unauthorized response code.
204+
*
205+
* If API respond with 401 unauthorized response code, it means:
206+
*
207+
* - `access_token_not_found` (the access token was not recognised); or
208+
* - `access_token_revoked` (the user has revoked your access to their account); or
209+
* - `access_token_not_active` (the access token is inactive for another reason)
210+
*
211+
* We need to disconnect from GoCardless and display a notice to the user to connect again.
212+
*/
213+
if ( 401 === $response_code && 'invalid_api_usage' === $parsed_resp['error']['type'] ) {
214+
// Unauthorized response code, disconnect from GoCardless.
215+
wc_gocardless()->log( sprintf( '%s - Unauthorized response code, disconnecting from GoCardless', __METHOD__ ) );
216+
$settings = get_option( 'woocommerce_gocardless_settings', array() );
217+
$settings['access_token'] = '';
218+
update_option( 'woocommerce_gocardless_settings', $settings );
219+
220+
// Clear the available scheme transient.
221+
delete_transient( 'wc_gocardless_available_scheme_identifiers' );
222+
223+
wc_gocardless()->log( sprintf( '%s - Disconnected from GoCardless', __METHOD__ ) );
224+
225+
// Add option to display notice to connect GoCardless again.
226+
update_option( 'wc_gocardless_access_token_unauthorized', true );
227+
}
228+
201229
$new_mandate = null;
202230
if ( ! empty( $parsed_resp['error']['errors'] ) && is_array( $parsed_resp['error']['errors'] ) ) {
203231
$message .= '. ' . esc_html__( 'Error details: ', 'woocommerce-gateway-gocardless' );

includes/class-wc-gocardless-gateway.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,9 @@ public function connect_gocardless() {
159159
// Clear the available scheme transient.
160160
delete_transient( 'wc_gocardless_available_scheme_identifiers' );
161161

162+
// Clear option which displays notice to connect GoCardless.
163+
delete_option( 'wc_gocardless_access_token_unauthorized' );
164+
162165
// Delete notice that informs merchant to connect with GoCardless.
163166
WC_Admin_Notices::remove_notice( 'gocardless_connect_prompt' );
164167

includes/class-wc-gocardless-order-admin.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public function init() {
2525
$this->add_order_actions();
2626

2727
add_action( 'admin_notices', array( $this, 'display_connection_notices' ) );
28+
add_action( 'admin_notices', array( $this, 'display_access_token_unauthorized_notice' ) );
2829

2930
// GoCardless Connect/Disconnect actions.
3031
add_action( 'admin_post_wc_connect_gocardless', array( $this, 'connect_gocardless' ) );
@@ -576,4 +577,45 @@ public function get_connection_notice() {
576577

577578
return $notice;
578579
}
580+
581+
/**
582+
* Display notice for access token unauthorized.
583+
*
584+
* @since 2.9.8
585+
*/
586+
public function display_access_token_unauthorized_notice() {
587+
// Check if option is set to display notice.
588+
if ( ! get_option( 'wc_gocardless_access_token_unauthorized' ) ) {
589+
return;
590+
}
591+
592+
// Check if access token is there.
593+
$settings = get_option( 'woocommerce_gocardless_settings', array() );
594+
if ( ! empty( $settings['access_token'] ) ) {
595+
// Remove the option to display notice, as we have an access token now (in case it missed to remove while connect to GoCardless).
596+
delete_option( 'wc_gocardless_access_token_unauthorized' );
597+
return;
598+
}
599+
?>
600+
<div class="notice notice-warning">
601+
<p>
602+
<?php
603+
echo wp_kses(
604+
sprintf(
605+
/* translators: %s: settings URL */
606+
__( 'The connection to your <strong>GoCardless</strong> account has been disconnected because the access token is no longer active or valid. Please <a href="%s">connect</a> your GoCardless account to continue accepting payments.', 'woocommerce-gateway-gocardless' ),
607+
wc_gocardless()->get_setting_url()
608+
),
609+
array(
610+
'a' => array(
611+
'href' => array(),
612+
),
613+
'strong' => array(),
614+
)
615+
);
616+
?>
617+
</p>
618+
</div>
619+
<?php
620+
}
579621
}

0 commit comments

Comments
 (0)