使用java在Stripe中为卡充电 [英] Charging a card in Stripe using java

查看:18
本文介绍了使用java在Stripe中为卡充电的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我也是 Stripe 集成和 Java 的新手,我想做的第一件事就是向信用卡收费.我正在使用Java.这是充值卡的代码.

I'm new at Stripe integration and java too and the first thing I want to do is charging a credit card. I'm using java. Here is the code for charging the card.

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 库,它们似乎运行良好,但是在尝试执行此代码时,这些错误输出:HashMap 无法解析为类型"、请求无法解析".我不明白为什么即使我创建这些无法解析的变量也会输出这些错误.有人可以解释一下吗?问候!

I added the Stripe libraries and they seem to work well but when trying to execute this code these errors output: "HashMap cannot be resolved to a type", "request cannot be resolved". I don't understand why these errors output even when I create these variables that cannot be resolved.Can someone explain this? Regards!

推荐答案

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

In the github release page you can find several examples: 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;

这篇关于使用java在Stripe中为卡充电的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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