Skip to content

Instantly share code, notes, and snippets.

@cesarbarone
Created November 1, 2021 20:06
Show Gist options
  • Save cesarbarone/c0db17d2c5b15e40927bd1f2d958071f to your computer and use it in GitHub Desktop.
Save cesarbarone/c0db17d2c5b15e40927bd1f2d958071f to your computer and use it in GitHub Desktop.
function createOneTimePayment({ paymentMethodId, priceId, email, fullName, recaptchaToken }) {
fetch(`${GRAPHQL_HOST}/graphql`, { method: 'post', referrerPolicy: 'unsafe-url', headers: { 'Content-type': 'application/json', 'Client-Captcha-Token': recaptchaToken }, body: JSON.stringify({
query:
`mutation createStripeOneTimePayment {
createStripeOneTimePayment(paymentMethodId: "${paymentMethodId}", priceId: "${priceId}", email: "${email}", fullName: "${fullName}", phone: "${phone}")
{ status error }
}`,
})
})
.then(responseToJson)
.then(function(result) {
var responseObj = result.data.createStripeOneTimePayment
var status = responseObj.status
if(status === 'success') {
window.location.replace('at-home-purchase-successful')
return
}
stopLoading()
if(status === 'card_declined') {
stripeErrorMessage.textContent = CARD_DECLINED
} else if {
stripeErrorMessage.textContent = SERVER_ERROR_MESSAGE
}
showElement(stripeErrorMessage)
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment