use of com.stripe.model.Refund in project alf.io by alfio-event.
the class BaseStripeManager method refund.
// https://stripe.com/docs/api#create_refund
boolean refund(Transaction transaction, PurchaseContext purchaseContext, Integer amountToRefund) {
Optional<Integer> amount = Optional.ofNullable(amountToRefund);
String chargeId = transaction.getTransactionId();
try {
String amountOrFull = amount.map(p -> MonetaryUtil.formatCents(p, transaction.getCurrency())).orElse("full");
log.info("Stripe: trying to do a refund for payment {} with amount: {}", chargeId, amountOrFull);
Map<String, Object> params = new HashMap<>();
params.put("charge", chargeId);
amount.ifPresent(a -> params.put("amount", a));
if (transaction.getPlatformFee() > 0 && isConnectEnabled(new PaymentContext(purchaseContext))) {
params.put("refund_application_fee", true);
}
Optional<RequestOptions> requestOptionsOptional = options(purchaseContext);
if (requestOptionsOptional.isPresent()) {
RequestOptions options = requestOptionsOptional.get();
Refund r = Refund.create(params, options);
boolean pending = PENDING.equals(r.getStatus());
if (SUCCEEDED.equals(r.getStatus()) || pending) {
log.info("Stripe: refund for payment {} {} for amount: {}", chargeId, pending ? "registered" : "executed with success", amountOrFull);
return true;
} else {
log.warn("Stripe: was not able to refund payment with id {}, returned status is not 'succeded' but {}", chargeId, r.getStatus());
return false;
}
}
return false;
} catch (StripeException e) {
log.warn("Stripe: was not able to refund payment with id " + chargeId, e);
return false;
}
}
use of com.stripe.model.Refund in project stripe-java by stripe.
the class RefundTest method testChargeRefundListAndRetrievePerCallAPIKey.
@Test
public void testChargeRefundListAndRetrievePerCallAPIKey() throws StripeException {
Charge ch = Charge.create(defaultChargeParams);
ch = ch.refund();
Map<String, Object> listParams = new HashMap<String, Object>();
listParams.put("count", 1);
Refund created = ch.getRefunds().all(listParams, Stripe.apiKey).getData().get(0);
Refund retrieved = ch.getRefunds().retrieve(created.getId(), Stripe.apiKey);
assertEquals(created.getId(), retrieved.getId());
}
use of com.stripe.model.Refund in project stripe-java by stripe.
the class RefundTest method testChargeRefundCreate.
@Test
public void testChargeRefundCreate() throws StripeException {
Charge ch = Charge.create(defaultChargeParams);
Map<String, Object> params = new HashMap<String, Object>();
params.put("amount", 10);
ChargeRefundCollection refunds = ch.getRefunds();
Refund created = refunds.create(params);
Refund retrieved = ch.getRefunds().retrieve(created.getId());
assertEquals(created.getId(), retrieved.getId());
}
use of com.stripe.model.Refund in project stripe-java by stripe.
the class RefundTest method testChargeRefundListAndRetrieve.
@Test
public void testChargeRefundListAndRetrieve() throws StripeException {
Charge ch = Charge.create(defaultChargeParams);
ch = ch.refund();
Map<String, Object> listParams = new HashMap<String, Object>();
listParams.put("count", 1);
Refund created = ch.getRefunds().all(listParams).getData().get(0);
Refund retrieved = ch.getRefunds().retrieve(created.getId());
assertEquals(created.getId(), retrieved.getId());
}
use of com.stripe.model.Refund in project stripe-java by stripe.
the class RefundTest method testUpdate.
@Test
public void testUpdate() throws StripeException {
Refund refund = new Refund();
refund.setId("re_foo");
HashMap<String, Object> params = new HashMap<String, Object>();
params.put("reason", "fraudulent");
refund.update(params);
verifyPost(Refund.class, "https://api.stripe.com/v1/refunds/re_foo", params);
verifyNoMoreInteractions(networkMock);
}
Aggregations