File: /var/www/html/shootinschool/wp-content/plugins/shootin-school-plugin/webhooks.php
<?php
// Exit if accessed directly
add_action('rest_api_init', function () {
register_rest_route('stipeCallback', '/postData', array(
'methods' => 'POST',
'callback' => 'my_awesome_func',
));
});
function my_awesome_func($data)
{
$response = json_decode($data->get_body(), true);
$customer = $response['data']['object']['id'];
require_once(YITH_WCSTRIPE_DIR . 'includes/class-yith-stripe-api.php');
require_once(YITH_WCSTRIPE_DIR . 'includes/class-yith-stripe-gateway.php');
require_once(YITH_WCSTRIPE_DIR . 'includes/class-yith-stripe-gateway-advanced.php');
$gateway = new YITH_WCStripe_Gateway_Advanced();
$gateway->init_stripe_sdk();
try {
$customer = $gateway->api->get_customer($customer);
YITH_WCStripe()->get_customer()->update_usermeta_info($customer->metadata->user_id, array(
'id' => $customer->id,
'cards' => $customer->sources->data,
'default_source' => $response['data']['object']['default_source']
));
return json_encode(['status' => true, 'message' => "Success"]);
} catch (Exception $e) {
return json_encode(['status' => false, 'message' => $e]);
}
}