将Strip Javascript转换为CFscript错误

问题描述 投票:0回答:1

我在顶部制作过程中获得了一些帮助,但是它可以正常工作,但是当我为重定向编写最后两段代码时,我认为它很费劲,因为它无法读取cfscript中制作的变量。该链接说明了我试图使用Java进行https://stripe.com/docs/payments/checkout/server并将其转换的方法。

<cfscript>
secKey = "sk_test_aHhoYVOnsayNSIleB1ETUCSq00vUOS9YVQ";

/* 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_9EGWNLDg0ix3v8cPDyl8zrPA00SgCsjLCl');
</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>
stripe-payments cfml
1个回答
0
投票

听起来好像您从cfscript代码中获得了chkSession,然后需要在客户端使用它。为此,您只需要输出带有可变输出的js脚本即可。

  sessionId: '<cfoutput>#chkSession.id#</cfoutput>'

如果变量在需要输出的地方不可用,则在设置和输出时将request.添加到请求范围中,该范围可从在同一请求中运行的CF服务器上的所有代码获得。

© www.soinside.com 2019 - 2024. All rights reserved.