Merge pull request #23690 from woocommerce/update/obw-stripe
Update OWB Payment Gateway structure
This commit is contained in:
commit
afd7e72c03
File diff suppressed because it is too large
Load Diff
Binary file not shown.
After Width: | Height: | Size: 17 KiB |
Binary file not shown.
After Width: | Height: | Size: 21 KiB |
|
@ -1393,7 +1393,7 @@ class WC_Admin_Setup_Wizard {
|
|||
'name' => __( 'WooCommerce PayPal Checkout Gateway', 'woocommerce' ),
|
||||
'image' => WC()->plugin_url() . '/assets/images/paypal.png',
|
||||
'description' => $paypal_checkout_description,
|
||||
'enabled' => true,
|
||||
'enabled' => false,
|
||||
'class' => 'checked paypal-logo',
|
||||
'repo-slug' => 'woocommerce-gateway-paypal-express-checkout',
|
||||
'settings' => array(
|
||||
|
@ -1432,7 +1432,7 @@ class WC_Admin_Setup_Wizard {
|
|||
'klarna_checkout' => array(
|
||||
'name' => __( 'Klarna Checkout for WooCommerce', 'woocommerce' ),
|
||||
'description' => $klarna_checkout_description,
|
||||
'image' => WC()->plugin_url() . '/assets/images/klarna-white.png',
|
||||
'image' => WC()->plugin_url() . '/assets/images/klarna-black.png',
|
||||
'enabled' => true,
|
||||
'class' => 'klarna-logo',
|
||||
'repo-slug' => 'klarna-checkout-for-woocommerce',
|
||||
|
@ -1440,7 +1440,7 @@ class WC_Admin_Setup_Wizard {
|
|||
'klarna_payments' => array(
|
||||
'name' => __( 'Klarna Payments for WooCommerce', 'woocommerce' ),
|
||||
'description' => $klarna_payments_description,
|
||||
'image' => WC()->plugin_url() . '/assets/images/klarna-white.png',
|
||||
'image' => WC()->plugin_url() . '/assets/images/klarna-black.png',
|
||||
'enabled' => true,
|
||||
'class' => 'klarna-logo',
|
||||
'repo-slug' => 'klarna-payments-for-woocommerce',
|
||||
|
@ -1448,9 +1448,9 @@ class WC_Admin_Setup_Wizard {
|
|||
'square' => array(
|
||||
'name' => __( 'WooCommerce Square', 'woocommerce' ),
|
||||
'description' => $square_description,
|
||||
'image' => WC()->plugin_url() . '/assets/images/square-white.png',
|
||||
'image' => WC()->plugin_url() . '/assets/images/square-black.png',
|
||||
'class' => 'square-logo',
|
||||
'enabled' => true,
|
||||
'enabled' => false,
|
||||
'repo-slug' => 'woocommerce-square',
|
||||
),
|
||||
'eway' => array(
|
||||
|
@ -1503,18 +1503,33 @@ class WC_Admin_Setup_Wizard {
|
|||
}
|
||||
|
||||
if ( $spotlight ) {
|
||||
$offered_gateways = array(
|
||||
$spotlight => $gateways[ $spotlight ],
|
||||
);
|
||||
$offered_gateways = array();
|
||||
|
||||
if ( $can_stripe ) {
|
||||
$gateways['stripe']['enabled'] = true;
|
||||
$gateways['stripe']['featured'] = true;
|
||||
$offered_gateways += array( 'stripe' => $gateways['stripe'] );
|
||||
} elseif ( $can_paypal ) {
|
||||
$gateways['ppec_paypal']['enabled'] = true;
|
||||
}
|
||||
|
||||
if ( in_array( $spotlight, array( 'klarna_checkout', 'klarna_payments' ), true ) ) {
|
||||
$gateways[ $spotlight ]['enabled'] = true;
|
||||
$gateways[ $spotlight ]['featured'] = false;
|
||||
$offered_gateways += array(
|
||||
$spotlight => $gateways[ $spotlight ],
|
||||
);
|
||||
|
||||
} else {
|
||||
$offered_gateways += array(
|
||||
$spotlight => $gateways[ $spotlight ],
|
||||
);
|
||||
}
|
||||
|
||||
if ( $can_paypal ) {
|
||||
$offered_gateways += array( 'ppec_paypal' => $gateways['ppec_paypal'] );
|
||||
}
|
||||
|
||||
if ( $can_stripe ) {
|
||||
$offered_gateways += array( 'stripe' => $gateways['stripe'] );
|
||||
}
|
||||
|
||||
if ( $can_eway ) {
|
||||
$offered_gateways += array( 'eway' => $gateways['eway'] );
|
||||
}
|
||||
|
@ -1532,6 +1547,8 @@ class WC_Admin_Setup_Wizard {
|
|||
$gateways['stripe']['enabled'] = true;
|
||||
$gateways['stripe']['featured'] = true;
|
||||
$offered_gateways += array( 'stripe' => $gateways['stripe'] );
|
||||
} elseif ( $can_paypal ) {
|
||||
$gateways['ppec_paypal']['enabled'] = true;
|
||||
}
|
||||
|
||||
if ( $can_paypal ) {
|
||||
|
@ -1596,7 +1613,7 @@ class WC_Admin_Setup_Wizard {
|
|||
// Show the user-saved state if it was previously saved.
|
||||
// Otherwise, rely on the item info.
|
||||
if ( is_array( $previously_saved_settings ) ) {
|
||||
$should_enable_toggle = isset( $previously_saved_settings['enabled'] ) && 'yes' === $previously_saved_settings['enabled'];
|
||||
$should_enable_toggle = ( isset( $previously_saved_settings['enabled'] ) && 'yes' === $previously_saved_settings['enabled'] ) ? true : ( isset( $item_info['enabled'] ) && $item_info['enabled'] );
|
||||
} else {
|
||||
$should_enable_toggle = isset( $item_info['enabled'] ) && $item_info['enabled'];
|
||||
}
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
<?php
|
||||
/**
|
||||
* Class WC_Tests_Setup_Functions.
|
||||
* @package WooCommerce\Tests\Setup
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class Functions.
|
||||
* @package WooCommerce\Tests\Setup
|
||||
* Class WC_Tests_Setup_Functions.
|
||||
*/
|
||||
class WC_Tests_Setup_Functions extends WC_Unit_Test_Case {
|
||||
|
||||
|
@ -15,73 +18,90 @@ class WC_Tests_Setup_Functions extends WC_Unit_Test_Case {
|
|||
public function test_wizard_in_cart_payment_gateways() {
|
||||
$setup_wizard = new WC_Admin_Setup_Wizard();
|
||||
|
||||
function get_enabled( $gateway ) {
|
||||
return isset( $gateway['enabled'] ) && $gateway['enabled'];
|
||||
}
|
||||
function gateways( $setup_wizard ) {
|
||||
return array_map( 'get_enabled', $setup_wizard->get_wizard_in_cart_payment_gateways() );
|
||||
}
|
||||
|
||||
// non-admin user
|
||||
// non-admin user.
|
||||
$this->user_id = $this->factory->user->create( array( 'role' => 'shop_manager' ) );
|
||||
wp_set_current_user( $this->user_id );
|
||||
$this->assertEquals(
|
||||
gateways( $setup_wizard ),
|
||||
array(
|
||||
'paypal' => false,
|
||||
)
|
||||
),
|
||||
$this->get_gateways_statuses( $setup_wizard )
|
||||
);
|
||||
|
||||
// set admin user
|
||||
// set admin user.
|
||||
$this->user_id = $this->factory->user->create( array( 'role' => 'administrator' ) );
|
||||
wp_set_current_user( $this->user_id );
|
||||
|
||||
update_option( 'woocommerce_default_country', 'US' );
|
||||
$this->assertEquals(
|
||||
gateways( $setup_wizard ),
|
||||
array(
|
||||
'stripe' => true,
|
||||
'ppec_paypal' => true,
|
||||
)
|
||||
'ppec_paypal' => false,
|
||||
),
|
||||
$this->get_gateways_statuses( $setup_wizard )
|
||||
);
|
||||
|
||||
update_option( 'woocommerce_default_country', 'CN' );
|
||||
$this->assertEquals(
|
||||
gateways( $setup_wizard ),
|
||||
array(
|
||||
'ppec_paypal' => true,
|
||||
)
|
||||
),
|
||||
$this->get_gateways_statuses( $setup_wizard )
|
||||
);
|
||||
|
||||
update_option( 'woocommerce_default_country', 'SE' );
|
||||
$this->assertEquals(
|
||||
gateways( $setup_wizard ),
|
||||
array(
|
||||
'klarna_checkout' => true,
|
||||
'ppec_paypal' => true,
|
||||
'stripe' => false,
|
||||
)
|
||||
'ppec_paypal' => false,
|
||||
'stripe' => true,
|
||||
),
|
||||
$this->get_gateways_statuses( $setup_wizard )
|
||||
);
|
||||
|
||||
update_option( 'woocommerce_default_country', 'DE' );
|
||||
$this->assertEquals(
|
||||
gateways( $setup_wizard ),
|
||||
array(
|
||||
'klarna_payments' => true,
|
||||
'ppec_paypal' => true,
|
||||
'stripe' => false,
|
||||
)
|
||||
'ppec_paypal' => false,
|
||||
'stripe' => true,
|
||||
),
|
||||
$this->get_gateways_statuses( $setup_wizard )
|
||||
);
|
||||
|
||||
update_option( 'woocommerce_default_country', 'GB' );
|
||||
update_option( 'woocommerce_sell_in_person', 'yes' );
|
||||
$this->assertEquals(
|
||||
gateways( $setup_wizard ),
|
||||
array(
|
||||
'square' => true,
|
||||
'ppec_paypal' => true,
|
||||
'stripe' => false,
|
||||
)
|
||||
'square' => false,
|
||||
'ppec_paypal' => false,
|
||||
'stripe' => true,
|
||||
),
|
||||
$this->get_gateways_statuses( $setup_wizard )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to call the tested method and return a simplified version
|
||||
* of the returned values. It returns only if the gateways are enable or not
|
||||
* which is what we are currently checking in the tests.
|
||||
*
|
||||
* @param WC_Admin_Setup_Wizard $setup_wizard Setup wizard object.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function get_gateways_statuses( $setup_wizard ) {
|
||||
return array_map( array( $this, 'get_enabled' ), $setup_wizard->get_wizard_in_cart_payment_gateways() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Return wheter a given gateway is enable or not.
|
||||
*
|
||||
* @param array $gateway Gateway information.
|
||||
* @return bool
|
||||
*/
|
||||
protected function get_enabled( $gateway ) {
|
||||
return isset( $gateway['enabled'] ) && $gateway['enabled'];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue