Skip to content

Commit

Permalink
invoice: send InvoiceAdjustmentEvent from InvoiceDao as needed
Browse files Browse the repository at this point in the history
Each time we modify an invoice (adjustment, credit, chargeback, refund, ...),
send an InvoiceAdjustmentEvent on the bus.

This is needed for overdue to refresh its state and for Analytics.

Signed-off-by: Pierre-Alexandre Meyer <pierre@ning.com>
  • Loading branch information
Pierre-Alexandre Meyer committed Aug 31, 2012
1 parent 9a80396 commit 5274849
Show file tree
Hide file tree
Showing 12 changed files with 568 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright 2010-2012 Ning, Inc.
*
* Ning licenses this file to you under the Apache License, version 2.0
* (the "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/

package com.ning.billing.invoice.api;

import java.util.UUID;

public interface InvoiceAdjustmentEvent extends InvoiceEvent {

public UUID getInvoiceId();
}
1 change: 1 addition & 0 deletions api/src/main/java/com/ning/billing/util/bus/BusEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public enum BusEventType {
BUNDLE_REPAIR,
INVOICE_EMPTY,
INVOICE_CREATION,
INVOICE_ADJUSTMENT,
PAYMENT_INFO,
PAYMENT_ERROR,
CONTROL_TAG_CREATION,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,18 @@
import com.ning.billing.entitlement.api.user.Subscription;
import com.ning.billing.entitlement.api.user.SubscriptionData;
import com.ning.billing.invoice.api.Invoice;
import com.ning.billing.invoice.api.InvoiceApiException;
import com.ning.billing.invoice.api.InvoiceItem;
import com.ning.billing.invoice.api.InvoicePayment;
import com.ning.billing.invoice.api.InvoicePaymentApi;
import com.ning.billing.invoice.api.InvoiceService;
import com.ning.billing.invoice.api.InvoiceUserApi;
import com.ning.billing.invoice.model.InvoicingConfiguration;
import com.ning.billing.junction.plumbing.api.BlockingSubscription;
import com.ning.billing.mock.MockAccountBuilder;
import com.ning.billing.mock.api.MockBillCycleDay;
import com.ning.billing.overdue.wrapper.OverdueWrapperFactory;
import com.ning.billing.payment.api.Payment;
import com.ning.billing.payment.api.PaymentApi;
import com.ning.billing.payment.api.PaymentApiException;
import com.ning.billing.payment.api.PaymentMethodPlugin;
Expand Down Expand Up @@ -148,6 +152,9 @@ public class TestIntegrationBase extends BeatrixTestSuiteWithEmbeddedDB implemen
@Inject
protected InvoiceUserApi invoiceUserApi;

@Inject
protected InvoicePaymentApi invoicePaymentApi;

@Inject
protected PaymentApi paymentApi;

Expand Down Expand Up @@ -371,6 +378,48 @@ public Void apply(@Nullable final Void input) {
}, events);
}

protected void createExternalPaymentAndCheckForCompletion(final Account account, final Invoice invoice, final NextEvent... events) {
doCallAndCheckForCompletion(new Function<Void, Void>() {
@Override
public Void apply(@Nullable final Void input) {
try {
paymentApi.createExternalPayment(account, invoice.getId(), invoice.getBalance(), new DefaultCallContext("test", null, null, clock));
} catch (PaymentApiException e) {
fail(e.toString());
}
return null;
}
}, events);
}

protected void refundPaymentAndCheckForCompletion(final Account account, final Payment payment, final NextEvent... events) {
doCallAndCheckForCompletion(new Function<Void, Void>() {
@Override
public Void apply(@Nullable final Void input) {
try {
paymentApi.createRefund(account, payment.getId(), payment.getPaidAmount(), new DefaultCallContext("test", null, null, clock));
} catch (PaymentApiException e) {
fail(e.toString());
}
return null;
}
}, events);
}

protected void createChargeBackAndCheckForCompletion(final InvoicePayment payment, final NextEvent... events) {
doCallAndCheckForCompletion(new Function<Void, Void>() {
@Override
public Void apply(@Nullable final Void input) {
try {
invoicePaymentApi.createChargeback(payment.getId(), payment.getAmount(), new DefaultCallContext("test", null, null, clock));
} catch (InvoiceApiException e) {
fail(e.toString());
}
return null;
}
}, events);
}

protected Subscription createSubscriptionAndCheckForCompletion(final UUID bundleId,
final String productName,
final ProductCategory productCategory,
Expand Down Expand Up @@ -433,6 +482,36 @@ public Subscription apply(@Nullable final Void dontcare) {
}, events);
}

protected void fullyAdjustInvoiceAndCheckForCompletion(final Account account, final Invoice invoice, final NextEvent... events) {
doCallAndCheckForCompletion(new Function<Void, Void>() {
@Override
public Void apply(@Nullable final Void input) {
try {
invoiceUserApi.insertCreditForInvoice(account.getId(), invoice.getId(), invoice.getBalance(), invoice.getInvoiceDate(),
account.getCurrency(), new DefaultCallContext("test", null, null, clock));
} catch (InvoiceApiException e) {
fail(e.toString());
}
return null;
}
}, events);
}

protected void fullyAdjustInvoiceItemAndCheckForCompletion(final Account account, final Invoice invoice, final int itemNb, final NextEvent... events) {
doCallAndCheckForCompletion(new Function<Void, Void>() {
@Override
public Void apply(@Nullable final Void input) {
try {
invoiceUserApi.insertInvoiceItemAdjustment(account.getId(), invoice.getId(), invoice.getInvoiceItems().get(itemNb - 1).getId(),
invoice.getInvoiceDate(), new DefaultCallContext("test", null, null, clock));
} catch (InvoiceApiException e) {
fail(e.toString());
}
return null;
}
}, events);
}

private <T> T doCallAndCheckForCompletion(Function<Void, T> f, final NextEvent... events) {

Joiner joiner = Joiner.on(", ");
Expand Down
Loading

0 comments on commit 5274849

Please sign in to comment.