Add Square to wizard payment step

This commit is contained in:
Valerie 2017-11-16 10:38:18 -05:00 committed by Marcin Bot
parent e28341a9a3
commit 8c6d069377
2 changed files with 41 additions and 3 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

View File

@ -1036,6 +1036,22 @@ class WC_Admin_Setup_Wizard {
return in_array( $country_code, $klarna_supported_countries, true );
}
/**
* Is Square country supported
*
* @param string $country_code Country code.
*/
protected function is_square_supported_country( $country_code ) {
$square_supported_countries = array(
'US',
'CA',
'JP',
'UK',
'AU',
);
return in_array( $country_code, $square_supported_countries, true );
}
/**
* Helper method to retrieve the current user's email address.
*
@ -1057,6 +1073,7 @@ class WC_Admin_Setup_Wizard {
$country = WC()->countries->get_base_country();
$can_stripe = $this->is_stripe_supported_country( $country );
$should_display_klarna = $this->is_klarna_supported_country( $country );
$should_display_square = $this->is_square_supported_country( $country ) && get_option( 'woocommerce_sell_in_person' );
$user_email = $this->get_current_user_email();
$stripe_description = '<p>' . sprintf(
@ -1075,6 +1092,10 @@ class WC_Admin_Setup_Wizard {
__( 'Pay directly at the checkout. No credit card numbers, no passwords, no worries. <a href="%s" target="_blank">Learn more about Klarna.</a>.', 'woocommerce' ),
'https://woocommerce.com/products/klarna/'
) . '</p>';
$square_description = '<p>' . sprintf(
__( 'Accept Visa, Mastercard, Discover, and American Express all for one low rate, with no surprise fees.', 'woocommerce. <a href="%s" target="_blank">Learn more about Square.</a>.', 'woocommerce' ),
'https://woocommerce.com/products/square/'
) . '</p>';
$stripe = array(
'name' => __( 'Stripe', 'woocommerce' ),
@ -1099,8 +1120,8 @@ class WC_Admin_Setup_Wizard {
'required' => true,
),
),
'enabled' => $can_stripe && ! $should_display_klarna,
'featured' => ! $should_display_klarna,
'enabled' => $can_stripe && ! ( $should_display_klarna || $should_display_square ),
'featured' => ! ( $should_display_klarna || $should_display_square ),
);
$braintree_paypal = array(
'name' => __( 'PayPal by Braintree', 'woocommerce' ),
@ -1113,7 +1134,7 @@ class WC_Admin_Setup_Wizard {
'image' => WC()->plugin_url() . '/assets/images/paypal.png',
'description' => $paypal_ec_description,
'repo-slug' => 'woocommerce-gateway-paypal-express-checkout',
'enabled' => $should_display_klarna,
'enabled' => $should_display_klarna || $should_display_square,
);
$paypal = array(
'name' => __( 'PayPal Standard', 'woocommerce' ),
@ -1137,6 +1158,14 @@ class WC_Admin_Setup_Wizard {
'enabled' => true,
'repo-slug' => 'woocommerce-gateway-klarna',
);
$square = array(
'name' => __( 'Square', 'woocommerce' ),
'description' => $square_description,
'image' => WC()->plugin_url() . '/assets/images/square-white.png',
'class' => 'inverted-logo',
'enabled' => true,
'repo-slug' => 'woocommerce-square',
);
$gateways = array(
'stripe' => $stripe,
@ -1163,11 +1192,20 @@ class WC_Admin_Setup_Wizard {
);
}
if ( $should_display_square ) {
$gateways = array(
'square' => $square,
'ppec_paypal' => $ppec_paypal,
'stripe' => $stripe,
);
}
if ( ! current_user_can( 'install_plugins' ) ) {
unset( $gateways['braintree_paypal'] );
unset( $gateways['ppec_paypal'] );
unset( $gateways['stripe'] );
unset( $gateways['klarna'] );
unset( $gateways['square'] );
}
return $gateways;