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
|
|
|
|
*
|
2021-01-03 22:54:54 +01:00
|
|
|
* @copyright Copyright (c) 2021. 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
|
|
|
{
|
2021-06-30 05:56:11 +02:00
|
|
|
|
2021-12-21 10:27:51 +01:00
|
|
|
if(in_array($amount, ["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;
|
|
|
|
|
2020-06-01 14:17:29 +02:00
|
|
|
return $amount / pow(10, $precision);
|
2021-06-30 05:56:11 +02:00
|
|
|
|
2020-06-01 14:17:29 +02:00
|
|
|
}
|
|
|
|
|
2021-06-30 05:56:11 +02:00
|
|
|
public function convertToStripeAmount($amount, $precision, $currency)
|
2020-06-01 14:17:29 +02:00
|
|
|
{
|
2021-06-30 05:56:11 +02:00
|
|
|
|
2021-12-21 10:27:51 +01:00
|
|
|
if(in_array($amount, ["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;
|
|
|
|
|
|
|
|
return round(($amount * pow(10, $precision)),0);
|
|
|
|
|
2020-06-01 14:17:29 +02:00
|
|
|
}
|
|
|
|
}
|