Search in sources :

Example 6 with AuditLog

use of org.killbill.billing.client.model.AuditLog in project killbill by killbill.

the class TestAccountTimeline method verifyPayments.

private void verifyPayments(final UUID accountId, final DateTime startTime, final DateTime endTime, final BigDecimal refundAmount, final BigDecimal chargebackAmount) throws Exception {
    for (final AuditLevel auditLevel : AuditLevel.values()) {
        final AccountTimeline timeline = getAccountTimeline(accountId, auditLevel);
        Assert.assertEquals(timeline.getPayments().size(), 1);
        final InvoicePayment payment = timeline.getPayments().get(0);
        // Verify payments
        final List<PaymentTransaction> purchaseTransactions = getPaymentTransactions(timeline.getPayments(), TransactionType.PURCHASE.toString());
        Assert.assertEquals(purchaseTransactions.size(), 1);
        final PaymentTransaction purchaseTransaction = purchaseTransactions.get(0);
        // Verify refunds
        final List<PaymentTransaction> refundTransactions = getPaymentTransactions(timeline.getPayments(), TransactionType.REFUND.toString());
        Assert.assertEquals(refundTransactions.size(), 1);
        final PaymentTransaction refundTransaction = refundTransactions.get(0);
        Assert.assertEquals(refundTransaction.getPaymentId(), payment.getPaymentId());
        Assert.assertEquals(refundTransaction.getAmount().compareTo(refundAmount), 0);
        final List<PaymentTransaction> chargebackTransactions = getPaymentTransactions(timeline.getPayments(), TransactionType.CHARGEBACK.toString());
        Assert.assertEquals(chargebackTransactions.size(), 1);
        final PaymentTransaction chargebackTransaction = chargebackTransactions.get(0);
        Assert.assertEquals(chargebackTransaction.getPaymentId(), payment.getPaymentId());
        Assert.assertEquals(chargebackTransaction.getAmount().compareTo(chargebackAmount), 0);
        // Verify audits
        final List<AuditLog> paymentAuditLogs = purchaseTransaction.getAuditLogs();
        final List<AuditLog> refundAuditLogs = refundTransaction.getAuditLogs();
        final List<AuditLog> chargebackAuditLogs = chargebackTransaction.getAuditLogs();
        if (AuditLevel.NONE.equals(auditLevel)) {
            // Audits for payments
            Assert.assertEquals(paymentAuditLogs.size(), 0);
            // Audits for refunds
            Assert.assertEquals(refundAuditLogs.size(), 0);
            // Audits for chargebacks
            Assert.assertEquals(chargebackAuditLogs.size(), 0);
        } else if (AuditLevel.MINIMAL.equals(auditLevel)) {
            // Audits for payments
            Assert.assertEquals(paymentAuditLogs.size(), 1);
            verifyAuditLog(paymentAuditLogs.get(0), ChangeType.INSERT, null, null, PAYMENT_REQUEST_PROCESSOR, startTime, endTime);
            // Audits for refunds
            Assert.assertEquals(refundAuditLogs.size(), 1);
            verifyAuditLog(refundAuditLogs.get(0), ChangeType.INSERT, reason, comment, createdBy, startTime, endTime);
            // Audits for chargebacks
            Assert.assertEquals(chargebackAuditLogs.size(), 1);
            verifyAuditLog(chargebackAuditLogs.get(0), ChangeType.INSERT, reason, comment, createdBy, startTime, endTime);
        } else {
            // Audits for payments
            Assert.assertEquals(paymentAuditLogs.size(), 2);
            verifyAuditLog(paymentAuditLogs.get(0), ChangeType.INSERT, null, null, PAYMENT_REQUEST_PROCESSOR, startTime, endTime);
            verifyAuditLog(paymentAuditLogs.get(1), ChangeType.UPDATE, null, null, PAYMENT_REQUEST_PROCESSOR, startTime, endTime);
            // Audits for refunds
            Assert.assertEquals(refundAuditLogs.size(), 2);
            verifyAuditLog(refundAuditLogs.get(0), ChangeType.INSERT, reason, comment, createdBy, startTime, endTime);
            verifyAuditLog(refundAuditLogs.get(1), ChangeType.UPDATE, reason, comment, createdBy, startTime, endTime);
            // Audits for chargebacks
            Assert.assertEquals(chargebackAuditLogs.size(), 2);
            verifyAuditLog(chargebackAuditLogs.get(0), ChangeType.INSERT, reason, comment, createdBy, startTime, endTime);
            verifyAuditLog(chargebackAuditLogs.get(1), ChangeType.UPDATE, reason, comment, createdBy, startTime, endTime);
        }
    }
}
Also used : PaymentTransaction(org.killbill.billing.client.model.PaymentTransaction) InvoicePaymentTransaction(org.killbill.billing.client.model.InvoicePaymentTransaction) InvoicePayment(org.killbill.billing.client.model.InvoicePayment) AuditLevel(org.killbill.billing.util.api.AuditLevel) AccountTimeline(org.killbill.billing.client.model.AccountTimeline) AuditLog(org.killbill.billing.client.model.AuditLog)

Example 7 with AuditLog

use of org.killbill.billing.client.model.AuditLog in project killbill by killbill.

the class TestAccount method testTags.

@Test(groups = "slow", description = "Add tags to account")
public void testTags() throws Exception {
    final Account input = createAccount();
    // Use tag definition for AUTO_PAY_OFF
    final UUID autoPayOffId = new UUID(0, 1);
    // Add a tag
    killBillClient.createAccountTag(input.getAccountId(), autoPayOffId, requestOptions);
    // Retrieves all tags
    final List<Tag> tags1 = killBillClient.getAccountTags(input.getAccountId(), AuditLevel.FULL, requestOptions);
    Assert.assertEquals(tags1.size(), 1);
    Assert.assertEquals(tags1.get(0).getTagDefinitionId(), autoPayOffId);
    // Verify adding the same tag a second time doesn't do anything
    killBillClient.createAccountTag(input.getAccountId(), autoPayOffId, requestOptions);
    // Retrieves all tags again
    killBillClient.createAccountTag(input.getAccountId(), autoPayOffId, requestOptions);
    final List<Tag> tags2 = killBillClient.getAccountTags(input.getAccountId(), AuditLevel.FULL, requestOptions);
    Assert.assertEquals(tags2, tags1);
    // Verify audit logs
    Assert.assertEquals(tags2.get(0).getAuditLogs().size(), 1);
    final AuditLog auditLogJson = tags2.get(0).getAuditLogs().get(0);
    Assert.assertEquals(auditLogJson.getChangeType(), "INSERT");
    Assert.assertEquals(auditLogJson.getChangedBy(), createdBy);
    Assert.assertEquals(auditLogJson.getReasonCode(), reason);
    Assert.assertEquals(auditLogJson.getComments(), comment);
    Assert.assertNotNull(auditLogJson.getChangeDate());
    Assert.assertNotNull(auditLogJson.getUserToken());
}
Also used : Account(org.killbill.billing.client.model.Account) Tag(org.killbill.billing.client.model.Tag) UUID(java.util.UUID) AuditLog(org.killbill.billing.client.model.AuditLog) Test(org.testng.annotations.Test)

Aggregations

AuditLog (org.killbill.billing.client.model.AuditLog)7 AccountTimeline (org.killbill.billing.client.model.AccountTimeline)4 AuditLevel (org.killbill.billing.util.api.AuditLevel)4 Account (org.killbill.billing.client.model.Account)3 Test (org.testng.annotations.Test)3 Invoice (org.killbill.billing.client.model.Invoice)2 BigDecimal (java.math.BigDecimal)1 UUID (java.util.UUID)1 DateTime (org.joda.time.DateTime)1 LocalDate (org.joda.time.LocalDate)1 Credit (org.killbill.billing.client.model.Credit)1 InvoiceDryRun (org.killbill.billing.client.model.InvoiceDryRun)1 InvoiceItem (org.killbill.billing.client.model.InvoiceItem)1 InvoicePayment (org.killbill.billing.client.model.InvoicePayment)1 InvoicePaymentTransaction (org.killbill.billing.client.model.InvoicePaymentTransaction)1 PaymentTransaction (org.killbill.billing.client.model.PaymentTransaction)1 Tag (org.killbill.billing.client.model.Tag)1