| 1 |
<?php |
| 2 |
/** |
| 3 |
* Abstract base class for native-checkout payment gateways. |
| 4 |
* |
| 5 |
* Concrete gateways extend this and implement the create_payment() / |
| 6 |
* capture_payment() lifecycle. Adding a new gateway is a matter of |
| 7 |
* dropping a subclass into ./gateways/ and registering it with the |
| 8 |
* gateway manager — no edits to the checkout flow are required. |
| 9 |
*/ |
| 10 |
|
| 11 |
if ( ! defined( 'ABSPATH' ) ) exit; |
| 12 |
|
| 13 |
abstract class ESHB_Native_Abstract_Gateway { |
| 14 |
|
| 15 |
/** Unique gateway identifier (e.g. 'paypal'). */ |
| 16 |
protected $id = ''; |
| 17 |
|
| 18 |
/** Human-readable title shown in the checkout. */ |
| 19 |
protected $title = ''; |
| 20 |
|
| 21 |
/** Short description shown under the title. */ |
| 22 |
protected $description = ''; |
| 23 |
|
| 24 |
public function get_id() { |
| 25 |
return $this->id; |
| 26 |
} |
| 27 |
|
| 28 |
public function get_title() { |
| 29 |
return $this->title; |
| 30 |
} |
| 31 |
|
| 32 |
public function get_description() { |
| 33 |
return $this->description; |
| 34 |
} |
| 35 |
|
| 36 |
/** |
| 37 |
* Whether this gateway is fully configured and enabled. |
| 38 |
*/ |
| 39 |
abstract public function is_enabled(); |
| 40 |
|
| 41 |
/** |
| 42 |
* Frontend payload (script handles, API keys, gateway-specific |
| 43 |
* settings) needed by the JS layer to render the gateway button. |
| 44 |
* |
| 45 |
* @return array |
| 46 |
*/ |
| 47 |
public function get_frontend_data() { |
| 48 |
return [ |
| 49 |
'id' => $this->id, |
| 50 |
'title' => $this->title, |
| 51 |
'description' => $this->description, |
| 52 |
]; |
| 53 |
} |
| 54 |
|
| 55 |
/** |
| 56 |
* Create a server-side payment intent / order for the given reservation. |
| 57 |
* Returns gateway-specific data the JS layer needs to launch the flow |
| 58 |
* (e.g. PayPal order id). |
| 59 |
* |
| 60 |
* @return array { success: bool, data: array, message?: string } |
| 61 |
*/ |
| 62 |
abstract public function create_payment( array $reservation, array $customer, array $pricing ); |
| 63 |
|
| 64 |
/** |
| 65 |
* Verify and capture a previously-created payment. Called server-side |
| 66 |
* once the JS layer signals user approval. Must return a normalized |
| 67 |
* result so the checkout flow can persist payment metadata. |
| 68 |
* |
| 69 |
* @return array { success: bool, transaction_id?: string, amount?: float, currency?: string, mode?: string, raw?: array, message?: string } |
| 70 |
*/ |
| 71 |
abstract public function capture_payment( array $params ); |
| 72 |
} |
| 73 |
|