1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-13 22:54:25 +01:00
invoiceninja/app/PaymentDrivers/Stripe/Utilities.php

36 lines
1.1 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
*
2023-01-28 23:21:40 +01:00
* @copyright Copyright (c) 2023. 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
{
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);
}
public function convertToStripeAmount($amount, $precision, $currency)
2020-06-01 14:17:29 +02: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
}
}