use of com.salesmanager.core.model.payments.Transaction in project shopizer by shopizer-ecommerce.
the class Stripe3Payment method refund.
@Override
public Transaction refund(boolean partial, MerchantStore store, Transaction transaction, Order order, BigDecimal amount, IntegrationConfiguration configuration, IntegrationModule module) throws IntegrationException {
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;
}
try {
String trnID = transaction.getTransactionDetails().get("TRNORDERNUMBER");
String amnt = productPriceUtils.getAdminFormatedAmount(store, amount);
Stripe.apiKey = apiKey;
// stripe does not support floating point
// so amnt * 100 or remove floating point
// 553.47 = 55347
String strAmount = String.valueOf(amnt);
strAmount = strAmount.replace(".", "");
PaymentIntent paymentIntent = PaymentIntent.retrieve(trnID);
Map<String, Object> params = new HashMap<>();
params.put("payment_intent", paymentIntent.getId());
params.put("amount", strAmount);
Refund re = Refund.create(params);
transaction = new Transaction();
transaction.setAmount(order.getTotal());
transaction.setOrder(order);
transaction.setTransactionDate(new Date());
transaction.setTransactionType(TransactionType.CAPTURE);
transaction.setPaymentType(PaymentType.CREDITCARD);
transaction.getTransactionDetails().put("TRANSACTIONID", transaction.getTransactionDetails().get("TRANSACTIONID"));
transaction.getTransactionDetails().put("TRNAPPROVED", re.getReason());
transaction.getTransactionDetails().put("TRNORDERNUMBER", re.getId());
transaction.getTransactionDetails().put("MESSAGETEXT", null);
return transaction;
} catch (Exception e) {
throw buildException(e);
}
}
use of com.salesmanager.core.model.payments.Transaction in project shopizer by shopizer-ecommerce.
the class Stripe3Payment method authorize.
/* ----------------------------------------- */
@Override
public Transaction authorize(MerchantStore store, Customer customer, List<ShoppingCartItem> items, BigDecimal amount, Payment payment, IntegrationConfiguration configuration, IntegrationModule module) throws IntegrationException {
Transaction transaction = new Transaction();
try {
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;
}
/**
* This is the PaymentIntent ID created on the Frontend, that we will now store.
*/
String token = payment.getPaymentMetaData().get("stripe_token");
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;
}
Stripe.apiKey = apiKey;
PaymentIntent paymentIntent = PaymentIntent.retrieve(token);
transaction.setAmount(amount);
// transaction.setOrder(order);
transaction.setTransactionDate(new Date());
transaction.setTransactionType(TransactionType.AUTHORIZE);
transaction.setPaymentType(PaymentType.CREDITCARD);
transaction.getTransactionDetails().put("TRANSACTIONID", token);
transaction.getTransactionDetails().put("TRNAPPROVED", paymentIntent.getStatus());
// <---- We store the PI id here
transaction.getTransactionDetails().put("TRNORDERNUMBER", paymentIntent.getId());
transaction.getTransactionDetails().put("MESSAGETEXT", null);
} catch (Exception e) {
throw buildException(e);
}
return transaction;
}
use of com.salesmanager.core.model.payments.Transaction 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);
}
}
use of com.salesmanager.core.model.payments.Transaction in project shopizer by shopizer-ecommerce.
the class StripePayment 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;
}
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;
}
Stripe.apiKey = apiKey;
Charge ch = Charge.retrieve(chargeId);
ch.capture();
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", ch.getStatus());
transaction.getTransactionDetails().put("TRNORDERNUMBER", ch.getId());
transaction.getTransactionDetails().put("MESSAGETEXT", null);
return transaction;
} catch (Exception e) {
throw buildException(e);
}
}
use of com.salesmanager.core.model.payments.Transaction in project shopizer by shopizer-ecommerce.
the class StripePayment method initTransaction.
@Override
public Transaction initTransaction(MerchantStore store, Customer customer, BigDecimal amount, Payment payment, IntegrationConfiguration configuration, IntegrationModule module) throws IntegrationException {
Validate.notNull(configuration, "Configuration cannot be null");
String publicKey = configuration.getIntegrationKeys().get("publishableKey");
Validate.notNull(publicKey, "Publishable key not found in configuration");
Transaction transaction = new Transaction();
transaction.setAmount(amount);
transaction.setDetails(publicKey);
transaction.setPaymentType(payment.getPaymentType());
transaction.setTransactionDate(new Date());
transaction.setTransactionType(payment.getTransactionType());
return transaction;
}
Aggregations