Created
November 1, 2021 20:06
-
-
Save cesarbarone/c0db17d2c5b15e40927bd1f2d958071f 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
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