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