HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
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]);
	}
}