Coldfusion 你能把stripejava代码转换成CFscript吗

Coldfusion 你能把stripejava代码转换成CFscript吗,coldfusion,stripe-payments,cfml,Coldfusion,Stripe Payments,Cfml,下面的代码是如何实现stripe payment API,我想知道我是否只是将其转换为CFscript并调用我的普通变量,它会工作吗 // Set your secret key: remember to change this to your live secret key in production // See your keys here: https://dashboard.stripe.com/account/apikeys Stripe.apiKey = "sk_test_

下面的代码是如何实现stripe payment API,我想知道我是否只是将其转换为CFscript并调用我的普通变量,它会工作吗

    // Set your secret key: remember to change this to your live secret key in production
// See your keys here: https://dashboard.stripe.com/account/apikeys
Stripe.apiKey = "sk_test_aHhoYVOnsayNSIleB1ETUCSq00vUOS9YVQ";

Map<String, Object> params = new HashMap<String, Object>();

ArrayList<String> paymentMethodTypes = new ArrayList<>();
paymentMethodTypes.add("card");
params.put("payment_method_types", paymentMethodTypes);

ArrayList<HashMap<String, Object>> lineItems = new ArrayList<>();
HashMap<String, Object> lineItem = new HashMap<String, Object>();
lineItem.put("name", "T-shirt");
lineItem.put("description", "Comfortable cotton t-shirt");
lineItem.put("amount", 500);
lineItem.put("currency", "usd");
lineItem.put("quantity", 1);
lineItems.add(lineItem);
params.put("line_items", lineItems);

params.put("success_url", "https://example.com/success?session_id={CHECKOUT_SESSION_ID}");
params.put("cancel_url", "https://example.com/cancel");

Session session = Session.create(params);
//设置您的密钥:请记住在生产中将其更改为您的实时密钥
//请在此处查看您的钥匙:https://dashboard.stripe.com/account/apikeys
Stripe.apiKey=“sk_test_aHhoYVOnsayNSIleB1ETUCSq00vUOS9YVQ”;
Map params=新的HashMap();
ArrayList paymentMethodTypes=新的ArrayList();
paymentMethodTypes.add(“卡”);
参数put(“付款方式类型”,paymentMethodTypes);
ArrayList lineItems=新的ArrayList();
HashMap lineItem=新建HashMap();
行项目。放置(“姓名”、“T恤”);
lineItem.put(“描述”,“舒适棉t恤”);
行项目。投入(“金额”,500);
行项目。卖出(“货币”、“美元”);
行项目。放置(“数量”,1);
lineItems.add(lineItem);
参数put(“行项目”,行项目);
参数put(“成功url”)https://example.com/success?session_id={CHECKOUT_SESSION_ID}”);
参数put(“取消url”)https://example.com/cancel");
Session=Session.create(参数);

虽然不是对上面提供的Java代码的直接转换,但使用函数来实现这一点应该相当简单。例如:

<cfscript>
secKey = "sk_test_xxxx";

/* 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>

secKey=“sk_测试_xxxx”;
/*创建新的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)

Perfect让我进入了下一步,我真的非常感谢您的帮助,我还有两个需要转换的位。我正在努力处理其他两个部分,如果您能帮助的话,那将是非常棒的另一个部分就是javascript!因此,没有转换,您只需创建html页面,并包含从上述服务器端签出代码创建的会话id。我还建议#将条带作为一种资源,许多在那里闲逛的开发人员现在都希望聊天更多因为CF在java上运行,大多数java代码都可以转换。请参阅上的提示。话虽如此。。。“仅仅因为你可以,并不意味着你应该”。正如下面的答案所指出的,CF已经具备了进行http调用的功能。因此,您可能根本不需要外部java库来完成此任务。