Java条带库:收集拒绝或无效CVC等错误
我在应用程序中使用Stripe作为支付处理器,在使用Java库时获得错误响应,而不是通过HTTP接收错误,这在 我根据以前使用stripe创建的客户对象对信用卡收费的方法是:Java条带库:收集拒绝或无效CVC等错误,java,stripe-payments,Java,Stripe Payments,我在应用程序中使用Stripe作为支付处理器,在使用Java库时获得错误响应,而不是通过HTTP接收错误,这在 我根据以前使用stripe创建的客户对象对信用卡收费的方法是: public void charge(BigDecimal amount) throws AuthenticationException, InvalidRequestException, APIConnectionException, CardException, APIException { //Convert
public void charge(BigDecimal amount) throws AuthenticationException, InvalidRequestException, APIConnectionException, CardException, APIException {
//Convert amount to cents
NumberFormat usdCostFormat = NumberFormat.getCurrencyInstance(Locale.US);
usdCostFormat.setMinimumFractionDigits(1);
usdCostFormat.setMaximumFractionDigits(2);
double chargeAmountDollars = Double.valueOf(usdCostFormat.format(amount.doubleValue()));
int chargeAmountCents = (int) chargeAmountDollars * 100;
Map<String, Object> chargeParams = new HashMap<String, Object>();
chargeParams.put("amount", chargeAmountCents);
chargeParams.put("currency", "usd");
chargeParams.put("customer", subscription.getCustomerId());
Charge charge = Charge.create(chargeParams);
//Should I be inspecting the returned charge object and throwing my own errors here?
}
第二,我应该担心来自美国以外的付款,还是Stripe为我处理所有这些我是否需要根据用户的区域设置检测货币并设置正确的货币代码,或者将所有付款转换为美元,因为美元是存入我帐户的货币?
更新:
根据我从Stripe的支持团队收到的一封电子邮件,非美国卡的发行银行将自动执行从本地到美元的所有货币转换。我不必根据收费卡的来源调整货币代码。似乎
CardException
会给您带来与卡相关(无效CVC)和与支付相关(拒绝)的错误
,这里介绍如何使用Charge.create()
方法:
如果充电成功,则返回充电对象。将出现错误
如果出现问题,将返回。常见的错误源是
无效或过期的卡,或可用卡不足的有效卡
平衡
从:
至于货币,在映射中有一个货币值被传递到Charge.create()
方法,该方法似乎指示您希望以何种货币进行收费。但我不确定这与和解有什么关系
BigDecimal discount = cost.multiply(BigDecimal.valueOf(discountPercentage).setScale(2, RoundingMode.HALF_EVEN));
cost = cost.subtract(discount);
if(cost.compareTo(BigDecimal.ZERO) > 0) {
//Charge the credit card.
try {
paymentManager.charge(cost);
//Everything went ok, return success to user.
} catch (AuthenticationException e) {
//Authentication with API failed. Log error.
} catch (InvalidRequestException e) {
//Invalid parameters, log error.
} catch (APIConnectionException e) {
//Network communication failure. Try again.
} catch (CardException e) {
String errorCode = e.getCode();
String errorMsg = e.getParam();
if(errorCode.equals("incorrect_number")) {
//Tell the user the cc number is incorrect.
} else if(errorCode.equals("invalid_cvc")) {
//Tell the user the cvc is wrong.
}
//This is a sample, production will check all possible errors.
} catch (APIException e) {
//Something went wrong on Stripes end.
}
}
Card Errors
Type: card_error
Code Details
incorrect_number The card number is incorrect
invalid_number The card number is not a valid credit card number
invalid_expiry_month The card's expiration month is invalid
invalid_expiry_year The card's expiration year is invalid
invalid_cvc The card's security code is invalid
expired_card The card has expired
incorrect_cvc The card's security code is incorrect
card_declined The card was declined.
missing There is no card on a customer that is being charged.
processing_error An error occurred while processing the card.