-3
如何在laravel中集成API條紋?我想在我的項目中爲laravel做api集成條帶。請別人說一些好主意。如何在laravel中集成API條紋?
如何在laravel中集成API條紋?我想在我的項目中爲laravel做api集成條帶。請別人說一些好主意。如何在laravel中集成API條紋?
這是簡單的API,你可以用它檢查,以便快速瞭解有關條紋上Laravel:
public function postStripeTest(Request $request){
$rules = [
'token' => 'required',
'amount' => 'required',
];
$validator = Validator::make($request->all(), $rules);
if ($validator->passes()) {
try {
$charge = Stripe::charges()->create([
// 'customer' => 'cus_4EBumIjyaKooft',
'currency' => 'USD',
'amount' => $request['amount'],
"source" => $request['token'],
"description" => "Example charge"
]);
return response()->json([
'status' => true,
'data' => $charge['id']
]);
} catch (Exception $e) {
return response()->json([
'status' => false,
'data' => "charges stripe fail!"
]);
}
}
// get all error messages
foreach ($validator->messages()->toArray() as $key => $msg) {
$messages[$key] = reset($msg);
}
return response()->json([
'status' => false,
'data' => $messages
], 412);
}