| 1 |
<?php |
| 2 |
|
| 3 |
namespace Booktics\Payment\Payment_Methods; |
| 4 |
|
| 5 |
use Booktics\Payment\Contracts\Payment_Method_Interface; |
| 6 |
use Booktics\Payment\Payment_Status; |
| 7 |
use Booktics\Models\Order_Model; |
| 8 |
|
| 9 |
abstract class Abstract_Payment_Method implements Payment_Method_Interface { |
| 10 |
|
| 11 |
/** |
| 12 |
* The unpaid order was actually paid — repair it, do not release the slot. |
| 13 |
*/ |
| 14 |
const RESERVATION_REPAIR = 'repair'; |
| 15 |
|
| 16 |
/** |
| 17 |
* The customer never completed payment — release the held slot. |
| 18 |
*/ |
| 19 |
const RESERVATION_RELEASE = 'release'; |
| 20 |
|
| 21 |
/** |
| 22 |
* Payment is still legitimately in progress — keep the slot and re-check later. |
| 23 |
*/ |
| 24 |
const RESERVATION_WAIT = 'wait'; |
| 25 |
|
| 26 |
protected $id; |
| 27 |
protected $name; |
| 28 |
private $order; |
| 29 |
|
| 30 |
/** |
| 31 |
* Decide what to do with a slot held by an unpaid order that has passed the |
| 32 |
* reservation timeout: repair (payment actually went through), release (free |
| 33 |
* the slot), or wait (payment still genuinely in progress — check again later). |
| 34 |
* |
| 35 |
* Default implementation infers the action from get_payment_status(). Gateways |
| 36 |
* with richer lifecycle states (e.g. Stripe's 3D-Secure flow) should override |
| 37 |
* this to avoid canceling a customer who is mid-payment. |
| 38 |
* |
| 39 |
* @param Order_Model $order The order whose reservation is being evaluated. |
| 40 |
* |
| 41 |
* @return string One of the RESERVATION_* constants. |
| 42 |
*/ |
| 43 |
public function resolve_reservation_action( $order ): string { |
| 44 |
return Payment_Status::COMPLETED === $this->get_payment_status( $order ) |
| 45 |
? self::RESERVATION_REPAIR |
| 46 |
: self::RESERVATION_RELEASE; |
| 47 |
} |
| 48 |
|
| 49 |
/** |
| 50 |
* Get the unique identifier for this payment method |
| 51 |
* |
| 52 |
* @return string |
| 53 |
*/ |
| 54 |
public function get_id(): string { |
| 55 |
return $this->id; |
| 56 |
} |
| 57 |
|
| 58 |
/** |
| 59 |
* Get the display name of the payment method |
| 60 |
* |
| 61 |
* @return string |
| 62 |
*/ |
| 63 |
public function get_name(): string { |
| 64 |
return $this->name; |
| 65 |
} |
| 66 |
|
| 67 |
/** |
| 68 |
* Get Order |
| 69 |
* |
| 70 |
* @return Order_Model |
| 71 |
*/ |
| 72 |
protected function get_order() { |
| 73 |
return $this->order; |
| 74 |
} |
| 75 |
} |
| 76 |
|