Skip to content

Commit d565a8a

Browse files
authored
Merge branch 'develop' into fix/2297-statement-descriptor
2 parents a17071f + ae2baf8 commit d565a8a

File tree

5 files changed

+103
-3
lines changed

5 files changed

+103
-3
lines changed

changelog.txt

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

33
= 6.2.0 - 2022-xx-xx =
4+
* Add - Add onboarding payment gateway setup methods.
5+
* Fix - Enable Stripe payment method after connecting account.
46
* Fix - Missing statement descriptor in account summary API when not set in Stripe.
57

68
= 6.1.0 - 2022-01-26 =

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/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

readme.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@ If you get stuck, you can ask for help in the Plugin Forum.
129129
== Changelog ==
130130

131131
= 6.2.0 - 2022-xx-xx =
132+
* Add - Add onboarding payment gateway setup methods.
133+
* Fix - Enable Stripe payment method after connecting account.
132134
* Fix - Missing statement descriptor in account summary API when not set in Stripe.
133135

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

0 commit comments

Comments
 (0)