Skip to content

Commit

Permalink
Mandatory currency class in stripe gateways
Browse files Browse the repository at this point in the history
- using moneyphp required currency class as argument for DecimalMoneyParser::parse
- updated stripe-php version to 7.155.0 in order to support php 8.1

#2764
  • Loading branch information
Milan Martinkovič committed Feb 17, 2023
1 parent e71ac1f commit 57837ee
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"license": "MIT",
"require": {
"php": "^8.0",
"stripe/stripe-php": "7.22"
"stripe/stripe-php": "v7.105.0"
},
"minimum-stability": "dev",
"autoload": {
Expand Down
11 changes: 7 additions & 4 deletions src/Gateways/AbstractStripe.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Crm\PaymentsModule\Repository\PaymentMetaRepository;
use Crm\UsersModule\Repository\UserMetaRepository;
use Money\Currencies\ISOCurrencies;
use Money\Currency;
use Money\Number;
use Money\Parser\DecimalMoneyParser;
use Nette\Application\LinkGenerator;
Expand Down Expand Up @@ -62,11 +63,12 @@ protected function processCheckout($payment, $futureUsage = 'on_session')
]);

$lineItems = [];
$currency = new Currency($this->applicationConfig->get('currency'));
foreach ($payment->related('payment_items') as $paymentItem) {
$lineItems[] = [
'price_data' => [
'unit_amount' => $this->calculateStripeAmount($paymentItem->amount, $this->applicationConfig->get('currency')),
'currency' => $this->applicationConfig->get('currency'),
'unit_amount' => $this->calculateStripeAmount($paymentItem->amount, $currency),
'currency' => $currency->getCode(),
'product_data' => [
'name' => $paymentItem->name,
],
Expand Down Expand Up @@ -137,9 +139,10 @@ protected function processSetupIntent($paymentMethodId, $payment, $futureUsage =
}

// create payment intent instance for charging
$currency = new Currency($this->applicationConfig->get('currency'));
$this->paymentIntent = PaymentIntent::create([
'amount' => $this->calculateStripeAmount($payment->amount, $this->applicationConfig->get('currency')),
'currency' => $this->applicationConfig->get('currency'),
'amount' => $this->calculateStripeAmount($payment->amount, $currency),
'currency' => $currency->getCode(),
'customer' => $stripeCustomerId,
'payment_method' => $paymentMethodId,
'setup_future_usage' => $futureUsage,
Expand Down
6 changes: 4 additions & 2 deletions src/Gateways/StripeRecurrent.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Crm\PaymentsModule\Gateways\RecurrentPaymentInterface;
use Crm\PaymentsModule\RecurrentPaymentFailStop;
use Crm\PaymentsModule\RecurrentPaymentFailTry;
use Money\Currency;
use Omnipay\Common\Exception\InvalidRequestException;
use Stripe\ErrorObject;
use Stripe\PaymentIntent;
Expand Down Expand Up @@ -36,9 +37,10 @@ public function charge($payment, $token): string
$stripeCustomerId = $this->userMetaRepository->userMetaValueByKey($payment->user, 'stripe_customer');

try {
$currency = new Currency($this->applicationConfig->get('currency'));
$this->paymentIntent = PaymentIntent::create([
'amount' => $this->calculateStripeAmount($payment->amount, $this->applicationConfig->get('currency')),
'currency' => $this->applicationConfig->get('currency'),
'amount' => $this->calculateStripeAmount($payment->amount, $currency),
'currency' => $currency->getCode(),
'customer' => $stripeCustomerId,
'payment_method' => $token,
'confirm' => true,
Expand Down

0 comments on commit 57837ee

Please sign in to comment.