PluginProbe
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments / 3.1.5
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments v3.1.5
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 / Payout.php
Payout.php
138 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\HasAffiliation;
6 use SureCart\Models\Traits\HasDates;
7 use SureCart\Models\Traits\HasReferrals;
8 use SureCart\Support\TimeDate;
9
10 /**
11 * Payout model
12 */
13 class Payout extends Model {
14 use HasReferrals, HasAffiliation, HasDates;
15
16
17 /**
18 * Rest API endpoint
19 *
20 * @var string
21 */
22 protected $endpoint = 'payouts';
23
24 /**
25 * Object name
26 *
27 * @var string
28 */
29 protected $object_name = 'payout';
30
31 /**
32 * Set the payout group attribute.
33 *
34 * @param object $value Array of payout objects.
35 *
36 * @return void
37 */
38 public function setPayoutGroupAttribute( $value ) {
39 $this->setRelation( 'payout_group', $value, PayoutGroup::class );
40 }
41
42 /**
43 * Complete a payout
44 *
45 * @param string $id Payout ID.
46 *
47 * @return $this|\WP_Error
48 */
49 protected function complete( $id = null ) {
50 if ( $id ) {
51 $this->setAttribute( 'id', $id );
52 }
53
54 if ( $this->fireModelEvent( 'completing' ) === false ) {
55 return $this;
56 }
57
58 if ( empty( $this->attributes['id'] ) ) {
59 return new \WP_Error( 'not_saved', 'Please create the payout.' );
60 }
61
62 $completed = \SureCart::request(
63 $this->endpoint . '/' . $this->attributes['id'] . '/complete',
64 [
65 'method' => 'PATCH',
66 'query' => $this->query,
67 ]
68 );
69
70 if ( is_wp_error( $completed ) ) {
71 return $completed;
72 }
73
74 $this->resetAttributes();
75 $this->fill( $completed );
76 $this->fireModelEvent( 'completed' );
77
78 return $this;
79 }
80
81 /**
82 * Make a payout as processing
83 *
84 * @param string $id Payout ID.
85 *
86 * @return $this|\WP_Error
87 */
88 protected function make_processing( $id = null ) {
89 if ( $id ) {
90 $this->setAttribute( 'id', $id );
91 }
92
93 if ( $this->fireModelEvent( 'processing' ) === false ) {
94 return $this;
95 }
96
97 if ( empty( $this->attributes['id'] ) ) {
98 return new \WP_Error( 'not_saved', 'Please create the payout.' );
99 }
100
101 $processing = \SureCart::request(
102 $this->endpoint . '/' . $this->attributes['id'] . '/make_processing',
103 [
104 'method' => 'PATCH',
105 'query' => $this->query,
106 ]
107 );
108
109 if ( is_wp_error( $processing ) ) {
110 return $processing;
111 }
112
113 $this->resetAttributes();
114 $this->fill( $processing );
115 $this->fireModelEvent( 'processed' );
116
117 return $this;
118 }
119
120 /**
121 * Get status display
122 *
123 * @return string
124 */
125 protected function getStatusDisplayTextAttribute() {
126 return 'completed' === $this->status ? esc_html__( 'Completed', 'surecart' ) : esc_html__( 'Processing', 'surecart' );
127 }
128
129 /**
130 * Get the end at date.
131 *
132 * @return string
133 */
134 public function getEndAtDateAttribute() {
135 return ! empty( $this->end_date ) ? TimeDate::formatDate( $this->end_date ) : '';
136 }
137 }
138