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());
}
}
}
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;
}
Aggregations