Search in sources :

Example 11 with Charge

use of com.stripe.model.Charge in project stripe-java by stripe.

the class DisputeTest method createDisputedCharge.

private Charge createDisputedCharge(int chargeValueCents, RequestOptions options) throws AuthenticationException, InvalidRequestException, APIConnectionException, CardException, APIException, InterruptedException {
    Map<String, Object> chargeParams = new HashMap<String, Object>();
    chargeParams.putAll(defaultChargeParams);
    chargeParams.put("amount", chargeValueCents);
    chargeParams.put("source", "tok_createDispute");
    Charge charge = Charge.create(chargeParams, options);
    // This test relies on the server asynchronously marking the charge as disputed.
    // TODO: find a more reliable way to do this instead of sleeping
    Thread.sleep(10000);
    Map<String, Object> retrieveParams = new HashMap<String, Object>();
    retrieveParams.put("expand[]", "dispute");
    return Charge.retrieve(charge.getId(), retrieveParams, options);
}
Also used : HashMap(java.util.HashMap) Charge(com.stripe.model.Charge) EvidenceSubObject(com.stripe.model.EvidenceSubObject)

Example 12 with Charge

use of com.stripe.model.Charge in project stripe-java by stripe.

the class DisputeTest method testDisputedCharge.

@Test
public void testDisputedCharge() throws StripeException, InterruptedException {
    int chargeValueCents = 100;
    Charge disputedCharge = createDisputedCharge(chargeValueCents, null);
    Dispute dispute = disputedCharge.getDisputeObject();
    assertNotNull(dispute);
    assertFalse(dispute.getIsChargeRefundable());
    assertEquals(1, dispute.getBalanceTransactions().size());
    assertEquals(-chargeValueCents, dispute.getBalanceTransactions().get(0).getAmount().intValue());
}
Also used : Charge(com.stripe.model.Charge) Dispute(com.stripe.model.Dispute) BaseStripeFunctionalTest(com.stripe.BaseStripeFunctionalTest) Test(org.junit.Test)

Example 13 with Charge

use of com.stripe.model.Charge in project stripe-java by stripe.

the class DisputeTest method testFraudDetails.

// FraudDetails Test:
@Test
public void testFraudDetails() throws StripeException, InterruptedException {
    Charge charge = Charge.create(defaultChargeParams);
    FraudDetails expected = new FraudDetails();
    assertEquals(expected, charge.getFraudDetails());
    Charge refundedCharge = charge.refund();
    assertEquals(expected, refundedCharge.getFraudDetails());
    Charge updatedCharge = charge.update(ImmutableMap.<String, Object>of("fraud_details", ImmutableMap.of("user_report", "fraudulent")));
    FraudDetails expectedReported = new FraudDetails();
    expectedReported.setUserReport("fraudulent");
    assertEquals(expectedReported, updatedCharge.getFraudDetails());
    Charge nowSafe = updatedCharge.markSafe(null);
    expectedReported.setUserReport("safe");
    assertEquals(expectedReported, nowSafe.getFraudDetails());
    Charge nowFraudulent = nowSafe.markFraudulent(null);
    expectedReported.setUserReport("fraudulent");
    assertEquals(expectedReported, nowFraudulent.getFraudDetails());
}
Also used : FraudDetails(com.stripe.model.FraudDetails) Charge(com.stripe.model.Charge) BaseStripeFunctionalTest(com.stripe.BaseStripeFunctionalTest) Test(org.junit.Test)

Example 14 with Charge

use of com.stripe.model.Charge in project stripe-java by stripe.

the class DisputeTest method testUpdateDispute.

@Test
public void testUpdateDispute() throws StripeException, InterruptedException {
    int chargeValueCents = 100;
    Charge disputedCharge = createDisputedCharge(chargeValueCents, null);
    Dispute initialDispute = disputedCharge.getDisputeObject();
    EvidenceSubObject emptyEvidence = new EvidenceSubObject();
    assertEquals(emptyEvidence, initialDispute.getEvidenceSubObject());
    assertEquals(new HashMap<String, String>(), initialDispute.getMetadata());
    Map<String, Object> evidence = new HashMap<String, Object>();
    evidence.put("product_description", "my productDescription");
    evidence.put("customer_name", "my customerName");
    evidence.put("uncategorized_text", "my uncategorizedText");
    Map<String, String> metadata = new HashMap<String, String>();
    metadata.put("some_info", "about the dispute");
    metadata.put("a_little_more", "12345");
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("evidence", evidence);
    params.put("metadata", metadata);
    Dispute updatedDispute = initialDispute.update(params);
    assertNotNull(updatedDispute);
    EvidenceSubObject evidenceSubObject = updatedDispute.getEvidenceSubObject();
    assertEquals(evidence.get("product_description"), evidenceSubObject.getProductDescription());
    assertEquals(evidence.get("customer_name"), evidenceSubObject.getCustomerName());
    assertEquals(evidence.get("uncategorized_text"), evidenceSubObject.getUncategorizedText());
    // Ensure this didn't get stored in the deprecated evidence field.
    assertNull(updatedDispute.getEvidence());
    Map<String, String> disputeMetadata = updatedDispute.getMetadata();
    assertNotNull(disputeMetadata);
    assertEquals(metadata, disputeMetadata);
}
Also used : EvidenceSubObject(com.stripe.model.EvidenceSubObject) HashMap(java.util.HashMap) Charge(com.stripe.model.Charge) Dispute(com.stripe.model.Dispute) EvidenceSubObject(com.stripe.model.EvidenceSubObject) BaseStripeFunctionalTest(com.stripe.BaseStripeFunctionalTest) Test(org.junit.Test)

Example 15 with Charge

use of com.stripe.model.Charge in project stripe-java by stripe.

the class IdempotentTest method testNotIdempotentWhenUnset.

@Test
public void testNotIdempotentWhenUnset() throws CardException, APIException, AuthenticationException, InvalidRequestException, APIConnectionException {
    RequestOptions options = RequestOptions.builder().build();
    Charge firstCharge = Charge.create(defaultChargeParams, options);
    Charge secondCharge = Charge.create(defaultChargeParams, options);
    assertNotSame(firstCharge.getId(), secondCharge.getId());
}
Also used : RequestOptions(com.stripe.net.RequestOptions) Charge(com.stripe.model.Charge) BaseStripeFunctionalTest(com.stripe.BaseStripeFunctionalTest) Test(org.junit.Test)

Aggregations

Charge (com.stripe.model.Charge)49 BaseStripeFunctionalTest (com.stripe.BaseStripeFunctionalTest)36 Test (org.junit.Test)36 HashMap (java.util.HashMap)19 RequestOptions (com.stripe.net.RequestOptions)12 Refund (com.stripe.model.Refund)8 Dispute (com.stripe.model.Dispute)7 Card (com.stripe.model.Card)5 EvidenceSubObject (com.stripe.model.EvidenceSubObject)5 Environment (org.springframework.core.env.Environment)5 PaymentResult (alfio.manager.support.PaymentResult)4 PaymentInformation (alfio.model.PaymentInformation)4 StripeException (com.stripe.exception.StripeException)3 BalanceTransaction (com.stripe.model.BalanceTransaction)3 ConfigurationManager (alfio.manager.system.ConfigurationManager)2 PurchaseContext (alfio.model.PurchaseContext)2 ConfigurationKeys (alfio.model.system.ConfigurationKeys)2 StripeCreditCardToken (alfio.model.transaction.token.StripeCreditCardToken)2 ConfigurationRepository (alfio.repository.system.ConfigurationRepository)2 Stripe (com.stripe.Stripe)2