2017-01-31 6 views
0

私は一回限りの支払いを可能にするwebappを開発しています。私はLashvelとCashierを使っています。Laravel stripe checkout.jsがロードされていません

一般的なストライプペイボタンを使用していくつかの商品を表示しています。これをクリックすると、checkout.jsフォームが表示されますが、これは起こっていません。

製品ビューは、基本的にはストライプのボタンを表示するループです:

<div class="row"> 
@foreach ($products as $product) 
    <form action="{{ route('frontend.user.pay', $product->id) }}" method="POST"> 
    {{ csrf_field() }} 
    <div class="col-sm-5 col-md-5"> 
     <div class="thumbnail"> 
     <div class="caption"> 
      <h3>{{ $product->name }}</h3> 
      <p>{{ $product->small_description }}</p> 
      <p>Buy for ${{ substr_replace($product->price, '.', 2, 0) }}</p> 
      <p> 
      <script src="https://checkout.stripe.com/checkout.js" class="stripe-button"      
      data-key="{{ env('STRIPE_PUBLIC') }}" 
      data-amount="{{ $product->price }}" 
      data-name="Stripe.com" 
      data-description="Widget" 
      data-locale="auto" 
      data-currency="usd"> 
      </script> 
      </p> 
     </div> 
     </div> 
     </div> 
    </form> 
    @endforeach 
    </div><!--row--> 

私はボタンをクリックすると、ストライプ有料オーバーレイがロードされません。

関連するルートが

Route::get('product', '[email protected]')->name('product'); 
Route::post('pay/{product}', '[email protected]')->name('pay'); 

あり、次のようにコントローラファイルは次のとおりです。

public function payWithStripe(Request $request, Product $product) { 
    $token = $request->input('_token'); 
    return $this->chargeCustomer($product->id, $product->price, $product->name, $token); 
} 

public function chargeCustomer($product_id, $product_price, $product_name, $token) { 
    \Stripe\Stripe::setApiKey(env('STRIPE_SECRET')); 

    if (!$this->isStripeCustomer()) { 
     $customer = $this->createStripeCustomer($token); 
    } 
    else { 
     $customer = \Stripe\Customer::retrieve(access()->user()->stripe_id); 
    } 
return $this->createStripeCharge($product_id, $product_price, $product_name, $customer); 
} 

public function createStripeCharge($product_id, $product_price, $product_name, $customer) { 
    try { 
     $charge = \Stripe\Charge::create(array(
      "amount" => $product_price, 
      "currency" => "usd", 
      "customer" => $customer->id, 
      "description" => $product_name 
     )); 
    } catch(\Stripe\Error\Card $e) { 
     return redirect() 
      ->route('frontend.user.product') 
      ->with('error', 'Your credit card was been declined. Please try again or contact us.'); 
    } 
     return $this->postStoreOrder($product_id); 
    } 


public function createStripeCustomer($token) { 
    \Stripe\Stripe::setApiKey(env('STRIPE_SECRET')); 

    $customer = \Stripe\Customer::create(array(
     "description" => access()->user()->email, 
     "source" => $token 
    )); 

    access()->user()->stripe_id = $customer->id; 
    access()->user()->save(); 

    return $customer; 
} 

public function isStripeCustomer() { 
    return access()->user() && \App\Models\Access\User\User::where('id', access()->user()->id)->whereNotNull('stripe_id')->first(); 
} 

問題は、次のとおりです。

  • 1)オーバーレイ支払い(VISAカードの詳細必要があります入力されている) は表示されません
  • 2)chargeCustomer関数では、顧客は がStripeで生成されていません。 「No such token:xxxxxxxx」というエラーが表示されます。 それを印刷することは、間違いなく隠しトークンです(ページビューからチェックします)。この問題は、_tokenに関連している可能性があります。ここで、stripeTokenを使用する必要があります。ただし、stripeTokenは常にnullを返します。
  • app.jsが呼び出されている。このため、多分

答えて

0

、彼らの両方の競合。 app.jsリンクを削除して、どのように反応するかを確認してください。

+0

問題はapp.jsにありますそれを削除し、私のために働いてみてください。 – thephpx

関連する問題