use of com.stripe.model.Refund in project stripe-java by stripe.
the class RefundTest method testChargeRefundCreateApiKey.
@Test
public void testChargeRefundCreateApiKey() throws StripeException {
Charge ch = Charge.create(defaultChargeParams);
Map<String, Object> params = new HashMap<String, Object>();
params.put("amount", 10);
Refund created = ch.getRefunds().create(params, Stripe.apiKey);
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 testChargeRefundListWithExpand.
@Test
public void testChargeRefundListWithExpand() throws StripeException {
Charge ch = Charge.create(defaultChargeParams);
ch = ch.refund();
List<String> expandList = new LinkedList<String>();
expandList.add("data.balance_transaction");
expandList.add("data.balance_transaction.source");
expandList.add("data.charge");
Map<String, Object> listParams = new HashMap<String, Object>();
listParams.put("charge", ch.getId());
listParams.put("count", 1);
listParams.put("expand", expandList);
Refund refund = Refund.list(listParams).getData().get(0);
Charge expCharge = refund.getChargeObject();
assertNotNull(expCharge);
assertEquals(ch.getId(), expCharge.getId());
BalanceTransaction expBT = refund.getBalanceTransactionObject();
assertNotNull(expBT);
Refund expRefundInBT = (Refund) expBT.getSourceObject();
assertEquals(refund.getId(), expRefundInBT.getId());
}
use of com.stripe.model.Refund in project stripe-java by stripe.
the class RefundTest method testChargeRefundUpdateApiKey.
@Test
public void testChargeRefundUpdateApiKey() throws StripeException {
Charge createdCharge = Charge.create(defaultChargeParams);
ChargeRefundCollection refunds = createdCharge.refund().getRefunds();
Refund refund = refunds.getData().get(0);
Map<String, String> metadata = new HashMap<String, String>();
metadata.put("foo", "bar");
Map<String, Object> updateParams = new HashMap<String, Object>();
updateParams.put("metadata", metadata);
refund = refund.update(updateParams, Stripe.apiKey);
assertEquals("bar", refund.getMetadata().get("foo"));
}
use of com.stripe.model.Refund 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.Refund in project alf.io by alfio-event.
the class StripeManager method refund.
// https://stripe.com/docs/api#create_refund
public boolean refund(Transaction transaction, Event event, Optional<Integer> amount) {
String chargeId = transaction.getTransactionId();
try {
String amountOrFull = amount.map(MonetaryUtil::formatCents).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 (isConnectEnabled(event)) {
params.put("refund_application_fee", true);
}
Optional<RequestOptions> requestOptionsOptional = options(event);
if (requestOptionsOptional.isPresent()) {
RequestOptions options = requestOptionsOptional.get();
Refund r = Refund.create(params, options);
if ("succeeded".equals(r.getStatus())) {
log.info("Stripe: refund for payment {} executed with success for amount: {}", chargeId, 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;
}
}
Aggregations