activity_model.php
3 months ago
agent_meta_model.php
3 months ago
agent_model.php
3 months ago
booking_meta_model.php
3 months ago
booking_model.php
17 hours ago
bundle_meta_model.php
3 months ago
bundle_model.php
1 week ago
cart_item_model.php
3 months ago
cart_meta_model.php
3 months ago
cart_model.php
2 weeks ago
connector_model.php
3 months ago
customer_meta_model.php
3 months ago
customer_model.php
1 month ago
invoice_model.php
2 weeks ago
join_bundles_services_model.php
3 months ago
location_category_model.php
3 months ago
location_model.php
3 months ago
meta_model.php
3 months ago
model.php
2 days ago
off_period_model.php
3 months ago
order_intent_meta_model.php
3 months ago
order_intent_model.php
1 week ago
order_item_model.php
3 months ago
order_meta_model.php
3 months ago
order_model.php
1 month ago
otp_model.php
3 months ago
payment_request_model.php
3 months ago
process_job_model.php
3 months ago
process_model.php
1 month ago
recurrence_model.php
3 months ago
service_category_model.php
3 months ago
service_meta_model.php
3 months ago
service_model.php
3 months ago
session_model.php
3 months ago
settings_model.php
3 months ago
step_settings_model.php
3 months ago
transaction_intent_model.php
3 months ago
transaction_model.php
3 months ago
transaction_refund_model.php
3 months ago
work_period_model.php
3 months ago
payment_request_model.php
123 lines
| 1 | <?php |
| 2 | /* |
| 3 | * Copyright (c) 2022 LatePoint LLC. All rights reserved. |
| 4 | */ |
| 5 | |
| 6 | class OsPaymentRequestModel extends OsModel { |
| 7 | var $id, |
| 8 | $invoice_id, |
| 9 | $order_id, |
| 10 | $portion, |
| 11 | $charge_amount, |
| 12 | $due_at, |
| 13 | $updated_at, |
| 14 | $created_at; |
| 15 | |
| 16 | function __construct( $id = false ) { |
| 17 | parent::__construct(); |
| 18 | $this->table_name = LATEPOINT_TABLE_PAYMENT_REQUESTS; |
| 19 | |
| 20 | if ( $id ) { |
| 21 | $this->load_by_id( $id ); |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | |
| 26 | public function get_invoice(): OsInvoiceModel { |
| 27 | if ( $this->invoice_id ) { |
| 28 | if ( ! isset( $this->invoice ) || ( isset( $this->invoice ) && ( $this->invoice->id != $this->invoice_id ) ) ) { |
| 29 | $this->invoice = new OsInvoiceModel( $this->invoice_id ); |
| 30 | } |
| 31 | } else { |
| 32 | $this->invoice = new OsInvoiceModel(); |
| 33 | } |
| 34 | |
| 35 | return $this->invoice; |
| 36 | } |
| 37 | |
| 38 | |
| 39 | public function properties_to_query(): array { |
| 40 | return [ |
| 41 | 'portion' => __( 'Payment Portion', 'latepoint' ), |
| 42 | ]; |
| 43 | } |
| 44 | |
| 45 | public function get_readable_due_at(): string { |
| 46 | try { |
| 47 | return OsTimeHelper::get_readable_date( new OsWpDateTime( $this->due_at, new DateTimeZone( 'UTC' ) ) ); |
| 48 | } catch ( Exception $e ) { |
| 49 | return 'n/a'; |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | public function get_order(): OsOrderModel { |
| 54 | if ( $this->order_id ) { |
| 55 | if ( ! isset( $this->order ) || ( isset( $this->order ) && ( $this->order->id != $this->order_id ) ) ) { |
| 56 | $this->order = new OsOrderModel( $this->order_id ); |
| 57 | } |
| 58 | } else { |
| 59 | $this->order = new OsOrderModel(); |
| 60 | } |
| 61 | |
| 62 | return $this->order; |
| 63 | } |
| 64 | |
| 65 | public function get_customer(): OsCustomerModel { |
| 66 | return $this->get_order()->get_customer(); |
| 67 | } |
| 68 | |
| 69 | public function generate_data_vars(): array { |
| 70 | |
| 71 | $vars['id'] = $this->id; |
| 72 | $vars['portion'] = $this->portion; |
| 73 | $vars['charge_amount'] = $this->charge_amount; |
| 74 | $vars['due_at'] = $this->due_at; |
| 75 | $vars['invoice_id'] = $this->invoice_id; |
| 76 | $vars['order_id'] = $this->order_id; |
| 77 | $vars['customer'] = $this->get_customer()->get_data_vars(); |
| 78 | $vars['order'] = $this->get_order()->get_data_vars(); |
| 79 | |
| 80 | return $vars; |
| 81 | } |
| 82 | |
| 83 | |
| 84 | protected function params_to_sanitize() { |
| 85 | return [ |
| 86 | 'charge_amount' => 'money', |
| 87 | ]; |
| 88 | } |
| 89 | |
| 90 | protected function params_to_save( $role = 'admin' ) { |
| 91 | $params_to_save = [ |
| 92 | 'id', |
| 93 | 'portion', |
| 94 | 'charge_amount', |
| 95 | 'due_at', |
| 96 | 'invoice_id', |
| 97 | 'order_id', |
| 98 | ]; |
| 99 | |
| 100 | return $params_to_save; |
| 101 | } |
| 102 | |
| 103 | protected function allowed_params( $role = 'admin' ) { |
| 104 | $allowed_params = [ |
| 105 | 'id', |
| 106 | 'portion', |
| 107 | 'charge_amount', |
| 108 | 'due_at', |
| 109 | 'invoice_id', |
| 110 | 'order_id', |
| 111 | ]; |
| 112 | |
| 113 | return $allowed_params; |
| 114 | } |
| 115 | |
| 116 | |
| 117 | protected function properties_to_validate() { |
| 118 | $validations = []; |
| 119 | |
| 120 | return $validations; |
| 121 | } |
| 122 | } |
| 123 |