本文整理汇总了Java中com.stripe.model.Charge类的典型用法代码示例。如果您正苦于以下问题:Java Charge类的具体用法?Java Charge怎么用?Java Charge使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Charge类属于com.stripe.model包,在下文中一共展示了Charge类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: retrieve
import com.stripe.model.Charge; //导入依赖的package包/类
public static StripeLightrailSplitTenderCharge retrieve(Map<String, Object> chargeParams) throws AuthorizationException, CurrencyMismatchException, InsufficientValueException, IOException, CouldNotFindObjectException, ThirdPartyException {
Map<String, Object> lightrailRetrieveParams = new HashMap<>(chargeParams);
removeStripeParams(lightrailRetrieveParams);
LightrailCharge lightrailCharge = LightrailCharge.retrieve(lightrailRetrieveParams);
int originalTransactionAmount = ((Double) lightrailCharge.getMetadata().get(LightrailEcommerceConstants.HybridTransactionMetadata.SPLIT_TENDER_TOTAL)).intValue();
int transactionAmount = (Integer) chargeParams.get(StripeConstants.Parameters.AMOUNT);
if (transactionAmount != originalTransactionAmount)
throw new BadParameterException("Idempotency Error. The parameters do not match the original transaction.");
String stripeTxId = ((String) lightrailCharge.getMetadata().get(LightrailEcommerceConstants.HybridTransactionMetadata.SPLIT_TENDER_PARTNER_TRANSACTION_ID));
Charge stripeTransaction = null;
if (originalTransactionAmount - lightrailCharge.getAmount() != 0) { //then there was no stripe
try {
stripeTransaction = Charge.retrieve(stripeTxId);
} catch (StripeException e) {
throw new ThirdPartyException(e);
}
}
return new StripeLightrailSplitTenderCharge(lightrailCharge, stripeTransaction);
}
示例2: 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;
}
}
示例3: 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);
}
}
示例4: 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);
}
示例5: 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();
}
}
示例6: 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());
}
示例7: 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");
}
示例8: 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");
}
示例9: convertTheirChargesToOurs
import com.stripe.model.Charge; //导入依赖的package包/类
private Charges convertTheirChargesToOurs(Map<String, Object> chargeParams)
throws AuthenticationException, InvalidRequestException,
APIConnectionException, CardException, APIException {
ChargeCollection list = Charge.list(chargeParams);
Charges charges = new Charges();
for (Charge charge : list.getData()) {
charges.getCharges().add(
new com.example.legacyapp.dto.Charge(charge.getCustomer(), charge.getAmount(), charge.getCaptured())
);
}
return charges;
}
示例10: 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)
);
}
示例11: 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;
}
示例12: getInfo
import com.stripe.model.Charge; //导入依赖的package包/类
Optional<PaymentInformation> getInfo(Transaction transaction, Event event) {
try {
RequestOptions options = options(event);
Charge charge = Charge.retrieve(transaction.getTransactionId(), options);
String paidAmount = MonetaryUtil.formatCents(charge.getAmount());
String refundedAmount = MonetaryUtil.formatCents(charge.getAmountRefunded());
List<Fee> fees = retrieveBalanceTransaction(charge.getBalanceTransaction(), options).getFeeDetails();
return Optional.of(new PaymentInformation(paidAmount, refundedAmount, getFeeAmount(fees, "stripe_fee"), getFeeAmount(fees, "application_fee")));
} catch (StripeException e) {
return Optional.empty();
}
}
示例13: processStripePayment
import com.stripe.model.Charge; //导入依赖的package包/类
/**
* This method processes the pending payment using the configured payment gateway (at the time of writing, only STRIPE)
* and returns a PaymentResult.
* In order to preserve the consistency of the payment, when a non-gateway Exception is thrown, it rethrows an IllegalStateException
*
* @param reservationId
* @param gatewayToken
* @param price
* @param event
* @param email
* @param customerName
* @param billingAddress
* @return PaymentResult
* @throws java.lang.IllegalStateException if there is an error after charging the credit card
*/
PaymentResult processStripePayment(String reservationId,
String gatewayToken,
int price,
Event event,
String email,
CustomerName customerName,
String billingAddress) {
try {
final Charge charge = stripeManager.chargeCreditCard(gatewayToken, price,
event, reservationId, email, customerName.getFullName(), billingAddress);
log.info("transaction {} paid: {}", reservationId, charge.getPaid());
Pair<Long, Long> fees = Optional.ofNullable(charge.getBalanceTransactionObject()).map(bt -> {
List<Fee> feeDetails = bt.getFeeDetails();
return Pair.of(Optional.ofNullable(StripeManager.getFeeAmount(feeDetails, "application_fee")).map(Long::parseLong).orElse(0L),
Optional.ofNullable(StripeManager.getFeeAmount(feeDetails, "stripe_fee")).map(Long::parseLong).orElse(0L));
}).orElse(null);
transactionRepository.insert(charge.getId(), null, reservationId,
ZonedDateTime.now(), price, event.getCurrency(), charge.getDescription(), PaymentProxy.STRIPE.name(),
fees != null ? fees.getLeft() : 0L, fees != null ? fees.getRight() : 0L);
return PaymentResult.successful(charge.getId());
} catch (Exception e) {
if(e instanceof StripeException) {
return PaymentResult.unsuccessful(stripeManager.handleException((StripeException)e));
}
throw new IllegalStateException(e);
}
}
示例14: 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);
}
示例15: 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());
}