use of org.killbill.billing.catalog.api.Currency in project killbill by killbill.
the class TestBlockingCalculator method createRealEvent.
protected BillingEvent createRealEvent(final DateTime effectiveDate, final SubscriptionBase subscription, final SubscriptionBaseTransitionType type) {
try {
final Integer billCycleDay = 1;
final Plan plan = new MockPlan();
final Currency currency = Currency.USD;
final String description = "";
final BillingPeriod billingPeriod = BillingPeriod.MONTHLY;
final Long totalOrdering = 0L;
final DateTimeZone tz = DateTimeZone.UTC;
final PlanPhase planPhase = Mockito.mock(PlanPhase.class);
final InternationalPrice recurringPrice = Mockito.mock(InternationalPrice.class);
Mockito.when(recurringPrice.getPrice(Mockito.<Currency>any())).thenReturn(BigDecimal.TEN);
final Recurring recurring = Mockito.mock(Recurring.class);
Mockito.when(recurring.getRecurringPrice()).thenReturn(recurringPrice);
Mockito.when(planPhase.getRecurring()).thenReturn(recurring);
Mockito.when(planPhase.getUsages()).thenReturn(new DefaultUsage[0]);
final BigDecimal fixedPrice = BigDecimal.TEN;
return new DefaultBillingEvent(subscription, effectiveDate, true, plan, planPhase, fixedPrice, currency, billingPeriod, billCycleDay, description, totalOrdering, type, tz, null, false);
} catch (final CatalogApiException e) {
Assert.fail("", e);
}
throw new IllegalStateException();
}
use of org.killbill.billing.catalog.api.Currency in project killbill by killbill.
the class TestCreditJson method testJson.
@Test(groups = "fast")
public void testJson() throws Exception {
final BigDecimal creditAmount = BigDecimal.TEN;
final Currency currency = Currency.AED;
final String invoiceId = UUID.randomUUID().toString();
final String invoiceNumber = UUID.randomUUID().toString();
final LocalDate effectiveDate = clock.getUTCToday();
final String accountId = UUID.randomUUID().toString();
final List<AuditLogJson> auditLogs = createAuditLogsJson(clock.getUTCNow());
final CreditJson creditJson = new CreditJson(creditAmount, currency.name(), invoiceId, invoiceNumber, effectiveDate, accountId, null, auditLogs);
Assert.assertEquals(creditJson.getEffectiveDate(), effectiveDate);
Assert.assertEquals(creditJson.getCreditAmount(), creditAmount);
Assert.assertEquals(creditJson.getInvoiceId(), invoiceId);
Assert.assertEquals(creditJson.getInvoiceNumber(), invoiceNumber);
Assert.assertEquals(creditJson.getAccountId(), accountId);
final String asJson = mapper.writeValueAsString(creditJson);
final CreditJson fromJson = mapper.readValue(asJson, CreditJson.class);
Assert.assertEquals(fromJson, creditJson);
}
use of org.killbill.billing.catalog.api.Currency in project killbill by killbill.
the class AccountResource method processPayment.
private Response processPayment(final PaymentTransactionJson json, final Account account, final String paymentMethodIdStr, final List<String> paymentControlPluginNames, final List<String> pluginPropertiesString, final UriInfo uriInfo, final CallContext callContext, final HttpServletRequest request) throws PaymentApiException {
verifyNonNullOrEmpty(json, "PaymentTransactionJson body should be specified");
verifyNonNullOrEmpty(json.getTransactionType(), "PaymentTransactionJson transactionType needs to be set", json.getAmount(), "PaymentTransactionJson amount needs to be set");
final Iterable<PluginProperty> pluginProperties = extractPluginProperties(pluginPropertiesString);
final Currency currency = json.getCurrency() == null ? account.getCurrency() : Currency.valueOf(json.getCurrency());
final UUID paymentId = json.getPaymentId() == null ? null : UUID.fromString(json.getPaymentId());
//
// If paymentId was specified, it means we are attempting a payment completion. The preferred way is to use the PaymentResource
// (PUT /1.0/kb/payments/{paymentId}/completeTransaction), but for backward compatibility we still allow the call to proceed
// as long as the request/existing state is healthy (i.e there is a matching PENDING transaction)
//
final UUID paymentMethodId;
if (paymentId != null) {
final Payment initialPayment = paymentApi.getPayment(paymentId, false, false, pluginProperties, callContext);
final PaymentTransaction pendingOrSuccessTransaction = lookupPendingOrSuccessTransaction(initialPayment, json != null ? json.getTransactionId() : null, json != null ? json.getTransactionExternalKey() : null, json != null ? json.getTransactionType() : null);
// If transaction was already completed, return early (See #626)
if (pendingOrSuccessTransaction.getTransactionStatus() == TransactionStatus.SUCCESS) {
return uriBuilder.buildResponse(uriInfo, PaymentResource.class, "getPayment", pendingOrSuccessTransaction.getPaymentId(), request);
}
paymentMethodId = initialPayment.getPaymentMethodId();
} else {
paymentMethodId = paymentMethodIdStr == null ? account.getPaymentMethodId() : UUID.fromString(paymentMethodIdStr);
}
validatePaymentMethodForAccount(account.getId(), paymentMethodId, callContext);
final TransactionType transactionType = TransactionType.valueOf(json.getTransactionType());
final PaymentOptions paymentOptions = createControlPluginApiPaymentOptions(paymentControlPluginNames);
final Payment result;
switch(transactionType) {
case AUTHORIZE:
result = paymentApi.createAuthorizationWithPaymentControl(account, paymentMethodId, paymentId, json.getAmount(), currency, json.getPaymentExternalKey(), json.getTransactionExternalKey(), pluginProperties, paymentOptions, callContext);
break;
case PURCHASE:
result = paymentApi.createPurchaseWithPaymentControl(account, paymentMethodId, paymentId, json.getAmount(), currency, json.getPaymentExternalKey(), json.getTransactionExternalKey(), pluginProperties, paymentOptions, callContext);
break;
case CREDIT:
result = paymentApi.createCreditWithPaymentControl(account, paymentMethodId, paymentId, json.getAmount(), currency, json.getPaymentExternalKey(), json.getTransactionExternalKey(), pluginProperties, paymentOptions, callContext);
break;
default:
return Response.status(Status.PRECONDITION_FAILED).entity("TransactionType " + transactionType + " is not allowed for an account").build();
}
return createPaymentResponse(uriInfo, result, transactionType, json.getTransactionExternalKey(), request);
}
use of org.killbill.billing.catalog.api.Currency in project killbill by killbill.
the class TestInvoiceModuleNoDB method installCurrencyConversionApi.
private void installCurrencyConversionApi() {
final CurrencyConversionApi currencyConversionApi = Mockito.mock(CurrencyConversionApi.class);
final CurrencyConversion currencyConversion = Mockito.mock(CurrencyConversion.class);
final Set<Rate> rates = new HashSet<Rate>();
rates.add(new Rate() {
@Override
public Currency getBaseCurrency() {
return Currency.USD;
}
@Override
public Currency getCurrency() {
return Currency.BRL;
}
@Override
public BigDecimal getValue() {
return new BigDecimal("0.4234");
}
@Override
public DateTime getConversionDate() {
return new DateTime(DateTimeZone.UTC);
}
});
Mockito.when(currencyConversion.getRates()).thenReturn(rates);
try {
Mockito.when(currencyConversionApi.getCurrencyConversion(Mockito.<Currency>any(), Mockito.<DateTime>any())).thenReturn(currencyConversion);
} catch (CurrencyConversionException e) {
throw new RuntimeException(e);
}
bind(CurrencyConversionApi.class).toInstance(currencyConversionApi);
}
use of org.killbill.billing.catalog.api.Currency in project killbill by killbill.
the class TestExternalChargeInvoiceItem method testEquals.
@Test(groups = "fast")
public void testEquals() throws Exception {
final UUID id = UUID.randomUUID();
final UUID invoiceId = UUID.randomUUID();
final UUID accountId = UUID.randomUUID();
final UUID bundleId = UUID.randomUUID();
final String description = UUID.randomUUID().toString();
final LocalDate effectiveDate = clock.getUTCToday();
final BigDecimal amount = BigDecimal.TEN;
final Currency currency = Currency.GBP;
final ExternalChargeInvoiceItem item = new ExternalChargeInvoiceItem(id, invoiceId, accountId, bundleId, description, effectiveDate, effectiveDate, amount, currency, null);
Assert.assertEquals(item.getAccountId(), accountId);
Assert.assertEquals(item.getAmount().compareTo(amount), 0);
Assert.assertEquals(item.getBundleId(), bundleId);
Assert.assertEquals(item.getCurrency(), currency);
Assert.assertEquals(item.getInvoiceItemType(), InvoiceItemType.EXTERNAL_CHARGE);
Assert.assertEquals(item.getDescription(), description);
Assert.assertEquals(item.getStartDate().compareTo(effectiveDate), 0);
Assert.assertEquals(item.getEndDate().compareTo(effectiveDate), 0);
Assert.assertNull(item.getPlanName());
Assert.assertNull(item.getLinkedItemId());
Assert.assertNull(item.getPhaseName());
Assert.assertNull(item.getRate());
Assert.assertNull(item.getSubscriptionId());
Assert.assertNull(item.getItemDetails());
Assert.assertEquals(item, item);
final ExternalChargeInvoiceItem otherItem = new ExternalChargeInvoiceItem(id, invoiceId, UUID.randomUUID(), bundleId, description, effectiveDate, effectiveDate, amount, currency, null);
Assert.assertNotEquals(otherItem, item);
// Check comparison (done by start date)
final ExternalChargeInvoiceItem itemBefore = new ExternalChargeInvoiceItem(id, invoiceId, accountId, bundleId, description, effectiveDate.minusDays(1), effectiveDate.minusDays(1), amount, currency, null);
Assert.assertFalse(itemBefore.matches(item));
final ExternalChargeInvoiceItem itemAfter = new ExternalChargeInvoiceItem(id, invoiceId, accountId, bundleId, description, effectiveDate.plusDays(1), effectiveDate.minusDays(1), amount, currency, null);
Assert.assertFalse(itemAfter.matches(item));
}
Aggregations