2020-06-01 14:17:29 +02:00
|
|
|
<?php
|
|
|
|
|
2020-06-10 17:38:10 +02:00
|
|
|
/**
|
2020-09-06 11: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
|
|
|
|
{
|
2021-06-30 05:56:11 +02:00
|
|
|
/*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-06-21 11:57:17 +02:00
|
|
|
if (in_array($currency->code, ['BIF', 'CLP', 'DJF', 'GNF', 'JPY', 'KMF', 'KRW', 'MGA', 'PYG', 'RWF', 'UGX', 'VND', 'VUV', 'XAF', 'XOF', 'XPF'])) {
|
2021-06-30 05:56:11 +02:00
|
|
|
return $amount;
|
2022-06-21 11:57:17 +02:00
|
|
|
}
|
2021-06-30 05:56:11 +02:00
|
|
|
|
2020-06-01 14:17:29 +02:00
|
|
|
return $amount / pow(10, $precision);
|
|
|
|
}
|
|
|
|
|
2021-06-30 05:56:11 +02:00
|
|
|
public function convertToStripeAmount($amount, $precision, $currency)
|
2020-06-01 14:17:29 +02:00
|
|
|
{
|
2022-06-21 11:57:17 +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;
|
|
|
|
}
|
2021-06-30 05:56:11 +02:00
|
|
|
|
2022-06-21 11:57:17 +02:00
|
|
|
return round(($amount * pow(10, $precision)), 0);
|
2020-06-01 14:17:29 +02:00
|
|
|
}
|
|
|
|
}
|