use of com.stripe.model.Charge in project stripe-java by stripe.
the class RefundTest method testChargeRefund.
@Test
public void testChargeRefund() throws StripeException {
Charge createdCharge = Charge.create(defaultChargeParams);
Charge refundedCharge = createdCharge.refund();
assertTrue(refundedCharge.getRefunded());
ChargeRefundCollection refunds = refundedCharge.getRefunds();
assertTrue(refunds.getData() instanceof List);
assertEquals(1, refunds.getData().size());
assertTrue(refunds.getData().get(0) instanceof Refund);
}
use of com.stripe.model.Charge in project alf.io by alfio-event.
the class BaseStripeManager method getInfo.
Optional<PaymentInformation> getInfo(Transaction transaction, PurchaseContext purchaseContext) {
try {
Optional<RequestOptions> requestOptionsOptional = options(purchaseContext);
if (requestOptionsOptional.isPresent()) {
RequestOptions options = requestOptionsOptional.get();
Charge charge = Charge.retrieve(transaction.getTransactionId(), options);
String paidAmount = MonetaryUtil.formatCents(charge.getAmount(), charge.getCurrency());
String refundedAmount = MonetaryUtil.formatCents(charge.getAmountRefunded(), charge.getCurrency());
List<BalanceTransaction.Fee> fees = retrieveBalanceTransaction(charge.getBalanceTransaction(), options).getFeeDetails();
return Optional.of(new PaymentInformation(paidAmount, refundedAmount, getFeeAmount(fees, "stripe_fee"), getFeeAmount(fees, "application_fee")));
}
return Optional.empty();
} catch (StripeException e) {
return Optional.empty();
}
}
use of com.stripe.model.Charge in project alf.io by alfio-event.
the class StripeManagerTest method successFlow.
@Test
public void successFlow() {
BaseStripeManager baseStripeManager = new BaseStripeManager(configurationManager, configurationRepository, ticketRepository, mock(Environment.class)) {
@Override
protected Optional<Charge> charge(PaymentSpecification spec, Map<String, Object> chargeParams) {
return Optional.of(new Charge() {
{
setId(paymentId);
setDescription("description");
}
});
}
};
StripeCreditCardManager stripeCreditCardManager = new StripeCreditCardManager(transactionRepository, baseStripeManager, TestUtil.clockProvider());
PaymentSpecification spec = new PaymentSpecification("", new StripeCreditCardToken(""), 100, event, "", customerName);
PaymentResult result = stripeCreditCardManager.doPayment(spec);
assertEquals(result, PaymentResult.successful(paymentId));
}
use of com.stripe.model.Charge in project alf.io by alfio-event.
the class StripeManagerTest method internalError.
@Test
public void internalError() {
BaseStripeManager baseStripeManager = new BaseStripeManager(configurationManager, configurationRepository, ticketRepository, mock(Environment.class)) {
@Override
protected Optional<Charge> charge(PaymentSpecification spec, Map<String, Object> chargeParams) {
return Optional.of(new Charge() {
{
setId(paymentId);
setDescription("description");
}
});
}
};
StripeCreditCardManager stripeCreditCardManager = new StripeCreditCardManager(transactionRepository, baseStripeManager, TestUtil.clockProvider());
when(event.getCurrency()).thenReturn("CHF");
when(transactionRepository.insert(anyString(), isNull(), anyString(), any(ZonedDateTime.class), anyInt(), eq("CHF"), anyString(), anyString(), anyLong(), anyLong(), eq(Transaction.Status.COMPLETE), anyMap())).thenThrow(new NullPointerException());
PaymentSpecification spec = new PaymentSpecification("", new StripeCreditCardToken(""), 100, event, "", customerName);
Assertions.assertThrows(IllegalStateException.class, () -> stripeCreditCardManager.doPayment(spec));
}
use of com.stripe.model.Charge in project alf.io by alfio-event.
the class StripeManager method getInfo.
Optional<PaymentInformation> getInfo(Transaction transaction, Event event) {
try {
Optional<RequestOptions> requestOptionsOptional = options(event);
if (requestOptionsOptional.isPresent()) {
RequestOptions options = requestOptionsOptional.get();
Charge charge = Charge.retrieve(transaction.getTransactionId(), options);
String paidAmount = MonetaryUtil.formatCents(charge.getAmount());
String refundedAmount = MonetaryUtil.formatCents(charge.getAmountRefunded());
List<Fee> fees = retrieveBalanceTransaction(charge.getBalanceTransaction(), options).getFeeDetails();
return Optional.of(new PaymentInformation(paidAmount, refundedAmount, getFeeAmount(fees, "stripe_fee"), getFeeAmount(fees, "application_fee")));
}
return Optional.empty();
} catch (StripeException e) {
return Optional.empty();
}
}
Aggregations