Created
May 28, 2023 18:29
-
-
Save kosatyi/b7eb3b87174ff022dff74c943ea7fab9 to your computer and use it in GitHub Desktop.
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
define('FONDY_MERCHANT_ID',0000000000); | |
define('FONDY_SECRET_KEY','1829381923919023918239819238'); | |
add_action( 'rest_api_init', function () { | |
register_rest_route( 'v1', '/checkout', [ | |
'methods' => 'POST', | |
'callback' => 'coreicon_v1_checkout', | |
]); | |
}); | |
function coreicon_v1_checkout( WP_REST_Request $request ) { | |
require get_template_directory() . '/vendor/autoload.php'; | |
\Cloudipsp\Configuration::setMerchantId( FONDY_MERCHANT_ID ); | |
\Cloudipsp\Configuration::setSecretKey( FONDY_SECRET_KEY); | |
$response = new WP_REST_Response(); | |
$params = $request->get_json_params(); | |
$amount = $params['amount'] * 100; | |
$currency = $params['currency']; | |
$products = json_encode($params['products']); | |
$data = [ | |
'currency' => $currency, | |
'amount' => $amount, | |
'merchant_data' => $products | |
]; | |
try{ | |
$url = \Cloudipsp\Checkout::url( $data ); | |
$response->set_data([ | |
'url' => $url->getUrl() | |
]); | |
} catch(\Exception $e) { | |
$response->set_status(500); | |
$response->set_data([ | |
'error' => $e->getMessage() | |
]); | |
} | |
return $response; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment