how to do a curl on wix

Hello World of Wix :slightly_smiling_face:

how to use this code on Wix corvid

init();

function init(){
    $url = 'https://api.com/v3/post';
    $data =  array(
        'token'=> 'api token',
        'amount'  => 10.23 ,
        'currencyCode' => 'GB' ,
        'orderId' => '8484811888',
        'note' => ' Post title' ,
        'lang' => 'EN-US' ,
        'customerEmail' => 'info@wix.com'   ,
        'customerCountry' => 'United Kingdome' ,
    );
    $result = curl_post($url,  $data );
    var_dump( $result);

}

function curl_post($url, array $post = NULL, array $options = array()) {
    $defaults = array(
        CURLOPT_POST => 1,
        CURLOPT_HEADER => 0,
        CURLOPT_URL => $url,
        CURLOPT_FRESH_CONNECT => 1,
        CURLOPT_RETURNTRANSFER => 1,
        CURLOPT_FORBID_REUSE => 1,
        CURLOPT_TIMEOUT => 4,
        CURLOPT_POSTFIELDS => http_build_query($post) );
    $ch = curl_init();
    curl_setopt_array($ch, ($options + $defaults));
    if( ! $result = curl_exec($ch)) {
        trigger_error(curl_error($ch));

    } curl_close($ch);

    return $result;

}

https://www.wix.com/corvid/forum/community-discussion/curl-help-me
https://www.wix.com/corvid/forum/community-discussion/curl-to-fetch

Sorry but this didn’t help :slight_smile: thanks for your reply :heart:

@ibrhajjaj

Okay, then I suggest that you try to expose your site through Wix HTTP Functions then.
https://www.wix.com/corvid/reference/wix-http-functions.html
https://support.wix.com/en/article/corvid-exposing-a-site-api-with-http-functions

There is also Wix Fetch, however I think the http option would be better for you.
https://www.wix.com/corvid/reference/wix-fetch.html
https://support.wix.com/en/article/corvid-accessing-third-party-services-with-the-fetch-api

See this previous forum post too.
https://www.wix.com/corvid/forum/community-discussion/custom-code-can-i-put-php-here