首页 > 解决方案 > Stripe/Laravel - 更新条带客户导致 GET 方法错误

问题描述

我目前正在尝试在充电之前更新 Stripe 客户的默认来源,所有这些都在存储/充电控制器中。如果我添加更新方法,我会收到此错误:

The GET method is not supported for this route. Supported methods: POST.

我不明白 GET 方法来自哪里,除非它来自 Stripes 更新方法,在这种情况下,如果有人知道如何解决这个问题,我会很高兴的 :)

HTML:

<form action="{{ route('item.charge') }}" method="post" id="payment-form">
    @csrf
    @method('POST')
    <h2>Billing</h2>
    <div class="form-row">
        <div class="form-group">
            <label for="email">Email Address</label>
            <input placeholder="JohnDoe@gmail.com" type="email" class="form-control" id="email" name="email">
        </div>
        <div class="form-group">
            <label for="customerName">Name</label>
            <input placeholder="John Doe" type="text" class="form-control" id="customerName" name="customerName">
        </div>
        <div class="form-group">
            <label for="address">Adresse</label>
            <input placeholder="23 Kendral Ave" type="text" class="form-control" id="addresse" name="address">
        </div>
        <div class="form-group">
            <label for="city">City</label>
            <input placeholder="Sydney" type="text" class="form-control" id="city" name="city">
        </div>
        <div class="form-group">
            <label for="state">State or Territory</label>
            <input placeholder="New South Wales" type="text" class="form-control" id="state" name="state">
        </div>
    </div>
    <h2>Financial</h2>
    <div class="form-row">
        <div class="form-group">
            <label for="cardName">Name on card</label>
            <input placeholder="MR JOHN DOE" type="text" class="form-control" id="cardName" name="cardName">
        </div>
        <div class="form-group">
            <label for="card-element">Card Details</label>
            <div id="card-element" style="width: 50vw;">
              <!-- A Stripe Element will be inserted here. -->
            </div>

            <!-- Used to display form errors. -->
            <div id="card-errors" role="alert"></div>
        </div>
    </div>
  <input type="hidden" value="{{ $checkoutSession->id }}" name="session">
  <input type="hidden" value="{{ $customer }}" name="customerID">
 <button class='btn-primary'>Submit Payment</button>
</form>

充电/存储控制器:

public function charge(Request $request)
{
    \Stripe\Stripe::setApiKey('my key');


    $data = request()->validate([
        'name' => 'required|string|min:3|max:30',
        'cardName' => 'required|string',
        'email' => 'required|email',
        'city' => 'string|max:40',
        'state' => 'string|max:20',
        'customerID' => 'required',
        'stripeToken' => 'required',
        '_token' => 'required',
        'address' => 'string|max:65',
    ]);

    // UPDATING CUSTOMER INFORMATION
    \Stripe\Customer::update(
      $data['customerID'],
      [
        'default_source' => $data['stripeToken'],
      ]
    );

    dd($customer);

    // RETRIEVING SESSION VARIABLES
    $checkoutSession = \Stripe\Checkout\Session::retrieve($request->session);
    // dd($checkoutSession->display_items[0]->amount);

    $amount = $checkoutSession->display_items[0]->amount;


    dd($data);

    // When it's time to charge the customer again, retrieve the customer ID.
    $charge = \Stripe\Charge::create([
        'amount' => 1500, // $15.00 this time
        'currency' => 'usd',
        'customer' => $customer_id, // Previously stored, then retrieved
    ]);
        }

路线:

Route::post('/charge', 'items\customerItemController@charge')->name('item.charge');

任何帮助将不胜感激!谢谢 :)

标签: phplaravelstripe-payments

解决方案


推荐阅读