Created
June 30, 2020 06:40
-
-
Save shanwixcode/e07c371c410630a5c7ca36b8b70284c8 to your computer and use it in GitHub Desktop.
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
//stripeAPI.js | |
import {fetch} from 'wix-fetch'; | |
export async function createToken(card) { | |
const apiKey = "PUBLIC_API_KEY"; | |
const response = await fetch("https://api.stripe.com/v1/tokens", { | |
method: 'post', | |
headers: { | |
"Content-Type": "application/x-www-form-urlencoded", | |
"Authorization": "Bearer " + apiKey | |
}, | |
body: card | |
}); | |
if (response.status >= 200 && response.status < 300) { | |
const json = await response.json(); | |
return json.id; | |
} | |
const responseText = await response.text(); | |
return response.status; | |
} | |
export function encodeCard(card){ | |
let encoded = ""; | |
for (let [k, v] of Object.entries(card)) { | |
encoded = encoded.concat("card[", k, "]=", encodeURI(v), "&"); | |
} | |
return encoded.substr(0, encoded.length - 1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment