use of com.stripe.param.PaymentIntentCaptureParams in project shopizer by shopizer-ecommerce.
the class Stripe3Payment method authorizeAndCapture.
@Override
public Transaction authorizeAndCapture(MerchantStore store, Customer customer, List<ShoppingCartItem> items, BigDecimal amount, Payment payment, IntegrationConfiguration configuration, IntegrationModule module) throws IntegrationException {
String apiKey = configuration.getIntegrationKeys().get("secretKey");
if (payment.getPaymentMetaData() == null || 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;
}
String token = payment.getPaymentMetaData().get("stripe_token");
if (StringUtils.isBlank(token)) {
// possibly from api
token = payment.getPaymentMetaData().get("paymentToken");
}
if (StringUtils.isBlank(token)) {
IntegrationException te = new IntegrationException("Can't process Stripe, missing stripe token");
te.setExceptionType(IntegrationException.TRANSACTION_EXCEPTION);
te.setMessageCode("message.payment.error");
te.setErrorCode(IntegrationException.TRANSACTION_EXCEPTION);
throw te;
}
Transaction transaction = new Transaction();
try {
String amnt = productPriceUtils.getAdminFormatedAmount(store, amount);
// stripe does not support floating point
// so amnt * 100 or remove floating point
// 553.47 = 55347
String strAmount = String.valueOf(amnt);
strAmount = strAmount.replace(".", "");
/*Map<String, Object> chargeParams = new HashMap<String, Object>();
chargeParams.put("amount", strAmount);
chargeParams.put("capture", true);
chargeParams.put("currency", store.getCurrency().getCode());
chargeParams.put("source", token); // obtained with Stripe.js
chargeParams.put("description", new StringBuilder().append(TRANSACTION).append(" - ").append(store.getStorename()).toString());
*/
Stripe.apiKey = apiKey;
PaymentIntent paymentIntent = PaymentIntent.retrieve(token);
PaymentIntentCaptureParams params = PaymentIntentCaptureParams.builder().setAmountToCapture(Long.parseLong(strAmount)).setStatementDescriptor(store.getStorename().length() > 22 ? store.getStorename().substring(0, 22) : store.getStorename()).build();
paymentIntent = paymentIntent.capture(params);
// Map<String,String> metadata = ch.getMetadata();
transaction.setAmount(amount);
// transaction.setOrder(order);
transaction.setTransactionDate(new Date());
transaction.setTransactionType(TransactionType.AUTHORIZECAPTURE);
transaction.setPaymentType(PaymentType.CREDITCARD);
transaction.getTransactionDetails().put("TRANSACTIONID", token);
transaction.getTransactionDetails().put("TRNAPPROVED", paymentIntent.getStatus());
transaction.getTransactionDetails().put("TRNORDERNUMBER", paymentIntent.getId());
transaction.getTransactionDetails().put("MESSAGETEXT", null);
} catch (Exception e) {
e.printStackTrace();
throw buildException(e);
}
return transaction;
}
use of com.stripe.param.PaymentIntentCaptureParams in project shopizer by shopizer-ecommerce.
the class Stripe3Payment method capture.
@Override
public Transaction capture(MerchantStore store, Customer customer, Order order, Transaction capturableTransaction, IntegrationConfiguration configuration, IntegrationModule module) throws IntegrationException {
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;
}
// <---- We retrieve the PI id here
String chargeId = capturableTransaction.getTransactionDetails().get("TRNORDERNUMBER");
if (StringUtils.isBlank(chargeId)) {
IntegrationException te = new IntegrationException("Can't process Stripe capture, missing TRNORDERNUMBER");
te.setExceptionType(IntegrationException.TRANSACTION_EXCEPTION);
te.setMessageCode("message.payment.error");
te.setErrorCode(IntegrationException.TRANSACTION_EXCEPTION);
throw te;
}
String amnt = productPriceUtils.getAdminFormatedAmount(store, order.getTotal());
String strAmount = String.valueOf(amnt);
strAmount = strAmount.replace(".", "");
Stripe.apiKey = apiKey;
PaymentIntent paymentIntent = PaymentIntent.retrieve(chargeId);
PaymentIntentCaptureParams params = PaymentIntentCaptureParams.builder().setAmountToCapture(Long.parseLong(strAmount)).setStatementDescriptor(store.getStorename().length() > 22 ? store.getStorename().substring(0, 22) : store.getStorename()).build();
paymentIntent = paymentIntent.capture(params);
transaction.setAmount(order.getTotal());
transaction.setOrder(order);
transaction.setTransactionDate(new Date());
transaction.setTransactionType(TransactionType.CAPTURE);
transaction.setPaymentType(PaymentType.CREDITCARD);
transaction.getTransactionDetails().put("TRANSACTIONID", capturableTransaction.getTransactionDetails().get("TRANSACTIONID"));
transaction.getTransactionDetails().put("TRNAPPROVED", paymentIntent.getStatus());
transaction.getTransactionDetails().put("TRNORDERNUMBER", paymentIntent.getId());
transaction.getTransactionDetails().put("MESSAGETEXT", null);
return transaction;
} catch (Exception e) {
throw buildException(e);
}
}
Aggregations