Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[10.0] Implement SetupIntent create method #700

Merged
merged 1 commit into from
Jul 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/Billable.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Stripe\Customer as StripeCustomer;
use Stripe\BankAccount as StripeBankAccount;
use Stripe\InvoiceItem as StripeInvoiceItem;
use Stripe\SetupIntent as StripeSetupIntent;
use Stripe\Error\Card as StripeCardException;
use Stripe\PaymentIntent as StripePaymentIntent;
use Stripe\PaymentMethod as StripePaymentMethod;
Expand Down Expand Up @@ -340,6 +341,23 @@ public function invoicesIncludingPending(array $parameters = [])
return $this->invoices(true, $parameters);
}

/**
* Create a new SetupIntent instance.
*
* @param array $options
* @return \Stripe\SetupIntent
*/
public function createSetupIntent(array $options = [])
{
if ($this->stripe_id) {
$options['customer'] = $this->stripe_id;
}

return StripeSetupIntent::create(
$options, Cashier::stripeOptions()
);
}

/**
* Determines if the customer currently has a payment method.
*
Expand Down
12 changes: 12 additions & 0 deletions tests/Integration/PaymentMethodsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,22 @@
use Laravel\Cashier\Cashier;
use Stripe\Card as StripeCard;
use Laravel\Cashier\PaymentMethod;
use Stripe\SetupIntent as StripeSetupIntent;
use Stripe\PaymentMethod as StripePaymentMethod;

class PaymentMethodsTest extends IntegrationTestCase
{
public function test_we_can_start_a_new_setup_intents_session()
{
$user = $this->createCustomer('we_can_start_a_new_setup_intents_session');
$customer = $user->createAsStripeCustomer();

$setupIntent = $user->createSetupIntent();

$this->assertInstanceOf(StripeSetupIntent::class, $setupIntent);
$this->assertEquals($customer->id, $setupIntent->customer);
}

public function test_we_can_set_a_default_payment_method()
{
$user = $this->createCustomer('we_can_set_a_default_payment_method');
Expand Down