使用openexchangerates.org以欧元货币转发任何PayPal付款

时间:2016-08-14 09:12:20

标签: php json wordpress paypal

我想转发任何以欧元货币进行的付款交易。我已经修改了我负责任的php文件来做到这一点,但我很难让它使用实时汇率。目前这是我发送给PayPal的,它起作用了:

    if ( $selected != 'EUR' )    {
                          $themex_final_payable_amount = ((3.672538)*($themex_final_payable_amount))/(66.809999);
            } 

          $p->add_field('business', trim($busi));
          $p->add_field('currency_code','EUR');
          $p->add_field('return', $ themex_paypal_success_page);
          $p->add_field('cancel_return', $cancel_url);
          $p->add_field('notify_url', get_bloginfo('siteurl').'/?payment_response=paypal_response');
          $p->add_field('item_name', $page_title);
          $p->add_field('custom', $order_id);
          $p->add_field('amount', ($themex_final_payable_amount));
          $p->submit_paypal_post(); // submit the fields to paypal

我希望使用此API答案中的变量代替3.672538和66.809999,该变量每天自动更新一次。

JSON - latest.json

{
    disclaimer: "https://openexchangerates.org/terms/",
    license: "https://openexchangerates.org/license/",
    timestamp: 1449877801,
    base: "USD",
    rates: {
        AED: 3.672538,
        AFN: 66.809999,
        ALL: 125.716501,
        AMD: 484.902502,
        ANG: 1.788575,
        AOA: 135.295998,
        ARS: 9.750101,
        AUD: 1.390866,
        /* ... */
    }
}

问题在于我无法找到一种方法来调用它们 - 比如使用AED和AFN的今天值...这是我在管理页面中使用的代码的一部分(另一个PHP文件)我的API密钥:

if(isset($_POST['themex_save5']))
  {
    $json = get_option('exchange_rates');
    $exchangeRates = json_decode($json);

    global $themex_currencies_array;
    foreach ($themex_currencies_array as $themex_currency) {
      if ($themex_currency != "USD") {
        $exchangeRates->rates->$ themex_currency = $_POST['themex_' . $themex_currency . '_currency'];
      }
    }

    $json = json_encode($exchangeRates);
    update_option('exchange_rates', $json);

    update_option('openexchangerates_appid', trim($_POST['openexchangerates_appid']));

    echo '<div class="updated fade"><p>'.__('Settings saved!',' themex').'</p></div>';
  } 

基于以上所述,我认为它应该像这样工作,但它不是

if ( $selected != 'EUR' )    {
               $ themex_final_payable_amount = (($themex_AED_currency)*($ themex_final_payable_amount))/($themex_AFN_currency);
            } 

1 个答案:

答案 0 :(得分:1)

所以这是我需要的代码部分。我设法让它运作起来:))

               //--------------------------------------------------------------------------------

            if ( $selected != 'EUR' )    {

            $json = get_option('exchange_rates');
            $exchangeRates = json_decode($json);

            global $themex_currencies_array;
            foreach ($themex_currencies_array as $themex_currency) {
                if ($themex_currency != "USD") {
                            switch($themex_currency) {
                            case "AFN":
                                  $myAFN = $exchangeRates->rates->$themex_currency; ;
                            break;
                            case "AED":
                                  $myAED = $exchangeRates->rates->$themex_currency; ;
                            break;
                            }
                }   
            }

             $themex_final_payable_amount = (($myAED)*($themex_final_payable_amount))/($myAFN);
            } 


        $p->add_field('business', trim($busi));
        $p->add_field('currency_code','EUR');
        $p->add_field('return', $ themex_paypal_success_page);
        $p->add_field('cancel_return', $cancel_url);
        $p->add_field('notify_url', get_bloginfo('siteurl').'/?payment_response=paypal_response');
        $p->add_field('item_name', $page_title);
        $p->add_field('custom', $order_id);
        $p->add_field('amount', ($themex_final_payable_amount));
        $p->submit_paypal_post(); // submit the fields to paypal