Skip to content

Commit dbb2c58

Browse files
authored
Merge pull request #90 from ChrisHardie/feature/subscriptions-endpoint
Add support for WooCommerce Subscriptions endpoints
2 parents 3fd5b47 + 6603da5 commit dbb2c58

File tree

2 files changed

+108
-0
lines changed

2 files changed

+108
-0
lines changed

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/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+
}

0 commit comments

Comments
 (0)