This forum is no longer open and is for reading/searching only.

Please use our new MachForm Community Forum instead.

MachForm Community Forums » MachForm 4

SAR to USD in Paypal


  1. abdullah
    Member

    I already added SAR currency in payment_settings.php

    http://i.imgur.com/G1tOkHE.jpg

    my question now is how can i use the below code to convert the total price from SAR to USD before redirect to paypal site?

    <?php
    function currencyConverter($currency_from,$currency_to,$currency_input){
        $yql_base_url = "http://query.yahooapis.com/v1/public/yql";
        $yql_query = 'select * from yahoo.finance.xchange where pair in ("'.$currency_from.$currency_to.'")';
        $yql_query_url = $yql_base_url . "?q=" . urlencode($yql_query);
        $yql_query_url .= "&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys";
        $yql_session = file_get_contents($yql_query_url);
        $yql_json =  json_decode($yql_session,true);
        $currency_output = (float) $currency_input*$yql_json['query']['results']['rate']['Rate'];
    	//$currency_output = (double) $currency_input*$yql_json['query']['results']['rate']['Rate'];
    
        return $currency_output;
    }
    
     $currency_input = 2;
     $currency_from = "SAR";
     $currency_to = "USD";
     $currency = currencyConverter($currency_from,$currency_to,$currency_input);
    
     echo $currency_input.' '.$currency_from.' = '.$currency.' '.$currency_to;
    ?>
    Posted 8 years ago #
  2. abdullah
    Member

    @yuniar

    any help for this?

    Posted 8 years ago #

RSS feed for this topic

Reply