|
11 | 11 | * @author wallee AG (http://www.wallee.com/)
|
12 | 12 | * @license http://www.apache.org/licenses/LICENSE-2.0 Apache Software License (ASL 2.0)
|
13 | 13 | */
|
| 14 | + |
| 15 | +use Automattic\Jetpack\Constants; |
14 | 16 |
|
15 | 17 | if ( ! defined( 'ABSPATH' ) ) {
|
16 | 18 | exit();
|
|
20 | 22 | */
|
21 | 23 | class WC_PostFinanceCheckout_Helper {
|
22 | 24 |
|
| 25 | + const SHOP_SYSTEM = 'x-meta-shop-system'; |
| 26 | + const SHOP_SYSTEM_VERSION = 'x-meta-shop-system-version'; |
| 27 | + const SHOP_SYSTEM_AND_VERSION = 'x-meta-shop-system-and-version'; |
23 | 28 |
|
24 | 29 | /**
|
25 | 30 | * Instance.
|
@@ -84,6 +89,9 @@ public function get_api_client() {
|
84 | 89 | if ( ! empty( $user_id ) && ! empty( $user_key ) ) {
|
85 | 90 | $this->api_client = new \PostFinanceCheckout\Sdk\ApiClient( $user_id, $user_key );
|
86 | 91 | $this->api_client->setBasePath( rtrim( $this->get_base_gateway_url(), '/' ) . '/api' );
|
| 92 | + foreach (self::getDefaultHeaderData() as $key => $value) { |
| 93 | + $this->api_client->addDefaultHeader($key, $value); |
| 94 | + } |
87 | 95 | } else {
|
88 | 96 | throw new Exception( __( 'The API access data is incomplete.', 'woo-postfinancecheckout' ) );
|
89 | 97 | }
|
@@ -528,4 +536,20 @@ protected function restock_items_for_order( WC_Order $order ) {
|
528 | 536 | do_action( 'wc_postfinancecheckout_restocked_order', $order );
|
529 | 537 | }
|
530 | 538 | }
|
| 539 | + |
| 540 | + /** |
| 541 | + * @return array |
| 542 | + */ |
| 543 | + protected static function getDefaultHeaderData() |
| 544 | + { |
| 545 | + $version = Constants::get_constant( 'WC_VERSION' ); |
| 546 | + |
| 547 | + $shop_version = str_replace('v', '', $version); |
| 548 | + [$major_version, $minor_version, $_] = explode('.', $shop_version, 3); |
| 549 | + return [ |
| 550 | + self::SHOP_SYSTEM => 'woocommerce', |
| 551 | + self::SHOP_SYSTEM_VERSION => $shop_version, |
| 552 | + self::SHOP_SYSTEM_AND_VERSION => 'woocommerce-' . $major_version . '.' . $minor_version, |
| 553 | + ]; |
| 554 | + } |
531 | 555 | }
|
0 commit comments