示例#1
0
  private List<ChargebackResult> bulkReverse(
      final List<Transfer> transfers, final List<AccountDTO> accountsToLock) {
    final List<ChargebackResult> results = new LinkedList<ChargebackResult>();
    boolean failed = false;

    try {
      accountService.lockAccounts(true, accountsToLock);
    } catch (final Exception e) {
      WebServiceFaultsEnum.CURRENTLY_UNAVAILABLE.throwFault(e);
    }

    for (final Transfer transfer : transfers) {
      try {
        if (failed) {
          results.add(new ChargebackResult(ChargebackStatus.NOT_PERFORMED, null, null));
        } else {
          final ChargebackResult result = doChargeback(transfer);
          results.add(result);
          if (!result.getStatus().isSuccessful()) {
            failed = true;
          }
        }
      } catch (final Exception e) {
        failed = true;
        webServiceHelper.error(e);
        results.add(
            new ChargebackResult(ChargebackStatus.TRANSFER_CANNOT_BE_CHARGEDBACK, null, null));
      }
    }

    return results;
  }
示例#2
0
  public List<PaymentResult> doBulkPayment(final List<PaymentParameters> params) {
    final List<PaymentResult> results =
        new ArrayList<PaymentResult>(params == null ? 0 : params.size());
    if (params != null) {
      // We should lock at once all from accounts for all payments, but only if all accounts are
      // passed ok
      boolean hasError = false;
      final List<AccountDTO> allAccounts = new ArrayList<AccountDTO>();
      for (int i = 0; i < params.size(); i++) {
        final PaymentParameters param = params.get(i);
        final PrepareParametersResult result = prepareParameters(param);

        if (result.getStatus() == null) {
          try {
            final DoExternalPaymentDTO dto =
                paymentHelper.toExternalPaymentDTO(param, result.getFrom(), result.getTo());
            if (!validateTransferType(dto)) {
              results.add(new PaymentResult(PaymentStatus.INVALID_PARAMETERS, null));
              webServiceHelper.error(
                  "The specified transfer type is invalid: " + dto.getTransferType());
              hasError = true;
            } else {
              allAccounts.add(new AccountDTO(result.getFrom(), dto.getTransferType().getFrom()));
              results.add(new PaymentResult(PaymentStatus.NOT_PERFORMED, null));
            }
          } catch (final Exception e) {
            webServiceHelper.error(e);
            hasError = true;
            results.add(new PaymentResult(paymentHelper.toStatus(e), null));
          }
        } else {
          hasError = true;
          results.add(new PaymentResult(result.getStatus(), null));
          webServiceHelper.error(
              "Bulk payment validation status [" + i + "]: " + result.getStatus());
        }
      }
      if (!hasError) {
        // No validation error. Lock all accounts and perform each payment
        try {
          accountService.lockAccounts(true, allAccounts);
        } catch (final Exception e) {
          WebServiceFaultsEnum.CURRENTLY_UNAVAILABLE.throwFault(e);
        }
        for (int i = 0; i < params.size(); i++) {
          final PaymentParameters param = params.get(i);
          PaymentResult result;
          if (hasError) {
            result = new PaymentResult(PaymentStatus.NOT_PERFORMED, null);
          } else {
            result = doPayment(param);
            if (!result.getStatus().isSuccessful()) {
              hasError = true;
            }
          }
          results.set(i, result);
        }
      }
    }
    return results;
  }