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