当前位置: 首页>>代码示例>>Java>>正文


Java Stripe类代码示例

本文整理汇总了Java中com.stripe.Stripe的典型用法代码示例。如果您正苦于以下问题:Java Stripe类的具体用法?Java Stripe怎么用?Java Stripe使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Stripe类属于com.stripe包,在下文中一共展示了Stripe类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: CheckoutClassSample

import com.stripe.Stripe; //导入依赖的package包/类
public void CheckoutClassSample() throws IOException, CurrencyMismatchException, BadParameterException, InsufficientValueException, AuthorizationException, CouldNotFindObjectException, CardException, APIException, AuthenticationException, InvalidRequestException, APIConnectionException, ThirdPartyException {
    //this is your order
    int orderTotal = 7505;
    String orderCurrency = "USD";

    //set up your API keys
    Stripe.apiKey = "...";
    Lightrail.apiKey = "...";

    //get the stripe token and the gift code
    String stripeToken = "...";
    String giftCode = "...";
    CheckoutWithStripeAndLightrail checkoutWithGiftCode = new CheckoutWithStripeAndLightrail(orderTotal, orderCurrency);
    checkoutWithGiftCode.useLightrailGiftCode(giftCode);
    //or: checkoutWithGiftCode.useLightrailCardId("...");
    //or: checkoutWithGiftCode.useLightrailContact("...");
    checkoutWithGiftCode.useStripeToken(stripeToken);
    //or: checkoutWithGiftCode.useStripeCustomer("...");

    SimulatedStripeLightrailSplitTenderCharge simulatedCharge = checkoutWithGiftCode.simulate();
    int creditCardShare = simulatedCharge.getStripeShare();
    int giftCodeShare = simulatedCharge.getLightrailShare();
    System.out.println(String.format("Will charge %s%s on your gift card and %s%s on your credit card..", orderCurrency, giftCodeShare, orderCurrency, creditCardShare));

    StripeLightrailSplitTenderCharge committedCharge = simulatedCharge.commit();
}
 
开发者ID:Giftbit,项目名称:lightrail-stripe-java,代码行数:27,代码来源:IntegrationSample.java

示例2: hybridChargeCreditCardOnlyTest

import com.stripe.Stripe; //导入依赖的package包/类
@Test
public void hybridChargeCreditCardOnlyTest() throws IOException, CurrencyMismatchException, AuthorizationException, InsufficientValueException, CouldNotFindObjectException, ThirdPartyException {
    Properties properties = TestParams.getProperties();

    Lightrail.apiKey = properties.getProperty("lightrail.testApiKey");
    Stripe.apiKey = properties.getProperty("stripe.testApiKey");

    int transactionAmount = 500;
    Map<String, Object> hybridChargeParams = new HashMap<>();
    hybridChargeParams.put(StripeConstants.Parameters.CURRENCY, properties.getProperty("happyPath.code.currency"));
    hybridChargeParams.put(StripeConstants.Parameters.AMOUNT, transactionAmount);
    hybridChargeParams.put(StripeConstants.Parameters.TOKEN, properties.getProperty("stripe.demoToken"));

    StripeLightrailSplitTenderCharge simulatedTx = StripeLightrailSplitTenderCharge.simulate(hybridChargeParams);
    assertEquals(0, simulatedTx.getLightrailShare());
    StripeLightrailSplitTenderCharge stripeLightrailSplitTenderCharge = StripeLightrailSplitTenderCharge.create(hybridChargeParams);
    assertEquals(0, stripeLightrailSplitTenderCharge.getLightrailShare());
}
 
开发者ID:Giftbit,项目名称:lightrail-stripe-java,代码行数:19,代码来源:StripeLightrailSplitTenderChargeTest.java

示例3: splitTransactionValueWithStripeMinimumTransactionValueInMindTest

