protected Map<UUID, List<InvoicePayment>> getAccountInvoicePayments(final Iterable<Payment> payments, final TenantContext context) throws OSGIServiceNotAvailable { final InvoicePaymentApi invoicePaymentApi = getInvoicePaymentUserApi(); final Map<UUID, List<InvoicePayment>> allInvoicePaymentsByPaymentId = new HashMap<UUID, List<InvoicePayment>>(); for (final Payment payment : payments) { // Retrieve all invoice payment types (including refunds and chargebacks) for that payment allInvoicePaymentsByPaymentId.put(payment.getId(), invoicePaymentApi.getInvoicePayments(payment.getId(), context)); } return allInvoicePaymentsByPaymentId; }
private InvoicePayment getInvoicePaymentEntry(final UUID paymentId, final InvoicePaymentType type, final CallContext context) { final List<InvoicePayment> invoicePayments = invoicePaymentApi.getInvoicePayments(paymentId, context); final Collection<InvoicePayment> refundInvoicePayments = Collections2.filter(invoicePayments, new Predicate<InvoicePayment>() { @Override public boolean apply(@Nullable final InvoicePayment invoicePayment) { return invoicePayment.getType() == type && invoicePayment.getPaymentId().equals(paymentId); } }); Assert.assertEquals(refundInvoicePayments.size(), 1); return refundInvoicePayments.iterator().next(); }
@TimedResource @GET @Path("/{paymentId:" + UUID_PATTERN + "}/") @Produces(APPLICATION_JSON) @ApiOperation(value = "Retrieve a payment by id", response = InvoicePaymentJson.class) @ApiResponses(value = {@ApiResponse(code = 400, message = "Invalid payment id supplied"), @ApiResponse(code = 404, message = "Payment not found")}) public Response getInvoicePayment(@PathParam("paymentId") final UUID paymentId, @QueryParam(QUERY_WITH_PLUGIN_INFO) @DefaultValue("false") final Boolean withPluginInfo, @QueryParam(QUERY_WITH_ATTEMPTS) @DefaultValue("false") final Boolean withAttempts, @QueryParam(QUERY_PLUGIN_PROPERTY) final List<String> pluginPropertiesString, @QueryParam(QUERY_AUDIT) @DefaultValue("NONE") final AuditMode auditMode, @javax.ws.rs.core.Context final HttpServletRequest request) throws PaymentApiException { final Iterable<PluginProperty> pluginProperties = extractPluginProperties(pluginPropertiesString); final TenantContext tenantContext = context.createTenantContextNoAccountId(request); final Payment payment = paymentApi.getPayment(paymentId, withPluginInfo, withAttempts, pluginProperties, tenantContext); final AccountAuditLogs accountAuditLogs = auditUserApi.getAccountAuditLogs(payment.getAccountId(), auditMode.getLevel(), tenantContext); final List<InvoicePayment> invoicePayments = invoicePaymentApi.getInvoicePayments(paymentId, tenantContext); final InvoicePayment invoicePayment = Iterables.tryFind(invoicePayments, new Predicate<InvoicePayment>() { @Override public boolean apply(final InvoicePayment input) { return input.getType() == InvoicePaymentType.ATTEMPT; } }).orNull(); final UUID invoiceId = invoicePayment != null ? invoicePayment.getInvoiceId() : null; final InvoicePaymentJson result = new InvoicePaymentJson(payment, invoiceId, accountAuditLogs); return Response.status(Response.Status.OK).entity(result).build(); }
final TenantContext tenantContext = context.createTenantContextNoAccountId(request); final Payment payment = paymentApi.getPayment(paymentId, false, false, ImmutableList.<PluginProperty>of(), tenantContext); final List<InvoicePayment> invoicePayments = invoicePaymentApi.getInvoicePayments(paymentId, tenantContext);
private void checkPayment(final UUID accountId, final Payment payment, final CallContext context, final ExpectedPaymentCheck expected) { Assert.assertEquals(payment.getAccountId(), accountId); Assert.assertEquals(payment.getCurrency(), expected.getCurrency()); if (expected.getInvoiceId() != null) { for (final InvoicePayment invoicePayment : invoicePaymentApi.getInvoicePayments(payment.getId(), context)) { Assert.assertEquals(invoicePayment.getInvoiceId(), expected.getInvoiceId()); } } final PaymentTransaction transaction = getPurchaseTransaction(payment); Assert.assertTrue(transaction.getAmount().compareTo(expected.getAmount()) == 0, "Actual amount " + transaction.getAmount() + ", expected amount " + expected.getAmount()); Assert.assertEquals(transaction.getTransactionStatus(), expected.getStatus()); Assert.assertEquals(transaction.getEffectiveDate().toLocalDate().compareTo(expected.getPaymentDate()), 0, "Actual date " + transaction.getEffectiveDate() + ", expected date " + expected.getPaymentDate()); auditChecker.checkPaymentCreated(payment, context); }
final InvoicePayment invoicePayment = invoicePaymentApi.getInvoicePayments(invoiceUserApi.getInvoicesByAccount(account.getId(), false, false, callContext).get(1).getPayments().get(0).getPaymentId(), callContext).get(0); Payment payment = paymentApi.getPayment(invoicePayment.getPaymentId(), false, false, ImmutableList.<PluginProperty>of(), callContext); payment = createChargeBackAndCheckForCompletion(account, payment, NextEvent.PAYMENT, NextEvent.INVOICE_PAYMENT, NextEvent.BLOCK);