Stripe payments 将条带Javascript转换为CFscript错误时出错

Stripe payments 将条带Javascript转换为CFscript错误时出错,stripe-payments,cfml,Stripe Payments,Cfml,我正在与收到的一些帮助进行http调用。下面代码的顶部部分正在工作。然而,当我为重定向编写最后两段代码时,我认为它很困难,因为它无法读取cfscript中生成的变量 这个链接解释了我试图用java做什么,以及如何转换它 <cfscript> secKey = "sk_test_********"; /* create new http service */ httpService = new http(); httpService.setMethod("po

我正在与收到的一些帮助进行http调用。下面代码的顶部部分正在工作。然而,当我为重定向编写最后两段代码时,我认为它很困难,因为它无法读取cfscript中生成的变量

这个链接解释了我试图用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>

secKey=“sk_测试*******”;
/*创建新的http服务*/
httpService=newhttp();
httpService.setMethod(“post”);
httpService.setCharset(“utf-8”);
httpService.setUrl(“https://api.stripe.com/v1/checkout/sessions");
/*添加标题*/
httpService.addParam(type=“header”、name=“Authorization”、value=“Bearer”和secKey);
/*添加参数*/
httpService.addParam(type=“formfield”,name=“success\u url”,value=”https://example.com/success");
httpService.addParam(type=“formfield”,name=“cancel\u url”,value=”https://example.com/fail");
httpService.addParam(type=“formfield”,name=“payment\u method\u 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”);
/*进行http调用*/
结果=httpService.send().getPrefix();
/*解析json和打印id*/
chkSession=反序列化JSON(result.fileContent);
写输出(chkSession.id);
常量条带=条带('pk_测试*********');
const{error}=wait stripe.redirectToCheckout({
//从签出会话创建API响应生成id字段
//可用于此文件,因此您可以在此处将其作为参数提供
//而不是{{CHECKOUT\u SESSION\u ID}占位符。
会话id:'(chkSession.id)'
})
//如果“redirectToCheckout”由于浏览器或网络而失败
//错误,向您的客户显示本地化的错误消息
//使用“error.message”。

听起来您好像从cfscript代码中获得了
chkSession
,然后需要它在客户端提供。要做到这一点,您只需要使用变量output输出js脚本

  sessionId: '<cfoutput>#chkSession.id#</cfoutput>'
sessionId:“#chkSession.id#”
如果变量在需要输出的地方不可用,则在设置和输出变量时添加
request.
,以将其放入请求范围,该范围可从运行在同一请求中的CF服务器上的所有代码获得