import com.stripe.Stripe; //导入依赖的package包/类
@Test
public void splitTransactionValueWithStripeMinimumTransactionValueInMindTest() throws IOException, AuthorizationException, CurrencyMismatchException, InsufficientValueException, CouldNotFindObjectException, ThirdPartyException {
    Properties properties = TestParams.getProperties();

    Lightrail.apiKey = properties.getProperty("lightrail.testApiKey");
    Stripe.apiKey = properties.getProperty("stripe.testApiKey");

    int transactionAmount = getGiftCodeValue()+ 1;

    Map<String, Object> hybridChargeParams = TestParams.readCodeParamsFromProperties();
    hybridChargeParams.put(StripeConstants.Parameters.AMOUNT, transactionAmount);
    hybridChargeParams.put(StripeConstants.Parameters.TOKEN, properties.getProperty("stripe.demoToken"));

    StripeLightrailSplitTenderCharge simulatedTx = StripeLightrailSplitTenderCharge.simulate(hybridChargeParams);
    int giftCodeShare = simulatedTx.getLightrailShare();
    int creditCardShare = simulatedTx.getStripeShare();
    assertEquals(StripeConstants.STRIPE_MINIMUM_TRANSACTION_VALUE, creditCardShare);
    StripeLightrailSplitTenderCharge stripeLightrailSplitTenderCharge = StripeLightrailSplitTenderCharge.create(hybridChargeParams);

    assertEquals(StripeConstants.STRIPE_MINIMUM_TRANSACTION_VALUE, stripeLightrailSplitTenderCharge.getStripeShare());

    returnFundsToCode(stripeLightrailSplitTenderCharge.getLightrailCharge().getAmount());
}
 
开发者ID:Giftbit,项目名称:lightrail-stripe-java,代码行数:24,代码来源:StripeLightrailSplitTenderChargeTest.java

示例4: createCheckoutObject

import com.stripe.Stripe; //导入依赖的package包/类
private CheckoutWithStripeAndLightrail createCheckoutObject(int orderTotal, boolean addGiftCode, boolean addStripe)
        throws IOException, AuthorizationException, CurrencyMismatchException, InsufficientValueException {
    Properties properties = TestParams.getProperties();

    Lightrail.apiKey = properties.getProperty("lightrail.testApiKey");
    Stripe.apiKey = properties.getProperty("stripe.testApiKey");

    String orderCurrency = properties.getProperty("happyPath.code.currency");

    CheckoutWithStripeAndLightrail checkoutWithGiftCode = new CheckoutWithStripeAndLightrail(orderTotal, orderCurrency);
    if (addGiftCode) {
        checkoutWithGiftCode.useLightrailGiftCode(properties.getProperty("happyPath.code"));
    }
    if (addStripe) {
        int randomNum = ThreadLocalRandom.current().nextInt(0, 2);
        if (randomNum > 0)
            checkoutWithGiftCode.useStripeToken(properties.getProperty("stripe.demoToken"));
        else
            checkoutWithGiftCode.useStripeCustomer(properties.getProperty("stripe.demoCustomer"));
    }
    return checkoutWithGiftCode;
}
 
开发者ID:Giftbit,项目名称:lightrail-stripe-java,代码行数:23,代码来源:CheckoutWithStripeAndLightrailTest.java

示例5: checkoutWithoutGiftCode

import com.stripe.Stripe; //导入依赖的package包/类
@Test
public void checkoutWithoutGiftCode() throws IOException, AuthorizationException, CurrencyMismatchException, InsufficientValueException, CouldNotFindObjectException, ThirdPartyException {
    Properties properties = TestParams.getProperties();
    Lightrail.apiKey = properties.getProperty("lightrail.testApiKey");

    String orderCurrency = properties.getProperty("happyPath.code.currency");

    CheckoutWithStripeAndLightrail checkoutWithGiftCode = new CheckoutWithStripeAndLightrail(100, orderCurrency);
    try {
        checkoutWithGiftCode.checkout();
    } catch (Exception e) {
        assertEquals(BadParameterException.class.getName(), e.getClass().getName());
    }
    Stripe.apiKey = properties.getProperty("stripe.testApiKey");
    checkoutWithGiftCode = createCheckoutObject(100, false, true);
    StripeLightrailSplitTenderCharge charge = checkoutWithGiftCode.checkout();
    assertEquals(0, charge.getLightrailShare());
}
 
