Я работаю с Stripe API получил некоторую помощь , преобразовав Java-пример , совершив http-вызов. Верхняя часть кода ниже работает. Однако, когда я делаю последние два куска кода для перенаправления, я думаю, что это сложно, потому что он не может читать переменные, сделанные в cfscript.
Эта ссылка объясняет, что я пытаюсь сделать https://stripe.com/docs/payments/checkout/server, используя Java и конвертируя его.
<cfscript>
secKey = "sk_test_********";
/* create new http service */
httpService = new http();
httpService.setMethod("post");
httpService.setCharset("utf-8");
httpService.setUrl("https://api.stripe.com/v1/checkout/sessions");
/* add header */
httpService.addParam(type="header", name="Authorization", value="Bearer " & secKey);
/* add params */
httpService.addParam(type="formfield",name="success_url", value="https://example.com/success");
httpService.addParam(type="formfield",name="cancel_url", value="https://example.com/fail");
httpService.addParam(type="formfield",name="payment_method_types[]", value="card");
httpService.addParam(type="formfield",name="line_items[0][amount]", value="1000");
httpService.addParam(type="formfield",name="line_items[0][currency]", value="usd");
httpService.addParam(type="formfield",name="line_items[0][quantity]", value="1");
httpService.addParam(type="formfield",name="line_items[0][name]", value="widget");
/* make the http call */
result = httpService.send().getPrefix();
/* parse json and print id */
chkSession = DeserializeJSON(result.fileContent);
writeoutput(chkSession.id);
</cfscript>
<script src="https://js.stripe.com/v3/"></script>
<script>
const stripe = Stripe('pk_test_**********');
</script>
<script>
const {error} = await stripe.redirectToCheckout({
// Make the id field from the Checkout Session creation API response
// available to this file, so you can provide it as parameter here
// instead of the {{CHECKOUT_SESSION_ID}} placeholder.
sessionId: '(chkSession.id)'
})
// If `redirectToCheckout` fails due to a browser or network
// error, display the localized error message to your customer
// using `error.message`.
</script>