Trouble setting up a subscription with Laravel 5.8 / Cashier / Stripe

前端 未结 6 1786
暖寄归人
暖寄归人 2020-12-30 16:38

I followed this tutorial step by step: https://appdividend.com/2018/12/05/laravel-stripe-payment-gateway-integration-tutorial-with-example/

However, when I go to tes

6条回答
  •  孤独总比滥情好
    2020-12-30 16:49

    Maybe im late but you dont always need to setup the payment intent. i was able to do the following

    $user = new User();
    $user->fill($payload);
    
    $user->createAsStripeCustomer([
      'name' => $user->fullname,
    ]);
    
    $user->updateDefaultPaymentMethod($data->stripeToken);
    
    $user->newSubscription(env('STRIPE_SUBSCRIPTION_NAME'), env('STRIPE_PLAN_ID'))
        ->create(null, [
          'name' => $this->fullname,
          'email' => $this->email,
        ]) // may not be required as we already do this above;
    

    stripeToken is the token returned when using stripe.createPaymentMethod. One thing of note is that i no longer have to specify a payment method when creating a subscription. Also in my case i had to collect the credit card during user registration. I only start the subscription when the user verifies their email.

    The steps are

    1. Create User
    2. Create Stripe User
    3. Create payment method from payment_token returned from stripe elements for user
    4. Start subscription

    I really dislike the stripe docs. Too many breaking changes and i feel its incomplete as they are more than one way to do things that arent being documented

    .

提交回复
热议问题