PluginProbe
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments / 2.31.2
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments v2.31.2
4.7.2 4.7.1 4.7.0 4.6.6 4.6.5 4.6.4 4.6.3 4.6.2 4.6.1 4.6.0 4.5.1 4.5.0 4.4.2 4.4.1 4.4.0 4.3.3 4.3.2 4.3.1 4.3.0 4.2.3 4.2.2 4.2.1 1.0.3 1.0.4 1.0.5 All 281 releases
surecart / app / src / Models / ReturnRequest.php
ReturnRequest.php
116 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace SureCart\Models;
4
5 use SureCart\Models\Model;
6 use SureCart\Models\Traits\HasOrder;
7
8 /**
9 * ReturnRequest model.
10 */
11 class ReturnRequest extends Model {
12 use HasOrder;
13
14 /**
15 * Rest API endpoint
16 *
17 * @var string
18 */
19 protected $endpoint = 'return_requests';
20
21 /**
22 * Object name
23 *
24 * @var string
25 */
26 protected $object_name = 'return_request';
27
28 /**
29 * Open a return request.
30 *
31 * @param string $id Model id.
32 * @return $this|\WP_Error
33 */
34 protected function open( $id = null ) {
35 if ( $id ) {
36 $this->setAttribute( 'id', $id );
37 }
38
39 if ( $this->fireModelEvent( 'opening' ) === false ) {
40 return false;
41 }
42
43 if ( empty( $this->id ) ) {
44 return new \WP_Error( 'not_saved', 'You can only open an existing return request.' );
45 }
46
47 $attributes = $this->attributes;
48 unset( $attributes['id'] );
49
50 $opened = $this->makeRequest(
51 [
52 'method' => 'PATCH',
53 'query' => $this->query,
54 'body' => [
55 $this->object_name => $attributes,
56 ],
57 ],
58 $this->endpoint . '/' . $this->id . '/open/'
59 );
60
61 if ( is_wp_error( $opened ) ) {
62 return $opened;
63 }
64
65 $this->resetAttributes();
66 $this->fill( $opened );
67 $this->fireModelEvent( 'opened' );
68
69 return $this;
70 }
71
72 /**
73 * Complete a return request.
74 *
75 * @param string $id Model id.
76 * @return $this|\WP_Error
77 */
78 protected function complete( $id = null ) {
79 if ( $id ) {
80 $this->setAttribute( 'id', $id );
81 }
82
83 if ( $this->fireModelEvent( 'completing' ) === false ) {
84 return false;
85 }
86
87 if ( empty( $this->id ) ) {
88 return new \WP_Error( 'not_saved', 'You can only complete an existing return request.' );
89 }
90
91 $attributes = $this->attributes;
92 unset( $attributes['id'] );
93
94 $completed = $this->makeRequest(
95 [
96 'method' => 'PATCH',
97 'query' => $this->query,
98 'body' => [
99 $this->object_name => $attributes,
100 ],
101 ],
102 $this->endpoint . '/' . $this->id . '/complete/'
103 );
104
105 if ( is_wp_error( $completed ) ) {
106 return $completed;
107 }
108
109 $this->resetAttributes();
110 $this->fill( $completed );
111 $this->fireModelEvent( 'completed' );
112
113 return $this;
114 }
115 }
116