ストライプを Laravel 5.2 と統合するのに役立つものをオンラインで見つけることは絶対にできません。バージョン間の非推奨が非常に多いため、このフレームワークを学ぶのは困難でした:(
とにかく、これが私が取り組んでいるものです
入力をキャプチャする JS ファイル
$(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();
}
};
フォームが完成したら、フォームの属性を{{ route('success') }}
介してユーザーをルーティングします。action=""
Route::any('/success', ['as' => 'success', 'uses' =>'ChargeController@pay']);
これがストライプによって提供されたコードを含む私のコントローラーです...ご覧のとおり、動作しません
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!';
}
}
}
キャッシャーの代わりにStripeJS ドキュメントの使用を検討しています。現在、私はこのエラーを見ています
Fatal error: Class 'App\Http\Controllers\Stripe_Customer' not found
これでドキュメントは終了です。何か助けはありますか?キャッシャーを使用したいのですが、「非サブスクリプション」ベースの使用に関するドキュメントが見つからず、laravel Web サイトはあまり役に立ちません。