Search in sources :

Example 1 with PaymentIntentCreateParams

use of com.stripe.param.PaymentIntentCreateParams in project javlo by Javlo.

the class StripeOrderComponent method prepareView.

@Override
public void prepareView(ContentContext ctx) throws Exception {
    super.prepareView(ctx);
    ctx.getRequest().setAttribute("publicKey", getPublicKey(ctx));
    Map<String, String> urlParam = new HashMap<>();
    urlParam.put("webaction", TYPE + ".createSession");
    urlParam.put(IContentVisualComponent.COMP_ID_REQUEST_PARAM, getId());
    String url = URLHelper.createURL(ctx, urlParam);
    ctx.getRequest().setAttribute("createSessionUrl", url);
    ctx.getRequest().setAttribute("bancontact", isBancontact(ctx));
    Basket basket = Basket.getInstance(ctx);
    basket.setLanguage(ctx.getRequestContentLanguage());
    // bancontact
    if (isBancontact(ctx) && basket.getStep() == Basket.PAY_STEP) {
        basket.setLock(true);
        synchronized (Stripe.class) {
            // Set your secret key. Remember to switch to your live secret key in
            // production.
            // See your keys here: https://dashboard.stripe.com/apikeys
            Stripe.apiKey = getPrivateKey(ctx);
            PaymentIntentCreateParams params = PaymentIntentCreateParams.builder().setAmount(Math.round(basket.getTotal(ctx, true) * 100)).setCurrency(basket.getCurrencyCode()).addPaymentMethodType("bancontact").setPaymentMethodOptions(PaymentIntentCreateParams.PaymentMethodOptions.builder().putExtraParam("bancontact[preferred_language]", ctx.getRequestContentLanguage()).build()).build();
            PaymentIntent paymentIntent = PaymentIntent.create(params);
            basket.setPaymentIntentBancontact(paymentIntent.getId());
            basket.setComponentId(getId());
            BasketPersistenceService.getInstance(ctx.getGlobalContext()).storeBasket(basket);
            urlParam.clear();
            urlParam.put("webaction", TYPE + ".successBancontact");
            urlParam.put(IContentVisualComponent.COMP_ID_REQUEST_PARAM, getId());
            String bancontactSuccessURL = URLHelper.createURL(ctx.getContextForAbsoluteURL(), ctx.getPath(), urlParam) + "&id=" + paymentIntent.getId();
            ctx.getRequest().setAttribute("PAYMENT_INTENT_CLIENT_SECRET", paymentIntent.getClientSecret());
            ctx.getRequest().setAttribute("bancontactSuccessURL", bancontactSuccessURL);
            ctx.getRequest().setAttribute("name", basket.getRealFirstName() + ' ' + basket.getRealLastName());
        }
    }
}
Also used : HashMap(java.util.HashMap) Stripe(com.stripe.Stripe) Basket(org.javlo.ecom.Basket) PaymentIntentCreateParams(com.stripe.param.PaymentIntentCreateParams) PaymentIntent(com.stripe.model.PaymentIntent)

Example 2 with PaymentIntentCreateParams

use of com.stripe.param.PaymentIntentCreateParams in project shopizer by shopizer-ecommerce.

the class Stripe3Payment method initTransaction.

@Override
public Transaction initTransaction(MerchantStore store, Customer customer, BigDecimal amount, Payment payment, IntegrationConfiguration configuration, IntegrationModule module) throws IntegrationException {
    String strAmount = String.valueOf(amount);
    strAmount = strAmount.replace(".", "");
    Transaction transaction = new Transaction();
    try {
        String apiKey = configuration.getIntegrationKeys().get("secretKey");
        if (StringUtils.isBlank(apiKey)) {
            IntegrationException te = new IntegrationException("Can't process Stripe, missing payment.metaData");
            te.setExceptionType(IntegrationException.TRANSACTION_EXCEPTION);
            te.setMessageCode("message.payment.error");
            te.setErrorCode(IntegrationException.TRANSACTION_EXCEPTION);
            throw te;
        }
        Stripe.apiKey = apiKey;
        PaymentIntentCreateParams createParams = new PaymentIntentCreateParams.Builder().setCurrency(store.getCurrency().getCode()).setAmount(Long.parseLong(strAmount)).setCaptureMethod(PaymentIntentCreateParams.CaptureMethod.MANUAL).build();
        // Create a PaymentIntent with the order amount and currency
        PaymentIntent intent = PaymentIntent.create(createParams);
        intent.getClientSecret();
        transaction.setAmount(amount);
        // transaction.setOrder(order);
        transaction.setTransactionDate(new Date());
        transaction.setTransactionType(TransactionType.AUTHORIZE);
        transaction.setPaymentType(PaymentType.CREDITCARD);
        transaction.getTransactionDetails().put("TRANSACTIONID", intent.getId());
        transaction.getTransactionDetails().put("TRNAPPROVED", intent.getStatus());
        transaction.getTransactionDetails().put("TRNORDERNUMBER", intent.getId());
        transaction.getTransactionDetails().put("INTENTSECRET", intent.getClientSecret());
        transaction.getTransactionDetails().put("MESSAGETEXT", null);
    } catch (Exception e) {
        throw buildException(e);
    }
    return transaction;
}
Also used : Transaction(com.salesmanager.core.model.payments.Transaction) IntegrationException(com.salesmanager.core.modules.integration.IntegrationException) PaymentIntentCreateParams(com.stripe.param.PaymentIntentCreateParams) PaymentIntent(com.stripe.model.PaymentIntent) Date(java.util.Date) CardException(com.stripe.exception.CardException) InvalidRequestException(com.stripe.exception.InvalidRequestException) AuthenticationException(com.stripe.exception.AuthenticationException) StripeException(com.stripe.exception.StripeException) IntegrationException(com.salesmanager.core.modules.integration.IntegrationException)

Aggregations

PaymentIntent (com.stripe.model.PaymentIntent)2 PaymentIntentCreateParams (com.stripe.param.PaymentIntentCreateParams)2 Transaction (com.salesmanager.core.model.payments.Transaction)1 IntegrationException (com.salesmanager.core.modules.integration.IntegrationException)1 Stripe (com.stripe.Stripe)1 AuthenticationException (com.stripe.exception.AuthenticationException)1 CardException (com.stripe.exception.CardException)1 InvalidRequestException (com.stripe.exception.InvalidRequestException)1 StripeException (com.stripe.exception.StripeException)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Basket (org.javlo.ecom.Basket)1