woocommerce
/
src
/
Admin
/
Features
/
PaymentGatewaySuggestions
/
PaymentGatewaySuggestionsDataSourcePoller.php
DefaultPaymentGateways.php
1 year ago
EvaluateSuggestion.php
1 year ago
Init.php
1 year ago
PaymentGatewaySuggestionsDataSourcePoller.php
1 year ago
PaymentGatewaysController.php
4 years ago
PaymentGatewaySuggestionsDataSourcePoller.php
67 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Automattic\WooCommerce\Admin\Features\PaymentGatewaySuggestions; |
| 4 | |
| 5 | use Automattic\WooCommerce\Admin\RemoteSpecs\DataSourcePoller; |
| 6 | use WC_Helper; |
| 7 | |
| 8 | /** |
| 9 | * Specs data source poller class for payment gateway suggestions. |
| 10 | */ |
| 11 | class PaymentGatewaySuggestionsDataSourcePoller extends DataSourcePoller { |
| 12 | |
| 13 | /** |
| 14 | * Data Source Poller ID. |
| 15 | */ |
| 16 | const ID = 'payment_gateway_suggestions'; |
| 17 | |
| 18 | /** |
| 19 | * Default data sources array. |
| 20 | * |
| 21 | * @deprecated since 9.5.0. Use get_data_sources() instead. |
| 22 | */ |
| 23 | const DATA_SOURCES = array(); |
| 24 | |
| 25 | /** |
| 26 | * Class instance. |
| 27 | * |
| 28 | * @var PaymentGatewaySuggestionsDataSourcePoller instance |
| 29 | */ |
| 30 | protected static $instance = null; |
| 31 | |
| 32 | /** |
| 33 | * Get class instance. |
| 34 | */ |
| 35 | public static function get_instance() { |
| 36 | if ( ! self::$instance ) { |
| 37 | self::$instance = new self( self::ID, self::get_data_sources() ); |
| 38 | } |
| 39 | return self::$instance; |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * Get data sources with dynamic base URL. |
| 44 | * |
| 45 | * @return array |
| 46 | */ |
| 47 | public static function get_data_sources() { |
| 48 | $data_sources = array( |
| 49 | WC_Helper::get_woocommerce_com_base_url() . 'wp-json/wccom/payment-gateway-suggestions/2.0/suggestions.json', |
| 50 | ); |
| 51 | |
| 52 | // Add country query param to data sources. |
| 53 | $base_location = wc_get_base_location(); |
| 54 | $data_sources_with_country = array_map( |
| 55 | function ( $url ) use ( $base_location ) { |
| 56 | return add_query_arg( |
| 57 | 'country', |
| 58 | $base_location['country'], |
| 59 | $url |
| 60 | ); |
| 61 | }, |
| 62 | $data_sources |
| 63 | ); |
| 64 | return $data_sources_with_country; |
| 65 | } |
| 66 | } |
| 67 |