Create_Account::request_account( array $submission, WP_Error $errors )
Summary
No summary available.Parameters
- $submission
-
(array) (Required) The data submitted to the new account form
- $errors
-
(WP_Error) (Required) Error object to collect any errors that occur
Return
(void)
Source
File: src/BigCommerce/Merchant/Create_Account.php
public function request_account( $submission, $errors ) { $secret_key = wp_generate_password( 32, true, true ); update_option( Onboarding_Api::AUTH_KEY, $secret_key, false ); $contact = new Account_Contact([ 'email' => sanitize_email( $submission[ 'email' ] ), 'first_name' => sanitize_text_field( $submission[ 'first_name' ] ), 'last_name' => sanitize_text_field( $submission[ 'last_name' ] ), 'address_line_1' => sanitize_text_field( $submission[ 'street_1' ] ), 'address_line_2' => sanitize_text_field( $submission[ 'street_2' ] ), 'city' => sanitize_text_field( $submission[ 'city' ] ), 'district' => sanitize_text_field( $submission[ 'state' ] ), 'postal_code' => sanitize_text_field( $submission[ 'zip' ] ), 'country' => sanitize_text_field( $submission[ 'country' ] ), 'phone_number' => sanitize_text_field( $submission[ 'phone' ] ), ]); $request = new Create_Account_Request( $secret_key, sanitize_text_field( $submission[ 'store_name' ] ), home_url( '/' ), $contact ); $response = $this->onboarding->create_account( $request ); if ( is_wp_error( $response ) ) { $errors->add( $response->get_error_code(), $response->get_error_message(), $response->get_error_data() ); return; } $response_code = (int) wp_remote_retrieve_response_code( $response ); if ( $response_code < 200 || $response_code >= 400 ) { $this->handle_error_response( $response, $errors ); return; } $response_body = json_decode( wp_remote_retrieve_body( $response ), true ); if ( empty( $response_body[ 'account_id' ] ) || empty( $response_body[ 'store_id' ] ) ) { $errors->add( 'invalid_response', __( 'We encountered an unexpected error creating your account. Please try again.' ), $response ); return; } update_option( Onboarding_Api::ACCOUNT_ID, $response_body[ 'account_id' ] ); update_option( Onboarding_Api::STORE_ID, $response_body[ 'store_id' ] ); return; }