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