| @@ -0,0 +1,162 @@ | ||
| /* | ||
| * Copyright 2008-2009 the original author or authors. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.broadleafcommerce.core.web.api.wrapper; | ||
|
|
||
| import org.broadleafcommerce.common.money.Money; | ||
| import org.broadleafcommerce.core.order.domain.Order; | ||
| import org.broadleafcommerce.core.order.service.CartService; | ||
| import org.broadleafcommerce.core.payment.domain.AmountItem; | ||
| import org.broadleafcommerce.core.payment.domain.PaymentInfo; | ||
| import org.broadleafcommerce.core.payment.service.PaymentInfoService; | ||
| import org.broadleafcommerce.core.payment.service.type.PaymentInfoType; | ||
| import org.springframework.context.ApplicationContext; | ||
|
|
||
| import javax.servlet.http.HttpServletRequest; | ||
| import javax.xml.bind.annotation.*; | ||
| import java.util.ArrayList; | ||
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| /** | ||
| * This is a JAXB wrapper around PaymentInfo. | ||
| * <p/> | ||
| * User: Elbert Bautista | ||
| * Date: 4/26/12 | ||
| */ | ||
| @XmlRootElement(name = "paymentInfo") | ||
| @XmlAccessorType(value = XmlAccessType.FIELD) | ||
| public class PaymentInfoWrapper extends BaseWrapper implements APIWrapper<PaymentInfo>, APIUnwrapper<PaymentInfo> { | ||
|
|
||
| @XmlElement | ||
| protected Long id; | ||
|
|
||
| @XmlElement | ||
| protected Long orderId; | ||
|
|
||
| @XmlElement | ||
| protected String type; | ||
|
|
||
| @XmlElement | ||
| protected AddressWrapper address; | ||
|
|
||
| @XmlElement | ||
| protected PhoneWrapper phone; | ||
|
|
||
| @XmlElement(name = "element") | ||
| @XmlElementWrapper(name = "additionalFields") | ||
| protected List<MapElementWrapper> additionalFields; | ||
|
|
||
| @XmlElement | ||
| protected Money amount; | ||
|
|
||
| @XmlElement(name = "amountItem") | ||
| @XmlElementWrapper(name = "amountItems") | ||
| protected List<AmountItemWrapper> amountItems; | ||
|
|
||
| @XmlElement | ||
| protected String customerIpAddress; | ||
|
|
||
| @XmlElement | ||
| protected String referenceNumber; | ||
|
|
||
| @Override | ||
| public void wrap(PaymentInfo model, HttpServletRequest request) { | ||
| this.id = model.getId(); | ||
|
|
||
| if (model.getOrder() != null) { | ||
| this.orderId = model.getOrder().getId(); | ||
| } | ||
|
|
||
| if (model.getType() != null) { | ||
| this.type = model.getType().getType(); | ||
| } | ||
|
|
||
| if (model.getAddress() != null) { | ||
| AddressWrapper addressWrapper = (AddressWrapper) context.getBean(AddressWrapper.class.getName()); | ||
| addressWrapper.wrap(model.getAddress(), request); | ||
| this.address = addressWrapper; | ||
| } | ||
|
|
||
| if (model.getPhone() != null) { | ||
| PhoneWrapper phoneWrapper = (PhoneWrapper) context.getBean(PhoneWrapper.class.getName()); | ||
| phoneWrapper.wrap(model.getPhone(), request); | ||
| this.phone = phoneWrapper; | ||
| } | ||
|
|
||
| if (model.getAdditionalFields() != null && !model.getAdditionalFields().isEmpty()) { | ||
| List<MapElementWrapper> mapElementWrappers = new ArrayList<MapElementWrapper>(); | ||
| for (String key : model.getAdditionalFields().keySet()) { | ||
| MapElementWrapper mapElementWrapper = new MapElementWrapper(); | ||
| mapElementWrapper.setKey(key); | ||
| mapElementWrapper.setValue(model.getAdditionalFields().get(key)); | ||
| mapElementWrappers.add(mapElementWrapper); | ||
| } | ||
| this.additionalFields = mapElementWrappers; | ||
| } | ||
|
|
||
| this.amount = model.getAmount(); | ||
|
|
||
| if (model.getAmountItems() != null) { | ||
| List<AmountItemWrapper> wrappers = new ArrayList<AmountItemWrapper>(); | ||
| for (AmountItem amountItem : model.getAmountItems()) { | ||
| AmountItemWrapper amountItemWrapper = (AmountItemWrapper) context.getBean(AmountItemWrapper.class.getName()); | ||
| amountItemWrapper.wrap(amountItem, request); | ||
| wrappers.add(amountItemWrapper); | ||
| } | ||
| this.amountItems = wrappers; | ||
| } | ||
|
|
||
| this.customerIpAddress = model.getCustomerIpAddress(); | ||
| this.referenceNumber = model.getReferenceNumber(); | ||
| } | ||
|
|
||
| @Override | ||
| public PaymentInfo unwrap(HttpServletRequest request, ApplicationContext context) { | ||
| PaymentInfoService paymentInfoService = (PaymentInfoService) context.getBean("blPaymentInfoService"); | ||
| PaymentInfo paymentInfo = paymentInfoService.create(); | ||
|
|
||
| CartService cartService = (CartService) context.getBean("blCartService"); | ||
| Order order = cartService.findOrderById(this.orderId); | ||
| paymentInfo.setOrder(order); | ||
|
|
||
| paymentInfo.setType(PaymentInfoType.getInstance(this.type)); | ||
|
|
||
| if (this.address != null) { | ||
| paymentInfo.setAddress(this.address.unwrap(request, context)); | ||
| } | ||
|
|
||
| if (this.phone != null) { | ||
| paymentInfo.setPhone(this.phone.unwrap(request, context)); | ||
| } | ||
|
|
||
| if (this.additionalFields != null && !this.additionalFields.isEmpty()) { | ||
| Map<String, String> fields = new HashMap<String, String>(); | ||
| for (MapElementWrapper mapElementWrapper : this.additionalFields) { | ||
| fields.put(mapElementWrapper.getKey(), mapElementWrapper.getValue().toString()); | ||
| } | ||
|
|
||
| paymentInfo.setAdditionalFields(fields); | ||
| } | ||
|
|
||
| paymentInfo.setAmount(this.amount); | ||
| paymentInfo.setCustomerIpAddress(this.customerIpAddress); | ||
| paymentInfo.setReferenceNumber(this.referenceNumber); | ||
|
|
||
| return paymentInfo; | ||
| } | ||
| } |
| @@ -0,0 +1,68 @@ | ||
| /* | ||
| * Copyright 2008-2009 the original author or authors. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
|
|
||
| package org.broadleafcommerce.core.web.api.wrapper; | ||
|
|
||
| import org.broadleafcommerce.core.payment.domain.PaymentResponseItem; | ||
|
|
||
| import javax.servlet.http.HttpServletRequest; | ||
| import javax.xml.bind.annotation.*; | ||
| import java.util.ArrayList; | ||
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| /** | ||
| * This is a JAXB wrapper around PaymentResponseItem. | ||
| * <p/> | ||
| * User: Elbert Bautista | ||
| * Date: 4/26/12 | ||
| */ | ||
| @XmlRootElement(name = "paymentResponseItem") | ||
| @XmlAccessorType(value = XmlAccessType.FIELD) | ||
| public class PaymentResponseItemWrapper extends BaseWrapper implements APIWrapper<PaymentResponseItem> { | ||
|
|
||
| @XmlElement | ||
| protected Long paymentInfoId; | ||
|
|
||
| @XmlElement | ||
| protected Boolean transactionSuccess; | ||
|
|
||
| @XmlElement | ||
| protected String processorResponseCode; | ||
|
|
||
| @XmlElement(name = "element") | ||
| @XmlElementWrapper(name = "additionalFields") | ||
| protected List<MapElementWrapper> additionalFields; | ||
|
|
||
| @Override | ||
| public void wrap(PaymentResponseItem model, HttpServletRequest request) { | ||
| this.paymentInfoId = model.getPaymentInfoId(); | ||
| this.processorResponseCode = model.getProcessorResponseCode(); | ||
| this.transactionSuccess = model.getTransactionSuccess(); | ||
| if (model.getAdditionalFields() != null && !model.getAdditionalFields().isEmpty()) { | ||
| List<MapElementWrapper> mapElementWrappers = new ArrayList<MapElementWrapper>(); | ||
| for (String key : model.getAdditionalFields().keySet()) { | ||
| MapElementWrapper mapElementWrapper = new MapElementWrapper(); | ||
| mapElementWrapper.setKey(key); | ||
| mapElementWrapper.setValue(model.getAdditionalFields().get(key)); | ||
| mapElementWrappers.add(mapElementWrapper); | ||
| } | ||
| this.additionalFields = mapElementWrappers; | ||
| } | ||
| } | ||
| } |
| @@ -0,0 +1,151 @@ | ||
| /* | ||
| * Copyright 2008-2009 the original author or authors. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.broadleafcommerce.core.web.api.wrapper; | ||
|
|
||
| import org.broadleafcommerce.core.payment.domain.*; | ||
| import org.broadleafcommerce.core.payment.service.SecurePaymentInfoService; | ||
| import org.broadleafcommerce.core.payment.service.type.PaymentInfoType; | ||
| import org.springframework.context.ApplicationContext; | ||
|
|
||
| import javax.servlet.http.HttpServletRequest; | ||
| import javax.xml.bind.annotation.XmlAccessType; | ||
| import javax.xml.bind.annotation.XmlAccessorType; | ||
| import javax.xml.bind.annotation.XmlElement; | ||
| import javax.xml.bind.annotation.XmlRootElement; | ||
|
|
||
| /** | ||
| * <p> | ||
| * This is a JAXB wrapper around Referenced. | ||
| * This wrapper can either be an instance of: | ||
| * <code>CreditCardPaymentInfo</code> | ||
| * <code>BankAccountPaymentInfo</code> | ||
| * <code>GiftCardPaymentInfo</code> | ||
| * <code>EmptyReferenced</code> | ||
| * | ||
| * <p/> | ||
| * User: Elbert Bautista | ||
| * Date: 4/26/12 | ||
| */ | ||
| @XmlRootElement(name = "referenced") | ||
| @XmlAccessorType(value = XmlAccessType.FIELD) | ||
| public class ReferencedWrapper extends BaseWrapper implements APIWrapper<Referenced>, APIUnwrapper<Referenced>{ | ||
|
|
||
| @XmlElement | ||
| protected Long id; | ||
|
|
||
| protected String referenceNumber; | ||
|
|
||
| protected String type; | ||
|
|
||
| protected String pan; | ||
|
|
||
| protected String cvvCode; | ||
|
|
||
| protected Integer expirationMonth; | ||
|
|
||
| protected Integer expirationYear; | ||
|
|
||
| protected String accountNumber; | ||
|
|
||
| protected String routingNumber; | ||
|
|
||
| protected String pin; | ||
|
|
||
| @Override | ||
| public void wrap(Referenced model, HttpServletRequest request) { | ||
| this.id = model.getId(); | ||
| this.referenceNumber = model.getReferenceNumber(); | ||
|
|
||
| if (model instanceof CreditCardPaymentInfo) { | ||
| CreditCardPaymentInfo referenced = (CreditCardPaymentInfo) model; | ||
| this.type = CreditCardPaymentInfo.class.getName(); | ||
|
|
||
| this.pan = referenced.getPan(); | ||
| this.cvvCode = referenced.getCvvCode(); | ||
| this.expirationMonth = referenced.getExpirationMonth(); | ||
| this.expirationYear = referenced.getExpirationYear(); | ||
| } | ||
|
|
||
| if (model instanceof BankAccountPaymentInfo) { | ||
| BankAccountPaymentInfo referenced = (BankAccountPaymentInfo) model; | ||
| this.type = BankAccountPaymentInfo.class.getName(); | ||
|
|
||
| this.accountNumber = referenced.getAccountNumber(); | ||
| this.routingNumber = referenced.getRoutingNumber(); | ||
| } | ||
|
|
||
| if (model instanceof GiftCardPaymentInfo) { | ||
| GiftCardPaymentInfo referenced = (GiftCardPaymentInfo) model; | ||
| this.type = GiftCardPaymentInfo.class.getName(); | ||
|
|
||
| this.pan = referenced.getPan(); | ||
| this.pin = referenced.getPin(); | ||
| } | ||
|
|
||
| if (model instanceof EmptyReferenced) { | ||
| this.type = EmptyReferenced.class.getName(); | ||
| } | ||
|
|
||
| } | ||
|
|
||
| @Override | ||
| public Referenced unwrap(HttpServletRequest request, ApplicationContext context) { | ||
| SecurePaymentInfoService securePaymentInfoService = (SecurePaymentInfoService) context.getBean("blSecurePaymentInfoService"); | ||
|
|
||
| if (CreditCardPaymentInfo.class.getName().equals(this.type)) { | ||
| CreditCardPaymentInfo paymentInfo = (CreditCardPaymentInfo) securePaymentInfoService.create(PaymentInfoType.CREDIT_CARD); | ||
| paymentInfo.setId(this.id); | ||
| paymentInfo.setReferenceNumber(this.referenceNumber); | ||
| paymentInfo.setPan(this.pan); | ||
| paymentInfo.setCvvCode(this.cvvCode); | ||
| paymentInfo.setExpirationMonth(this.expirationMonth); | ||
| paymentInfo.setExpirationYear(this.expirationYear); | ||
|
|
||
| return paymentInfo; | ||
| } | ||
|
|
||
| if (BankAccountPaymentInfo.class.getName().equals(this.type)) { | ||
| BankAccountPaymentInfo paymentInfo = (BankAccountPaymentInfo) securePaymentInfoService.create(PaymentInfoType.BANK_ACCOUNT); | ||
| paymentInfo.setId(this.id); | ||
| paymentInfo.setReferenceNumber(this.referenceNumber); | ||
| paymentInfo.setAccountNumber(this.accountNumber); | ||
| paymentInfo.setRoutingNumber(this.routingNumber); | ||
|
|
||
| return paymentInfo; | ||
| } | ||
|
|
||
| if (GiftCardPaymentInfo.class.getName().equals(this.type)) { | ||
| GiftCardPaymentInfo paymentInfo = (GiftCardPaymentInfo) securePaymentInfoService.create(PaymentInfoType.GIFT_CARD); | ||
| paymentInfo.setId(this.id); | ||
| paymentInfo.setReferenceNumber(this.referenceNumber); | ||
| paymentInfo.setPan(this.pan); | ||
| paymentInfo.setPin(this.pin); | ||
|
|
||
| return paymentInfo; | ||
| } | ||
|
|
||
| if (EmptyReferenced.class.getName().equals(this.type)) { | ||
| EmptyReferenced emptyReferenced = new EmptyReferenced(); | ||
| emptyReferenced.setId(this.id); | ||
| emptyReferenced.setReferenceNumber(this.referenceNumber); | ||
|
|
||
| return emptyReferenced; | ||
| } | ||
|
|
||
| return null; | ||
| } | ||
| } |