I've created a html widget that includes a script that people can fill the form and the script will send a request on my end. Now the request will be sent to a Laravel project and the project in which it is configured is a simple html bootstrap template. I'm having an issue while sending a POST request. It says CORS policy issue. If I try to pass datatype as jsonp, I get the request but since I'm trying to pass card information in that to a payment gateway from my controller, it should be secured. Any solution?
$.ajax({
url: "url",
method:'POST',
type: 'POST',
data: {
'amount':total_amount,
'customer_name':customer_name,
'customer_email':customer_email,
'customer_phone':customer_phone,
'card_number': card_number,
'card_expiry': card_expiry_date,
'cvc': card_cvc
},
success: function(result){
console.log('test');
}});
Route::post('/checkout-post', 'CheckoutController@checkout')->name('checkout-post')->middleware('cors');
public function handle($request, Closure $next) { return $next($request) ->header('Access-Control-Allow-Origin', '*') ->header('Access-Control-Allow-Methods', 'GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS') ->header('Access-Control-Allow-Headers', 'Content-Type, Authorization'); }