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

标签 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 key :

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);
            } 

最佳答案

所以这是我需要的代码部分。我已经设法让它工作了:)

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

            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

关于php - 使用 openexchangerates.org 以欧元货币转发任何 PayPal 付款,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38940749/

相关文章:

python - 在python中将一个json字典添加到另一个json字典中

java - 在android中使用自定义适配器的Listview

wordpress - 从 og :title Yoast seo plugin 中删除站点名称

html - 仅在计算机屏幕上应用 CSS 规则,而不是在手机和平​​板电脑上

php - 打印 HTML 设计内容的最佳方式?

c# - 计算一个位置与许多其他位置之间的接近度

php - Laravel SQLSTATE[HY000] [2002] 当命令在 "Controller"时连接被拒绝,但 Tinker 中的单词正常

python - 无法使用 json.loads() 在 Django 1.8 中从 request.body 创建列表

php - post_excerpt 而不是 post_content,在循环之外

php - 拉维尔 4 : Deploy custom artisan command in package