Blocks
1 year ago
Concerns
1 year ago
Traits
1 year ago
AbandonedCheckout.php
1 year ago
AbandonedCheckoutProtocol.php
3 years ago
Account.php
3 years ago
AccountPortalSession.php
4 years ago
Activation.php
1 year ago
Affiliation.php
1 year ago
AffiliationProduct.php
1 year ago
AffiliationProtocol.php
2 years ago
AffiliationRequest.php
1 year ago
ApiToken.php
3 years ago
BalanceTransaction.php
1 year ago
Brand.php
4 years ago
BulkAction.php
2 years ago
Bump.php
1 year ago
BuyLink.php
2 years ago
CancellationAct.php
1 year ago
CancellationReason.php
3 years ago
Charge.php
1 year ago
Checkout.php
1 year ago
Click.php
1 year ago
Collection.php
2 years ago
CommissionStructure.php
2 years ago
Component.php
4 years ago
Coupon.php
1 year ago
Customer.php
1 year ago
CustomerLink.php
4 years ago
CustomerNotificationProtocol.php
4 years ago
CustomerPortalProtocol.php
1 year ago
DatabaseModel.php
1 year ago
Discount.php
1 year ago
Download.php
4 years ago
Event.php
4 years ago
Export.php
2 years ago
ExternalApiModel.php
1 year ago
Form.php
3 years ago
Fulfillment.php
1 year ago
FulfillmentItem.php
1 year ago
GalleryItem.php
1 year ago
GalleryItemAttachment.php
1 year ago
GalleryItemMedia.php
1 year ago
GalleryItemProductMedia.php
1 year ago
IncomingWebhook.php
1 year ago
Integration.php
2 years ago
IntegrationCatalog.php
1 year ago
Invoice.php
1 year ago
License.php
1 year ago
LineItem.php
1 year ago
ManualPaymentMethod.php
1 year ago
Media.php
1 year ago
Model.php
1 year ago
ModelInterface.php
4 years ago
Order.php
1 year ago
OrderProtocol.php
4 years ago
PaymentFailure.php
1 year ago
PaymentInstrument.php
1 year ago
PaymentIntent.php
4 years ago
PaymentMethod.php
1 year ago
Payout.php
1 year ago
PayoutGroup.php
2 years ago
Period.php
1 year ago
PortalSession.php
4 years ago
Price.php
1 year ago
Processor.php
1 year ago
Product.php
1 year ago
ProductCollection.php
1 year ago
ProductGroup.php
1 year ago
ProductMedia.php
1 year ago
Promotion.php
1 year ago
ProvisionalAccount.php
2 years ago
Purchase.php
2 years ago
Referral.php
1 year ago
ReferralItem.php
2 years ago
Refund.php
1 year ago
RegisteredWebhook.php
2 years ago
ReturnItem.php
2 years ago
ReturnReason.php
2 years ago
ReturnRequest.php
1 year ago
ShippingMethod.php
3 years ago
ShippingProfile.php
3 years ago
ShippingProtocol.php
3 years ago
ShippingRate.php
3 years ago
ShippingZone.php
3 years ago
Statistic.php
4 years ago
Subscription.php
1 year ago
SubscriptionProtocol.php
4 years ago
TaxOverride.php
2 years ago
TaxProtocol.php
4 years ago
TaxRegistration.php
1 year ago
TaxZone.php
4 years ago
Upload.php
4 years ago
Upsell.php
1 year ago
UpsellFunnel.php
1 year ago
User.php
2 years ago
Variant.php
1 year ago
VariantOption.php
2 years ago
VariantOptionValue.php
1 year ago
VariantValue.php
2 years ago
VerificationCode.php
3 years ago
Webhook.php
1 year ago
WebhookRegistration.php
2 years ago
Payout.php
138 lines
| 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 |