Add function to handle stripe currency format while sending request
This commit is contained in:
parent
329edb354d
commit
51bc7fea2b
|
@ -12,3 +12,26 @@ if(!function_exists('randomString')){
|
|||
return $randomString;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(!function_exists('stripeFormatCurrency')){
|
||||
function stripeFormatCurrency($amount, $currency = "USD"){
|
||||
// https://stripe.com/docs/currencies#zero-decimal
|
||||
if(in_array($currency,['BIF','CLP','DJF','GNF','JPY','KMF','KRW', 'MGA', 'PYG', 'RWF', 'UGX', 'VND', 'VUV', 'XAF', 'XOF', 'XPF'])) {
|
||||
return number_format(ceil($amount) , 0, '', '');
|
||||
}
|
||||
|
||||
if(in_array($currency,['BHD','JOD','KWD','OMR','TND'])) {
|
||||
$number = $amount*1000;
|
||||
$remainder = $number % 10;
|
||||
if ($remainder != 0) {
|
||||
$number += 10 - $remainder;
|
||||
}
|
||||
return number_format($number , 0, '', '');
|
||||
}
|
||||
|
||||
return number_format(($amount*100) , 0, '', '');
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -143,7 +143,7 @@ class StripeController extends Controller
|
|||
|
||||
// Init payment
|
||||
$charge = $this->client->charges->create([
|
||||
"amount" => round($transaction->amount,2),
|
||||
"amount" => stripeFormatCurrency(round($transaction->amount,2), $transaction->currency),
|
||||
"currency" => $transaction->currency,
|
||||
"description" => $transaction->reason,
|
||||
// "customer" => 15,
|
||||
|
@ -192,7 +192,7 @@ class StripeController extends Controller
|
|||
return $code;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function refund(Request $request)
|
||||
{
|
||||
$this->validate($request, [
|
||||
|
@ -321,7 +321,7 @@ class StripeController extends Controller
|
|||
// Create payment intent
|
||||
// https://stripe.com/docs/api/payment_intents/create
|
||||
$paymentIntent = $this->client->paymentIntents->create([
|
||||
"amount" => $amount,
|
||||
"amount" => stripeFormatCurrency($amount, $request->input('currency')),
|
||||
"currency" => $request->input('currency'),
|
||||
"description" => $request->input('reason'),
|
||||
'payment_method_types' => ['card'],
|
||||
|
@ -462,7 +462,7 @@ class StripeController extends Controller
|
|||
// Create payout in Stripe
|
||||
// https://stripe.com/docs/api/payouts/create
|
||||
$payout = $this->client->payouts->create([
|
||||
"amount" => $amount,
|
||||
"amount" => stripeFormatCurrency($amount, $currency),
|
||||
"currency" => $currency,
|
||||
'description' => $request->input('reason'),
|
||||
"destination" => $destination->id,
|
||||
|
|
Loading…
Reference in New Issue