开发者ID:Giftbit,项目名称:lightrail-stripe-java,代码行数:19,代码来源:CheckoutWithStripeAndLightrailTest.java

示例6: checkoutWithGiftCodeSample

import com.stripe.Stripe; //导入依赖的package包/类
public void checkoutWithGiftCodeSample() throws IOException, CurrencyMismatchException, InsufficientValueException, AuthorizationException, CouldNotFindObjectException, ThirdPartyException {
    Properties properties = TestParams.getProperties();

    //set up your api keys
    Lightrail.apiKey = properties.getProperty("lightrail.testApiKey");
    Stripe.apiKey = properties.getProperty("stripe.testApiKey");

    CheckoutWithStripeAndLightrail checkoutWithGiftCode = new CheckoutWithStripeAndLightrail(7645, "USD")
            .useLightrailGiftCode(properties.getProperty("happyPath.code"))
            .useStripeToken(properties.getProperty("stripe.demoToken"));
    StripeLightrailSplitTenderCharge simulatedCharge = checkoutWithGiftCode.simulate();

    //show this summary to the user and get them to confirm
    System.out.println(simulatedCharge.getSummary());
    if (simulatedCharge instanceof SimulatedStripeLightrailSplitTenderCharge) {
        StripeLightrailSplitTenderCharge charge = ((SimulatedStripeLightrailSplitTenderCharge) simulatedCharge).commit();
        //show final summary to the user
        System.out.println(charge.getSummary());
    }
}
 
开发者ID:Giftbit,项目名称:lightrail-stripe-java,代码行数:21,代码来源:CheckoutWithStripeAndLightrailTest.java

示例7: createCharge

import com.stripe.Stripe; //导入依赖的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;
  }
}
 
开发者ID:glen-rock-indian-community,项目名称:gric-event-management,代码行数:49,代码来源:Talk2Stripe.java

示例8: makeStripeCharge

import com.stripe.Stripe; //导入依赖的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);
    }
}
 
开发者ID:mischat,项目名称:stripe-charge-dropwizard,代码行数:21,代码来源:ChargeResource.java

示例9: contribute

import com.stripe.Stripe; //导入依赖的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);
}
 
开发者ID:fayder,项目名称:restcountries,代码行数:25,代码来源:StripeRest.java

示例10: main

import com.stripe.Stripe; //导入依赖的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();
    }
}
 
开发者ID:JoeyMercs,项目名称:UO.me,代码行数:18,代码来源:SripeExample.java

示例11: listAllCharges

import com.stripe.Stripe; //导入依赖的package包/类
@Override
public Charges listAllCharges(String name) {
	Stripe.apiKey = "sk_test_BQokikJOvBiI2HlWgH4olfQ2";
	if (StringUtils.hasText(url)) {
		Stripe.overrideApiBase(url);
	}
	Map<String, Object> chargeParams = new HashMap<>();
	chargeParams.put("limit", 25);
	try {
		return convertTheirChargesToOurs(chargeParams);
	}
	catch (Exception e) {
		throw new RuntimeException(e);
	}
}
 
开发者ID:marcingrzejszczak,项目名称:the-legacy-app,代码行数:16,代码来源:CustomerRentalHistoryManagerImpl.java

示例12: SplitTenderCheckoutSample

