2017-01-31 4 views
0

일회성 지불을 허용하는 webapp를 개발 중입니다. 나는 Cashier와 Laravel을 사용하고 있습니다.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--> 

:

제품보기는 스트라이프 버튼을 표시하는 루프는 기본적으로.

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(); 
} 

이슈는 다음과 같습니다 :

관련 경로는 다음과 같이 컨트롤러 파일이

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

있습니다

  • 1) 오버레이 지불 (여기서 VISA 카드 정보해야 입력 됨)은 입니다. 표시되지 않습니다.
  • 2) chargeCustomer 함수에서 고객은 이 Stripe에서 생성되지 않습니다. "No such token : xxxxxxxx"라는 오류 메시지가 나타납니다. 인쇄는 확실히 숨겨진 토큰입니다 (페이지 뷰에서 확인). 문제는 _token과 관련 될 수 있습니다. _token은 stripeToken을 사용해야 함을 나타냅니다. 그러나 stripeToken은 항상 null을 반환합니다.

답변

0

아마도 app.js가 호출되고 있으며 둘 다 충돌하기 때문일 수 있습니다. app.js 링크를 제거하고 어떻게 반응하는지보십시오.

+0

문제는 app.js에서 발생합니다. 그것을 제거하고 시도는 나를 위해 일했다. – thephpx