All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.broadleafcommerce.common.payment.dto.PaymentRequestDTO Maven / Gradle / Ivy

There is a newer version: 3.1.15-GA
Show newest version
/*
 * #%L
 * BroadleafCommerce Common Libraries
 * %%
 * Copyright (C) 2009 - 2013 Broadleaf Commerce
 * %%
 * 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.
 * #L%
 */

package org.broadleafcommerce.common.payment.dto;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 

* A DTO that is comprised of all the information that is sent to a Payment Gateway * to complete a transaction. This DTO uses a modified builder pattern in order to * provide an easy way of constructing the request. You can construct a DTO * using the following notation: *

*

* IMPORTANT: note that some of the convenience methods generate a new instance of the object. * (e.g. billTo, shipTo, etc...) So, if you need to modify the shipping or billing information * after you have invoked requestDTO.shipTo()..., use the getShipTo() method to append more information. * Otherwise, you will overwrite the shipping information with a new instance. *

* *

 *      PaymentRequestDTO requestDTO = new PaymentRequestDTO()
 *          .orderId(referenceNumber)
 *          .customer()
 *              .customerId("1")
 *              .done()
 *          .shipTo()
 *              .addressFirstName("Bill")
 *              .addressLastName("Broadleaf")
 *              .addressLine1("123 Test Dr.")
 *              .addressCityLocality("Austin")
 *              .addressStateRegion("TX")
 *              .addressPostalCode("78759")
 *              .done()
 *          .billTo()
 *              .addressFirstName("Bill")
 *              .addressLastName("Broadleaf")
 *              .addressLine1("123 Test Dr.")
 *              .addressCityLocality("Austin")
 *              .addressStateRegion("TX")
 *              .addressPostalCode("78759")
 *              .done()
 *          .shippingTotal("0")
 *          .taxTotal("0")
 *          .orderCurrencyCode("USD")
 *          .orderDescription("My Order Description")
 *          .orderSubtotal("10.00")
 *          .transactionTotal("10.00")
 *          .lineItem()
 *              .name("My Product")
 *              .description("My Product Description")
 *              .shortDescription("My Product Short Description")
 *              .systemId("1")
 *              .amount("10.00")
 *              .quantity("1")
 *              .itemTotal("10.00")
 *              .tax("0")
 *              .total("10.00")
 *              .done();
 * 
* * @author Elbert Bautista (elbertbautista) */ public class PaymentRequestDTO { protected GatewayCustomerDTO customer; protected AddressDTO shipTo; protected AddressDTO billTo; protected CreditCardDTO creditCard; protected SubscriptionDTO subscription; protected List> giftCards; protected List> customerCredits; protected List lineItems; protected Map additionalFields; protected String orderId; protected String orderCurrencyCode; protected String orderDescription; protected String orderSubtotal; protected String shippingTotal; protected String taxTotal; protected String transactionTotal; protected boolean completeCheckoutOnCallback = true; public PaymentRequestDTO() { this.giftCards = new ArrayList>(); this.customerCredits = new ArrayList>(); this.lineItems = new ArrayList(); this.additionalFields = new HashMap(); } /** * You should only call this once, as it will create a new customer * if called more than once. Use the getter if you need to append more information later. */ public GatewayCustomerDTO customer() { customer = new GatewayCustomerDTO(this); return customer; } /** * You should only call this once, as it will create a new credit card * if called more than once. Use the getter if you need to append more information later. */ public CreditCardDTO creditCard() { creditCard = new CreditCardDTO(this); return creditCard; } /** * You should only call this once, as it will create a new subscription * if called more than once. Use the getter if you need to append more information later. */ public SubscriptionDTO subscription() { subscription = new SubscriptionDTO(this); return subscription; } /** * You should only call this once, as it will create a new customer * if called more than once. Use the getter if you need to append more information later. */ public AddressDTO shipTo() { shipTo = new AddressDTO(this); return shipTo; } /** * You should only call this once, as it will create a new bill to address * if called more than once. Use the getter if you need to append more information later. */ public AddressDTO billTo() { billTo = new AddressDTO(this); return billTo; } /** * You should only call this once, as it will create a new gift card * if called more than once. Use the getter if you need to append more information later. */ public GiftCardDTO giftCard() { GiftCardDTO giftCardDTO = new GiftCardDTO(this); giftCards.add(giftCardDTO); return giftCardDTO; } /** * You should only call this once, as it will create a new gift card * if called more than once. Use the getter if you need to append more information later. */ public CustomerCreditDTO customerCredit() { CustomerCreditDTO customerCreditDTO = new CustomerCreditDTO(this); customerCredits.add(customerCreditDTO); return customerCreditDTO; } public LineItemDTO lineItem() { return new LineItemDTO(this); } public PaymentRequestDTO additionalField(String key, Object value) { additionalFields.put(key, value); return this; } public PaymentRequestDTO orderId(String orderId) { this.orderId = orderId; return this; } public PaymentRequestDTO orderCurrencyCode(String orderCurrencyCode) { this.orderCurrencyCode = orderCurrencyCode; return this; } public PaymentRequestDTO orderDescription(String orderDescription) { this.orderDescription = orderDescription; return this; } public PaymentRequestDTO orderSubtotal(String orderSubtotal) { this.orderSubtotal = orderSubtotal; return this; } public PaymentRequestDTO shippingTotal(String shippingTotal) { this.shippingTotal = shippingTotal; return this; } public PaymentRequestDTO taxTotal(String taxTotal) { this.taxTotal = taxTotal; return this; } public PaymentRequestDTO transactionTotal(String transactionTotal) { this.transactionTotal = transactionTotal; return this; } public PaymentRequestDTO completeCheckoutOnCallback(boolean completeCheckoutOnCallback) { this.completeCheckoutOnCallback = completeCheckoutOnCallback; return this; } public List getLineItems() { return lineItems; } public List> getGiftCards() { return giftCards; } public List> getCustomerCredits() { return customerCredits; } public AddressDTO getShipTo() { return shipTo; } public AddressDTO getBillTo() { return billTo; } public CreditCardDTO getCreditCard() { return creditCard; } public SubscriptionDTO getSubscription() { return subscription; } public GatewayCustomerDTO getCustomer() { return customer; } public Map getAdditionalFields() { return additionalFields; } public String getOrderId() { return orderId; } public String getOrderCurrencyCode() { return orderCurrencyCode; } public String getOrderDescription() { return orderDescription; } public String getOrderSubtotal() { return orderSubtotal; } public String getShippingTotal() { return shippingTotal; } public String getTaxTotal() { return taxTotal; } public String getTransactionTotal() { return transactionTotal; } public boolean isCompleteCheckoutOnCallback() { return completeCheckoutOnCallback; } public boolean shipToPopulated() { return (getShipTo() != null && getShipTo().addressPopulated()); } public boolean billToPopulated() { return (getBillTo() != null && getBillTo().addressPopulated()); } public boolean creditCardPopulated() { return (getCreditCard() != null && getCreditCard().creditCardPopulated()); } public boolean customerPopulated() { return (getCustomer() != null && getCustomer().customerPopulated()); } public boolean subscriptionPopulated() { return (getSubscription() != null && getSubscription().subscriptionPopulated()); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy