Created
December 28, 2016 14:44
-
-
Save jrmcdona/8dcd0c3f2e8eb5ebebd30fca97aa63a3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
var cardDetails = { | |
"card[number]": '4242424242424242', | |
"card[exp_month]": '09', | |
"card[exp_year]": '2019', | |
"card[cvc]": '303' | |
}; | |
var formBody = []; | |
for (var property in cardDetails) { | |
var encodedKey = encodeURIComponent(property); | |
var encodedValue = encodeURIComponent(cardDetails[property]); | |
formBody.push(encodedKey + "=" + encodedValue); | |
} | |
formBody = formBody.join("&"); | |
let response = await fetch(stripe_url + 'tokens', { | |
method: 'post', | |
headers: { | |
'Accept': 'application/json', | |
'Content-Type': 'application/x-www-form-urlencoded', | |
'Authorization': 'Bearer ' + secret_key | |
}, | |
body: formBody | |
}).then(function (response) { | |
if (response.ok) { | |
console.log("response") | |
console.log(response) | |
} else { | |
console.log('Network response was not ok.'); | |
} | |
}) | |
.catch(function (error) { | |
console.log('There has been a problem with your fetch operation: ' + error.message); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment