class-appointment-payment-status.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. class Booked_WC_Appointment_Payment_Status {
  3. public $app_id;
  4. public $order_id;
  5. public $order_obj = null;
  6. public $is_paid;
  7. public $payment_status;
  8. public $payment_status_text;
  9. public function __construct($app_id) {
  10. if ( !is_integer($app_id) ) {
  11. $message = sprintf( __('%s integer expected when %s given.', 'booked-woocommerce-payments'), 'new Booked_WC_Appointment_Payment_Status::get($app_id)', gettype($app_id) );
  12. throw new Exception($message);
  13. } else if ( $app_id===0 ) {
  14. $message = sprintf( __('%s invalid ID is given. %s', 'booked-woocommerce-payments'), 'new Booked_WC_Appointment_Payment_Status::get($app_id)', '$app_id=0' );
  15. throw new Exception($message);
  16. }
  17. $this->app_id = $app_id;
  18. // set default status values
  19. $this->is_paid = false;
  20. $this->payment_status = 'awaiting_checkout';
  21. $this->payment_status_text = __('Awaiting Payment', 'booked-woocommerce-payments');
  22. $this->get_order();
  23. $this->set_statuses();
  24. }
  25. public function get_order() {
  26. $this->order_id = get_post_meta($this->app_id, '_' . BOOKED_WC_PLUGIN_PREFIX . 'appointment_order_id', true);
  27. if ( $this->order_id && $this->order_id != 'manual') {
  28. $this->order_id = (int) $this->order_id;
  29. $this->order_obj = Booked_WC_Order::get($this->order_id);
  30. }
  31. return $this;
  32. }
  33. public function set_statuses() {
  34. if ( $this->order_id && $this->order_id === 'manual' || $this->order_id && $this->order_obj->order->get_status() === 'wc-completed' || $this->order_id && $this->order_obj->order->get_status() === 'completed' ) {
  35. $this->is_paid = true;
  36. $this->payment_status = 'paid';
  37. $this->payment_status_text = __('Order Paid', 'booked-woocommerce-payments');
  38. } elseif ( $this->order_id ) {
  39. $this->is_paid = ( $this->order_obj->order->get_status() === 'wc-completed' || $this->order_obj->order->get_status() === 'completed' );
  40. $this->payment_status = $this->order_obj->order->get_status();
  41. $this->payment_status_text = __('Order ', 'booked-woocommerce-payments') . $this->order_obj->order->post_status_text;
  42. }
  43. return $this;
  44. }
  45. }