使用java在Stripe中为卡充电

时间:2016-07-14 16:31:44

标签: java stripe-payments

我是Stripe整合和java的新手,我想要做的第一件事就是收取信用卡费用。我正在使用java。这是为卡充电的代码。

enter code here
 //CHARGING THE CARD

Stripe.apiKey = "cgchhcchv";
// Get the credit card details submitted by the form
String token = request.getParameter("stripeToken");

// Create the charge on Stripe's servers - this will charge the user's card
try {
Map<String, Object> chargeParams = new HashMap<String, Object>();
chargeParams.put("amount", 1000); // amount in cents, again
chargeParams.put("currency", "usd");
chargeParams.put("source", token);
chargeParams.put("description", "Example charge");

Charge charge = Charge.create(chargeParams);
} catch (CardException e) {
// The card has been declined
}

我添加了Stripe库并且它们似乎运行良好但是当尝试执行此代码时,这些错误输出:&#34; HashMap无法解析为类型&#34;,&#34;请求无法解析&#34 ;。即使我创建了无法解决的变量,我也不明白为什么会输出这些错误。有人可以解释一下吗?此致!

1 个答案:

答案 0 :(得分:1)

在github发布页面中,您可以找到几个示例: https://github.com/stripe/stripe-java

import java.util.HashMap;
import java.util.Map;

import com.stripe.Stripe;
import com.stripe.exception.StripeException;
import com.stripe.model.Charge;
import com.stripe.net.RequestOptions;