Stripe is opening checkout popup in same page in PC but on mobile it's opening in new window which is bad for user experience.
So What I'm trying to do is make the user agent is like PC browser and this is worked in PHP but I couldn't find a way to send user agent when I call checkout.js, and her is my code:
$.ajaxSetup({
beforeSend: function(xhr) {
xhr.setRequestHeader('User-Agent', 'Mozilla/5.0 (Windows NT 10.0; WOW64; rv:46.0) Gecko/20100101 Firefox/46.0');
}
});
$.ajax({
url: 'https://checkout.stripe.com/checkout.js',
type: 'GET',
dataType: 'script',
xhrFields: {
withCredentials: true,
},
crossDomain: true,
success: function(){
var handler = StripeCheckout.configure({
key: 'pk_test_6pRNASCoBOKtI',
locale: 'auto',
token: function(token) {
// You can access the token ID with `token.id`.
// Get the token ID to your server-side code for use.
}
});
$('#customButton').on('click', function(e) {
// Open Checkout with further options:
handler.open({
name: 'Stripe.com',
description: '2 widgets',
amount: 2000
});
e.preventDefault();
});
// Close Checkout on page navigation:
$(window).on('popstate', function() {
handler.close();
});
}
});