import com.stripe.Stripe; //导入依赖的package包/类
public void SplitTenderCheckoutSample() throws IOException, CurrencyMismatchException, BadParameterException, InsufficientValueException, AuthorizationException, CouldNotFindObjectException, CardException, APIException, AuthenticationException, InvalidRequestException, APIConnectionException, ThirdPartyException {

        //this is your order
        int orderTotal = 7505;
        String orderCurrency = "USD";

        //set up your API keys
        Stripe.apiKey = "...";
        Lightrail.apiKey = "...";

        //get the stripe token and the gift code
        String stripeToken = "...";
        String giftCode = "...";

        Map<String, Object> chargeParams = new HashMap<String, Object>();
        chargeParams.put("amount", orderTotal);
        chargeParams.put("currency", orderCurrency);
        chargeParams.put("source", stripeToken);
        chargeParams.put("code", giftCode);

        SimulatedStripeLightrailSplitTenderCharge simulatedCharge = StripeLightrailSplitTenderCharge.simulate(chargeParams);
        int creditCardShare = simulatedCharge.getStripeShare();
        int giftCodeShare = simulatedCharge.getLightrailShare();
        System.out.println(String.format("Will charge %s%s on your gift card and %s%s on your credit card..", orderCurrency, giftCodeShare, orderCurrency, creditCardShare));

        StripeLightrailSplitTenderCharge committedCharge = simulatedCharge.commit();
    }
 
开发者ID:Giftbit,项目名称:lightrail-stripe-java,代码行数:28,代码来源:IntegrationSample.java

示例13: giftCodeValueTooSmall

import com.stripe.Stripe; //导入依赖的package包/类
@Test
public void giftCodeValueTooSmall() throws IOException, AuthorizationException, CurrencyMismatchException, InsufficientValueException, CouldNotFindObjectException, ThirdPartyException {
    Properties properties = TestParams.getProperties();

    Lightrail.apiKey = properties.getProperty("lightrail.testApiKey");
    Stripe.apiKey = properties.getProperty("stripe.testApiKey");

    int drainGiftCodeTransactionAmount = getGiftCodeValue() - 3;

    Map<String, Object> hybridChargeParams = TestParams.readCodeParamsFromProperties();
    hybridChargeParams.put(StripeConstants.Parameters.AMOUNT, drainGiftCodeTransactionAmount);
    StripeLightrailSplitTenderCharge stripeLightrailSplitTenderCharge = StripeLightrailSplitTenderCharge.create(hybridChargeParams);

    assertEquals(3, getGiftCodeValue());

    int impossibleForGiftCodeTransaction = StripeConstants.STRIPE_MINIMUM_TRANSACTION_VALUE - 1;

    hybridChargeParams = TestParams.readCodeParamsFromProperties();
    hybridChargeParams.put(StripeConstants.Parameters.AMOUNT, impossibleForGiftCodeTransaction);
    hybridChargeParams.put(StripeConstants.Parameters.TOKEN, properties.getProperty("stripe.demoToken"));
    try {
        stripeLightrailSplitTenderCharge = StripeLightrailSplitTenderCharge.create(hybridChargeParams);
    } catch (Exception e) {
        assertEquals(InsufficientValueException.class.getName(), e.getClass().getName());
    }

    returnFundsToCode(drainGiftCodeTransactionAmount + 3);
}
 
开发者ID:Giftbit,项目名称:lightrail-stripe-java,代码行数:29,代码来源:StripeLightrailSplitTenderChargeTest.java

示例14: retrieve

import com.stripe.Stripe; //导入依赖的package包/类
public static BalanceTransaction retrieve(String id, String apiKey)
		throws AuthenticationException, InvalidRequestException,
		APIConnectionException, CardException, APIException {
	String url = String.format("%s/%s/%s", Stripe.API_BASE, "v1/balance/history", id);
	return request(RequestMethod.GET, url, null,
			BalanceTransaction.class, apiKey);
}
 
开发者ID:JoeyMercs,项目名称:UO.me,代码行数:8,代码来源:BalanceTransaction.java

示例15: all

import com.stripe.Stripe; //导入依赖的package包/类
public static BalanceTransactionCollection all(Map<String, Object> params, String apiKey)
		throws AuthenticationException, InvalidRequestException,
		APIConnectionException, CardException, APIException {
	String url = String.format("%s/%s", Stripe.API_BASE, "v1/balance/history");
	return request(RequestMethod.GET, url, params,
			BalanceTransactionCollection.class, apiKey);
}
 
开发者ID:JoeyMercs,项目名称:UO.me,代码行数:8,代码来源:BalanceTransaction.java


注:本文中的com.stripe.Stripe类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。