From 1e26ddad9887810855ed53c8365a8495753b434e Mon Sep 17 00:00:00 2001 From: Joshua Flowers Date: Wed, 19 May 2021 16:10:11 -0400 Subject: [PATCH 1/3] Add paystack to fallback payment gateways --- .../DefaultPaymentGateways.php | 50 ++++++++++++++----- 1 file changed, 38 insertions(+), 12 deletions(-) diff --git a/src/Features/RemotePaymentMethods/DefaultPaymentGateways.php b/src/Features/RemotePaymentMethods/DefaultPaymentGateways.php index d2490f060df..7718e6de412 100644 --- a/src/Features/RemotePaymentMethods/DefaultPaymentGateways.php +++ b/src/Features/RemotePaymentMethods/DefaultPaymentGateways.php @@ -20,16 +20,6 @@ class DefaultPaymentGateways { * @return array Default specs. */ public static function get_all() { - $stripe_countries = OnboardingTasks::get_stripe_supported_countries(); - $stripe_countries_rules = array(); - foreach ( $stripe_countries as $country ) { - $stripe_countries_rules[] = (object) array( - 'type' => 'base_location_country', - 'value' => $country, - 'operation' => '=', - ); - } - return array( array( 'key' => 'payfast', @@ -58,10 +48,23 @@ public static function get_all() { 'image' => WC()->plugin_url() . '/assets/images/stripe.png', 'plugins' => array( 'woocommerce-gateway-stripe' ), 'is_visible' => array( + self::get_rules_for_countries( OnboardingTasks::get_stripe_supported_countries() ), (object) array( - 'type' => 'or', - 'operands' => $stripe_countries_rules, + 'type' => 'option', + 'option_name' => 'woocommerce_onboarding_profile', + 'value' => 'cbd-other-hemp-derived-products', + 'operation' => '!contains', ), + ), + ), + array( + 'key' => 'paystack', + 'title' => __( 'Paystack', 'woocommerce-admin' ), + 'content' => __( 'Paystack helps African merchants accept one-time and recurring payments online with a modern, safe, and secure payment gateway.', 'woocommerce-admin' ), + 'image' => plugins_url( 'images/onboarding/paystack.png', WC_ADMIN_PLUGIN_FILE ), + 'plugins' => array( 'woo-paystack' ), + 'is_visible' => array( + self::get_rules_for_countries( array( 'ZA', 'GH', 'NG' ) ), (object) array( 'type' => 'option', 'option_name' => 'woocommerce_onboarding_profile', @@ -73,4 +76,27 @@ public static function get_all() { ); } + /** + * Get rules that match the store base location to one of the provided countries. + * + * @param array $countries Array of countries to match. + * @return object Rules to match. + */ + public function get_rules_for_countries( $countries ) { + $rules = array(); + + foreach ( $countries as $country ) { + $rules[] = (object) array( + 'type' => 'base_location_country', + 'value' => $country, + 'operation' => '=', + ); + } + + return (object) array( + 'type' => 'or', + 'operands' => $rules, + ); + } + } From c97ef572fe856af4c05da37f6c38c3f7bfca43cf Mon Sep 17 00:00:00 2001 From: Joshua Flowers Date: Wed, 19 May 2021 18:55:24 -0400 Subject: [PATCH 2/3] Add changelog entry --- readme.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/readme.txt b/readme.txt index bcd4ccbe708..235748b26cc 100644 --- a/readme.txt +++ b/readme.txt @@ -89,6 +89,7 @@ Release and roadmap notes are available on the [WooCommerce Developers Blog](htt - Add: Free extension list powered by remote config #6952 - Add: Add PayPal to fallback payment gateways #7001 - Add: Add a data store for WC Payments REST APIs #6918 +- Add: Add Paystack as fallback gateway #7025 - Dev: Update package-lock to fix versioning of local packages. #6843 - Dev: Use rule processing for remote payment methods #6830 - Dev: Update E2E jest config, so it correctly creates screenshots on failure. #6858 From 63a0f9743f2f1ed1ef474d97ba23bda6c3606764 Mon Sep 17 00:00:00 2001 From: Joshua Flowers Date: Tue, 25 May 2021 10:54:17 -0400 Subject: [PATCH 3/3] Fix CBD rules --- .../DefaultPaymentGateways.php | 39 +++++++++++++++---- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/src/Features/RemotePaymentMethods/DefaultPaymentGateways.php b/src/Features/RemotePaymentMethods/DefaultPaymentGateways.php index 7718e6de412..729d9579fff 100644 --- a/src/Features/RemotePaymentMethods/DefaultPaymentGateways.php +++ b/src/Features/RemotePaymentMethods/DefaultPaymentGateways.php @@ -65,12 +65,7 @@ public static function get_all() { 'plugins' => array( 'woo-paystack' ), 'is_visible' => array( self::get_rules_for_countries( array( 'ZA', 'GH', 'NG' ) ), - (object) array( - 'type' => 'option', - 'option_name' => 'woocommerce_onboarding_profile', - 'value' => 'cbd-other-hemp-derived-products', - 'operation' => '!contains', - ), + self::get_rules_for_cbd( false ), ), ), ); @@ -82,7 +77,7 @@ public static function get_all() { * @param array $countries Array of countries to match. * @return object Rules to match. */ - public function get_rules_for_countries( $countries ) { + public static function get_rules_for_countries( $countries ) { $rules = array(); foreach ( $countries as $country ) { @@ -99,4 +94,34 @@ public function get_rules_for_countries( $countries ) { ); } + /** + * Get default rules for CBD based on given argument. + * + * @param bool $should_have Whether or not the store should have CBD as an industry (true) or not (false). + * @return array Rules to match. + */ + public static function get_rules_for_cbd( $should_have ) { + return (object) array( + 'type' => 'option', + 'transformers' => array( + (object) array( + 'use' => 'dot_notation', + 'arguments' => (object) array( + 'path' => 'industry', + ), + ), + (object) array( + 'use' => 'array_column', + 'arguments' => (object) array( + 'key' => 'slug', + ), + ), + ), + 'option_name' => 'woocommerce_onboarding_profile', + 'operation' => $should_have ? 'contains' : '!contains', + 'value' => 'cbd-other-hemp-derived-products', + 'default' => array(), + ); + } + }