Class OrderToPaymentRequestDTOServiceImpl

java.lang.Object
org.broadleafcommerce.core.payment.service.OrderToPaymentRequestDTOServiceImpl
All Implemented Interfaces:
OrderToPaymentRequestDTOService

@Service("blOrderToPaymentRequestDTOService") public class OrderToPaymentRequestDTOServiceImpl extends Object implements OrderToPaymentRequestDTOService
Service that translates various pieces of information such as: - Order - PaymentTransaction into a PaymentRequestDTO so that the gateway can create the appropriate request for a specific transaction.
Author:
Elbert Bautista (elbertbautista)
  • Field Details

  • Constructor Details

    • OrderToPaymentRequestDTOServiceImpl

      public OrderToPaymentRequestDTOServiceImpl()
  • Method Details

    • translateOrder

      public org.broadleafcommerce.common.payment.dto.PaymentRequestDTO translateOrder(Order order)
      Description copied from interface: OrderToPaymentRequestDTOService

      This translates an Order into a PaymentRequestDTO. This method assumes that the total transaction amount being sent to the gateway will be calculated from the "final payment" on the order. This means that the transaction amount for the returned PaymentRequestDTO will be Order.getTotalAfterAppliedPayments() It assumes that all other payments (e.g. gift cards/account credit) have already been applied to the Order.

      Specified by:
      translateOrder in interface OrderToPaymentRequestDTOService
      Parameters:
      order - the Order to be translated
      Returns:
      a PaymentRequestDTO based on the properties of an order.
    • translatePaymentTransaction

      public org.broadleafcommerce.common.payment.dto.PaymentRequestDTO translatePaymentTransaction(org.broadleafcommerce.common.money.Money transactionAmount, PaymentTransaction paymentTransaction)
      Description copied from interface: OrderToPaymentRequestDTOService
      Utilizes the PaymentTransaction.getAdditionalFields() map to populate necessary request parameters on the resulting PaymentRequestDTO. These additional fields are then used by the payment gateway to construct additional requests. For example, an existing PaymentTransaction of type PaymentTransactionType.AUTHORIZE might be passed into this method in order for the gateway issue a "reverse auth" against this original transaction.
      Specified by:
      translatePaymentTransaction in interface OrderToPaymentRequestDTOService
      Parameters:
      transactionAmount - the amount that should be placed on PaymentRequestDTO.getTransactionTotal()
      paymentTransaction - the transaction whose additional fields should be placed on PaymentRequestDTO.getAdditionalFields() for the gateway to use
      Returns:
      a new PaymentRequestDTO populated with the additional fields from paymentTransaction and the amount from transactionAmount OR override with final payment details on the order if coming in from a payment flow.
    • translatePaymentTransaction

      public org.broadleafcommerce.common.payment.dto.PaymentRequestDTO translatePaymentTransaction(org.broadleafcommerce.common.money.Money transactionAmount, PaymentTransaction paymentTransaction, boolean autoCalculateFinalPaymentTotals)
      Description copied from interface: OrderToPaymentRequestDTOService
      Important: As of 4.0.1-GA+, there is a requirement to automatically populate the transaction amount on the DTO only if coming from a "checkout payment flow". That is, if you are invoking this method via the ValidateAndConfirmPaymentActivity and the payment transaction passed in is of type PaymentTransactionType.UNCONFIRMED. If the totals need to be auto-calculated, the transaction total will be set from the "final payment" details that are coming off the order itself (along with other details like shipping/billing info etc...)
      Specified by:
      translatePaymentTransaction in interface OrderToPaymentRequestDTOService
      Returns:
    • refreshTransaction

      protected PaymentTransaction refreshTransaction(PaymentTransaction paymentTransaction)
    • populateTotals

      public void populateTotals(Order order, org.broadleafcommerce.common.payment.dto.PaymentRequestDTO requestDTO)
      Description copied from interface: OrderToPaymentRequestDTOService
      Uses total information on the Order to populate the PaymentRequestDTO.transactionTotal(String)()} PaymentRequestDTO.taxTotal(String)()} PaymentRequestDTO.shippingTotal(String)()} PaymentRequestDTO.orderCurrencyCode(String)()}
      Specified by:
      populateTotals in interface OrderToPaymentRequestDTOService
      Parameters:
      order - the Order to get data from
      requestDTO - the PaymentRequestDTO that should be populated
    • populateCustomerInfo

      public void populateCustomerInfo(Order order, org.broadleafcommerce.common.payment.dto.PaymentRequestDTO requestDTO)
      Description copied from interface: OrderToPaymentRequestDTOService
      Uses customer information on the Order to populate the PaymentRequestDTO.customer() object
      Specified by:
      populateCustomerInfo in interface OrderToPaymentRequestDTOService
      Parameters:
      order - the Order to get data from
      requestDTO - the PaymentRequestDTO that should be populated
    • populateShipTo

      public void populateShipTo(Order order, org.broadleafcommerce.common.payment.dto.PaymentRequestDTO requestDTO)
      Uses the first shippable fulfillment group to populate the PaymentRequestDTO.shipTo() object
      Specified by:
      populateShipTo in interface OrderToPaymentRequestDTOService
      Parameters:
      order - the Order to get data from
      requestDTO - the PaymentRequestDTO that should be populated
    • populateBillTo

      public void populateBillTo(Order order, org.broadleafcommerce.common.payment.dto.PaymentRequestDTO requestDTO)
      Description copied from interface: OrderToPaymentRequestDTOService
      Uses billing information on the Order to populate the PaymentRequestDTO.billTo() object
      Specified by:
      populateBillTo in interface OrderToPaymentRequestDTOService
      Parameters:
      order - the Order to get data from
      requestDTO - the PaymentRequestDTO that should be populated
    • populateAddressInfo

      protected void populateAddressInfo(org.broadleafcommerce.common.payment.dto.AddressDTO<org.broadleafcommerce.common.payment.dto.PaymentRequestDTO> dto, org.broadleafcommerce.profile.core.domain.Address address)
    • getName

      protected OrderToPaymentRequestDTOServiceImpl.NameResponse getName(org.broadleafcommerce.profile.core.domain.Address address)
    • populateDefaultLineItemsAndSubtotal

      public void populateDefaultLineItemsAndSubtotal(Order order, org.broadleafcommerce.common.payment.dto.PaymentRequestDTO requestDTO)
      IMPORTANT:

      If you would like to pass Line Item information to a payment gateway so that it shows up on the hosted site, you will need to override this method and construct line items to conform to the requirements of that particular gateway:

      For Example: The Paypal Express Checkout NVP API validates that the order subtotal that you pass in, add up to the amount of the line items that you pass in. So, In that case you will need to take into account any additional fees, promotions, credits, gift cards, etc... that are applied to the payment and add them as additional line items with a negative amount when necessary.

      Each gateway that accepts line item information may require you to construct this differently. Please consult the module documentation on how it should be properly constructed.

      In this default implementation, just the subtotal is set, without any line item details.

      Specified by:
      populateDefaultLineItemsAndSubtotal in interface OrderToPaymentRequestDTOService
      Parameters:
      order -
      requestDTO -