使用IQD(Dinar)在PHP中进行条带化付款货币转换

时间:2018-12-03 05:22:15

标签: cakephp stripe-payments currency

我正在使用Stripe付款流程。站点国家是伊拉克。因此,Stripe不支持伊拉克。所以我正在使用货币换算。

//Currecy Convertion IQD to USD
            $totalAmount = number_format($totalAmount, 2);
            $from = CURRENCY_CODE; //IQD
            $to = "USD";

            $http = new Client();

            $data = $http->get("https://v3.exchangerate-api.com/bulk/4e5d018d4c9b30bda0ed5a7e/$from");

            $data = (!empty($data->body)) ? $data->json : [];

            if(!empty($data['result']) && $data['result'] == 'success') {
                if(!empty($data['rates'][$to])) {

                    $currency = !empty($data['rates'][$to]) ? $data['rates'][$to] : 0.00;

                    $convertedAmount = $totalAmount * $currency;
                    $totalAmount = $convertedAmount;
                    //$payableAmount = Number::precision($convertedAmount, 2);
                } 
            }

应付金额为:ع.د154.50
输出为:0.12983253 这就是输出,我必须通过该方式传递金额。

$payableAmount = $payableAmount * 100;

                // YOUR CODE (LATER): When it's time to charge the customer again, retrieve the customer ID.
                $charge = \Stripe\Charge::create(array(
                    "amount" => $payableAmount, // $15.00 this time
                    "currency" => 'USD',
                    "customer" => $stripeDetails['stripe_customer_id']
                ));

0 个答案:

没有答案