Skip to content

Commit fb399a9

Browse files
author
Kristófer R
committed
Merge remote-tracking branch 'origin/release/6.2.0' into trunk
2 parents c99eb51 + bfa912f commit fb399a9

11 files changed

+137
-25
lines changed

changelog.txt

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

3+
= 6.2.0 - 2022-02-17 =
4+
* Add - Add onboarding payment gateway setup methods.
5+
* Fix - Enable Stripe payment method after connecting account.
6+
* Fix - Missing statement descriptor in account summary API when not set in Stripe.
7+
38
= 6.1.0 - 2022-01-26 =
49
* Tweak - Use the newly exposed LoadableMask component provided by WooCommerce Blocks to trigger the loading state for Payment Request Buttons.
510
* Fix - Response type for account summary API.

includes/admin/class-wc-rest-stripe-account-controller.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,15 @@ class WC_REST_Stripe_Account_Controller extends WC_Stripe_REST_Base_Controller {
2525
*/
2626
private $account;
2727

28-
public function __construct( WC_Stripe_Account $account ) {
28+
/**
29+
* Stripe payment gateway.
30+
*
31+
* @var WC_Gateway_Stripe
32+
*/
33+
private $gateway;
34+
35+
public function __construct( WC_Gateway_Stripe $gateway, WC_Stripe_Account $account ) {
36+
$this->gateway = $gateway;
2937
$this->account = $account;
3038
}
3139

@@ -98,13 +106,22 @@ public function get_account() {
98106
public function get_account_summary() {
99107
$account = $this->account->get_cached_account_data();
100108

109+
// Use statement descriptor from settings, falling back to Stripe account statement descriptor if needed.
110+
$statement_descriptor = WC_Stripe_Helper::clean_statement_descriptor( $this->gateway->get_option( 'statement_descriptor' ) );
111+
if ( empty( $statement_descriptor ) ) {
112+
$statement_descriptor = $account['settings']['payments']['statement_descriptor'];
113+
}
114+
if ( empty( $statement_descriptor ) ) {
115+
$statement_descriptor = null;
116+
}
117+
101118
return new WP_REST_Response(
102119
[
103120
'has_pending_requirements' => $this->account->has_pending_requirements(),
104121
'has_overdue_requirements' => $this->account->has_overdue_requirements(),
105122
'current_deadline' => $account['requirements']['current_deadline'] ?? null,
106123
'status' => $this->account->get_account_status(),
107-
'statement_descriptor' => $account['settings']['payments']['statement_descriptor'] ?? '',
124+
'statement_descriptor' => $statement_descriptor,
108125
'store_currencies' => [
109126
'default' => $account['default_currency'] ?? get_woocommerce_currency(),
110127
'supported' => $this->account->get_supported_store_currencies(),

includes/admin/class-wc-rest-stripe-account-keys-controller.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,15 @@ public function set_account_keys( WP_REST_Request $request ) {
193193
$settings = get_option( self::STRIPE_GATEWAY_SETTINGS_OPTION_NAME, [] );
194194

195195
// If all keys were empty, then is a new account; we need to set the test/live mode.
196-
$new_account = ! trim( $settings['publishable_key'] ) && ! trim( $settings['secret_key'] ) && ! trim( $settings['test_publishable_key'] ) && ! trim( $settings['test_secret_key'] );
196+
$new_account = ! trim( $settings['publishable_key'] )
197+
&& ! trim( $settings['secret_key'] )
198+
&& ! trim( $settings['test_publishable_key'] )
199+
&& ! trim( $settings['test_secret_key'] );
200+
// If all new keys are empty, then account is being disconnected. We should disable the payment gateway.
201+
$is_deleting_account = ! trim( $publishable_key )
202+
&& ! trim( $secret_key )
203+
&& ! trim( $test_publishable_key )
204+
&& ! trim( $test_secret_key );
197205

198206
$settings['publishable_key'] = is_null( $publishable_key ) ? $settings['publishable_key'] : $publishable_key;
199207
$settings['secret_key'] = is_null( $secret_key ) ? $settings['secret_key'] : $secret_key;
@@ -203,11 +211,14 @@ public function set_account_keys( WP_REST_Request $request ) {
203211
$settings['test_webhook_secret'] = is_null( $test_webhook_secret ) ? $settings['test_webhook_secret'] : $test_webhook_secret;
204212

205213
if ( $new_account ) {
214+
$settings['enabled'] = 'yes';
206215
if ( trim( $settings['publishable_key'] ) && trim( $settings['secret_key'] ) ) {
207216
$settings['testmode'] = 'no';
208-
} else if ( trim( $settings['test_publishable_key'] ) && trim( $settings['test_secret_key'] ) ) {
217+
} elseif ( trim( $settings['test_publishable_key'] ) && trim( $settings['test_secret_key'] ) ) {
209218
$settings['testmode'] = 'yes';
210219
}
220+
} elseif ( $is_deleting_account ) {
221+
$settings['enabled'] = 'no';
211222
}
212223

213224
update_option( self::STRIPE_GATEWAY_SETTINGS_OPTION_NAME, $settings );

includes/class-wc-gateway-stripe.php

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ public function __construct() {
123123
add_action( 'set_logged_in_cookie', [ $this, 'set_cookie_on_current_request' ] );
124124
add_filter( 'woocommerce_get_checkout_payment_url', [ $this, 'get_checkout_payment_url' ], 10, 2 );
125125
add_filter( 'woocommerce_settings_api_sanitized_fields_' . $this->id, [ $this, 'settings_api_sanitized_fields' ] );
126+
add_filter( 'woocommerce_gateway_' . $this->id . '_settings_values', [ $this, 'update_onboarding_settings' ] );
126127

127128
// Note: display error is in the parent class.
128129
add_action( 'admin_notices', [ $this, 'display_errors' ], 9999 );
@@ -1162,4 +1163,88 @@ public function validate_account_statement_descriptor_field( $param, $value, $ma
11621163

11631164
return $value;
11641165
}
1166+
1167+
/**
1168+
* Get required setting keys for setup.
1169+
*
1170+
* @return array Array of setting keys used for setup.
1171+
*/
1172+
public function get_required_settings_keys() {
1173+
return [ 'publishable_key', 'secret_key' ];
1174+
}
1175+
1176+
/**
1177+
* Get the connection URL.
1178+
*
1179+
* @return string Connection URL.
1180+
*/
1181+
public function get_connection_url( $return_url = '' ) {
1182+
$api = new WC_Stripe_Connect_API();
1183+
$connect = new WC_Stripe_Connect( $api );
1184+
1185+
$url = $connect->get_oauth_url( $return_url );
1186+
1187+
return is_wp_error( $url ) ? null : $url;
1188+
}
1189+
1190+
/**
1191+
* Get help text to display during quick setup.
1192+
*
1193+
* @return string
1194+
*/
1195+
public function get_setup_help_text() {
1196+
return sprintf(
1197+
/* translators: %1$s Link to Stripe API details, %2$s Link to register a Stripe account */
1198+
__( 'Your API details can be obtained from your <a href="%1$s">Stripe account</a>. Don’t have a Stripe account? <a href="%2$s">Create one.</a>', 'woocommerce-gateway-stripe' ),
1199+
'https://dashboard.stripe.com/apikeys',
1200+
'https://dashboard.stripe.com/register'
1201+
);
1202+
}
1203+
1204+
/**
1205+
* Determine if the gateway still requires setup.
1206+
*
1207+
* @return bool
1208+
*/
1209+
public function needs_setup() {
1210+
return ! $this->get_option( 'publishable_key' ) || ! $this->get_option( 'secret_key' );
1211+
}
1212+
1213+
/**
1214+
* Updates the test mode based on keys provided when setting up the gateway via onboarding.
1215+
*
1216+
* @return array
1217+
*/
1218+
public function update_onboarding_settings( $settings ) {
1219+
if ( ! isset( $_SERVER['HTTP_REFERER'] ) ) {
1220+
return;
1221+
}
1222+
1223+
parse_str( wp_parse_url( $_SERVER['HTTP_REFERER'], PHP_URL_QUERY ), $queries ); // phpcs:ignore sanitization ok.
1224+
1225+
// Determine if merchant is onboarding (page='wc-admin' and task='payments').
1226+
if (
1227+
! isset( $queries ) ||
1228+
! isset( $queries['page'] ) ||
1229+
! isset( $queries['task'] ) ||
1230+
'wc-admin' !== $queries['page'] ||
1231+
'payments' !== $queries['task']
1232+
) {
1233+
return;
1234+
}
1235+
1236+
if ( ! empty( $settings['publishable_key'] ) && ! empty( $settings['secret_key'] ) ) {
1237+
if ( strpos( $settings['publishable_key'], 'pk_test_' ) === 0 || strpos( $settings['secret_key'], 'sk_test_' ) === 0 ) {
1238+
$settings['test_publishable_key'] = $settings['publishable_key'];
1239+
$settings['test_secret_key'] = $settings['secret_key'];
1240+
unset( $settings['publishable_key'] );
1241+
unset( $settings['secret_key'] );
1242+
$settings['testmode'] = 'yes';
1243+
} else {
1244+
$settings['testmode'] = 'no';
1245+
}
1246+
}
1247+
1248+
return $settings;
1249+
}
11651250
}

includes/class-wc-stripe-intent-controller.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,8 @@ public function update_payment_intent( $payment_intent_id = '', $order_id = null
407407
'amount' => WC_Stripe_Helper::get_stripe_amount( $amount, strtolower( $currency ) ),
408408
'currency' => strtolower( $currency ),
409409
'metadata' => $gateway->get_metadata_from_order( $order ),
410-
'description' => __( 'Stripe - Order', 'woocommerce-gateway-stripe' ) . ' ' . $order->get_id(),
410+
/* translators: 1) blog name 2) order number */
411+
'description' => sprintf( __( '%1$s - Order %2$s', 'woocommerce-gateway-stripe' ), wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ), $order->get_order_number() ),
411412
];
412413

413414
if ( '' !== $selected_upe_payment_type ) {

includes/connect/class-wc-stripe-connect.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ private function save_stripe_keys( $result ) {
128128
$prefix = $is_test ? 'test_' : '';
129129
$default_options = $this->get_default_stripe_config();
130130
$options = array_merge( $default_options, get_option( self::SETTINGS_OPTION, [] ) );
131+
$options['enabled'] = 'yes';
131132
$options['testmode'] = $is_test ? 'yes' : 'no';
132133
$options[ $prefix . 'publishable_key' ] = $result->publishableKey; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
133134
$options[ $prefix . 'secret_key' ] = $result->secretKey; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase

includes/payment-methods/class-wc-stripe-upe-payment-gateway.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public function __construct() {
121121
$this->maybe_init_pre_orders();
122122

123123
$main_settings = get_option( 'woocommerce_stripe_settings' );
124-
$this->title = $this->get_option( 'title_upe' );
124+
$this->title = ! empty( $this->get_option( 'title_upe' ) ) ? $this->get_option( 'title_upe' ) : $this->form_fields['title_upe']['default'];
125125
$this->description = '';
126126
$this->enabled = $this->get_option( 'enabled' );
127127
$this->saved_cards = 'yes' === $this->get_option( 'saved_cards' );

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "woocommerce-gateway-stripe",
33
"title": "WooCommerce Gateway Stripe",
4-
"version": "6.1.0",
4+
"version": "6.2.0",
55
"license": "GPL-3.0",
66
"homepage": "http://wordpress.org/plugins/woocommerce-gateway-stripe/",
77
"repository": {

readme.txt

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Tags: credit card, stripe, apple pay, payment request, google pay, sepa, sofort,
44
Requires at least: 5.6
55
Tested up to: 5.9
66
Requires PHP: 7.0
7-
Stable tag: 6.1.0
7+
Stable tag: 6.2.0
88
License: GPLv3
99
License URI: https://www.gnu.org/licenses/gpl-3.0.html
1010
Attributions: thorsten-stripe
@@ -128,17 +128,9 @@ If you get stuck, you can ask for help in the Plugin Forum.
128128

129129
== Changelog ==
130130

131-
= 6.1.0 - 2022-01-26 =
132-
* Tweak - Use the newly exposed LoadableMask component provided by WooCommerce Blocks to trigger the loading state for Payment Request Buttons.
133-
* Fix - Response type for account summary API.
134-
* Fix - Invalid response in account summary API when missing account data.
135-
* Add - Live and test mode information in account summary API.
136-
* Add - Add filter call when updating an existent intent (wc_stripe_update_existing_intent_request).
137-
* Add - Add ability to test Stripe account keys' validity.
138-
* Fix - Fixed full bank statement field description.
139-
* Fix - Notification messages are placed on top of the account keys modal.
140-
* Fix - Express checkout with 3DS card on product page when new checkout experience is enabled.
141-
* Fix - Remove duplicate call to `payment_scripts`.
142-
* Fix - Send bank statement descriptors to payment intents.
131+
= 6.2.0 - 2022-02-17 =
132+
* Add - Add onboarding payment gateway setup methods.
133+
* Fix - Enable Stripe payment method after connecting account.
134+
* Fix - Missing statement descriptor in account summary API when not set in Stripe.
143135

144136
[See changelog for all versions](https://raw.githubusercontent.com/woocommerce/woocommerce-gateway-stripe/trunk/changelog.txt).

0 commit comments

Comments
 (0)