I am trying to make a custom payment form for Stripe, and I want to make the AJAX call to Stripe manually. (instead of a submit event)
However, first off I am pretty
Disclaimer: This works, but it is TERRIBLE practice. Don't use this for a real project. I needed it for a front-end only testing environment. As other users on this page has pointed out, you should be doing this on the backend!
I finally found some useful documentation at: https://stripe.com/docs/api#create_charge
As I suspected the URL I was using was wrong.
after getting the right URL, the following ajax call works:
Hope That helps someone else as well! As most answers, are PHP or other backend languages.
$.ajax({
type: 'POST',
url: 'https://api.stripe.com/v1/charges',
headers: {
Authorization: 'Bearer sk_test_YourSecretKeyHere'
},
data: {
amount: 3000,
currency: 'usd',
source: response.id,
description: "Charge for madison.garcia@example.com"
},
success: (response) => {
console.log('successful payment: ', response);
},
error: (response) => {
console.log('error payment: ', response);
}
})