Extend payment gateways REST endpoint (https://github.com/woocommerce/woocommerce-admin/pull/6919)
* Extend the existing REST endpoint with gateway status data * Add settings URL to response * Add setup specific fields to response * Fix controller class name * Only pass required setting keys instead of fields * Add changelog entry
This commit is contained in:
parent
073a220b59
commit
487cdbb1bf
|
@ -79,6 +79,7 @@ Release and roadmap notes are available on the [WooCommerce Developers Blog](htt
|
|||
- Add: Consume remote payment methods on frontend #6867
|
||||
- Add: Add plugin installer to allow installation of plugins via URL #6805
|
||||
- Add: Optional children prop to SummaryNumber component #6748
|
||||
- Add: Extend payment gateways REST endpoint #6919
|
||||
- Dev: Add data source filter to remote inbox notification system #6794
|
||||
- Dev: Add A/A test #6669
|
||||
- Dev: Add support for nonces in note actions #6726
|
||||
|
|
|
@ -8,6 +8,7 @@ namespace Automattic\WooCommerce\Admin\Features\RemotePaymentMethods;
|
|||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
use Automattic\WooCommerce\Admin\RemoteInboxNotifications\SpecRunner;
|
||||
use Automattic\WooCommerce\Admin\Features\RemotePaymentMethods\PaymentGatewaysController;
|
||||
|
||||
/**
|
||||
* Remote Payment Methods engine.
|
||||
|
@ -21,6 +22,7 @@ class Init {
|
|||
*/
|
||||
public function __construct() {
|
||||
add_action( 'change_locale', array( __CLASS__, 'delete_specs_transient' ) );
|
||||
PaymentGatewaysController::init();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
<?php
|
||||
/**
|
||||
* Logic for extending WC_REST_Payment_Gateways_Controller.
|
||||
*/
|
||||
|
||||
namespace Automattic\WooCommerce\Admin\Features\RemotePaymentMethods;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* PaymentGateway class
|
||||
*/
|
||||
class PaymentGatewaysController {
|
||||
|
||||
/**
|
||||
* Initialize payment gateway changes.
|
||||
*/
|
||||
public static function init() {
|
||||
add_filter( 'woocommerce_rest_prepare_payment_gateway', array( __CLASS__, 'extend_response' ), 10, 3 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add necessary fields to REST API response.
|
||||
*
|
||||
* @param WP_REST_Response $response Response data.
|
||||
* @param WC_Payment_Gateway $gateway Payment gateway object.
|
||||
* @param WP_REST_Request $request Request object.
|
||||
* @return WP_REST_Response
|
||||
*/
|
||||
public static function extend_response( $response, $gateway, $request ) {
|
||||
$data = $response->get_data();
|
||||
|
||||
$data['needs_setup'] = $gateway->needs_setup();
|
||||
|
||||
if ( method_exists( $gateway, 'get_oauth_connection_url' ) ) {
|
||||
$data['oauth_connection_url'] = $gateway->get_oauth_connection_url();
|
||||
}
|
||||
|
||||
if ( method_exists( $gateway, 'get_required_settings_keys' ) ) {
|
||||
$data['required_settings_keys'] = $gateway->get_required_settings_keys();
|
||||
}
|
||||
|
||||
$data['settings_url'] = admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=' . strtolower( $gateway->id ) );
|
||||
|
||||
$response->set_data( $data );
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue