3

アプリケーションの支払い処理業者として Stripe を使用していますが、Stripe の公式ドキュメントのエラー コードの説明に記載されているように、HTTP 経由でエラーを受信するのではなく、Java ライブラリを使用するときにエラー応答を取得することに関していくつか質問があります。

以前にストライプで作成された顧客オブジェクトに基づいてクレジットカードに請求するために使用している方法は次のとおりです。

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?
}

このメソッドは、さまざまな例外をスローします。CardException は、支払いのエラーに関する詳細を教えてくれるように思えますが、実際には、拒否や無効なカード パラメータなどを検出するために使用するためのものですか? これらの例外は、「クレジット カードが拒否されました」または「cvc コードが正しくありませんでした」などのことを教えてくれますか?それとも、返された Charge オブジェクトを調べてそのデータを取得する必要がありますか?

請求メソッドを呼び出すメソッドの例は、次のようなものです。

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.
    }
}

次に、米国外からの支払いについて心配する必要がありますか?それとも Stripe がすべて処理してくれますか? ユーザーのロケールに基づいて通貨を検出し、適切な通貨コードを設定する必要がありますか? それとも、Stripe はすべての支払いを USD に換算しますか?

更新: Stripe のサポート チームから受け取ったメールによると、米国以外のカードの発行銀行は、現地通貨から米ドルへのすべての通貨換算を自動的に実行します。請求元のカードに基づいて通貨コードを調整する必要はありません。

4

1 に答える 1

4

CardExceptionカード関連 (無効な CVC) と支払い関連 (拒否) の両方のエラーが表示されるようです。

docs から、メソッドの使用Charge.create()方法は次のとおりです。

課金が成功した場合、課金オブジェクトを返します。何か問題が発生した場合、エラーが返されます。エラーの一般的な原因は、カードが無効または期限切れになっていること、または有効なカードで利用可能な残高が不足していることです。

Stripe Java ドキュメントから:

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.

通貨に関しては、Map でメソッドに渡される通貨値がありますCharge.create()。これは、請求を行う通貨を示しているようです。ただし、それが決済にどのように関係するかはわかりません。

于 2013-03-23T13:43:17.857 に答える