@Override public List<Payment> call() throws Exception { return paymentApi.getAccountPayments(accountId, false, false, ImmutableList.<PluginProperty>of(), tenantContext); } };
@TimedResource @GET @Path("/{accountId:" + UUID_PATTERN + "}/" + PAYMENTS) @Produces(APPLICATION_JSON) @ApiOperation(value = "Retrieve account payments", response = PaymentJson.class, responseContainer = "List") @ApiResponses(value = {@ApiResponse(code = 400, message = "Invalid account id supplied")}) public Response getPaymentsForAccount(@PathParam("accountId") final UUID accountId, @QueryParam(QUERY_WITH_ATTEMPTS) @DefaultValue("false") final Boolean withAttempts, @QueryParam(QUERY_WITH_PLUGIN_INFO) @DefaultValue("false") final Boolean withPluginInfo, @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.createTenantContextWithAccountId(accountId, request); final List<Payment> payments = paymentApi.getAccountPayments(accountId, withPluginInfo, withAttempts, pluginProperties, tenantContext); final AccountAuditLogs accountAuditLogs = auditUserApi.getAccountAuditLogs(accountId, auditMode.getLevel(), tenantContext); final List<PaymentJson> result = ImmutableList.copyOf(Iterables.transform(payments, new Function<Payment, PaymentJson>() { @Override public PaymentJson apply(final Payment payment) { return new PaymentJson(payment, accountAuditLogs); } })); return Response.status(Response.Status.OK).entity(result).build(); }
@TimedResource @GET @Path("/{accountId:" + UUID_PATTERN + "}/" + INVOICE_PAYMENTS) @Produces(APPLICATION_JSON) @ApiOperation(value = "Retrieve account invoice payments", response = InvoicePaymentJson.class, responseContainer = "List") @ApiResponses(value = {@ApiResponse(code = 400, message = "Invalid account id supplied"), @ApiResponse(code = 404, message = "Account not found")}) public Response getInvoicePayments(@PathParam("accountId") final UUID accountId, @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, AccountApiException { final Iterable<PluginProperty> pluginProperties = extractPluginProperties(pluginPropertiesString); final TenantContext tenantContext = context.createTenantContextWithAccountId(accountId, request); final Account account = accountUserApi.getAccountById(accountId, tenantContext); final List<Payment> payments = paymentApi.getAccountPayments(account.getId(), withPluginInfo, withAttempts, pluginProperties, tenantContext); final List<InvoicePayment> invoicePayments = invoicePaymentApi.getInvoicePaymentsByAccount(accountId, tenantContext); final AccountAuditLogs accountAuditLogs = auditUserApi.getAccountAuditLogs(accountId, auditMode.getLevel(), tenantContext); final List<InvoicePaymentJson> result = new ArrayList<InvoicePaymentJson>(payments.size()); for (final Payment payment : payments) { final UUID invoiceId = getInvoiceId(invoicePayments, payment); result.add(new InvoicePaymentJson(payment, invoiceId, accountAuditLogs)); } return Response.status(Status.OK).entity(result).build(); }
protected Collection<Payment> getPaymentsWithPluginInfoByAccountId(final UUID accountId, final TenantContext context) throws OSGIServiceNotAvailable { final PaymentApi paymentApi = getPaymentUserApi(); try { return paymentApi.getAccountPayments(accountId, true, false, PLUGIN_PROPERTIES, context); } catch (final PaymentApiException e) { logService.log(LogService.LOG_WARNING, "Error retrieving payments for account id " + accountId, e); throw new OSGIServiceNotAvailable(e); } }
public Payment checkPayment(final UUID accountId, final int paymentOrderingNumber, final CallContext context, final ExpectedPaymentCheck expected) throws PaymentApiException { final List<Payment> payments = paymentApi.getAccountPayments(accountId, false, false, ImmutableList.<PluginProperty>of(), context); Assert.assertEquals(payments.size(), paymentOrderingNumber); final Payment payment = payments.get(paymentOrderingNumber - 1); final PaymentTransaction transaction = getPurchaseTransaction(payment); if (transaction.getTransactionStatus() == TransactionStatus.UNKNOWN) { checkPaymentNoAuditForRuntimeException(accountId, payment, expected); } else { checkPayment(accountId, payment, context, expected); } return payment; }
@Override public Payment answer(final InvocationOnMock invocation) throws Throwable { final List<Payment> payments = paymentApi.getAccountPayments(account.getId(), false, false, ImmutableList.<PluginProperty>of(), (TenantContext) invocation.getArguments()[6]); final Payment payment; if (payments == null || payments.isEmpty()) { payment = buildPayment(account.getId(), account.getPaymentMethodId(), (Currency) invocation.getArguments()[3], killbillApi); } else { payment = payments.get(payments.size() - 1); } final PaymentTransaction chargeback = buildPaymentTransaction(payment, TransactionType.CHARGEBACK, (Currency) invocation.getArguments()[3]); Mockito.when(chargeback.getTransactionStatus()).thenReturn(TransactionStatus.SUCCESS); return payment; } });
public static Payment buildPayment(final UUID accountId, final UUID paymentMethodId, final UUID paymentId, final Currency currency, final String paymentExternalKey, @Nullable final OSGIKillbill killbillApi) throws PaymentApiException { final Payment payment = Mockito.mock(Payment.class); Mockito.when(payment.getId()).thenReturn(paymentId); Mockito.when(payment.getExternalKey()).thenReturn(paymentExternalKey); Mockito.when(payment.getAccountId()).thenReturn(accountId); Mockito.when(payment.getPaymentMethodId()).thenReturn(paymentMethodId); Mockito.when(payment.getPaymentNumber()).thenReturn(1); Mockito.when(payment.getCapturedAmount()).thenReturn(new BigDecimal("199999")); Mockito.when(payment.getRefundedAmount()).thenReturn(new BigDecimal("199998")); Mockito.when(payment.getCurrency()).thenReturn(currency); Mockito.when(payment.getTransactions()).thenReturn(new LinkedList<PaymentTransaction>()); Mockito.when(payment.getCreatedDate()).thenReturn(new DateTime(2016, 1, 22, 10, 56, 56, DateTimeZone.UTC)); if (killbillApi != null) { Mockito.when(killbillApi.getPaymentApi().getPayment(Mockito.eq(payment.getId()), Mockito.anyBoolean(), Mockito.anyBoolean(), Mockito.<Iterable<PluginProperty>>any(), Mockito.<TenantContext>any())).thenReturn(payment); final List<Payment> payments = MoreObjects.firstNonNull(killbillApi.getPaymentApi().getAccountPayments(accountId, false, false, ImmutableList.<PluginProperty>of(), Mockito.mock(TenantContext.class)), new LinkedList<Payment>()); payments.add(payment); Mockito.when(killbillApi.getPaymentApi().getAccountPayments(Mockito.eq(accountId), Mockito.anyBoolean(), Mockito.anyBoolean(), Mockito.<Iterable<PluginProperty>>any(), Mockito.<TenantContext>any())).thenReturn(payments); } return payment; }
@Override public Payment answer(final InvocationOnMock invocation) throws Throwable { Payment payment = null; PaymentTransaction paymentTransaction = null; final UUID kbPaymentTransactionId = (UUID) invocation.getArguments()[1]; for (final Payment p : paymentApi.getAccountPayments(account.getId(), false, false, ImmutableList.<PluginProperty>of(), (TenantContext) invocation.getArguments()[3])) { for (final PaymentTransaction t : p.getTransactions()) { if (kbPaymentTransactionId.equals(t.getId())) { payment = p; paymentTransaction = t; break; } } } Assert.assertNotNull(payment); Assert.assertNotNull(paymentTransaction); Assert.assertEquals(paymentTransaction.getTransactionStatus(), TransactionStatus.PENDING); final Boolean success = (Boolean) invocation.getArguments()[2]; Mockito.when(paymentTransaction.getTransactionStatus()).thenReturn(success ? TransactionStatus.SUCCESS : TransactionStatus.PAYMENT_FAILURE); final PaymentTransactionInfoPlugin paymentInfoPlugin = Mockito.mockingDetails(paymentTransaction.getPaymentInfoPlugin()).isMock() ? paymentTransaction.getPaymentInfoPlugin() : Mockito.spy(paymentTransaction.getPaymentInfoPlugin()); Mockito.when(paymentInfoPlugin.getStatus()).thenReturn(success ? PaymentPluginStatus.PROCESSED : PaymentPluginStatus.ERROR); Mockito.when(paymentTransaction.getPaymentInfoPlugin()).thenReturn(paymentInfoPlugin); return payment; } });
assertTrue(accountBalance1.compareTo(new BigDecimal("249.95")) == 0); final List<Payment> payments = paymentApi.getAccountPayments(account.getId(), false, false, ImmutableList.<PluginProperty>of(), callContext); assertEquals(payments.size(), 1); assertEquals(payments.get(0).getPurchasedAmount().compareTo(BigDecimal.ZERO), 0); assertTrue(accountBalance2.compareTo(BigDecimal.ZERO) == 0); final List<Payment> payments2 = paymentApi.getAccountPayments(account.getId(), false, false, ImmutableList.<PluginProperty>of(), callContext); assertEquals(payments2.size(), 1); assertEquals(payments2.get(0).getTransactions().size(), 2);
final List<Payment> payments = paymentApi.getAccountPayments(account.getId(), false, false, ImmutableList.<PluginProperty>of(), callContext); final ExpectedPaymentCheck expectedPaymentCheck = new ExpectedPaymentCheck(clock.getUTCNow().toLocalDate(), new BigDecimal("2399.95"), TransactionStatus.SUCCESS, invoice1.getId(), Currency.USD); final Payment payment1 = payments.get(0);
final List<Payment> payments = paymentApi.getAccountPayments(account.getId(), false, false, ImmutableList.<PluginProperty>of(), callContext); final ExpectedPaymentCheck expectedPaymentCheck = new ExpectedPaymentCheck(clock.getUTCNow().toLocalDate(), new BigDecimal("2399.95"), TransactionStatus.SUCCESS, invoice1.getId(), Currency.USD); final Payment payment1 = payments.get(0);
@Test(groups = "slow") public void testWithWrittenOffInvoice() throws Exception { clock.setTime(new DateTime(2012, 5, 1, 0, 3, 42, 0)); // Put the account in AUTO_PAY_OFF to make sure payment system does not try to pay initial invoices add_AUTO_PAY_OFF_Tag(account.getId(), ObjectType.ACCOUNT); // set next invoice to fail and create network final DefaultEntitlement bpEntitlement = createBaseEntitlementAndCheckForCompletion(account.getId(), "externalKey", productName, ProductCategory.BASE, term, NextEvent.CREATE, NextEvent.BLOCK, NextEvent.INVOICE); assertNotNull(bpEntitlement); List<Invoice> invoices = invoiceApi.getInvoicesByAccount(account.getId(), false, false, callContext); assertEquals(invoices.size(), 1); busHandler.pushExpectedEvents(NextEvent.PHASE, NextEvent.INVOICE); clock.addDays(31); assertListenerStatus(); invoices = invoiceApi.getInvoicesByAccount(account.getId(), false, false, callContext); assertEquals(invoices.size(), 2); // Tag non $0 invoice with WRITTEN_OFF and remove AUTO_PAY_OFF => System should still not pay anything add_WRITTEN_OFF_Tag(invoices.get(1).getId(), ObjectType.INVOICE); remove_AUTO_PAY_OFF_Tag(account.getId(), ObjectType.ACCOUNT); assertListenerStatus(); List<Payment> accountPayments = paymentApi.getAccountPayments(account.getId(), false, false, ImmutableList.<PluginProperty>of(), callContext); assertEquals(accountPayments.size(), 0); }
final List<Payment> accountPayments = paymentApi.getAccountPayments(account.getId(), false, false, ImmutableList.<PluginProperty>of(), callContext); assertEquals(accountPayments.size(), 1); final Payment payment = accountPayments.get(0);
Assert.assertEquals(invoiceUserApi.getAccountBalance(account.getId(), callContext).compareTo(invoice2.getBalance()), 0); final List<Payment> payments = paymentApi.getAccountPayments(account.getId(), false, false, ImmutableList.<PluginProperty>of(), callContext); Assert.assertEquals(payments.size(), 1); Assert.assertEquals(payments.get(0).getTransactions().size(), 1);
Assert.assertEquals(paymentApi.getAccountPayments(account.getId(), false, false, ImmutableList.<PluginProperty>of(), callContext).size(), 0); Assert.assertEquals(invoice2.getBalance().compareTo(new BigDecimal("249.95")), 0); Assert.assertEquals(invoiceUserApi.getAccountBalance(account.getId(), callContext).compareTo(invoice2.getBalance()), 0);
assertTrue(accountBalance.compareTo(BigDecimal.ZERO) == 0); final List<Payment> payments = paymentApi.getAccountPayments(account.getId(), false, false, ImmutableList.<PluginProperty>of(), callContext); assertEquals(payments.size(), 1);
assertEquals(parentInvoice.getCreditedAmount().compareTo(BigDecimal.ZERO), 0); final List<Payment> accountPayments = paymentApi.getAccountPayments(parentAccount.getId(), false, false, null, callContext); assertEquals(accountPayments.size(), 1); assertEquals(accountPayments.get(0).getPurchasedAmount().setScale(2).compareTo(BigDecimal.valueOf(19.95)), 0);
assertTrue(accountBalance3.compareTo(BigDecimal.ZERO) == 0); final List<Payment> payments = paymentApi.getAccountPayments(account.getId(), false, false, ImmutableList.<PluginProperty>of(), callContext); assertEquals(payments.size(), 1);
assertEquals(parentInvoice.getChargedAmount().compareTo(BigDecimal.valueOf(29.95)), 0); final List<Payment> accountPayments = paymentApi.getAccountPayments(parentAccount.getId(), false, false, null, callContext); assertEquals(accountPayments.size(), 1); assertEquals(accountPayments.get(0).getPurchasedAmount().setScale(2).compareTo(BigDecimal.valueOf(29.95)), 0);
assertListenerStatus(); final List<Payment> accountPayments = paymentApi.getAccountPayments(account.getId(), false, false, null, callContext); assertEquals(accountPayments.size(), 3); assertEquals(accountPayments.get(2).getPurchasedAmount(), new BigDecimal("10.00"));