Charging a card in Stripe using java

守給你的承諾、 提交于 2020-01-15 05:39:06

问题


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
}

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!


回答1:


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;


来源:https://stackoverflow.com/questions/38379580/charging-a-card-in-stripe-using-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!