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