// 20240312095525
// http://127.0.0.1:8000/payment
"Sending credit card numbers directly to the Stripe API is generally unsafe. We suggest you use test tokens that map to the test card you are using, see https://stripe.com/docs/testing. To enable raw card data APIs in test mode, see https://support.stripe.com/questions/enabling-access-to-raw-card-data-apis."
Bu şekilde bir hata veriyor ben test kartlarını kullanıyorum gelen kart bilgilerini de token'a çevirip yolluyorum ama yine bu hatayı dönüyor
Kodlarım bu şekilde
web.php dosyası da bu şekilde
Route::post('/payment', [PaymentController::class, 'store'])->name('payment_post');
Route::get('/stripe-3ds-result', [PaymentController::class, 'stripe3dsResult'])->name('stripe_3ds_result');
Kredi kartı bilgilerini aldığım formum bu şekilde
<form action="{{ route('payment_post') }}" method="post">
@csrf
<div><label class="credit-card-label">Ad Soyad</label><input type="text"
class="form-control credit-inputs"
placeholder="Name" name="holder_name"></div>
<div><label class="credit-card-label">Kart Numarası</label><input type="text"
class="form-control credit-inputs"
placeholder="0000 0000 0000 0000"
name="card_number">
</div>
<div class="row">
<div class="col-md-6"><label class="credit-card-label">Son Kullanma Tarihi Ay</label>
<input type="text" class="form-control credit-inputs" placeholder="month" name="month">
</div>
<div class="col-md-6"><label class="credit-card-label">Son Kullanma Tarihi Yıl</label>
<input type="text" class="form-control credit-inputs" placeholder="year" name="year">
</div>
<div class="col-md-6"><label class="credit-card-label">CVV</label>
<input type="text" class="form-control credit-inputs" placeholder="342" name="cvc">
</div>
</div>
<hr class="line">
<div class="d-flex justify-content-between information"><span>Kdv'siz Toplam</span><span>{{$basketSubTotal}} ₺</span>
</div>
<div class="d-flex justify-content-between information"><span>Toplam(KDV Dahil)</span><span>{{$basketTaxTotal}} ₺ </span>
</div>
<button class="btn btn-primary btn-block d-flex justify-content-between mt-3" type="submit">
<span>{{$basketTaxTotal}}₺ </span><span>Ödeme Yap<i
class="fa fa-long-arrow-right ml-1"></i></span>
</button>
</form>
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Redirect;
class PaymentController extends Controller
{
public function store()
{
$holder_name = request()->holder_name;
$card_number = request()->card_number;
$month = request()->month;
$year = request()->year;
$cvc = request()->cvc;
$currency = 'USD';
$price = 1 * 100;
$stripe = new \Stripe\StripeClient(
config('stripe.secret_key')
);
try {
$stripeToken = $stripe->tokens->create([
'card' => [
'number' => $card_number,
'exp_month' => $month,
'exp_year' => $year,
'cvc' => $cvc
]
]);
$customer = $stripe->customers->create([
'name' => $holder_name,
'source' => $stripeToken['id']
]);
$setupIntent = $stripe->setupIntents->create([
'customer' => $customer['id'],
'description' => 'test',
'payment_method' => $stripeToken['card']['id'],
'payment_method_types' => ['card'],
'payment_method_options' => [
'card' => [
'request_three_d_secure' => 'any'
]
],
'confirm' => true,
'return_url' => config('stripe.merchant_url') .'/stripe-3ds-result',
'metadata' => [
'price' => $price,
'currency' => $currency
]
]);
}
catch (\Stripe\Exception\ApiErrorException $e) {
return response()->json($e->getMessage(), 500);
}
if ($setupIntent['status'] == 'succeeded') {
try {
$charge = $stripe->charges->create([
'customer' => $setupIntent['customer'],
'amount' => $price,
'currency' => $currency,
'description' => 'test',
'source' => $stripeToken['card']['id']
]);
}
catch (\Stripe\Exception\ApiErrorException $e) {
return response()->json($e->getMessage(), 500);
}
if ($charge['status'] != 'succeeded') {
return response()->json('Payment error!', 500);
} else {
return response()->json($charge, 200);
}
}
if ($setupIntent['status'] == 'requires_action') {
return Redirect::to($setupIntent['next_action']['redirect_to_url']['url']);
} else {
return response()->json('3ds payment error!', 500);
}
}
public function stripe3dsResult()
{
$stripe = new \Stripe\StripeClient(
config('stripe.secret_key')
);
$setupIntent = $stripe->setupIntents->retrieve(
request()->setup_intent
);
$price = $setupIntent['metadata']['price'];
$currency = $setupIntent['metadata']['currency'];
if ($setupIntent['status'] == 'succeeded') {
try {
$charge = $stripe->charges->create([
'customer' => $setupIntent['customer'],
'amount' => $price,
'currency' => $currency,
'description' => 'test',
'source' => $setupIntent['payment_method']
]);
}
catch (\Stripe\Exception\ApiErrorException $e) {
return response()->json($e->getMessage(), 500);
}
if ($charge['status'] != 'succeeded') {
return response()->json('3ds payment error!', 500);
} else {
return response()->json($charge, 200);
}
} else {
return response()->json('3ds payment error!', 500);
}
}
}