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);
}
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());
}
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());
}
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);
}
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());
}
Aggregations