Skip to content

Commit 9799dd8

Browse files
authored
Merge branch 'Codexshaper:master' into master
2 parents e255626 + b54d809 commit 9799dd8

File tree

6 files changed

+182
-3
lines changed

6 files changed

+182
-3
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
},
1717
"require-dev": {
1818
"phpunit/phpunit": "^7.0|^8.0|^9.3",
19-
"illuminate/support": "~5.5.40|~5.6.0|~5.7.0|~5.8.0|^6.0|^7.0|^8.0"
19+
"illuminate/support": "~5.5.40|~5.6.0|~5.7.0|~5.8.0|^6.0|^7.0|^8.0|^9.0"
2020
},
2121
"license": "MIT",
2222
"authors": [
@@ -60,6 +60,7 @@
6060
"Variation": "Codexshaper\\WooCommerce\\Models\\Variation",
6161
"Webhook": "Codexshaper\\WooCommerce\\Facades\\Webhook",
6262
"WooCommerce": "Codexshaper\\WooCommerce\\Facades\\WooCommerce",
63+
"WooAnalytics": "Codexshaper\\WooCommerce\\Facades\\WooAnalytics",
6364
"Query": "Codexshaper\\WooCommerce\\Facades\\Query"
6465
}
6566
}

src/Facades/Subscription.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace Codexshaper\WooCommerce\Facades;
4+
5+
use Illuminate\Support\Facades\Facade;
6+
7+
class Subscription extends Facade
8+
{
9+
/**
10+
* Get the registered name of the component.
11+
*
12+
* @return string
13+
*/
14+
protected static function getFacadeAccessor()
15+
{
16+
return 'Codexshaper\WooCommerce\Models\Subscription';
17+
}
18+
}

src/Facades/WooAnalytics.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace Codexshaper\WooCommerce\Facades;
4+
5+
use Codexshaper\WooCommerce\WooCommerceAnalyticsApi;
6+
use Illuminate\Support\Facades\Facade;
7+
8+
class WooAnalytics extends Facade
9+
{
10+
/**
11+
* Get the registered name of the component.
12+
*
13+
* @return string
14+
*/
15+
protected static function getFacadeAccessor()
16+
{
17+
return WooCommerceAnalyticsApi::class;
18+
}
19+
}

src/Models/Subscription.php

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<?php
2+
3+
namespace Codexshaper\WooCommerce\Models;
4+
5+
use Codexshaper\WooCommerce\Facades\Query;
6+
use Codexshaper\WooCommerce\Traits\QueryBuilderTrait;
7+
8+
class Subscription extends BaseModel
9+
{
10+
use QueryBuilderTrait;
11+
12+
protected $endpoint = 'subscriptions';
13+
14+
/**
15+
* Retrieve all notes.
16+
*
17+
* @param int $subscription_id
18+
* @param array $options
19+
*
20+
* @return array
21+
*/
22+
protected function notes($subscription_id, $options = [])
23+
{
24+
return Query::init()
25+
->setEndpoint("subscriptions/{$subscription_id}/notes")
26+
->all($options);
27+
}
28+
29+
/**
30+
* Retreive a note.
31+
*
32+
* @param int $subscription_id
33+
* @param int $note_id
34+
* @param array $options
35+
*
36+
* @return object
37+
*/
38+
protected function note($subscription_id, $note_id, $options = [])
39+
{
40+
return Query::init()
41+
->setEndpoint("subscriptions/{$subscription_id}/notes")
42+
->find($note_id, $options);
43+
}
44+
45+
/**
46+
* Create a note.
47+
*
48+
* @param int $subscription_id
49+
* @param array $data
50+
*
51+
* @return object
52+
*/
53+
protected function createNote($subscription_id, $data = [])
54+
{
55+
return Query::init()
56+
->setEndpoint("subscriptions/{$subscription_id}/notes")
57+
->create($data);
58+
}
59+
60+
/**
61+
* Delete a note.
62+
*
63+
* @param int $subscription_id
64+
* @param int $note_id
65+
* @param array $options
66+
*
67+
* @return object
68+
*/
69+
protected function deleteNote($subscription_id, $note_id, $options = [])
70+
{
71+
return Query::init()
72+
->setEndpoint("subscriptions/{$subscription_id}/notes")
73+
->delete($note_id, $options);
74+
}
75+
76+
/**
77+
* Retrieve all orders for the subscription.
78+
*
79+
* @param int $subscription_id
80+
* @param array $options
81+
*
82+
* @return array
83+
*/
84+
protected function orders($subscription_id, $options = [])
85+
{
86+
return Query::init()
87+
->setEndpoint("subscriptions/{$subscription_id}/orders")
88+
->all($options);
89+
}
90+
}

src/Query.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
namespace Codexshaper\WooCommerce;
44

5-
use Codexshaper\WooCommerce\Models\BaseMOdel;
5+
use Codexshaper\WooCommerce\Models\BaseModel;
66
use Codexshaper\WooCommerce\Traits\QueryBuilderTrait;
77

8-
class Query extends BaseMOdel
8+
class Query extends BaseModel
99
{
1010
use QueryBuilderTrait;
1111

src/WooCommerceAnalyticsApi.php

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
namespace Codexshaper\WooCommerce;
4+
5+
use Automattic\WooCommerce\Client;
6+
use Codexshaper\WooCommerce\Traits\WooCommerceTrait;
7+
8+
class WooCommerceAnalyticsApi
9+
{
10+
use WooCommerceTrait;
11+
12+
/**
13+
*@var \Automattic\WooCommerce\Client
14+
*/
15+
protected $client;
16+
17+
/**
18+
*@var array
19+
*/
20+
protected $headers = [];
21+
22+
/**
23+
* Build Woocommerce connection.
24+
*
25+
* @return void
26+
*/
27+
public function __construct()
28+
{
29+
try {
30+
$this->headers = [
31+
'header_total' => config('woocommerce.header_total') ?? 'X-WP-Total',
32+
'header_total_pages' => config('woocommerce.header_total_pages') ?? 'X-WP-TotalPages',
33+
];
34+
35+
$this->client = new Client(
36+
config('woocommerce.store_url'),
37+
config('woocommerce.consumer_key'),
38+
config('woocommerce.consumer_secret'),
39+
[
40+
'version' => 'wc-analytics',
41+
'wp_api' => config('woocommerce.wp_api_integration'),
42+
'verify_ssl' => config('woocommerce.verify_ssl'),
43+
'query_string_auth' => config('woocommerce.query_string_auth'),
44+
'timeout' => config('woocommerce.timeout'),
45+
]
46+
);
47+
} catch (\Exception $e) {
48+
throw new \Exception($e->getMessage(), 1);
49+
}
50+
}
51+
}

0 commit comments

Comments
 (0)