use of com.salesmanager.core.model.payments.CreditCardPayment in project shopizer by shopizer-ecommerce.
the class BeanStreamPayment method processTransaction.
private Transaction processTransaction(MerchantStore store, Customer customer, TransactionType type, BigDecimal amount, Payment payment, IntegrationConfiguration configuration, IntegrationModule module) throws IntegrationException {
boolean bSandbox = false;
if (configuration.getEnvironment().equals("TEST")) {
// sandbox
bSandbox = true;
}
ModuleConfig configs = module.getModuleConfigs().get("PROD");
if (bSandbox) {
configs = module.getModuleConfigs().get("TEST");
}
if (configs == null) {
throw new IntegrationException("Module not configured for TEST or PROD");
}
String server = new StringBuffer().append(configs.getScheme()).append("://").append(configs.getHost()).append(":").append(configs.getPort()).append(configs.getUri()).toString();
HttpURLConnection conn = null;
try {
// TODO
String uniqueId = UUID.randomUUID().toString();
String orderNumber = uniqueId;
String amnt = productPriceUtils.getAdminFormatedAmount(store, amount);
StringBuilder messageString = new StringBuilder();
String transactionType = "P";
if (type == TransactionType.AUTHORIZE) {
transactionType = "PA";
} else if (type == TransactionType.AUTHORIZECAPTURE) {
transactionType = "P";
}
CreditCardPayment creditCardPayment = (CreditCardPayment) payment;
messageString.append("requestType=BACKEND&");
messageString.append("merchant_id=").append(configuration.getIntegrationKeys().get("merchantid")).append("&");
messageString.append("trnType=").append(transactionType).append("&");
messageString.append("username=").append(configuration.getIntegrationKeys().get("username")).append("&");
messageString.append("password=").append(configuration.getIntegrationKeys().get("password")).append("&");
messageString.append("orderNumber=").append(orderNumber).append("&");
messageString.append("trnCardOwner=").append(creditCardPayment.getCardOwner()).append("&");
messageString.append("trnCardNumber=").append(creditCardPayment.getCreditCardNumber()).append("&");
messageString.append("trnExpMonth=").append(creditCardPayment.getExpirationMonth()).append("&");
messageString.append("trnExpYear=").append(creditCardPayment.getExpirationYear().substring(2)).append("&");
messageString.append("trnCardCvd=").append(creditCardPayment.getCredidCardValidationNumber()).append("&");
messageString.append("trnAmount=").append(amnt).append("&");
StringBuilder nm = new StringBuilder();
nm.append(customer.getBilling().getFirstName()).append(" ").append(customer.getBilling().getLastName());
messageString.append("ordName=").append(nm.toString()).append("&");
messageString.append("ordAddress1=").append(customer.getBilling().getAddress()).append("&");
messageString.append("ordCity=").append(customer.getBilling().getCity()).append("&");
String stateProvince = customer.getBilling().getState();
if (customer.getBilling().getZone() != null) {
stateProvince = customer.getBilling().getZone().getCode();
}
String countryName = customer.getBilling().getCountry().getIsoCode();
messageString.append("ordProvince=").append(stateProvince).append("&");
messageString.append("ordPostalCode=").append(customer.getBilling().getPostalCode().replaceAll("\\s", "")).append("&");
messageString.append("ordCountry=").append(countryName).append("&");
messageString.append("ordPhoneNumber=").append(customer.getBilling().getTelephone()).append("&");
messageString.append("ordEmailAddress=").append(customer.getEmailAddress());
/**
* purchase (P)
* -----------
* REQUEST -> merchant_id=123456789&requestType=BACKEND&trnType=P&trnOrderNumber=1234TEST&trnAmount=5.00&trnCardOwner=Joe+Test&trnCardNumber=4030000010001234&trnExpMonth=10&trnExpYear=10&ordName=Joe+Test&ordAddress1=123+Test+Street&ordCity=Victoria&ordProvince=BC&ordCountry=CA&ordPostalCode=V8T2E7&ordPhoneNumber=5555555555&ordEmailAddress=joe%40testemail.com
* RESPONSE-> trnApproved=1&trnId=10003067&messageId=1&messageText=Approved&trnOrderNumber=E40089&authCode=TEST&errorType=N&errorFields=&responseType=T&trnAmount=10%2E00&trnDate=1%2F17%2F2008+11%3A36%3A34+AM&avsProcessed=0&avsId=0&avsResult=0&avsAddrMatch=0&avsPostalMatch=0&avsMessage=Address+Verification+not+performed+for+this+transaction%2E&rspCodeCav=0&rspCavResult=0&rspCodeCredit1=0&rspCodeCredit2=0&rspCodeCredit3=0&rspCodeCredit4=0&rspCodeAddr1=0&rspCodeAddr2=0&rspCodeAddr3=0&rspCodeAddr4=0&rspCodeDob=0&rspCustomerDec=&trnType=P&paymentMethod=CC&ref1=&ref2=&ref3=&ref4=&ref5=
*
* pre authorization (PA)
* ----------------------
*
* Prior to processing a pre-authorization through the API, you must modify the transaction settings in your Beanstream merchant member area to allow for this transaction type.
* - Log in to the Beanstream online member area at www.beanstream.com/admin/sDefault.asp.
* - Navigate to administration - account admin - order settings in the left menu.
* Under the heading �Restrict Internet Transaction Processing Types,� select either of the last two options. The �Purchases or Pre-Authorization Only� option will allow you to process both types of transaction through your web interface. De-selecting the �Restrict Internet Transaction Processing Types� checkbox will allow you to process all types of transactions including returns, voids and pre-auth completions.
*
* capture (PAC) -> requires trnId
* -------------
*
* refund (R)
* -------------
* REQUEST -> merchant_id=123456789&requestType=BACKEND&trnType=R&username=user1234&password=pass1234&trnOrderNumber=1234&trnAmount=1.00&adjId=10002115
* RESPONSE-> trnApproved=1&trnId=10002118&messageId=1&messageText=Approved&trnOrderNumber=1234R&authCode=TEST&errorType=N&errorFields=&responseType=T&trnAmount=1%2E00&trnDate=8%2F17%2F2009+1%3A44%3A56+PM&avsProcessed=0&avsId=0&avsResult=0&avsAddrMatch=0&avsPostalMatch=0&avsMessage=Address+Verification+not+performed+for+this+transaction%2E&cardType=VI&trnType=R&paymentMethod=CC&ref1=&ref2=&ref3=&ref4=&ref5=
*
* //notes
* //On receipt of the transaction response, the merchant must display order amount, transaction ID number, bank authorization code (authCode), currency, date and �messageText� to the customer on a confirmation page.
*/
// String agent = "Mozilla/4.0";
// String respText = "";
// Map nvp = null;
/**
* debug *
*/
StringBuilder messageLogString = new StringBuilder();
messageLogString.append("requestType=BACKEND&");
messageLogString.append("merchant_id=").append(configuration.getIntegrationKeys().get("merchantid")).append("&");
messageLogString.append("trnType=").append(type).append("&");
messageLogString.append("orderNumber=").append(orderNumber).append("&");
messageLogString.append("trnCardOwner=").append(creditCardPayment.getCardOwner()).append("&");
messageLogString.append("trnCardNumber=").append(CreditCardUtils.maskCardNumber(creditCardPayment.getCreditCardNumber())).append("&");
messageLogString.append("trnExpMonth=").append(creditCardPayment.getExpirationMonth()).append("&");
messageLogString.append("trnExpYear=").append(creditCardPayment.getExpirationYear()).append("&");
messageLogString.append("trnCardCvd=").append(creditCardPayment.getCredidCardValidationNumber()).append("&");
messageLogString.append("trnAmount=").append(amnt).append("&");
messageLogString.append("ordName=").append(nm.toString()).append("&");
messageLogString.append("ordAddress1=").append(customer.getBilling().getAddress()).append("&");
messageLogString.append("ordCity=").append(customer.getBilling().getCity()).append("&");
messageLogString.append("ordProvince=").append(stateProvince).append("&");
messageLogString.append("ordPostalCode=").append(customer.getBilling().getPostalCode()).append("&");
messageLogString.append("ordCountry=").append(customer.getBilling().getCountry().getName()).append("&");
messageLogString.append("ordPhoneNumber=").append(customer.getBilling().getTelephone()).append("&");
messageLogString.append("ordEmailAddress=").append(customer.getEmailAddress());
/**
* debug *
*/
LOGGER.debug("REQUEST SENT TO BEANSTREAM -> " + messageLogString.toString());
URL postURL = new URL(server);
conn = (HttpURLConnection) postURL.openConnection();
return sendTransaction(orderNumber, store, messageString.toString(), transactionType, type, payment.getPaymentType(), amount, configuration, module);
} catch (Exception e) {
if (e instanceof IntegrationException)
throw (IntegrationException) e;
throw new IntegrationException("Error while processing BeanStream transaction", e);
} finally {
if (conn != null) {
try {
conn.disconnect();
} catch (Exception ignore) {
}
}
}
}
use of com.salesmanager.core.model.payments.CreditCardPayment in project shopizer by shopizer-ecommerce.
the class OrderFacadeImpl method processOrderModel.
/**
* Commit an order
* @param order
* @param customer
* @param transaction
* @param store
* @param language
* @return
* @throws ServiceException
*/
private Order processOrderModel(ShopOrder order, Customer customer, Transaction transaction, MerchantStore store, Language language) throws ServiceException {
try {
if (order.isShipToBillingAdress()) {
// customer shipping is billing
PersistableCustomer orderCustomer = order.getCustomer();
Address billing = orderCustomer.getBilling();
orderCustomer.setDelivery(billing);
}
Order modelOrder = new Order();
modelOrder.setDatePurchased(new Date());
modelOrder.setBilling(customer.getBilling());
modelOrder.setDelivery(customer.getDelivery());
modelOrder.setPaymentModuleCode(order.getPaymentModule());
modelOrder.setPaymentType(PaymentType.valueOf(order.getPaymentMethodType()));
modelOrder.setShippingModuleCode(order.getShippingModule());
modelOrder.setCustomerAgreement(order.isCustomerAgreed());
// set the store
modelOrder.setLocale(LocaleUtils.getLocale(store));
// locale based
// on the
// country for
// order $
// formatting
List<ShoppingCartItem> shoppingCartItems = order.getShoppingCartItems();
Set<OrderProduct> orderProducts = new LinkedHashSet<OrderProduct>();
if (!StringUtils.isBlank(order.getComments())) {
OrderStatusHistory statusHistory = new OrderStatusHistory();
statusHistory.setStatus(OrderStatus.ORDERED);
statusHistory.setOrder(modelOrder);
statusHistory.setDateAdded(new Date());
statusHistory.setComments(order.getComments());
modelOrder.getOrderHistory().add(statusHistory);
}
OrderProductPopulator orderProductPopulator = new OrderProductPopulator();
orderProductPopulator.setDigitalProductService(digitalProductService);
orderProductPopulator.setProductAttributeService(productAttributeService);
orderProductPopulator.setProductService(productService);
String shoppingCartCode = null;
for (ShoppingCartItem item : shoppingCartItems) {
if (shoppingCartCode == null && item.getShoppingCart() != null) {
shoppingCartCode = item.getShoppingCart().getShoppingCartCode();
}
/**
* Before processing order quantity of item must be > 0
*/
Product product = productService.getById(item.getProductId());
if (product == null) {
throw new ServiceException(ServiceException.EXCEPTION_INVENTORY_MISMATCH);
}
LOGGER.debug("Validate inventory");
for (ProductAvailability availability : product.getAvailabilities()) {
if (availability.getRegion().equals(Constants.ALL_REGIONS)) {
int qty = availability.getProductQuantity();
if (qty < item.getQuantity()) {
throw new ServiceException(ServiceException.EXCEPTION_INVENTORY_MISMATCH);
}
}
}
OrderProduct orderProduct = new OrderProduct();
orderProduct = orderProductPopulator.populate(item, orderProduct, store, language);
orderProduct.setOrder(modelOrder);
orderProducts.add(orderProduct);
}
modelOrder.setOrderProducts(orderProducts);
OrderTotalSummary summary = order.getOrderTotalSummary();
List<com.salesmanager.core.model.order.OrderTotal> totals = summary.getTotals();
// re-order totals
Collections.sort(totals, new Comparator<com.salesmanager.core.model.order.OrderTotal>() {
public int compare(com.salesmanager.core.model.order.OrderTotal x, com.salesmanager.core.model.order.OrderTotal y) {
if (x.getSortOrder() == y.getSortOrder())
return 0;
return x.getSortOrder() < y.getSortOrder() ? -1 : 1;
}
});
Set<com.salesmanager.core.model.order.OrderTotal> modelTotals = new LinkedHashSet<com.salesmanager.core.model.order.OrderTotal>();
for (com.salesmanager.core.model.order.OrderTotal total : totals) {
total.setOrder(modelOrder);
modelTotals.add(total);
}
modelOrder.setOrderTotal(modelTotals);
modelOrder.setTotal(order.getOrderTotalSummary().getTotal());
// order misc objects
modelOrder.setCurrency(store.getCurrency());
modelOrder.setMerchant(store);
// customer object
orderCustomer(customer, modelOrder, language);
// populate shipping information
if (!StringUtils.isBlank(order.getShippingModule())) {
modelOrder.setShippingModuleCode(order.getShippingModule());
}
String paymentType = order.getPaymentMethodType();
Payment payment = new Payment();
payment.setPaymentType(PaymentType.valueOf(paymentType));
payment.setAmount(order.getOrderTotalSummary().getTotal());
payment.setModuleName(order.getPaymentModule());
payment.setCurrency(modelOrder.getCurrency());
if (order.getPayment() != null && order.getPayment().get("paymentToken") != null) {
// set
// token
String paymentToken = order.getPayment().get("paymentToken");
Map<String, String> paymentMetaData = new HashMap<String, String>();
payment.setPaymentMetaData(paymentMetaData);
paymentMetaData.put("paymentToken", paymentToken);
}
if (PaymentType.CREDITCARD.name().equals(paymentType)) {
payment = new CreditCardPayment();
((CreditCardPayment) payment).setCardOwner(order.getPayment().get("creditcard_card_holder"));
((CreditCardPayment) payment).setCredidCardValidationNumber(order.getPayment().get("creditcard_card_cvv"));
((CreditCardPayment) payment).setCreditCardNumber(order.getPayment().get("creditcard_card_number"));
((CreditCardPayment) payment).setExpirationMonth(order.getPayment().get("creditcard_card_expirationmonth"));
((CreditCardPayment) payment).setExpirationYear(order.getPayment().get("creditcard_card_expirationyear"));
Map<String, String> paymentMetaData = order.getPayment();
payment.setPaymentMetaData(paymentMetaData);
payment.setPaymentType(PaymentType.valueOf(paymentType));
payment.setAmount(order.getOrderTotalSummary().getTotal());
payment.setModuleName(order.getPaymentModule());
payment.setCurrency(modelOrder.getCurrency());
CreditCardType creditCardType = null;
String cardType = order.getPayment().get("creditcard_card_type");
// supported credit cards
if (CreditCardType.AMEX.name().equalsIgnoreCase(cardType)) {
creditCardType = CreditCardType.AMEX;
} else if (CreditCardType.VISA.name().equalsIgnoreCase(cardType)) {
creditCardType = CreditCardType.VISA;
} else if (CreditCardType.MASTERCARD.name().equalsIgnoreCase(cardType)) {
creditCardType = CreditCardType.MASTERCARD;
} else if (CreditCardType.DINERS.name().equalsIgnoreCase(cardType)) {
creditCardType = CreditCardType.DINERS;
} else if (CreditCardType.DISCOVERY.name().equalsIgnoreCase(cardType)) {
creditCardType = CreditCardType.DISCOVERY;
}
((CreditCardPayment) payment).setCreditCard(creditCardType);
if (creditCardType != null) {
CreditCard cc = new CreditCard();
cc.setCardType(creditCardType);
cc.setCcCvv(((CreditCardPayment) payment).getCredidCardValidationNumber());
cc.setCcOwner(((CreditCardPayment) payment).getCardOwner());
cc.setCcExpires(((CreditCardPayment) payment).getExpirationMonth() + "-" + ((CreditCardPayment) payment).getExpirationYear());
// hash credit card number
if (!StringUtils.isBlank(cc.getCcNumber())) {
String maskedNumber = CreditCardUtils.maskCardNumber(order.getPayment().get("creditcard_card_number"));
cc.setCcNumber(maskedNumber);
modelOrder.setCreditCard(cc);
}
}
}
if (PaymentType.PAYPAL.name().equals(paymentType)) {
// check for previous transaction
if (transaction == null) {
throw new ServiceException("payment.error");
}
payment = new com.salesmanager.core.model.payments.PaypalPayment();
((com.salesmanager.core.model.payments.PaypalPayment) payment).setPayerId(transaction.getTransactionDetails().get("PAYERID"));
((com.salesmanager.core.model.payments.PaypalPayment) payment).setPaymentToken(transaction.getTransactionDetails().get("TOKEN"));
}
modelOrder.setShoppingCartCode(shoppingCartCode);
modelOrder.setPaymentModuleCode(order.getPaymentModule());
payment.setModuleName(order.getPaymentModule());
if (transaction != null) {
orderService.processOrder(modelOrder, customer, order.getShoppingCartItems(), summary, payment, store);
} else {
orderService.processOrder(modelOrder, customer, order.getShoppingCartItems(), summary, payment, transaction, store);
}
return modelOrder;
} catch (ServiceException se) {
// may be invalid credit card
throw se;
} catch (Exception e) {
throw new ServiceException(e);
}
}
use of com.salesmanager.core.model.payments.CreditCardPayment in project shopizer by shopizer-ecommerce.
the class PaymentServiceImpl method processPayment.
@Override
public Transaction processPayment(Customer customer, MerchantStore store, Payment payment, List<ShoppingCartItem> items, Order order) throws ServiceException {
Validate.notNull(customer);
Validate.notNull(store);
Validate.notNull(payment);
Validate.notNull(order);
Validate.notNull(order.getTotal());
payment.setCurrency(store.getCurrency());
BigDecimal amount = order.getTotal();
// must have a shipping module configured
Map<String, IntegrationConfiguration> modules = this.getPaymentModulesConfigured(store);
if (modules == null) {
throw new ServiceException("No payment module configured");
}
IntegrationConfiguration configuration = modules.get(payment.getModuleName());
if (configuration == null) {
throw new ServiceException("Payment module " + payment.getModuleName() + " is not configured");
}
if (!configuration.isActive()) {
throw new ServiceException("Payment module " + payment.getModuleName() + " is not active");
}
String sTransactionType = configuration.getIntegrationKeys().get("transaction");
if (sTransactionType == null) {
sTransactionType = TransactionType.AUTHORIZECAPTURE.name();
}
try {
TransactionType.valueOf(sTransactionType);
} catch (IllegalArgumentException ie) {
LOGGER.warn("Transaction type " + sTransactionType + " does noe exist, using default AUTHORIZECAPTURE");
sTransactionType = "AUTHORIZECAPTURE";
}
if (sTransactionType.equals(TransactionType.AUTHORIZE.name())) {
payment.setTransactionType(TransactionType.AUTHORIZE);
} else {
payment.setTransactionType(TransactionType.AUTHORIZECAPTURE);
}
PaymentModule module = this.paymentModules.get(payment.getModuleName());
if (module == null) {
throw new ServiceException("Payment module " + payment.getModuleName() + " does not exist");
}
if (payment instanceof CreditCardPayment && "true".equals(coreConfiguration.getProperty("VALIDATE_CREDIT_CARD"))) {
CreditCardPayment creditCardPayment = (CreditCardPayment) payment;
validateCreditCard(creditCardPayment.getCreditCardNumber(), creditCardPayment.getCreditCard(), creditCardPayment.getExpirationMonth(), creditCardPayment.getExpirationYear());
}
IntegrationModule integrationModule = getPaymentMethodByCode(store, payment.getModuleName());
TransactionType transactionType = TransactionType.valueOf(sTransactionType);
if (transactionType == null) {
transactionType = payment.getTransactionType();
if (transactionType.equals(TransactionType.CAPTURE.name())) {
throw new ServiceException("This method does not allow to process capture transaction. Use processCapturePayment");
}
}
Transaction transaction = null;
if (transactionType == TransactionType.AUTHORIZE) {
transaction = module.authorize(store, customer, items, amount, payment, configuration, integrationModule);
} else if (transactionType == TransactionType.AUTHORIZECAPTURE) {
transaction = module.authorizeAndCapture(store, customer, items, amount, payment, configuration, integrationModule);
} else if (transactionType == TransactionType.INIT) {
transaction = module.initTransaction(store, customer, amount, payment, configuration, integrationModule);
}
if (transactionType != TransactionType.INIT) {
transactionService.create(transaction);
}
if (transactionType == TransactionType.AUTHORIZECAPTURE) {
order.setStatus(OrderStatus.ORDERED);
if (!payment.getPaymentType().name().equals(PaymentType.MONEYORDER.name())) {
order.setStatus(OrderStatus.PROCESSED);
}
}
return transaction;
}
Aggregations