Automattic\WooCommerce\Internal\Admin\Settings\PaymentsProviders\WooPayments
WooPaymentsService::finish_onboarding_kyc_session │ public │ WC 1.0
Finish the onboarding KYC account session.
Method of the class: WooPaymentsService{}
No Hooks.
Returns
Array. The response from the WooPayments API.
Usage
$WooPaymentsService = new WooPaymentsService();
$WooPaymentsService->finish_onboarding_kyc_session( $location, ?string $source ): array;
- $location(string) (required)
- The location for which we are onboarding. This is an ISO 3166-1 alpha-2 country code.
- ?string $source
- .
Default: self::SESSION_ENTRY_DEFAULT
WooPaymentsService::finish_onboarding_kyc_session() WooPaymentsService::finish onboarding kyc session code
WC 10.7.0
public function finish_onboarding_kyc_session( string $location, ?string $source = self::SESSION_ENTRY_DEFAULT ): array {
$this->check_if_onboarding_step_action_is_acceptable( self::ONBOARDING_STEP_BUSINESS_VERIFICATION, $location );
// Ensure the payment gateways logic is initialized in case actions need to be taken on payment gateway changes.
WC()->payment_gateways();
$source = $this->validate_onboarding_source( $source );
// Lock the onboarding to prevent concurrent actions.
$this->set_onboarding_lock();
try {
// Call the WooPayments API to finalize the KYC session.
$response = $this->proxy->call_static(
Utils::class,
'rest_endpoint_post_request',
'/wc/v3/payments/onboarding/kyc/finalize',
array(
'source' => $source,
'from' => self::FROM_NOX_IN_CONTEXT,
)
);
} catch ( Exception $e ) {
// Catch any exceptions to allow for proper error handling and onboarding unlock.
$response = new WP_Error(
'woocommerce_woopayments_onboarding_client_api_exception',
esc_html__( 'An unexpected error happened while finalizing the KYC session.', 'woocommerce' ),
array(
'code' => $e->getCode(),
'message' => $e->getMessage(),
'trace' => $e->getTrace(),
)
);
}
// Unlock the onboarding after the API call finished or errored.
$this->clear_onboarding_lock();
if ( is_wp_error( $response ) ) {
// Mark the onboarding step as failed.
$this->mark_onboarding_step_failed(
self::ONBOARDING_STEP_BUSINESS_VERIFICATION,
$location,
array(
'code' => $response->get_error_code(),
'message' => $response->get_error_message(),
'context' => $response->get_error_data(),
)
);
throw new ApiException(
'woocommerce_woopayments_onboarding_client_api_error',
esc_html( $response->get_error_message() ),
(int) WP_Http::FAILED_DEPENDENCY,
map_deep( (array) $response->get_error_data(), 'esc_html' )
);
}
if ( ! is_array( $response ) ) {
// Mark the onboarding step as failed.
$this->mark_onboarding_step_failed(
self::ONBOARDING_STEP_BUSINESS_VERIFICATION,
$location,
array(
'code' => 'malformed_response',
'message' => esc_html__( 'Received an unexpected response from the platform.', 'woocommerce' ),
'context' => array(
'response' => $response,
),
)
);
throw new ApiException(
'woocommerce_woopayments_onboarding_client_api_error',
esc_html__( 'Failed to finish the KYC session.', 'woocommerce' ),
(int) WP_Http::FAILED_DEPENDENCY
);
}
// For sanity, make sure the test account step is marked as completed, if not already,
// since we are doing live account KYC.
$this->mark_onboarding_step_completed( self::ONBOARDING_STEP_TEST_ACCOUNT, $location, false, $source );
// Record an event for the KYC session being finished.
$event_props = array(
'successful_kyc' => filter_var( $response['success'] ?? false, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE ) ?? false,
'account_mode' => ( 'live' === ( $response['mode'] ?? false ) ) ? 'live' : 'test',
'details_submitted' => filter_var( $response['details_submitted'] ?? false, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE ) ?? false,
'promotion_id' => $response['promotion_id'] ?? 'none',
'source' => $source,
);
$this->record_event(
self::EVENT_PREFIX . 'onboarding_kyc_session_finished',
$location,
$event_props
);
// Mark the business verification step as completed.
$this->mark_onboarding_step_completed( self::ONBOARDING_STEP_BUSINESS_VERIFICATION, $location, false, $source );
return $response;
}