public List<Refund> toRefunds(final List<RefundModelDao> in) { return new ArrayList<Refund>(Collections2.transform(in, new Function<RefundModelDao, Refund>() { @Override public Refund apply(final RefundModelDao cur) { return new DefaultRefund(cur.getId(), cur.getCreatedDate(), cur.getUpdatedDate(), cur.getPaymentId(), cur.getAmount(), cur.getCurrency(), cur.isAdjusted(), cur.getCreatedDate(), cur.getRefundStatus()); } })); }
public Pagination<Refund> getRefunds(final Long offset, final Long limit, final String pluginName, final TenantContext tenantContext, final InternalTenantContext internalTenantContext) throws PaymentApiException { final PaymentPluginApi pluginApi = getPaymentPluginApi(pluginName); return getEntityPagination(limit, new SourcePaginationBuilder<RefundModelDao, PaymentApiException>() { @Override public Pagination<RefundModelDao> build() { // Find all refunds for all accounts return paymentDao.getRefunds(pluginName, offset, limit, internalTenantContext); } }, new Function<RefundModelDao, Refund>() { @Override public Refund apply(final RefundModelDao refundModelDao) { List<RefundInfoPlugin> refundInfoPlugins = null; try { refundInfoPlugins = pluginApi.getRefundInfo(refundModelDao.getAccountId(), refundModelDao.getId(), tenantContext); } catch (final PaymentPluginApiException e) { log.warn("Unable to find refund id " + refundModelDao.getId() + " in plugin " + pluginName); // We still want to return a refund object, even though the plugin details are missing } final RefundInfoPlugin refundInfoPlugin = refundInfoPlugins == null ? null : findRefundInfoPlugin(refundModelDao, refundInfoPlugins); return new DefaultRefund(refundModelDao, refundInfoPlugin); } } ); }
@Override public Refund apply(final RefundModelDao refundModelDao) { List<RefundInfoPlugin> refundInfoPlugins = null; try { refundInfoPlugins = pluginApi.getRefundInfo(refundModelDao.getAccountId(), refundModelDao.getId(), tenantContext); } catch (final PaymentPluginApiException e) { log.warn("Unable to find refund id " + refundModelDao.getId() + " in plugin " + pluginName); // We still want to return a refund object, even though the plugin details are missing } final RefundInfoPlugin refundInfoPlugin = refundInfoPlugins == null ? null : findRefundInfoPlugin(refundModelDao, refundInfoPlugins); return new DefaultRefund(refundModelDao, refundInfoPlugin); } }
return new DefaultRefund(model, refundInfoPlugin);
@Override public Refund apply(final RefundInfoPlugin refundInfoPlugin) { if (refundInfoPlugin.getKbPaymentId() == null) { // Garbage from the plugin? log.debug("Plugin {} returned a refund without a kbPaymentId for searchKey {}", pluginName, searchKey); return null; } List<RefundModelDao> modelCandidates = refundModelDaosByPaymentId.get(refundInfoPlugin.getKbPaymentId()); if (modelCandidates == null) { refundModelDaosByPaymentId.put(refundInfoPlugin.getKbPaymentId(), paymentDao.getRefundsForPayment(refundInfoPlugin.getKbPaymentId(), internalTenantContext)); modelCandidates = refundModelDaosByPaymentId.get(refundInfoPlugin.getKbPaymentId()); } final RefundModelDao model = Iterables.<RefundModelDao>tryFind(modelCandidates, new Predicate<RefundModelDao>() { @Override public boolean apply(final RefundModelDao refundModelDao) { return refundObjectsMatch(refundModelDao, refundInfoPlugin); } }).orNull(); if (model == null) { log.warn("Unable to find refund for payment id " + refundInfoPlugin.getKbPaymentId() + " present in plugin " + pluginName); return null; } return new DefaultRefund(model, refundInfoPlugin); } }
return new DefaultRefund(refundInfo.getId(), refundInfo.getCreatedDate(), refundInfo.getUpdatedDate(), paymentId, refundInfo.getAmount(), account.getCurrency(), isAdjusted, refundInfo.getCreatedDate(), RefundStatus.COMPLETED); return new DefaultRefund(refundInfo.getId(), refundInfo.getCreatedDate(), refundInfo.getUpdatedDate(), paymentId, refundInfo.getAmount(), account.getCurrency(), isAdjusted, refundInfo.getCreatedDate(), RefundStatus.PENDING);
@Override public Refund apply(final RefundModelDao cur) { return new DefaultRefund(cur.getId(), cur.getCreatedDate(), cur.getUpdatedDate(), cur.getPaymentId(), cur.getAmount(), cur.getCurrency(), cur.isAdjusted(), cur.getCreatedDate(), cur.getRefundStatus()); } }));
public Refund getRefund(final UUID refundId, final boolean withPluginInfo, final InternalTenantContext context) throws PaymentApiException { RefundModelDao result = paymentDao.getRefund(refundId, context); if (result == null) { throw new PaymentApiException(ErrorCode.PAYMENT_NO_SUCH_REFUND, refundId); } final List<RefundModelDao> filteredInput = filterUncompletedPluginRefund(Collections.singletonList(result)); if (filteredInput.isEmpty()) { throw new PaymentApiException(ErrorCode.PAYMENT_NO_SUCH_REFUND, refundId); } if (completePluginCompletedRefund(filteredInput, context)) { result = paymentDao.getRefund(refundId, context); } final PaymentModelDao payment = paymentDao.getPayment(result.getPaymentId(), context); if (payment == null) { throw new PaymentApiException(ErrorCode.PAYMENT_NO_SUCH_PAYMENT, result.getPaymentId()); } final PaymentPluginApi plugin = withPluginInfo ? getPaymentProviderPlugin(payment.getPaymentMethodId(), context) : null; List<RefundInfoPlugin> refundInfoPlugins = ImmutableList.<RefundInfoPlugin>of(); if (plugin != null) { try { refundInfoPlugins = plugin.getRefundInfo(result.getAccountId(), result.getPaymentId(), buildTenantContext(context)); } catch (final PaymentPluginApiException e) { throw new PaymentApiException(ErrorCode.PAYMENT_PLUGIN_GET_REFUND_INFO, refundId, e.toString()); } } return new DefaultRefund(result, findRefundInfoPlugin(result, refundInfoPlugins)); }
return new DefaultRefund(refundInfo.getId(), refundInfo.getCreatedDate(), refundInfo.getUpdatedDate(), paymentId, refundInfo.getAmount(), account.getCurrency(), isAdjusted, refundInfo.getCreatedDate(), RefundStatus.COMPLETED); return new DefaultRefund(refundInfo.getId(), refundInfo.getCreatedDate(), refundInfo.getUpdatedDate(), paymentId, refundInfo.getAmount(), account.getCurrency(), isAdjusted, refundInfo.getCreatedDate(), RefundStatus.PENDING);