2016-07-07 8 views
-1

私は休憩アーキテクチャでスプリングブートを使用します。 私はエラー管理の初心者です。支払いにエラーがある場合はエラー管理

私のコードは

@Transactional 
@Override 
public void processPayment() throws CreditCardPaymentException{ 
    List<Payment> payments = paymentRepository.findByDateLessThanEqualAndPaymentModeAndStatus(LocalDate.now(), PaymentModeEnum.CREDITCARD, StatusEnum.STANDBY); 
    processCreditCardPayment(payments); 
} 

private void processCreditCardPayment(List<Payment> payments) throws ProcessPaymentException{ 
    PaymentGatewayConfig paymentGateway = new PaymentGatewayConfig(); 
    String crypt_type = "7"; 
    for (Payment payment : payments) { 
     chargeMemberCreditCard(payment, crypt_type, paymentGateway); 
    } 
} 

private ResolverReceipt chargeMemberCreditCard(Payment payment, String crypt_type, PaymentGatewayConfig paymentGateway) throws ProcessPaymentException { 

    try { 
     if (resreceipt != null) { 

      //information about customer we have sent are returned 
      ResolveData resdata = resreceipt.getResolveData(); 
      //todo check auth code 
      if (Boolean.valueOf(resreceipt.getComplete()) && !Boolean.valueOf(resreceipt.getTimedOut())) { 
       //if (resreceipt != null && resreceipt.getResponseCode() != null && Integer.getInteger(resreceipt.getResponseCode()) < 50) { 
       payment.setStatus(StatusEnum.COMPLETE); 
      } else { 
       payment.setStatus(StatusEnum.FAIL); 
      } 
     } 

    } catch (Exception e) { 
     throw new ProcessPaymentException(); 
     log.error("chargeMemberCreditCard - payment: " + payment.getPaymentId(), e); 
    } 

} 

このような構造を持って、私は次のいずれかに渡したいです。 最後に多くのエラーがある場合は、発生したエラーがあることを知りたいだけです。

もしこのコードがそれを行うなら、それが行く方法なのかどうかは分かりません。

+0

のtry/catchでPaymentsまたはExceptionsを失敗し蓄積しますか? –

答えて

0

はあなたの失敗の一覧をprocessCreditCardPayment

private void processCreditCardPayment(List<Payment> payments) throws ProcessPaymentException{ 
PaymentGatewayConfig paymentGateway = new PaymentGatewayConfig(); 
String crypt_type = "7"; 
List<Payment> failedPayments = new ArrayList<Payments>(); 
for (Payment payment : payments) { 
    try { 
     chargeMemberCreditCard(payment, crypt_type, paymentGateway); 
    } catch (ProcessPaymentException ppe) { 
     filedPayments.add(payment); 
     // or you can accumulate excetions instead of Payments 
    } 
} 
// create some higher level exception with failed Payent collection and throw it, or log it. 
+0

私がProcessPaymentExceptionで支払いのリストを持っている必要があると分かっていれば? –

+0

いいえ、サイクルの繰り返しごとにお支払い済みです。 'chargeMemberCreditCard'でスローされる可能性のあるすべての反復で例外を捕捉するだけです。例外をキャッチすると、filedPaymentsリストに例外を引き起こす支払いが追加されます。 ProcessPaymentExceptionには特別なデータはまったく含まれていない可能性があります。 – heyDude