Skip to content

Instantly share code, notes, and snippets.

@rafaelpadovani
Last active October 13, 2019 15:28
Show Gist options
  • Save rafaelpadovani/cd33a97d4f5c74d8f29b6c14d2bdd0c6 to your computer and use it in GitHub Desktop.
Save rafaelpadovani/cd33a97d4f5c74d8f29b6c14d2bdd0c6 to your computer and use it in GitHub Desktop.
Creating Stripe Payment Intent
export const createPaymentIntent = (amount, currency, payment_method, description) => {
let truncated = parseFloat(amount).toFixed(2);
let stripeAmount = truncated * 100;
fetch('https://api.stripe.com/v1/payment_intents?amount=' + stripeAmount + '&currency='+ currency +'&payment_method_types[]=card&payment_method=' + payment_method + '&confirmation_method=automatic&confirm=true&description=' + description, {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + secret_key
},
})
.then((response) => {
if (response.status == 200) {
return response.json();
}
})
.then((responseJson) => {
return responseJson;
})
.catch((error) => {
return error;
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment