Skip to content

Commit

Permalink
[15.x] Stripe API and SDK update (#1615)
Browse files Browse the repository at this point in the history
* Stripe API and SDK update

* wip

* wip

* wip
  • Loading branch information
driesvints authored Dec 13, 2023
1 parent 746a853 commit acc947b
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 5 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
2 changes: 1 addition & 1 deletion src/Cashier.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 7 additions & 0 deletions src/Concerns/ManagesInvoices.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}
Expand Down
4 changes: 4 additions & 0 deletions src/Concerns/PerformsCharges.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
Expand Down
12 changes: 9 additions & 3 deletions tests/Feature/ChargesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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());
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit acc947b

Please sign in to comment.