Interface OrderPayment

All Superinterfaces:
MultiTenantCloneable<OrderPayment>, Serializable, Status
All Known Implementing Classes:
OrderPaymentImpl

public interface OrderPayment extends Serializable, Status, MultiTenantCloneable<OrderPayment>

This entity is designed to deal with payments associated to an Order and is usually unique for a particular amount, PaymentGatewayType and PaymentType combination. This is immediately invalid for scenarios where multiple payments of the same PaymentType should be supported (like paying with 2 PaymentType.CREDIT_CARD or 2 PaymentType.GIFT_CARD). That said, even though the use case might be uncommon in, Broadleaf does not actively prevent that situation from occurring online payments it is very common in point of sale systems.

Once an OrderPayment is created, various PaymentTransactions can be applied to this payment as denoted by PaymentTransactionType. There should be at least 1 PaymentTransaction for every OrderPayment that is associated with an Order that has gone through checkout (which means that Order.getStatus() is OrderStatus.SUBMITTED).

OrderPayments are not actually deleted from the database but rather are only soft-deleted (archived = true)

Author:
Phillip Verheyden (phillipuniverse)
  • Method Details

    • getId

      Long getId()
    • setId

      void setId(Long id)
    • getOrder

      Order getOrder()
    • setOrder

      void setOrder(Order order)
    • getBillingAddress

      Address getBillingAddress()
      Gets the billing address associated with this payment. This might be null for some payments where no billing address is required (like gift cards or account credit)
    • setBillingAddress

      void setBillingAddress(Address billingAddress)
      Sets the billing address associated with this payment. This might be null for some payments where no billing address is required (like gift cards or account credit)
    • getAmount

      Money getAmount()
      The amount that this payment is allotted for. The summation of all of the OrderPayments for a particular Order should equal Order.getTotal()
    • setAmount

      void setAmount(Money amount)
      The amount that this payment is allotted for. The summation of all of the OrderPayments for a particular Order should equal Order.getTotal()
    • getReferenceNumber

      String getReferenceNumber()
      The soft link to a Referenced entity which will be stored in the blSecurePU persistence unit. If you are not attempting to store credit cards in your own database (which is the usual, recommended case) then this will not be used or set. If you do use this reference number, this can be anything that is unique (like System.currentTimeMillis()).
    • setReferenceNumber

      void setReferenceNumber(String referenceNumber)
      Sets the soft link to a Referenced entity stored in the blSecurePU persistence unit. This will likely not be used as the common case is to not store credit cards yourself.
    • getType

      PaymentType getType()
      The type of this payment like Credit Card or Gift Card.
    • setType

      void setType(PaymentType type)
      Sets the type of this payment like Credit Card or Gift Card
    • getGatewayType

      PaymentGatewayType getGatewayType()
      Gets the gateway that was used to process this order payment. Only a SINGLE payment gateway can modify transactions on a particular order payment.
    • setPaymentGatewayType

      void setPaymentGatewayType(PaymentGatewayType gatewayType)

      Gets the gateway that was used to process this order payment. Only a SINGLE payment gateway can modify transactions on a particular order payment.

      It usually does not make sense to modify the gateway type after it has already been set once. Instead, consider just archiving this payment type (by deleting it) and creating a new payment for the new gateway.

    • getTransactions

      List<PaymentTransaction> getTransactions()

      All of the transactions that have been applied to this particular payment. Transactions are denoted by the various PaymentTransactionTypes. In almost all scenarios (as in, 99.9999% of all cases) there will be a at least one PaymentTransaction for every OrderPayment.

      To add a transaction to an OrderPayment see addTransaction(PaymentTransaction).

    • setTransactions

      void setTransactions(List<PaymentTransaction> details)

      All of the transactions that have been applied to this particular payment. Transactions are denoted by the various PaymentTransactionTypes. In almost all scenarios (as in, 99.9999% of all cases) there will be a at least one PaymentTransaction for every OrderPayment.

      To add a transaction to an OrderPayment see addTransaction(PaymentTransaction).

    • addTransaction

      void addTransaction(PaymentTransaction transaction)
      A more declarative way to invoke {@link #getTransactions().add()}. This is the preferred way to add a transaction to this payment.
    • getTransactionsForType

      List<PaymentTransaction> getTransactionsForType(PaymentTransactionType type)
      Returns a transaction for given type. This is useful when validating whether or not a PaymentTransaction can actually be added to this payment. For instance, there can only be a single PaymentTransactionType.AUTHORIZE for a payment.
      Parameters:
      type - the type of transaction to look for within getTransactions()
      Returns:
      a list of transactions or an empty list if there are no transaction of that type
    • getInitialTransaction

      PaymentTransaction getInitialTransaction()
      Returns the initial transaction for this order payment. Implementation-wise this would be any PaymentTransaction whose parentTransaction is NULL.
      Returns:
      the initial transaction for this order payment or null if there isn't any
    • getAuthorizeTransaction

      PaymentTransaction getAuthorizeTransaction()
      Returns a successful transaction with type PaymentTransactionType.AUTHORIZE or PaymentTransactionType.AUTHORIZE_AND_CAPTURE if one exists. Note there can only be a single authorize transaction for a given payment.
      Returns:
    • getTransactionAmountForType

      Money getTransactionAmountForType(PaymentTransactionType type)
      Looks through all of the transactions for this payment and adds up the amount for the given transaction type. This ignores whether the transaction was successful or not
      Parameters:
      type -
      Returns:
      the amount of all of the transactions for the given type
    • getSuccessfulTransactionAmountForType

      Money getSuccessfulTransactionAmountForType(PaymentTransactionType type)
      Returns all of the transactions on this payment that were successful for the given type.
      Parameters:
      type - the type of transaction
      Returns:
      the amount of all of the transaction on this payment for the given type that have been successful
    • getStatus

      OrderPaymentStatus getStatus()
      Convenience method to get the calculated status of this order payment based on the state of the getTransactions()
      Returns:
      OrderPaymentStatus
    • isConfirmed

      boolean isConfirmed()
      Looks through all of the transactions for this payment and returns whether or not it contains a successful transaction of type PaymentTransactionType.AUTHORIZE_AND_CAPTURE or PaymentTransactionType.AUTHORIZE
      Returns:
    • isFinalPayment

      boolean isFinalPayment()
      Returns whether or not this payment is considered to be the final payment on the order. The default implementation considers those payment of type PaymentType.THIRD_PARTY_ACCOUNT and PaymentType.CREDIT_CARD final payments because integrations with external Payment Gateways require it.

      For example, a THIRD_PARTY_ACCOUNT payment's (e.g. PayPal Express Checkout) amount to charge to the customer will be automatically calculated based on other payments that have already been applied to the order, such as GIFT_CARDs or ACCOUNT_CREDITs. This final amount (OrderPayment) will be sent to the gateway.

      Returns:
    • getCurrency

      BroadleafCurrency getCurrency()
      The currency that this payment should be taken in. This is a delegate to {@link #getOrder()#getCurrency()}.