本文整理汇总了Java中com.stripe.model.Charge.create方法的典型用法代码示例。如果您正苦于以下问题:Java Charge.create方法的具体用法?Java Charge.create怎么用?Java Charge.create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.stripe.model.Charge
的用法示例。
在下文中一共展示了Charge.create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createCharge
import com.stripe.model.Charge; //导入方法依赖的package包/类
/**
* The checkout form only makes a token, the final charge happens using this
* call.
*
* @param email
* - Primary Email
* @param amount
* - Amount to be charged.
* @param token
* - Token created off "checkout"
* @return
* @throws AuthenticationException
* @throws InvalidRequestException
* @throws APIConnectionException
* @throws APIException
* @throws CardException
*/
public String createCharge(String email, BigDecimal amount, String token)
throws AuthenticationException, InvalidRequestException, APIConnectionException, APIException, CardException {
log.warn("Charging: " + email + " For: " + amount);
try {
// See your keys here: https://dashboard.stripe.com/account/apikeys
Stripe.apiKey = gricConfigProperties.getStripeApiKey();
// Create a charge: this will charge the user's card
Map<String, Object> chargeParams = new HashMap<String, Object>();
// Amount in cents, multiple by 100, and send it as integer for API.
chargeParams.put("amount", amount.multiply(new BigDecimal("100")).intValueExact());
chargeParams.put("currency", "usd");
chargeParams.put("source", token);
chargeParams.put("description", "Glen Rock Indian Community Event");
chargeParams.put("receipt_email", email);
chargeParams.put("statement_descriptor", "GRIC Payment");
Charge charge = Charge.create(chargeParams);
String chargeIdAndReceiptNumber = charge.getId() + "," + charge.getReceiptNumber();
return chargeIdAndReceiptNumber;
} catch (Exception e) {
// The card has been declined
log.error("Charge failed for: " + email + " For: " + amount);
throw e;
}
}
示例2: makeStripeCharge
import com.stripe.model.Charge; //导入方法依赖的package包/类
@POST
@Timed
public Response makeStripeCharge(@FormParam("token") String token, @FormParam("email") String email, @FormParam("amount") String amount) throws Exception {
Stripe.apiKey = stripeSecretKey;
Map<String, Object> chargeParams = new HashMap<>();
chargeParams.put("amount", amount);
chargeParams.put("currency", "gbp");
chargeParams.put("source", token); // obtained with Stripe.js
chargeParams.put("description", email);
try {
Charge.create(chargeParams);
logger.info("Success: '"+email+"' just made a payment of '"+amount+"' in pence with token '"+token+"'");
return Response.ok().build();
} catch (Exception e) {
throw new Exception(e);
}
}
示例3: contribute
import com.stripe.model.Charge; //导入方法依赖的package包/类
@POST
public Object contribute(Contribution contribution) {
LOG.debug("Contribution: " + contribution);
if (contribution == null || TextUtils.isBlank(contribution.getToken())) {
return getResponse(Response.Status.BAD_REQUEST);
}
Stripe.apiKey = "";
Map<String, Object> params = new HashMap<>();
params.put("amount", contribution.getAmount());
params.put("currency", "eur");
params.put("description", "REST Countries");
params.put("source", contribution.getToken());
try {
Charge.create(params);
} catch (AuthenticationException | InvalidRequestException | CardException | APIConnectionException | APIException e) {
LOG.error(e.getMessage(), e);
return getResponse(Response.Status.BAD_REQUEST);
}
return getResponse(Response.Status.ACCEPTED);
}
示例4: main
import com.stripe.model.Charge; //导入方法依赖的package包/类
public static void main(String[] args) {
Stripe.apiKey = "sk_test_RVommOo9ArONhawECkwu3Kz3";
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);
System.out.println(charge);
} catch (StripeException e) {
e.printStackTrace();
}
}
示例5: testBalanceTransactionRetrieval
import com.stripe.model.Charge; //导入方法依赖的package包/类
@Test
public void testBalanceTransactionRetrieval() throws StripeException {
Charge.create(defaultChargeParams);
BalanceTransactionCollection balanceTransactions = BalanceTransaction.all(null);
assertTrue(balanceTransactions.getCount() > 0);
assertFalse(balanceTransactions.getData().isEmpty());
BalanceTransaction first = balanceTransactions.getData().get(0);
assertNotNull(first.getStatus());
HashMap<String, Object> fetchParams = new HashMap<String, Object>();
fetchParams.put("count", 2);
assertEquals(BalanceTransaction.all(fetchParams).getData().size(), 2);
BalanceTransaction retrieved = BalanceTransaction.retrieve(first.getId());
assertEquals(retrieved.getId(), first.getId());
assertEquals(retrieved.getSource(), first.getSource());
}
示例6: testInvalidAddressZipTest
import com.stripe.model.Charge; //导入方法依赖的package包/类
@Test
public void testInvalidAddressZipTest() throws StripeException {
Map<String, Object> invalidChargeParams = new HashMap<String, Object>();
invalidChargeParams.putAll(defaultChargeParams);
Map<String, Object> invalidCardParams = new HashMap<String, Object>();
// See https://stripe.com/docs/testing
invalidCardParams.put("number", "4000000000000036");
invalidCardParams.put("address_zip", "94024");
invalidCardParams.put("address_line1", "42 Foo Street");
invalidCardParams.put("exp_month", 12);
invalidCardParams.put("exp_year", 2015);
invalidChargeParams.put("card", invalidCardParams);
Charge charge = Charge.create(invalidChargeParams);
assertEquals(charge.getPaid(), true);
assertEquals(charge.getCard().getAddressZipCheck(), "fail");
assertEquals(charge.getCard().getAddressLine1Check(), "pass");
}
示例7: testInvalidAddressLine1Test
import com.stripe.model.Charge; //导入方法依赖的package包/类
@Test
public void testInvalidAddressLine1Test() throws StripeException {
Map<String, Object> invalidChargeParams = new HashMap<String, Object>();
invalidChargeParams.putAll(defaultChargeParams);
Map<String, Object> invalidCardParams = new HashMap<String, Object>();
// See https://stripe.com/docs/testing
invalidCardParams.put("number", "4000000000000028");
invalidCardParams.put("address_zip", "94024");
invalidCardParams.put("address_line1", "42 Foo Street");
invalidCardParams.put("exp_month", 12);
invalidCardParams.put("exp_year", 2015);
invalidChargeParams.put("card", invalidCardParams);
Charge charge = Charge.create(invalidChargeParams);
assertEquals(charge.getPaid(), true);
assertEquals(charge.getCard().getAddressZipCheck(), "pass");
assertEquals(charge.getCard().getAddressLine1Check(), "fail");
}
示例8: rebill
import com.stripe.model.Charge; //导入方法依赖的package包/类
/**
* Charge him again.
* @throws IOException If fails
*/
private void rebill() throws IOException {
final Item item = this.item();
final Long cents = Long.parseLong(item.get("stripe_cents").getN());
final String customer = item.get("stripe_customer").getS();
try {
Charge.create(
new StickyMap<String, Object>(
new MapEntry<>("amount", cents),
new MapEntry<>("currency", "usd"),
new MapEntry<>(
"description",
String.format("ThreeCopies: %s", this.name)
),
new MapEntry<>("customer", customer)
),
new RequestOptions.RequestOptionsBuilder().setApiKey(
Manifests.read("ThreeCopies-StripeSecret")
).build()
);
} catch (final APIException | APIConnectionException
| AuthenticationException | CardException
| InvalidRequestException ex) {
throw new IOException(ex);
}
this.item().put(
"paid",
new AttributeValueUpdate().withValue(
new AttributeValue().withN(
Long.toString(cents * TimeUnit.HOURS.toSeconds(1L))
)
).withAction(AttributeAction.ADD)
);
}
示例9: chargeCreditCard
import com.stripe.model.Charge; //导入方法依赖的package包/类
/**
* After client side integration with stripe widget, our server receives the stripeToken
* StripeToken is a single-use token that allows our server to actually charge the credit card and
* get money on our account.
* <p>
* as documented in https://stripe.com/docs/tutorials/charges
*
* @return
* @throws StripeException
*/
Charge chargeCreditCard(String stripeToken, long amountInCent, Event event,
String reservationId, String email, String fullName, String billingAddress) throws StripeException {
int tickets = ticketRepository.countTicketsInReservation(reservationId);
Map<String, Object> chargeParams = new HashMap<>();
chargeParams.put("amount", amountInCent);
FeeCalculator.getCalculator(event, configurationManager).apply(tickets, amountInCent).ifPresent(fee -> chargeParams.put("application_fee", fee));
chargeParams.put("currency", event.getCurrency());
chargeParams.put("card", stripeToken);
chargeParams.put("description", String.format("%d ticket(s) for event %s", tickets, event.getDisplayName()));
Map<String, String> initialMetadata = new HashMap<>();
initialMetadata.put("reservationId", reservationId);
initialMetadata.put("email", email);
initialMetadata.put("fullName", fullName);
if (StringUtils.isNotBlank(billingAddress)) {
initialMetadata.put("billingAddress", billingAddress);
}
chargeParams.put("metadata", initialMetadata);
RequestOptions options = options(event);
Charge charge = Charge.create(chargeParams, options);
if(charge.getBalanceTransactionObject() == null) {
try {
charge.setBalanceTransactionObject(retrieveBalanceTransaction(charge.getBalanceTransaction(), options));
} catch(Exception e) {
log.warn("can't retrieve balance transaction", e);
}
}
return charge;
}
示例10: main
import com.stripe.model.Charge; //导入方法依赖的package包/类
public static void main(String[] args) {
Stripe.apiKey = "sk_test_RVommOo9ArONhawECkwu3Kz3";
Map<String, Object> chargeParams = new HashMap<String, Object>();
chargeParams.put("amount", 400);
chargeParams.put("currency", "usd");
chargeParams.put("card", "tok_102mRP2lXUqPieqhv2jub7lr"); // obtained with Stripe.js
chargeParams.put("description", "Charge for [email protected]");
chargeParams.put("metadata", initialMetadata);
Charge.create(chargeParams);
}
示例11: testChargeRetrieve
import com.stripe.model.Charge; //导入方法依赖的package包/类
@Test
public void testChargeRetrieve() throws StripeException {
Charge createdCharge = Charge.create(defaultChargeParams);
Charge retrievedCharge = Charge.retrieve(createdCharge.getId());
assertEquals(createdCharge.getCreated(), retrievedCharge.getCreated());
assertEquals(createdCharge.getId(), retrievedCharge.getId());
}
示例12: testChargeRefund
import com.stripe.model.Charge; //导入方法依赖的package包/类
@Test
public void testChargeRefund() throws StripeException {
Charge createdCharge = Charge.create(defaultChargeParams);
Charge refundedCharge = createdCharge.refund();
assertTrue(refundedCharge.getRefunded());
assertTrue(refundedCharge.getRefunds() instanceof List);
assertEquals(1, refundedCharge.getRefunds().size());
assertTrue(refundedCharge.getRefunds().get(0) instanceof Refund);
}
示例13: testChargeCapture
import com.stripe.model.Charge; //导入方法依赖的package包/类
@Test
public void testChargeCapture() throws StripeException {
HashMap<String, Object> options = (HashMap<String, Object>)defaultChargeParams.clone();
options.put("capture", false);
Charge created = Charge.create(options);
assertFalse(created.getCaptured());
Charge captured = created.capture();
assertTrue(captured.getCaptured());
}
示例14: testChargePartialRefund
import com.stripe.model.Charge; //导入方法依赖的package包/类
@Test
public void testChargePartialRefund() throws StripeException {
Charge createdCharge = Charge.create(defaultChargeParams);
Map<String, Object> refundParams = new HashMap<String, Object>();
final Integer REFUND_AMOUNT = 50;
refundParams.put("amount", REFUND_AMOUNT);
Charge refundedCharge = createdCharge.refund(refundParams);
assertFalse(refundedCharge.getRefunded());
assertEquals(refundedCharge.getAmountRefunded(), REFUND_AMOUNT);
}
示例15: testInvalidCard
import com.stripe.model.Charge; //导入方法依赖的package包/类
@Test(expected = CardException.class)
public void testInvalidCard() throws StripeException {
Map<String, Object> invalidChargeParams = new HashMap<String, Object>();
invalidChargeParams.putAll(defaultChargeParams);
Map<String, Object> invalidCardParams = new HashMap<String, Object>();
invalidCardParams.put("number", "4242424242424241");
invalidCardParams.put("exp_month", 12);
invalidCardParams.put("exp_year", 2015);
invalidChargeParams.put("card", invalidCardParams);
Charge.create(invalidChargeParams);
}