Created
December 28, 2017 12:38
-
-
Save ajayghaghretiya/0de340c3f9a47f7481a470ac82e4927d to your computer and use it in GitHub Desktop.
For the Get the Active Payment Method In WooCommerce REST API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_action( 'rest_api_init', 'custom_api_endpoints' ); | |
function custom_api_endpoints() { | |
/** | |
* Handle Get Payment Method request. | |
*/ | |
register_rest_route( 'wc/v2', 'get_payment_methods', array( | |
'methods' => 'POST', | |
'callback' => 'custom_get_payment_methods_endpoint_handler', | |
) ); | |
} | |
function custom_get_payment_methods_endpoint_handler(){ | |
$response = array(); | |
$payment = new WC_Payment_Gateways(); | |
$payment_methods = $payment->get_available_payment_gateways(); | |
if ( ! empty( $payment_methods ) ) { | |
foreach ( $payment_methods as $key => $values ) { | |
$payment_methods_details = array(); | |
$payment_methods_details['payment_method'] = $key; | |
$payment_methods_details['payment_method_title'] = $values->title; | |
$payment_methods_details['description'] = $values->description; | |
if ( $key === "stripe" ) { | |
$payment_methods_details['test_publishable_key'] = $values->settings['test_publishable_key']; | |
$payment_methods_details['test_secret_key'] = $values->settings['test_secret_key']; | |
$payment_methods_details['testmode'] = $values->settings['testmode']; | |
$payment_methods_details['publishable_key'] = $values->settings['publishable_key']; | |
$payment_methods_details['secret_key'] = $values->settings['secret_key']; | |
} | |
$payment_methods_details_arr [] = $payment_methods_details; | |
} | |
} | |
$response['payment_methods_details'] = $payment_methods_details_arr; | |
$response['code'] = 200; | |
return $response; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment