: $new_label ) ); } /** * Payment status update. * * @param Payment $payment The status updated payment. * @param bool $can_redirect Whether or not redirects should be performed. * @param string|null $old_status Old meta status. * @param string $new_status New meta status. * * @return void */ public function log_payment_status_update( $payment, $can_redirect, $old_status, $new_status ) { $note = $this->get_payment_status_update_note( $old_status, $new_status ); $payment->add_note( $note ); } /** * REST API init. * * @link https://developer.wordpress.org/rest-api/extending-the-rest-api/adding-custom-endpoints/ * @link https://developer.wordpress.org/reference/hooks/rest_api_init/ * * @return void */ public function rest_api_init() { \register_rest_route( 'pronamic-pay/v1', '/payments/(?P\d+)', array( 'methods' => 'GET', 'callback' => array( $this, 'rest_api_payment' ), 'permission_callback' => function() { return \current_user_can( 'edit_payments' ); }, 'args' => array( 'payment_id' => array( 'description' => __( 'Payment ID.', 'pronamic_ideal' ), 'type' => 'integer', ), ), ) ); register_rest_route( 'pronamic-pay/v1', '/gateways/(?P\d+)', array( 'methods' => 'GET', 'callback' => array( $this, 'rest_api_gateway' ), 'permission_callback' => function() { return current_user_can( 'manage_options' ); }, 'args' => array( 'config_id' => array( 'description' => __( 'Gateway configuration ID.', 'pronamic_ideal' ), 'type' => 'integer', ), 'gateway_id' => array( 'description' => __( 'Gateway ID.', 'pronamic_ideal' ), 'type' => 'string', ), 'gateway_mode' => array( 'description' => __( 'Gateway mode.', 'pronamic_ideal' ), 'type' => 'string', ), ), ) ); } /** * REST API payment. * * @param \WP_REST_Request $request Request. * @return object */ public function rest_api_payment( \WP_REST_Request $request ) { $payment_id = $request->get_param( 'payment_id' ); $payment = \get_pronamic_payment( $payment_id ); if ( null === $payment ) { return new \WP_Error( 'pronamic-pay-payment-not-found', \sprintf( /* translators: %s: payment ID */ \__( 'Could not find payment with ID `%s`.', 'pronamic_ideal' ), $payment_id ), $payment_id ); } return $payment->get_json(); } /** * REST API gateway. * * @param \WP_REST_Request $request Request. * @return object */ public function rest_api_gateway( \WP_REST_Request $request ) { $config_id = $request->get_param( 'config_id' ); $gateway_id = $request->get_param( 'gateway_id' ); $gateway_mode = $request->get_param( 'gateway_mode' ); // Gateway. $args = array( 'gateway_id' => $gateway_id, 'gateway_mode' => $gateway_mode, ); $gateway = Plugin::get_gateway( $config_id, $args ); if ( empty( $gateway ) ) { return new \WP_Error( 'pronamic-pay-gateway-not-found', sprintf( /* translators: %s: Gateway configuration ID */ __( 'Could not find gateway with ID `%s`.', 'pronamic_ideal' ), $config_id ), $config_id ); } // Settings. ob_start(); require __DIR__ . '/../../views/meta-box-gateway-settings.php'; $meta_box_settings = ob_get_clean(); // Object. return (object) array( 'config_id' => $config_id, 'gateway_id' => $gateway_id, 'gateway_mode' => $gateway_mode, 'meta_boxes' => (object) array( 'settings' => $meta_box_settings, ), ); } }