I absolutely cannot find anything online to help me integrate stripe with Laravel 5.2. It's been challenging to learn this framework because of so many deprecations between versions :(
Anyway, here's what I'm working with
JS file to capture input
$(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();
}
};
once the form is done, I route the user to via the action="" attribute in the form.
Route::any('/success', ['as' => 'success', 'uses' =>'ChargeController@pay']);
here is my controller with code provided by stripe...as you can see it will not work
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!';
}
}
}
I'm looking at using the StripeJS documentation instead of cashier. Currently, I'm looking at this error
Fatal error: Class 'App\Http\Controllers\Stripe_Customer' not found
And that's where the documentation ends. Any help? I would prefer to use cashier, but I can't find any documentation for "non-subscription" based use and the laravel website is not much help.
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/25F0gZC
via IFTTT
Aucun commentaire:
Enregistrer un commentaire