Skip to content

Commit

Permalink
Merge branch 'develop' into dev/bump-woocommerce-tested-to-8.9.2
Browse files Browse the repository at this point in the history
  • Loading branch information
dmvrtx authored Jun 10, 2024
2 parents 166cae3 + 557030d commit 2e9a40d
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 180 deletions.
8 changes: 4 additions & 4 deletions .husky/pre-push
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

# check if main stream (stdout and stderr) are attached to the terminal
Expand All @@ -7,12 +7,12 @@ if [ -t 1 ] && [ -t 2 ]; then
exec < /dev/tty
fi

PROTECTED_BRANCH=("develop" "trunk")
PROTECTED_BRANCH_LIST="develop trunk"
CURRENT_BRANCH=$(git branch --show-current)

if [[ " ${PROTECTED_BRANCH[@]} " =~ " ${CURRENT_BRANCH} " ]]; then
if echo "$PROTECTED_BRANCH_LIST" | grep -q -w "$CURRENT_BRANCH"; then
read -p "$CURRENT_BRANCH is a protected branch. Are you sure you want to push? (y/n): " confirmation
if [ "$confirmation" != "y" ]; then
if [ "$confirmation" != "y" ]; then
echo "Push aborted"
exit 1
fi
Expand Down
4 changes: 4 additions & 0 deletions changelog/dev-remove-unneeded-code
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: dev

Clean up and refactor some old code which is no longer in use.
4 changes: 4 additions & 0 deletions changelog/misc-move-prepush-to-sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: dev

Add sh support in pre-push husky script.
45 changes: 1 addition & 44 deletions includes/admin/class-wc-rest-payments-onboarding-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,6 @@ public function register_routes() {
]
);

register_rest_route(
$this->namespace,
'/' . $this->rest_base . '/required_verification_information',
[
'methods' => WP_REST_Server::READABLE,
'callback' => [ $this, 'get_required_verification_information' ],
'permission_callback' => [ $this, 'check_permission' ],
]
);

register_rest_route(
$this->namespace,
'/' . $this->rest_base . '/router/po_eligible',
Expand Down Expand Up @@ -122,7 +112,7 @@ public function register_routes() {
],
'callback' => [ $this, 'get_progressive_onboarding_eligible' ],
'permission_callback' => [ $this, 'check_permission' ],
],
]
);
}

Expand All @@ -138,39 +128,6 @@ public function get_business_types( WP_REST_Request $request ) {
return rest_ensure_response( [ 'data' => $business_types ] );
}

/**
* Get required verification information via API.
*
* @param WP_REST_Request $request Request object.
*
* @return WP_REST_Response|WP_Error
*
* @throws Rest_Request_Exception
*/
public function get_required_verification_information( WP_REST_Request $request ) {
$country_code = $request->get_param( 'country' ) ?? null;
$type = $request->get_param( 'type' ) ?? null;
$structure = $request->get_param( 'structure' ) ?? null;

try {
if ( ! $country_code || ! $type ) {
throw new Rest_Request_Exception( __( 'Country or type parameter was missing', 'woocommerce-payments' ) );
}

$verification_info = $this->onboarding_service->get_required_verification_information( $country_code, $type, $structure );

return rest_ensure_response(
[
'data' => $verification_info,
]
);
} catch ( Rest_Request_Exception $e ) {
return new WP_REST_Response( [ 'result' => self::RESULT_BAD_REQUEST ], 400 );
} catch ( API_Exception $e ) {
return new WP_Error( $e->get_error_code(), $e->getMessage() );
}
}

/**
* Get progressive onboarding eligibility via API.
*
Expand Down
15 changes: 0 additions & 15 deletions includes/class-wc-payments-onboarding-service.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,21 +142,6 @@ function () {
return $business_types;
}

/**
* Get the required verification information for the selected country/type/structure combination from the API.
*
* @param string $country_code The currently selected country code.
* @param string $type The currently selected business type.
* @param string|null $structure The currently selected business structure (optional).
*
* @return array
*
* @throws API_Exception
*/
public function get_required_verification_information( string $country_code, string $type, $structure = null ): array {
return $this->payments_api_client->get_onboarding_required_verification_information( $country_code, $type, $structure );
}

