use of com.stripe.net.RequestOptions in project cryptonomica by Cryptonomica.
the class StripeTestServlet method doPost.
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
/* --- request*/
String requestDataStr = ServletUtils.getAllRequestData(request);
String responseStr = "{\"paymentData\":" + requestDataStr + ",";
// Get the credit card details submitted by the form
String token = request.getParameter("stripeToken");
@SuppressWarnings("unused") String cardHolderName = request.getParameter("cardHolderName");
/* -- see example on: https://github.com/stripe/stripe-java#usage */
//
RequestOptions requestOptions = (new RequestOptions.RequestOptionsBuilder()).setApiKey(STRIPE_SECRET_KEY).build();
//
// -- Card options:
// ------------ // Map<String, Object> cardMap = new HashMap<>();
// cardMap.put("name", cardHolderName);// - "Received both card and source parameters. Please pass in only one."
/*
cardMap.put("number", "4242424242424242");
cardMap.put("exp_month", 12);
cardMap.put("exp_year", 2020);
*/
// -- Charge options:
Map<String, Object> chargeMap = new HashMap<>();
// -- this is ONE dollar
chargeMap.put("amount", 100);
chargeMap.put("currency", "usd");
// see: https://stripe.com/docs/charges (Java)
// chargeParams.put("source", token);
// chargeParams.put("description", "Example charge");
chargeMap.put("source", token);
chargeMap.put("description", "Example charge: " + token);
//
// ------------ // chargeMap.put("card", cardMap);
// -- make charge:
responseStr += "\"charge\":";
try {
Charge charge = Charge.create(chargeMap, requestOptions);
// System.out.println(charge);
responseStr += GSON.toJson(charge);
LOG.warning(GSON.toJson(charge));
ExternalAccount source = charge.getSource();
LOG.warning("source: " + GSON.toJson(source));
// -- "succeeded"
charge.getStatus();
// - boolean: true or false
charge.getPaid();
//
// String customerStr = source.getCustomer();
// LOG.warning("customerStr: " + customerStr); //
// responseStr += "," + "\"customerStr\":" + GSON.toJson(charge); // - same as source
} catch (StripeException e) {
String errorMessage = e.getMessage();
responseStr += "\"";
responseStr += errorMessage;
responseStr += "\"";
LOG.warning(errorMessage);
}
responseStr += "}";
ServletUtils.sendJsonResponse(response, responseStr);
}
use of com.stripe.net.RequestOptions in project cryptonomica by Cryptonomica.
the class TestStripe method makeCharge2.
// end makeCharge1
public void makeCharge2() {
// see:
// https://github.com/stripe/stripe-java#usage
RequestOptions requestOptions = (new RequestOptions.RequestOptionsBuilder()).setApiKey("YOUR-SECRET-KEY").build();
Map<String, Object> chargeMap = new HashMap<String, Object>();
chargeMap.put("amount", 100);
chargeMap.put("currency", "usd");
Map<String, Object> cardMap = new HashMap<String, Object>();
cardMap.put("number", "4242424242424242");
cardMap.put("exp_month", 12);
cardMap.put("exp_year", 2020);
chargeMap.put("card", cardMap);
try {
Charge charge = Charge.create(chargeMap, requestOptions);
System.out.println(charge);
} catch (StripeException e) {
e.printStackTrace();
}
}
use of com.stripe.net.RequestOptions in project stripe-java by stripe.
the class DisputeTest method testSubmitOldStyleEvidence.
@Test
public void testSubmitOldStyleEvidence() throws StripeException, InterruptedException {
RequestOptions options = RequestOptions.builder().setStripeVersion("2014-11-20").build();
int chargeValueCents = 100;
// Stripe.apiVersion = "2014-11-20";
Charge disputedCharge = createDisputedCharge(chargeValueCents, options);
String myEvidence = "Here's evidence showing this charge is legitimate.";
Dispute initialDispute = disputedCharge.getDisputeObject();
assertNull(initialDispute.getEvidence());
assertNull(initialDispute.getEvidenceSubObject());
Map<String, Object> disputeParams = ImmutableMap.<String, Object>of("evidence", myEvidence);
Dispute updatedDispute = disputedCharge.updateDispute(disputeParams, options);
assertNotNull(updatedDispute);
assertEquals(myEvidence, updatedDispute.getEvidence());
assertNull(updatedDispute.getEvidenceSubObject());
}
use of com.stripe.net.RequestOptions in project stripe-java by stripe.
the class IdempotentTest method testClearingIdempotentcyActuallyWorks.
@Test
public void testClearingIdempotentcyActuallyWorks() throws CardException, APIException, AuthenticationException, InvalidRequestException, APIConnectionException {
RequestOptions options = RequestOptions.builder().setIdempotencyKey(UUID.randomUUID().toString()).clearIdempotencyKey().build();
Charge firstCharge = Charge.create(defaultChargeParams, options);
Charge secondCharge = Charge.create(defaultChargeParams, options);
assertNotSame(firstCharge.getId(), secondCharge.getId());
}
use of com.stripe.net.RequestOptions in project stripe-java by stripe.
the class IdempotentTest method testIdempotentRequestSent.
@Test
public void testIdempotentRequestSent() throws CardException, APIException, AuthenticationException, InvalidRequestException, APIConnectionException {
RequestOptions options = RequestOptions.builder().setIdempotencyKey(UUID.randomUUID().toString()).build();
Charge firstCharge = Charge.create(defaultChargeParams, options);
Charge secondCharge = Charge.create(defaultChargeParams, options);
assertEquals(firstCharge.getId(), secondCharge.getId());
}
Aggregations