Last active
October 13, 2019 15:28
-
-
Save rafaelpadovani/cd33a97d4f5c74d8f29b6c14d2bdd0c6 to your computer and use it in GitHub Desktop.
Creating Stripe Payment Intent
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 + '¤cy='+ 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