/**
* Check whether the business types fetched from the cache are valid.
*
Expand Down
30 changes: 0 additions & 30 deletions includes/wc-payment-api/class-wc-payments-api-client.php
Original file line number Diff line number Diff line change
Expand Up @@ -972,36 +972,6 @@ public function get_onboarding_business_types(): array {
return $business_types;
}

/**
* Get the required verification information, needed for our KYC onboarding flow.
*
* @param string $country_code The country code.
* @param string $type The business type.
* @param string|null $structure The business structure (optional).
*
* @return array An array containing the required verification information.
*
* @throws API_Exception Exception thrown on request failure.
*/
public function get_onboarding_required_verification_information( string $country_code, string $type, $structure = null ) {
$params = [
'country' => $country_code,
'type' => $type,
];

if ( ! is_null( $structure ) ) {
$params = array_merge( $params, [ 'structure' => $structure ] );
}

return $this->request(
$params,
self::ONBOARDING_API . '/required_verification_information',
self::GET,
true,
true
);
}

/**
* Get a link's details from the server.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,59 +64,6 @@ public function test_get_business_types() {
$this->assertSame( [ 'data' => $mock_business_types ], $response->get_data() );
}

public function test_get_required_verification_information_with_missing_params() {
$request = new WP_REST_Request( 'GET', '', [ 'foo' => 'bar' ] );
$response = $this->controller->get_required_verification_information( $request );

$this->assertSame( 400, $response->status );
$this->assertSame(
[ 'result' => WC_REST_Payments_Onboarding_Controller::RESULT_BAD_REQUEST ],
$response->get_data()
);
}

public function test_get_required_verification_information() {
$mock_requirements = [
'business_profile.url',
'business_profile.mcc',
'representative.first_name',
'representative.last_name',
'representative.dob.day',
'representative.dob.month',
'representative.dob.year',
'representative.phone',
'representative.email',
'representative.address.line1',
'representative.address.postal_code',
'representative.address.city',
'representative.address.state',
'representative.ssn_last_4',
'company.name',
'company.tax_id',
'tos_acceptance.ip',
'tos_acceptance.date',
'external_account',
];

$this->mock_onboarding_service
->expects( $this->once() )
->method( 'get_required_verification_information' )
->willReturn( $mock_requirements );

$request = new WP_REST_Request( 'GET' );
$request->set_url_params(
[
'country' => Country_Code::UNITED_STATES,
'type' => 'company',
'structure' => 'sole_proprietor',
]
);
$response = $this->controller->get_required_verification_information( $request );

$this->assertSame( 200, $response->status );
$this->assertSame( [ 'data' => $mock_requirements ], $response->get_data() );
}

public function test_get_progressive_onboarding_eligible() {
$this->mock_api_client
->expects( $this->once() )
Expand Down
15 changes: 0 additions & 15 deletions tests/unit/test-class-wc-payments-onboarding-service.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,21 +141,6 @@ public function test_filters_registered_properly() {
$this->assertNotFalse( has_filter( 'admin_body_class', [ $this->onboarding_service, 'add_admin_body_classes' ] ) );
}

public function test_get_required_verification_information() {
$mock_requirements = [ 'requirement1', 'requirement2', 'requirement3' ];

$this->mock_api_client
->expects( $this->once() )
->method( 'get_onboarding_required_verification_information' )
->with( Country_Code::UNITED_STATES, 'company', 'sole_propietorship' )
->willReturn( $mock_requirements );

$this->assertEquals(
$mock_requirements,
$this->onboarding_service->get_required_verification_information( Country_Code::UNITED_STATES, 'company', 'sole_propietorship' )
);
}

public function test_get_cached_business_types_with_no_server_connection() {
$this->mock_api_client
->expects( $this->once() )
Expand Down
19 changes: 0 additions & 19 deletions tests/unit/wc-payment-api/test-class-wc-payments-api-client.php
Original file line number Diff line number Diff line change
Expand Up @@ -347,25 +347,6 @@ public function test_get_onboarding_business_types() {
$this->payments_api_client->get_onboarding_business_types();
}

/**
* Test getting onboarding required verification information.
*
* @throws API_Exception
*/
public function test_get_onboarding_required_verification_information() {
$this->mock_http_client
->expects( $this->once() )
->method( 'remote_request' )
->with(
$this->containsIdentical( 'https://public-api.wordpress.com/wpcom/v2/sites/%s/wcpay/onboarding/required_verification_information?test_mode=0&country=country&type=type' ),
null,
true,
true // get_onboarding_required_verification_information should use user token auth.
);

$this->payments_api_client->get_onboarding_required_verification_information( 'country', 'type' );
}

public function test_get_link() {
$this->mock_http_client
->expects( $this->once() )
Expand Down

0 comments on commit 2e9a40d

Please sign in to comment.