Skip to content

Instantly share code, notes, and snippets.

@studio-fars-company
Created June 25, 2018 07:17
Show Gist options
  • Save studio-fars-company/dbb16c807cb24463e387429c78be44d9 to your computer and use it in GitHub Desktop.
Save studio-fars-company/dbb16c807cb24463e387429c78be44d9 to your computer and use it in GitHub Desktop.
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Stripe\Stripe;
use Stripe\Customer;
use Stripe\Charge;
class ChargeController extends Controller
{
/*単発決済用のコード*/
public function charge(Request $request)
{
try {
Stripe::setApiKey(env('STRIPE_SECRET'));
$customer = Customer::create(array(
'email' => $request->stripeEmail,
'source' => $request->stripeToken
));
$charge = Charge::create(array(
'customer' => $customer->id,
'amount' => 1000,
'currency' => 'jpy'
));
return back();
} catch (\Exception $ex) {
return $ex->getMessage();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment