Categories Innovative Task

Stripe payment in laravel

routes.php 

Route::get(‘/’, function () {
return view(‘welcome’);
});
Route::post(‘/testdata’, function () {
$stripe = array(
// Note Please write secret_key and publishabel_key from your stripe account.
“secret_key” => “”,
“publishable_key” => “”
);

\Stripe\Stripe::setApiKey($stripe[‘secret_key’]);

echo $token = $_POST[‘stripeToken’];

$customer = \Stripe\Customer::create(array(
’email’ => ‘customer@example.com’,
‘source’ => $token
));

$charge = \Stripe\Charge::create(array(
‘customer’ => $customer->id,
‘amount’ => 5000,
‘currency’ => ‘usd’
));
echo ‘<h1>Successfully charged $50.00!</h1>’;
});

Welcome.blade.php

<form action=”{{URL(‘/testdata’)}}” method=”POST”>
{{ csrf_field() }}
<script
src=”https://checkout.stripe.com/checkout.js” class=”stripe-button”

// Write Private Key into data-key from Stripe account
data-key=””
data-amount=”999″
data-name=”Demo Site”
data-description=”Widget”
data-image=”/img/documentation/checkout/marketplace.png”
data-locale=”auto”>
</script>
</form>

Leave a Reply

Your email address will not be published. Required fields are marked *