1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-21 08:51:34 +02:00
invoiceninja/app/PaymentDrivers/Stripe/Utilities.php

38 lines
1.0 KiB
PHP
Raw Normal View History

2020-06-01 14:17:29 +02:00
<?php
2020-06-10 17:38:10 +02:00
/**
* Invoice Ninja (https://invoiceninja.com).
2020-06-10 17:38:10 +02:00
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
2022-04-27 05:20:41 +02:00
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
2020-06-10 17:38:10 +02:00
*
2021-06-16 08:58:16 +02:00
* @license https://www.elastic.co/licensing/elastic-license
2020-06-10 17:38:10 +02:00
*/
2020-06-01 14:17:29 +02:00
namespace App\PaymentDrivers\Stripe;
trait Utilities
{
/*Helpers for currency conversions, NOTE* for some currencies we need to change behaviour */
public function convertFromStripeAmount($amount, $precision, $currency)
2020-06-01 14:17:29 +02:00
{
2022-01-27 21:19:58 +01:00
if(in_array($currency->code, ["BIF","CLP","DJF","GNF","JPY","KMF","KRW","MGA","PYG","RWF","UGX","VND","VUV","XAF","XOF","XPF"]))
return $amount;
2020-06-01 14:17:29 +02:00
return $amount / pow(10, $precision);
2020-06-01 14:17:29 +02:00
}
public function convertToStripeAmount($amount, $precision, $currency)
2020-06-01 14:17:29 +02:00
{
2022-01-27 21:19:58 +01:00
if(in_array($currency->code, ["BIF","CLP","DJF","GNF","JPY","KMF","KRW","MGA","PYG","RWF","UGX","VND","VUV","XAF","XOF","XPF"]))
return $amount;
return round(($amount * pow(10, $precision)),0);
2020-06-01 14:17:29 +02:00
}
}