public PaymentJson(final Payment payment, final String bundleExternalKey, final List<RefundJson> refunds, final List<ChargebackJson> chargebacks, @Nullable final List<AuditLog> auditLogs) { this(payment.getAmount(), payment.getPaidAmount(), payment.getAccountId().toString(), payment.getInvoiceId().toString(), payment.getId().toString(), payment.getPaymentNumber().toString(), payment.getPaymentMethodId().toString(), payment.getEffectiveDate(), payment.getEffectiveDate(), payment.getAttempts().size(), payment.getCurrency().toString(), payment.getPaymentStatus().toString(), payment.getAttempts().get(payment.getAttempts().size() - 1).getGatewayErrorCode(), payment.getAttempts().get(payment.getAttempts().size() - 1).getGatewayErrorMsg(), bundleExternalKey, refunds, chargebacks, toAuditLogJson(auditLogs)); }
@Override public PaymentJson apply(final Payment payment) { // Cache audit logs per account if (accountsAuditLogs.get().get(payment.getAccountId()) == null) { accountsAuditLogs.get().put(payment.getAccountId(), auditUserApi.getAccountAuditLogs(payment.getAccountId(), auditMode.getLevel(), tenantContext)); } return new PaymentJson(payment, accountsAuditLogs.get().get(payment.getAccountId()).getAuditLogsForPayment(payment.getId())); } },
fail("Expected to fail because requested amount > invoice amount"); assertNotNull(paymentInfo.getId()); assertTrue(paymentInfo.getAmount().compareTo(expectedAmount.setScale(2, RoundingMode.HALF_EVEN)) == 0); assertNotNull(paymentInfo.getPaymentNumber()); assertEquals(paymentInfo.getPaymentStatus(), PaymentStatus.SUCCESS); assertEquals(paymentInfo.getAttempts().size(), 1); assertEquals(paymentInfo.getInvoiceId(), invoice.getId()); assertEquals(paymentInfo.getCurrency(), Currency.USD); final PaymentAttempt paymentAttempt = paymentInfo.getAttempts().get(0); assertNotNull(paymentAttempt); assertNotNull(paymentAttempt.getId());
payment.getAmount(), cardCountry, cardType, createdDate, payment.getCurrency(), payment.getEffectiveDate(), payment.getInvoiceId(), message, payment.getId(), paymentMethodString, "Electronic", paymentMethod == null ? null : paymentMethod.getPluginName(), payment.getPaymentStatus().toString(), payment.getAmount(), updatedDate, invoicePaymentType,
final Map<UUID, Payment> payments = new HashMap<UUID, Payment>(); for (final Payment payment : accountPayments) { payments.put(payment.getId(), payment); for (final UUID paymentId : paymentsId) { final Payment paymentInfo = payments.get(paymentId); bipDao.invoicePaymentPosted(paymentInfo.getAccountId(), paymentInfo.getId(), paymentInfo.getPaymentStatus().toString(), internalCallContext);
for (final Payment payment : payments) { final List<RefundJson> refunds = new ArrayList<RefundJson>(); for (final Refund refund : refundsByPayment.get(payment.getId())) { final List<AuditLog> auditLogs = accountAuditLogs.getAuditLogsForRefund(refund.getId()); for (final InvoicePayment chargeback : chargebacksByPayment.get(payment.getId())) { final List<AuditLog> auditLogs = accountAuditLogs.getAuditLogsForChargeback(chargeback.getId()); chargebacks.add(new ChargebackJson(payment.getAccountId(), chargeback, auditLogs)); final List<AuditLog> auditLogs = accountAuditLogs.getAuditLogsForPayment(payment.getId()); this.payments.add(new PaymentJson(payment, getBundleExternalKey(payment.getInvoiceId(), invoices, bundles), refunds, chargebacks,
for (final Payment cur : payments) { if (lastPaymentDate == null || cur.getEffectiveDate().isAfter(lastPaymentDate)) { lastPaymentDate = cur.getEffectiveDate(); lastPaymentStatus = cur.getPaymentStatus().toString();
final List<PaymentAttempt> attempts = payment.getAttempts(); assertEquals(payment.getPaymentStatus(), PaymentStatus.SUCCESS); } else { if (failureType == FailureType.PAYMENT_FAILURE) { assertEquals(cur.getPaymentStatus(), PaymentStatus.PAYMENT_FAILURE_ABORTED); assertEquals(payment.getPaymentStatus(), PaymentStatus.PAYMENT_FAILURE_ABORTED); } else { assertEquals(cur.getPaymentStatus(), PaymentStatus.PLUGIN_FAILURE_ABORTED); assertEquals(payment.getPaymentStatus(), PaymentStatus.PLUGIN_FAILURE_ABORTED);
@GET @Path("/{paymentId:" + UUID_PATTERN + "}/" + TAGS) @Produces(APPLICATION_JSON) public Response getTags(@PathParam(ID_PARAM_NAME) final String paymentIdString, @QueryParam(QUERY_AUDIT) @DefaultValue("NONE") final AuditMode auditMode, @QueryParam(QUERY_TAGS_INCLUDED_DELETED) @DefaultValue("false") final Boolean includedDeleted, @javax.ws.rs.core.Context final HttpServletRequest request) throws TagDefinitionApiException, PaymentApiException { final UUID paymentId = UUID.fromString(paymentIdString); final TenantContext tenantContext = context.createContext(request); final Payment payment = paymentApi.getPayment(paymentId, false, tenantContext); return super.getTags(payment.getAccountId(), paymentId, auditMode, includedDeleted, tenantContext); }
@Override public Boolean call() throws Exception { final Payment payment = getPaymentForInvoice(invoice.getId()); return payment.getPaymentStatus() == PaymentStatus.SUCCESS; } });
@Override public UUID apply(@Nullable final Payment input) { if (input == null) { return null; } else { return input.getId(); } } });
private Payment getPaymentForInvoice(final UUID invoiceId) throws PaymentApiException { final List<Payment> payments = paymentProcessor.getInvoicePayments(invoiceId, internalCallContext); assertEquals(payments.size(), 1); final Payment payment = payments.get(0); assertEquals(payment.getInvoiceId(), invoiceId); return payment; }
paymentMethod = paymentApi.getPaymentMethodById(payment.getPaymentMethodId(), true, context); } catch (PaymentApiException e) { log.info("For payment {}: payment method {} does not exist", paymentId, payment.getPaymentMethodId());
@Override public PaymentJson apply(final Payment payment) { // Cache audit logs per account if (accountsAuditLogs.get().get(payment.getAccountId()) == null) { accountsAuditLogs.get().put(payment.getAccountId(), auditUserApi.getAccountAuditLogs(payment.getAccountId(), auditMode.getLevel(), tenantContext)); } return new PaymentJson(payment, accountsAuditLogs.get().get(payment.getAccountId()).getAuditLogsForPayment(payment.getId())); } },
@PUT @Path("/{paymentId:" + UUID_PATTERN + "}") @Consumes(APPLICATION_JSON) @Produces(APPLICATION_JSON) public Response retryFailedPayment(@PathParam(ID_PARAM_NAME) final String paymentIdString, @HeaderParam(HDR_CREATED_BY) final String createdBy, @HeaderParam(HDR_REASON) final String reason, @HeaderParam(HDR_COMMENT) final String comment, @javax.ws.rs.core.Context final HttpServletRequest request) throws AccountApiException, PaymentApiException { final CallContext callContext = context.createContext(createdBy, reason, comment, request); final UUID paymentId = UUID.fromString(paymentIdString); final Payment payment = paymentApi.getPayment(paymentId, false, callContext); final Account account = accountUserApi.getAccountById(payment.getAccountId(), callContext); final Payment newPayment = paymentApi.retryPayment(account, paymentId, callContext); return Response.status(Status.OK).entity(new PaymentJson(newPayment, null)).build(); }
Assert.assertEquals(payment.getPaymentStatus(), PaymentStatus.PAYMENT_FAILURE_ABORTED);
@Override public Void inTransaction(final BusinessInvoicePaymentSqlDao transactional, final TransactionStatus status) throws Exception { // Delete the existing payment if it exists - this is to make the call idempotent transactional.deleteInvoicePayment(payment.getId().toString(), context); // Create the bip record transactional.createInvoicePayment(businessInvoicePayment, context); if (invoice != null) { // Update bin to get the latest invoice balance final BusinessInvoiceSqlDao invoiceSqlDao = transactional.become(BusinessInvoiceSqlDao.class); invoiceDao.rebuildInvoiceInTransaction(account.getExternalKey(), invoice, invoiceSqlDao, context); } // Update bac to get the latest account balance, total invoice balance, etc. final BusinessAccountSqlDao accountSqlDao = transactional.become(BusinessAccountSqlDao.class); accountDao.updateAccountInTransaction(bac, accountSqlDao, context); log.info("Added payment {}", businessInvoicePayment); return null; } });
@GET @Path("/{invoiceId:" + UUID_PATTERN + "}/" + PAYMENTS) @Produces(APPLICATION_JSON) public Response getPayments(@PathParam("invoiceId") final String invoiceId, @QueryParam(QUERY_AUDIT) @DefaultValue("NONE") final AuditMode auditMode, @javax.ws.rs.core.Context final HttpServletRequest request) throws PaymentApiException { final TenantContext tenantContext = context.createContext(request); final List<Payment> payments = paymentApi.getInvoicePayments(UUID.fromString(invoiceId), tenantContext); final List<PaymentJson> result = new ArrayList<PaymentJson>(payments.size()); if (payments.size() == 0) { return Response.status(Status.OK).entity(result).build(); } final AccountAuditLogsForObjectType auditLogsForPayments = auditUserApi.getAccountAuditLogs(payments.get(0).getAccountId(), ObjectType.PAYMENT, auditMode.getLevel(), tenantContext); for (final Payment cur : payments) { result.add(new PaymentJson(cur, auditLogsForPayments.getAuditLogs(cur.getId()))); } return Response.status(Status.OK).entity(result).build(); }
@GET @Path("/{paymentId:" + UUID_PATTERN + "}") @Produces(APPLICATION_JSON) public Response getPayment(@PathParam(ID_PARAM_NAME) final String paymentIdString, @QueryParam(QUERY_PAYMENT_WITH_REFUNDS_AND_CHARGEBACKS) @DefaultValue("false") final Boolean withRefundsAndChargebacks, @javax.ws.rs.core.Context final HttpServletRequest request) throws PaymentApiException { final TenantContext tenantContext = context.createContext(request); final UUID paymentId = UUID.fromString(paymentIdString); final Payment payment = paymentApi.getPayment(paymentId, false, tenantContext); final PaymentJson paymentJson; if (withRefundsAndChargebacks) { final List<RefundJson> refunds = new ArrayList<RefundJson>(); for (final Refund refund : paymentApi.getPaymentRefunds(paymentId, tenantContext)) { refunds.add(new RefundJson(refund)); } final List<ChargebackJson> chargebacks = new ArrayList<ChargebackJson>(); for (final InvoicePayment chargeback : invoicePaymentApi.getChargebacksByPaymentId(paymentId, tenantContext)) { chargebacks.add(new ChargebackJson(payment.getAccountId(), chargeback)); } paymentJson = new PaymentJson(payment, null, // TODO - the keys are really only used for the timeline refunds, chargebacks); } else { paymentJson = new PaymentJson(payment, null); } return Response.status(Status.OK).entity(paymentJson).build(); }
@Override public RefundJson apply(final Refund refund) { UUID kbAccountId = null; if (!AuditLevel.NONE.equals(auditMode.getLevel()) && paymentIdAccountIdMappings.get(refund.getPaymentId()) == null) { try { kbAccountId = paymentApi.getPayment(refund.getPaymentId(), false, tenantContext).getAccountId(); paymentIdAccountIdMappings.put(refund.getPaymentId(), kbAccountId); } catch (final PaymentApiException e) { log.warn("Unable to retrieve payment for id " + refund.getPaymentId()); } } // Cache audit logs per account if (accountsAuditLogs.get().get(kbAccountId) == null) { accountsAuditLogs.get().put(kbAccountId, auditUserApi.getAccountAuditLogs(kbAccountId, auditMode.getLevel(), tenantContext)); } final List<AuditLog> auditLogs = accountsAuditLogs.get().get(kbAccountId) == null ? null : accountsAuditLogs.get().get(kbAccountId).getAuditLogsForRefund(refund.getId()); return new RefundJson(refund, null, auditLogs); } },