diff --git a/composer.json b/composer.json index 8ce02c6c..68662402 100644 --- a/composer.json +++ b/composer.json @@ -32,7 +32,7 @@ "illuminate/view": "^9.21|^10.0", "moneyphp/money": "^4.0", "nesbot/carbon": "^2.0", - "stripe/stripe-php": "^7.39|^8.0|^9.0|^10.0", + "stripe/stripe-php": "^13.0", "symfony/http-kernel": "^6.0", "symfony/polyfill-intl-icu": "^1.22.1" }, diff --git a/src/Cashier.php b/src/Cashier.php index 5a975c78..c0fc78d0 100644 --- a/src/Cashier.php +++ b/src/Cashier.php @@ -26,7 +26,7 @@ class Cashier * * @var string */ - const STRIPE_VERSION = '2022-11-15'; + const STRIPE_VERSION = '2023-10-16'; /** * The base URL for the Stripe API. diff --git a/src/Concerns/ManagesInvoices.php b/src/Concerns/ManagesInvoices.php index 81dfa8cd..22162ddb 100644 --- a/src/Concerns/ManagesInvoices.php +++ b/src/Concerns/ManagesInvoices.php @@ -160,11 +160,18 @@ public function createInvoice(array $options = []) { $this->assertCustomerExists(); + $stripeCustomer = $this->asStripeCustomer(); + $parameters = array_merge([ 'automatic_tax' => $this->automaticTaxPayload(), 'customer' => $this->stripe_id, + 'currency' => $stripeCustomer->currency ?? config('cashier.currency'), ], $options); + if (isset($parameters['subscription'])) { + unset($parameters['currency']); + } + if (array_key_exists('subscription', $parameters)) { unset($parameters['pending_invoice_items_behavior']); } diff --git a/src/Concerns/PerformsCharges.php b/src/Concerns/PerformsCharges.php index dc91c8d8..9206ab6e 100644 --- a/src/Concerns/PerformsCharges.php +++ b/src/Concerns/PerformsCharges.php @@ -89,6 +89,10 @@ public function createPayment($amount, array $options = []) $options['customer'] = $this->stripe_id; } + if ($options['confirm'] ?? false) { + $options['return_url'] ??= route('home'); + } + return new Payment( static::stripe()->paymentIntents->create($options) ); diff --git a/tests/Feature/ChargesTest.php b/tests/Feature/ChargesTest.php index 2814790c..8fb03d80 100644 --- a/tests/Feature/ChargesTest.php +++ b/tests/Feature/ChargesTest.php @@ -12,7 +12,9 @@ public function test_customer_can_be_charged() $user = $this->createCustomer('customer_can_be_charged'); $user->createAsStripeCustomer(); - $response = $user->charge(1000, 'pm_card_visa'); + $response = $user->charge(1000, 'pm_card_visa', [ + 'return_url' => 'https://example.com/return', + ]); $this->assertInstanceOf(Payment::class, $response); $this->assertEquals(1000, $response->rawAmount()); @@ -23,7 +25,9 @@ public function test_non_stripe_customer_can_be_charged() { $user = $this->createCustomer('non_stripe_customer_can_be_charged'); - $response = $user->charge(1000, 'pm_card_visa'); + $response = $user->charge(1000, 'pm_card_visa', [ + 'return_url' => 'https://example.com/return', + ]); $this->assertInstanceOf(Payment::class, $response); $this->assertEquals(1000, $response->rawAmount()); @@ -81,7 +85,9 @@ public function test_charging_may_require_an_extra_action() $user->createAsStripeCustomer(); try { - $user->charge(1000, 'pm_card_threeDSecure2Required'); + $user->charge(1000, 'pm_card_threeDSecure2Required', [ + 'return_url' => 'https://example.com/return', + ]); $this->fail('Expected exception '.IncompletePayment::class.' was not thrown.'); } catch (IncompletePayment $e) {