您可以将Stripe Java代码转换为CFscript吗 [英] Can you Convert Stripe Java Code into CFscript

查看:61
本文介绍了您可以将Stripe Java代码转换为CFscript吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的代码是如何实现Stripe Payment API的,我想知道是否只是将其转换为CFscript并调用我的普通变量是否会起作用?

The code below is how to impletment stripe payment API, I was wondering if I just convert it to CFscript and call my normal variable will it work?

    // 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);


推荐答案

虽然不是Java代码的直接转换,上面提供的方法,使用cfscript 做到这一点应该很简单/script-functions-implemented-as-cfcs/http.html rel = nofollow noreferrer> http服务函数。例如:

While not a direct conversion of the Java code you've provided above, it should be fairly straight-forward to do this with cfscript using http service functions. For example:

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

这篇关于您可以将Stripe Java代码转换为CFscript吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