← All changes
|
core/payment/payment-methods/abstract-payment-method.php
+35
-0
1.0.21
→
1.0.28
View file →
| @@ -2,15 +2,50 @@ | ||
| 2 | 2 | |
| 3 | 3 | namespace Booktics\Payment\Payment_Methods; |
| 4 | 4 | |
| 5 | 5 | use Booktics\Payment\Contracts\Payment_Method_Interface; |
| 6 | +use Booktics\Payment\Payment_Status; | |
| 6 | 7 | use Booktics\Models\Order_Model; |
| 7 | 8 | |
| 8 | 9 | abstract class Abstract_Payment_Method implements Payment_Method_Interface { |
| 9 | 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 | + | |
| 10 | 26 | protected $id; |
| 11 | 27 | protected $name; |
| 12 | 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 | + } | |
| 13 | 48 | |
| 14 | 49 | /** |
| 15 | 50 | * Get the unique identifier for this payment method |
| 16 | 51 | * |