@@ -123,6 +123,7 @@ public function __construct() {
123
123
add_action ( 'set_logged_in_cookie ' , [ $ this , 'set_cookie_on_current_request ' ] );
124
124
add_filter ( 'woocommerce_get_checkout_payment_url ' , [ $ this , 'get_checkout_payment_url ' ], 10 , 2 );
125
125
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 ' ] );
126
127
127
128
// Note: display error is in the parent class.
128
129
add_action ( 'admin_notices ' , [ $ this , 'display_errors ' ], 9999 );
@@ -1162,4 +1163,88 @@ public function validate_account_statement_descriptor_field( $param, $value, $ma
1162
1163
1163
1164
return $ value ;
1164
1165
}
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
+ }
1165
1250
}
0 commit comments