Esempio n. 1
0
  private ChargebackResult doChargeback(final Transfer transfer) {
    ChargebackStatus status = null;
    Transfer chargebackTransfer = null;

    // Check if the transfer can be charged back
    if (!paymentService.canChargeback(transfer, false)) {
      if (transfer.getChargedBackBy() != null) {
        chargebackTransfer = transfer.getChargedBackBy();
        status = ChargebackStatus.TRANSFER_ALREADY_CHARGEDBACK;
      } else {
        if (transfer.getStatus() == Payment.Status.PENDING) {
          final TransferAuthorizationDTO transferAuthorizationDto = new TransferAuthorizationDTO();
          transferAuthorizationDto.setTransfer(transfer);
          transferAuthorizationDto.setShowToMember(false);
          chargebackTransfer =
              transferAuthorizationService.cancelFromMemberAsReceiver(transferAuthorizationDto);
          status = ChargebackStatus.SUCCESS;
        } else {
          status = ChargebackStatus.TRANSFER_CANNOT_BE_CHARGEDBACK;
        }
      }
    }

    // Do the chargeback
    if (status == null) {
      chargebackTransfer =
          paymentService.chargeback(transfer, WebServiceContext.getClient().getId());
      status = ChargebackStatus.SUCCESS;
    }

    if (!status.isSuccessful()) {
      webServiceHelper.error("Chargeback result: " + status);
    }

    final Member member = WebServiceContext.getMember();
    // Build the result
    if (status == ChargebackStatus.SUCCESS
        || status == ChargebackStatus.TRANSFER_ALREADY_CHARGEDBACK) {
      final AccountOwner owner = member == null ? transfer.getToOwner() : member;
      final AccountHistoryTransferVO originalVO = accountHelper.toVO(owner, transfer, null);
      final AccountHistoryTransferVO chargebackVO =
          accountHelper.toVO(owner, chargebackTransfer, null);
      return new ChargebackResult(status, originalVO, chargebackVO);
    } else {
      return new ChargebackResult(status, null, null);
    }
  }
Esempio n. 2
0
  private <V> ChargebackResult reverse(final V transferId, final TransferLoader<V> loader) {
    Exception errorException = null;
    ChargebackStatus status = null;
    Transfer transfer = null;

    try {
      transfer = loader.load(transferId);
      // Ensure the member is the one who received the payment
      final Member member = WebServiceContext.getMember();
      if (member != null && !transfer.getToOwner().equals(member)) {
        throw new EntityNotFoundException();
      } else {
        final Collection<TransferType> possibleTypes =
            fetchService
                .fetch(
                    WebServiceContext.getClient(),
                    ServiceClient.Relationships.CHARGEBACK_PAYMENT_TYPES)
                .getChargebackPaymentTypes();
        if (!possibleTypes.contains(transfer.getType())) {
          throw new EntityNotFoundException();
        }
      }
    } catch (final EntityNotFoundException e) {
      errorException = e;
      status = ChargebackStatus.TRANSFER_NOT_FOUND;
    }

    if (status == null) {
      try {
        return doChargeback(transfer);
      } catch (final Exception e) {
        webServiceHelper.error(e);
        return new ChargebackResult(ChargebackStatus.TRANSFER_CANNOT_BE_CHARGEDBACK, null, null);
      }
    } else {
      if (!status.isSuccessful()) {
        webServiceHelper.error(
            errorException != null
                ? errorException
                : new Exception("Chargeback status: " + status));
      }
      return new ChargebackResult(status, null, null);
    }
  }