Skip to content
This repository was archived by the owner on Jul 12, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
79 changes: 65 additions & 14 deletions src/Features/RemotePaymentMethods/DefaultPaymentGateways.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -58,10 +48,7 @@ public static function get_all() {
'image' => WC()->plugin_url() . '/assets/images/stripe.png',
'plugins' => array( 'woocommerce-gateway-stripe' ),
'is_visible' => array(
(object) array(
'type' => 'or',
'operands' => $stripe_countries_rules,
),
self::get_rules_for_countries( OnboardingTasks::get_stripe_supported_countries() ),
(object) array(
'type' => 'option',
'option_name' => 'woocommerce_onboarding_profile',
Expand All @@ -70,6 +57,70 @@ public static function get_all() {
),
),
),
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' ) ),
self::get_rules_for_cbd( false ),
),
),
);
}

/**
* 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 static 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,
);
}

/**
* 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(),
);
}

Expand Down