use of com.salesmanager.core.model.payments.Transaction 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;
}
use of com.salesmanager.core.model.payments.Transaction in project shopizer by shopizer-ecommerce.
the class StripePayment 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(".", "");
Charge ch = Charge.retrieve(trnID);
Map<String, Object> params = new HashMap<>();
params.put("charge", ch.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 StripePayment 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 send by stripe from tokenization ui
*/
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;
}
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", false);
chargeParams.put("currency", store.getCurrency().getCode());
// obtained with Stripe.js
chargeParams.put("source", token);
chargeParams.put("description", new StringBuilder().append(TRANSACTION).append(" - ").append(store.getStorename()).toString());
Stripe.apiKey = apiKey;
Charge ch = Charge.create(chargeParams);
// Map<String,String> metadata = ch.getMetadata();
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", ch.getStatus());
transaction.getTransactionDetails().put("TRNORDERNUMBER", ch.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 BeanStreamPayment method parseResponse.
private Transaction parseResponse(TransactionType transactionType, PaymentType paymentType, Map<String, String> nvp, BigDecimal amount) throws Exception {
Transaction transaction = new Transaction();
transaction.setAmount(amount);
// transaction.setOrder(order);
transaction.setTransactionDate(new Date());
transaction.setTransactionType(transactionType);
transaction.setPaymentType(PaymentType.CREDITCARD);
transaction.getTransactionDetails().put("TRANSACTIONID", (String) nvp.get("TRNID"));
transaction.getTransactionDetails().put("TRNAPPROVED", (String) nvp.get("TRNAPPROVED"));
transaction.getTransactionDetails().put("TRNORDERNUMBER", (String) nvp.get("TRNORDERNUMBER"));
transaction.getTransactionDetails().put("MESSAGETEXT", (String) nvp.get("MESSAGETEXT"));
if (nvp.get("INTERNALORDERID") != null) {
transaction.getTransactionDetails().put("INTERNALORDERID", (String) nvp.get("INTERNALORDERID"));
}
return transaction;
}
use of com.salesmanager.core.model.payments.Transaction in project shopizer by shopizer-ecommerce.
the class BraintreePayment method refund.
@Override
public Transaction refund(boolean partial, MerchantStore store, Transaction transaction, Order order, BigDecimal amount, IntegrationConfiguration configuration, IntegrationModule module) throws IntegrationException {
String merchantId = configuration.getIntegrationKeys().get("merchant_id");
String publicKey = configuration.getIntegrationKeys().get("public_key");
String privateKey = configuration.getIntegrationKeys().get("private_key");
Validate.notNull(merchantId, "merchant_id cannot be null");
Validate.notNull(publicKey, "public_key cannot be null");
Validate.notNull(privateKey, "private_key cannot be null");
String auth = transaction.getTransactionDetails().get("TRANSACTIONID");
if (StringUtils.isBlank(auth)) {
IntegrationException te = new IntegrationException("Can't process Braintree refund, missing transaction id");
te.setExceptionType(IntegrationException.TRANSACTION_EXCEPTION);
te.setMessageCode("message.payment.error");
te.setErrorCode(IntegrationException.TRANSACTION_EXCEPTION);
throw te;
}
Environment environment = Environment.PRODUCTION;
if (configuration.getEnvironment().equals("TEST")) {
// sandbox
environment = Environment.SANDBOX;
}
BraintreeGateway gateway = new BraintreeGateway(environment, merchantId, publicKey, privateKey);
Result<com.braintreegateway.Transaction> result = gateway.transaction().refund(auth, amount);
String trxId = null;
if (result.isSuccess()) {
com.braintreegateway.Transaction settledTransaction = result.getTarget();
trxId = settledTransaction.getId();
} else {
String errorString = "";
for (ValidationError error : result.getErrors().getAllDeepValidationErrors()) {
errorString += "Error: " + error.getCode() + ": " + error.getMessage() + "\n";
}
IntegrationException te = new IntegrationException("Can't process Braintree refund " + errorString);
te.setExceptionType(IntegrationException.TRANSACTION_EXCEPTION);
te.setMessageCode("message.payment.error");
te.setErrorCode(IntegrationException.TRANSACTION_EXCEPTION);
throw te;
}
if (StringUtils.isBlank(trxId)) {
IntegrationException te = new IntegrationException("Can't process Braintree refund, missing original transaction");
te.setExceptionType(IntegrationException.TRANSACTION_EXCEPTION);
te.setMessageCode("message.payment.error");
te.setErrorCode(IntegrationException.TRANSACTION_EXCEPTION);
throw te;
}
Transaction trx = new Transaction();
trx.setAmount(amount);
trx.setTransactionDate(new Date());
trx.setTransactionType(TransactionType.REFUND);
trx.setPaymentType(PaymentType.CREDITCARD);
trx.getTransactionDetails().put("TRANSACTIONID", trxId);
trx.getTransactionDetails().put("TRNAPPROVED", null);
trx.getTransactionDetails().put("TRNORDERNUMBER", trxId);
trx.getTransactionDetails().put("MESSAGETEXT", null);
return trx;
}
Aggregations