use of java.math.BigDecimal in project killbill by killbill.
the class TestPaymentApiNoDB method testSimplePayment.
private void testSimplePayment(final BigDecimal invoiceAmount, final BigDecimal requestedAmount, final BigDecimal expectedAmount) throws Exception {
final LocalDate now = clock.getUTCToday();
final Invoice invoice = testHelper.createTestInvoice(account, now, Currency.USD);
final UUID subscriptionId = UUID.randomUUID();
final UUID bundleId = UUID.randomUUID();
invoice.addInvoiceItem(new MockRecurringInvoiceItem(invoice.getId(), account.getId(), subscriptionId, bundleId, "test plan", "test phase", null, now, now.plusMonths(1), invoiceAmount, new BigDecimal("1.0"), Currency.USD));
try {
final List<PluginProperty> properties = new ArrayList<PluginProperty>();
final PluginProperty prop1 = new PluginProperty(InvoicePaymentControlPluginApi.PROP_IPCD_INVOICE_ID, invoice.getId().toString(), false);
properties.add(prop1);
final Payment paymentInfo = paymentApi.createPurchaseWithPaymentControl(account, account.getPaymentMethodId(), null, requestedAmount, account.getCurrency(), invoice.getId().toString(), UUID.randomUUID().toString(), properties, PAYMENT_OPTIONS, callContext);
if (expectedAmount == null) {
fail("Expected to fail because requested amount > invoice amount");
}
assertNotNull(paymentInfo.getId());
assertTrue(paymentInfo.getPurchasedAmount().compareTo(expectedAmount) == 0);
assertNotNull(paymentInfo.getPaymentNumber());
assertEquals(paymentInfo.getExternalKey(), invoice.getId().toString());
assertEquals(paymentInfo.getCurrency(), Currency.USD);
assertTrue(paymentInfo.getTransactions().get(0).getAmount().compareTo(expectedAmount) == 0);
assertEquals(paymentInfo.getTransactions().get(0).getCurrency(), Currency.USD);
assertEquals(paymentInfo.getTransactions().get(0).getPaymentId(), paymentInfo.getId());
assertEquals(paymentInfo.getTransactions().get(0).getTransactionType(), TransactionType.PURCHASE);
assertEquals(paymentInfo.getTransactions().get(0).getTransactionStatus(), TransactionStatus.SUCCESS);
} catch (final PaymentApiException e) {
if (expectedAmount != null) {
fail("Failed to create payment", e);
} else {
log.info(e.getMessage());
}
}
}
use of java.math.BigDecimal in project killbill by killbill.
the class TestPaymentApiNoDB method testSimpleInvoicePaymentWithNoAmount.
@Test(groups = "fast")
public void testSimpleInvoicePaymentWithNoAmount() throws Exception {
final BigDecimal invoiceAmount = new BigDecimal("10.0011");
final BigDecimal requestedAmount = null;
final BigDecimal expectedAmount = null;
testSimplePayment(invoiceAmount, requestedAmount, expectedAmount);
}
use of java.math.BigDecimal in project killbill by killbill.
the class TestPaymentApiNoDB method testSimpleInvoicePaymentWithInvalidAmount.
@Test(groups = "fast")
public void testSimpleInvoicePaymentWithInvalidAmount() throws Exception {
final BigDecimal invoiceAmount = BigDecimal.ONE;
final BigDecimal requestedAmount = BigDecimal.TEN;
final BigDecimal expectedAmount = null;
testSimplePayment(invoiceAmount, requestedAmount, expectedAmount);
}
use of java.math.BigDecimal in project KJFrameForAndroid by kymjs.
the class ImageUtils method reduce.
/**
* 压缩图片
*
* @param bitmap 源图片
* @param width 想要的宽度
* @param height 想要的高度
* @param isAdjust 是否自动调整尺寸, true图片就不会拉伸,false严格按照你的尺寸压缩
* @return Bitmap
*/
public static Bitmap reduce(Bitmap bitmap, int width, int height, boolean isAdjust) {
// 如果想要的宽度和高度都比源图片小,就不压缩了,直接返回原图
if (bitmap.getWidth() < width && bitmap.getHeight() < height) {
return bitmap;
}
if (width == 0 && height == 0) {
width = bitmap.getWidth();
height = bitmap.getHeight();
}
// 根据想要的尺寸精确计算压缩比例, 方法详解:public BigDecimal divide(BigDecimal divisor, int scale, int
// roundingMode);
// scale表示要保留的小数位, roundingMode表示如何处理多余的小数位,BigDecimal.ROUND_DOWN表示自动舍弃
float sx = new BigDecimal(width).divide(new BigDecimal(bitmap.getWidth()), 4, BigDecimal.ROUND_DOWN).floatValue();
float sy = new BigDecimal(height).divide(new BigDecimal(bitmap.getHeight()), 4, BigDecimal.ROUND_DOWN).floatValue();
if (isAdjust) {
// 如果想自动调整比例,不至于图片会拉伸
sx = (sx < sy ? sx : sy);
// 哪个比例小一点,就用哪个比例
sy = sx;
}
Matrix matrix = new Matrix();
// 调用api中的方法进行压缩,就大功告成了
matrix.postScale(sx, sy);
return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
}
use of java.math.BigDecimal in project disconf by knightliao.
the class MaxValidatorForDouble method isValid.
public boolean isValid(Double value, ConstraintValidatorContext constraintValidatorContext) {
// null values are valid
if (value == null) {
return true;
}
BigDecimal premium = BigDecimal.valueOf(value);
BigDecimal netToCompany = BigDecimal.valueOf(maxValue);
BigDecimal commission = premium.subtract(netToCompany);
return commission.compareTo(BigDecimal.ZERO) <= 0;
}
Aggregations