| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
namespace JFB_Modules\Gateways\Rest_Api; |
| 5 |
|
| 6 |
use Jet_Form_Builder\Admin\Exceptions\Not_Found_Page_Exception; |
| 7 |
use JFB_Components\Rest_Api; |
| 8 |
// do not change |
| 9 |
use Jet_Form_Builder\Gateways\Meta_Boxes\Payment_Details_Box; |
| 10 |
|
| 11 |
// If this file is called directly, abort. |
| 12 |
if ( ! defined( 'WPINC' ) ) { |
| 13 |
die; |
| 14 |
} |
| 15 |
|
| 16 |
class Receive_Payment extends Rest_Api\Rest_Api_Endpoint_Base { |
| 17 |
|
| 18 |
use Rest_Api\Dynamic_Rest_Url_Trait; |
| 19 |
|
| 20 |
public static function get_rest_base() { |
| 21 |
return 'payment/(?P<id>[\d]+)'; |
| 22 |
} |
| 23 |
|
| 24 |
public function get_common_args(): array { |
| 25 |
return array( |
| 26 |
'id' => array( |
| 27 |
'type' => 'integer', |
| 28 |
'required' => true, |
| 29 |
), |
| 30 |
); |
| 31 |
} |
| 32 |
|
| 33 |
public static function get_methods() { |
| 34 |
return \WP_REST_Server::READABLE; |
| 35 |
} |
| 36 |
|
| 37 |
public function check_permission(): bool { |
| 38 |
return current_user_can( 'manage_options' ); |
| 39 |
} |
| 40 |
|
| 41 |
public function get_box(): Payment_Details_Box { |
| 42 |
return new Payment_Details_Box(); |
| 43 |
} |
| 44 |
|
| 45 |
public function run_callback( \WP_REST_Request $request ) { |
| 46 |
$box = $this->get_box()->set_id( $request->get_param( 'id' ) ); |
| 47 |
|
| 48 |
try { |
| 49 |
$record = $box->get_list(); |
| 50 |
} catch ( Not_Found_Page_Exception $exception ) { |
| 51 |
return new \WP_REST_Response( |
| 52 |
array( |
| 53 |
'message' => __( 'Payment not found', 'jet-form-builder' ), |
| 54 |
), |
| 55 |
404 |
| 56 |
); |
| 57 |
} |
| 58 |
|
| 59 |
return new \WP_REST_Response( |
| 60 |
array( |
| 61 |
'list' => $box->prepare_record( $record ), |
| 62 |
) |
| 63 |
); |
| 64 |
} |
| 65 |
} |
| 66 |
|