Search in sources :

Example 1 with Refund

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());
}
Also used : Refund(com.stripe.model.Refund) HashMap(java.util.HashMap) Charge(com.stripe.model.Charge) BaseStripeFunctionalTest(com.stripe.BaseStripeFunctionalTest) Test(org.junit.Test)

Example 2 with Refund

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());
}
Also used : Refund(com.stripe.model.Refund) HashMap(java.util.HashMap) Charge(com.stripe.model.Charge) BalanceTransaction(com.stripe.model.BalanceTransaction) LinkedList(java.util.LinkedList) BaseStripeFunctionalTest(com.stripe.BaseStripeFunctionalTest) Test(org.junit.Test)

Example 3 with Refund

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"));
}
Also used : ChargeRefundCollection(com.stripe.model.ChargeRefundCollection) Refund(com.stripe.model.Refund) HashMap(java.util.HashMap) Charge(com.stripe.model.Charge) BaseStripeFunctionalTest(com.stripe.BaseStripeFunctionalTest) Test(org.junit.Test)

Example 4 with Refund

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);
}
Also used : ChargeRefundCollection(com.stripe.model.ChargeRefundCollection) Refund(com.stripe.model.Refund) Charge(com.stripe.model.Charge) List(java.util.List) LinkedList(java.util.LinkedList) BaseStripeFunctionalTest(com.stripe.BaseStripeFunctionalTest) Test(org.junit.Test)

Example 5 with 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;
    }
}
Also used : Refund(com.stripe.model.Refund) RequestOptions(com.stripe.net.RequestOptions)

Aggregations

Refund (com.stripe.model.Refund)10 Charge (com.stripe.model.Charge)8 Test (org.junit.Test)8 BaseStripeFunctionalTest (com.stripe.BaseStripeFunctionalTest)7 HashMap (java.util.HashMap)7 ChargeRefundCollection (com.stripe.model.ChargeRefundCollection)3 BalanceTransaction (com.stripe.model.BalanceTransaction)2 RequestOptions (com.stripe.net.RequestOptions)2 LinkedList (java.util.LinkedList)2 FeeCalculator (alfio.manager.support.FeeCalculator)1 PaymentResult (alfio.manager.support.PaymentResult)1 ConfigurationManager (alfio.manager.system.ConfigurationManager)1 UserManager (alfio.manager.user.UserManager)1 Configurable (alfio.model.Configurable)1 PaymentInformation (alfio.model.PaymentInformation)1 PurchaseContext (alfio.model.PurchaseContext)1 PurchaseContextType (alfio.model.PurchaseContext.PurchaseContextType)1 ConfigurationKeys (alfio.model.system.ConfigurationKeys)1 ConfigurationPathLevel (alfio.model.system.ConfigurationPathLevel)1 PaymentContext (alfio.model.transaction.PaymentContext)1