2016-06-03 1 views
0

온라인으로 Laravel 5.2와 스트라이프를 통합 할 수있는 온라인 도움말을 찾을 수 없습니다. 이 때문에 버전 :(어쨌든단발 StaraeJS로 Laravel을 사용하여 5.2

사이에 많은 중단 된이 프레임 워크를 배우고 도전하고있어, 여기에 양식이 완료되면 내가 입력을

$(function() { 
    var $form = $('#payment-form'); 
    $form.submit(function(event) { 
    // Disable the submit button to prevent repeated clicks: 
    $form.find('.submit').prop('disabled', true); 

    // Request a token from Stripe: 
    Stripe.card.createToken($form, stripeResponseHandler); 

    // Prevent the form from being submitted: 
    return false; 
    }); 
}); 
function stripeResponseHandler(status, response) { 
    // Grab the form: 
    var $form = $('#payment-form'); 
    var CSRF_TOKEN = $('meta[name="csrf-token"]').attr('content'); 

    if (response.error) { // Problem! 

    // Show the errors on the form: 
    $form.find('.payment-errors').text(response.error.message); 
    $form.find('.submit').prop('disabled', false); // Re-enable submission 

    } else { // Token was created! 

    // Get the token ID: 
    var token = response.id; 
    console.log(token); 
    // Insert the token ID into the form so it gets submitted to the server: 
    $form.append($('<input type="hidden" name="stripeToken">').val(token)); 

    // Submit the form: 
    $form.get(0).submit(); 
    } 
}; 

을 캡처

JS 파일과 함께 일하고 있어요 무엇 나는 여기

Route::any('/success', ['as' => 'success', 'uses' =>'[email protected]']); 

은 내 컨트롤러 형태로 action="" 속성을 통해 {{ route('success') }}에 대한 사용자.입니다 경로 당신이 내가 대신 점원의 StripeJS documentation을 사용하여 찾고 있어요

namespace App\Http\Controllers; 

use Illuminate\Http\Request; 
use App\Http\Requests; 
use App\Http\Requests\CreateSongRequest; 
use Illuminate\Foundation\Http\FormRequest; 
use Billable; 
use Input; 

class ChargeController extends Controller 
{ 
    public function pay(Request $request){ 
     if(Input::has('stripeToken')){ 
      $token = Input::get('stripeToken'); 
      $amount = 10; 
// I cannot use this part even though it is in the stripe documentation 
      $customer = Stripe_Customer::create(array(
           'card' => $token 
          )); 
      $charge = Stripe_Charge::create(array(
         'customer' => $customer->id, 
         'amount' => ($amount*100), 
         'currency' => 'usd', 
         'description' => "test" 
        )); 
      echo 'success!'; 
     } 
    } 
} 

작동하지 않습니다 볼 수있는 스트라이프 ...에서 제공하는 코드입니다. 현재,이 오류

Fatal error: Class 'App\Http\Controllers\Stripe_Customer' not found

찾고 있어요 그리고 설명서가 끝나는 곳이다. 어떤 도움이 필요합니까? 계산원을 사용하는 것을 선호하지만 "비 가입"기반의 사용에 대한 문서를 찾을 수 없으며 laravel 웹 사이트는별로 도움이되지 않습니다.

+0

고객에게 Stripe_Customer 클래스가 있습니까? –

+0

해당 오류가 컨트롤러를 찾고 있습니까? 해당 위치에 Stripe_Controller가 있습니까? –

+0

@AchrafKhouadja 거기에 무엇을 넣을 지 알려주는 튜토리얼이 없기 때문에 클래스가 존재하지 않습니다. StripeJS 문서가 그곳에서 멈추는 것 –

답변

1

케빈의 대답은 여전히 ​​코드 여기

에 어떤 문제가 있는지에의 intrested입니다 어쨌든 경우, 솔루션

모든

먼저 당신이 필요로하는 컨트롤러에이 코드를 사용해보십시오 잘된다 그런 노력이 패키지

composer require stripe/stripe-php 

를 추가

class ChargeController extends Controller 
{ 

    public function __construct(){ 
    \Stripe\Stripe::setApiKey('d8e8fca2dc0f896fd7cb4cb0031ba249'); 
    } 

    public function pay(Request $request){ 
     if(Input::has('stripeToken')){ 
      $token = Input::get('stripeToken'); 
      $amount = 10; 

      $charge = \Stripe\Charge::create(array(
         'customer' => $customer->id, 
         'amount' => ($amount*100), 
         'currency' => 'usd', 
         'description' => "test", 
         'card' => $token 
        )); 
      echo 'charged successfuly!'; 
     } 
    } 
} 

고객 ID와 관련된 오류가 발생하는 경우 먼저 고객을 생성 한 다음

2

계산원을 사용하는 것이 좋습니다. 당신의 작곡가에 필요합니다

"laravel/cashier": "~6.0" 

당신은/app.php뿐만 아니라 당신의 설정에 공급자에 추가해야합니다 :

설정에서
Laravel\Cashier\CashierServiceProvider::class 

/서비스는 스트라이프 API 키를 추가하고 그건에 대한 그것은 설정을 위해. 하나의 제품 구매에 대한 스트라이프를 사용하려면 단순히 스트라이프 구매 버튼 통합 :

{!! Form::open(array('url' => '/checkout')) !!} 
    {!! Form::hidden('product_id', $product->id) !!} 
    <script 
    src="https://checkout.stripe.com/checkout.js" class="stripe-button" 
    data-key="{{env('STRIPE_API_PUBLIC')}}" 
    data-name="your app" 
    data-billingAddress=true 
    data-shippingAddress=true 
    data-label="Buy ${{ $product->price }}" 
    data-description="{{ $product->name }}" 
    data-amount="{{ $product->priceToCents() }}"> 
    </script> 
{!! Form::close() !!} 

이 또는 당신이 카트를 통합하고 거기에서 스트라이프에 전체 구매를 전달할 수를,하지만 약간 더 복잡합니다. 양식 경로에서 한 번

https://leanpub.com/easyecommerce, 당신은 당신이 요청을 잡아 컨트롤러 메서드에 전달합니다 : 내가보기 엔 그것은 나를 내 가게에 대한 모든 것을 알아낼 도움이 추천

public function index(Request $request) 
{ .... 
당신을 위해서 var_dump 수

스트라이프 버튼이 전달하는 다양한 데이터를 확인하십시오.

+0

하지만 어떻게 백엔드에서 카드를 "청구"합니까? 이 방법으로 이해할 수있는 것은 그것이 토큰을 생성한다는 것입니다. 그러나 당신은 그것으로 무언가를 할 필요가 있습니다. –

+0

저는 그것을 알아 냈습니다. '/ checkout' 페이지에는 https://stripe.com/docs/charges –

+0

의 PHP 코드가 포함되어야합니다. 그들은 처리가 끝났지 만 컨트롤러에서 모든 데이터를 요청으로 받아 들일 수 있습니다. –