PluginProbe
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments / 4.2.2
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments v4.2.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 / AffiliationRequest.php
AffiliationRequest.php
143 lines 2.6 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\Traits\HasDates;
6
7 /**
8 * Affiliation Request Model
9 */
10 class AffiliationRequest extends Model {
11 use HasDates;
12
13 /**
14 * Rest API endpoint
15 *
16 * @var string
17 */
18 protected $endpoint = 'affiliation_requests';
19
20 /**
21 * Object name
22 *
23 * @var string
24 */
25 protected $object_name = 'affiliation_request';
26
27 /**
28 * Approve the affiliate request.
29 *
30 * @param string|null $id Request ID.
31 *
32 * @return self|\WP_Error
33 */
34 protected function approve( $id = null ) {
35 if ( $id ) {
36 $this->setAttribute( 'id', $id );
37 }
38
39 if ( $this->fireModelEvent( 'approving' ) === false ) {
40 return false;
41 }
42
43 if ( empty( $this->attributes['id'] ) ) {
44 return new \WP_Error( 'not_saved', 'Please create the affiliation request.' );
45 }
46
47 $approved = \SureCart::request(
48 $this->endpoint . '/' . $this->attributes['id'] . '/approve',
49 [
50 'method' => 'PATCH',
51 'query' => $this->query,
52 'body' => [
53 $this->object_name => $this->getAttributes(),
54 ],
55 ]
56 );
57
58 if ( is_wp_error( $approved ) ) {
59 return $approved;
60 }
61
62 $this->resetAttributes();
63
64 $this->fill( $approved );
65
66 $this->fireModelEvent( 'approved' );
67
68 return $this;
69 }
70
71 /**
72 * Deny the affiliate request.
73 *
74 * @param string|null $id The model id.
75 *
76 * @return self|\WP_Error
77 */
78 protected function deny( $id = null ) {
79 if ( $id ) {
80 $this->setAttribute( 'id', $id );
81 }
82
83 if ( $this->fireModelEvent( 'denying' ) === false ) {
84 return false;
85 }
86
87 if ( empty( $this->attributes['id'] ) ) {
88 return new \WP_Error( 'not_saved', 'Please create the affiliation request.' );
89 }
90
91 $denied = \SureCart::request(
92 $this->endpoint . '/' . $this->attributes['id'] . '/deny',
93 [
94 'method' => 'PATCH',
95 'query' => $this->query,
96 'body' => [
97 $this->object_name => $this->getAttributes(),
98 ],
99 ]
100 );
101
102 if ( is_wp_error( $denied ) ) {
103 return $denied;
104 }
105
106 $this->resetAttributes();
107
108 $this->fill( $denied );
109
110 $this->fireModelEvent( 'denied' );
111
112 return $this;
113 }
114
115 /**
116 * Get the display status attribute.
117 *
118 * @return string
119 */
120 public function getStatusDisplayTextAttribute() {
121 $statuses = [
122 'approved' => __( 'Approved', 'surecart' ),
123 'pending' => __( 'Pending', 'surecart' ),
124 'denied' => __( 'Denied', 'surecart' ),
125 ];
126 return $statuses[ $this->status ] ?? '';
127 }
128
129 /**
130 * Get the display status attribute.
131 *
132 * @return string
133 */
134 public function getStatusTypeAttribute() {
135 $types = [
136 'approved' => 'info',
137 'pending' => 'warning',
138 'denied' => 'danger',
139 ];
140 return $types[ $this->status ] ?? 'default';
141 }
142 }
143