Class DefaultPayPalCheckoutHostedService

java.lang.Object
com.broadleafcommerce.paypal.micro.gateway.service.DefaultPayPalCheckoutHostedService
All Implemented Interfaces:
com.broadleafcommerce.paymentgateway.service.PaymentGatewayHostedService, com.broadleafcommerce.paymentgateway.service.PaymentGatewayTypeAware, PayPalCheckoutHostedService

public class DefaultPayPalCheckoutHostedService extends Object implements PayPalCheckoutHostedService
Author:
Nathan Moore
  • Constructor Details

    • DefaultPayPalCheckoutHostedService

      public DefaultPayPalCheckoutHostedService(PayPalGatewayConfiguration configuration, com.broadleafcommerce.paymentgateway.service.PaymentGatewayTransactionService transactionService)
  • Method Details

    • updateShippingCallback

      public List<com.broadleafcommerce.paymentgateway.domain.ExternalGatewayFulfillmentUpdate> updateShippingCallback(@NonNull @NonNull com.broadleafcommerce.paymentgateway.domain.ExternalFulfillmentCallbackDTO callbackDTO) throws com.broadleafcommerce.paymentgateway.service.exception.PaymentException
      Specified by:
      updateShippingCallback in interface com.broadleafcommerce.paymentgateway.service.PaymentGatewayHostedService
      Throws:
      com.broadleafcommerce.paymentgateway.service.exception.PaymentException
    • buildShippingCallbackResponse

      public com.broadleafcommerce.paymentgateway.domain.ExternalFulfillmentCallbackTransformedResponse buildShippingCallbackResponse(@NonNull @NonNull com.broadleafcommerce.paymentgateway.domain.ExternalFulfillmentCallbackInfo callbackInfo) throws com.broadleafcommerce.paymentgateway.service.exception.PaymentException
      Specified by:
      buildShippingCallbackResponse in interface com.broadleafcommerce.paymentgateway.service.PaymentGatewayHostedService
      Throws:
      com.broadleafcommerce.paymentgateway.service.exception.PaymentException
    • requestHostedEndpoint

      public com.broadleafcommerce.paymentgateway.domain.PaymentResponse requestHostedEndpoint(@NonNull @NonNull com.broadleafcommerce.paymentgateway.domain.PaymentRequest paymentRequest, boolean capture) throws com.broadleafcommerce.paymentgateway.service.exception.PaymentException
      Specified by:
      requestHostedEndpoint in interface com.broadleafcommerce.paymentgateway.service.PaymentGatewayHostedService
      Throws:
      com.broadleafcommerce.paymentgateway.service.exception.PaymentException
    • buildOrderLookupPaymentRequest

      protected com.broadleafcommerce.paymentgateway.domain.PaymentRequest buildOrderLookupPaymentRequest(@NonNull @NonNull com.broadleafcommerce.paymentgateway.domain.ExternalFulfillmentCallbackDTO callbackDTO)
    • determineAndBuildAddressToUse

      protected void determineAndBuildAddressToUse(@NonNull @NonNull com.broadleafcommerce.paymentgateway.domain.ExternalGatewayFulfillmentUpdate fulfillmentUpdate, @NonNull @NonNull ShippingCallbackRequest shippingCallbackRequest, @NonNull @NonNull PurchaseUnit purchaseUnit, @NonNull @NonNull Order updatedOrder)
    • findAndValidateAddressToUse

      protected AddressPortable findAndValidateAddressToUse(@NonNull @NonNull ShippingCallbackRequest shippingCallbackRequest, @NonNull @NonNull PurchaseUnit purchaseUnit, @NonNull @NonNull Order updatedOrder)
    • validateAddress

      protected boolean validateAddress(@Nullable AddressPortable addressPortable)
    • determineFulfillmentType

      protected String determineFulfillmentType(String shippingOptionType)
    • buildPurchaseUnits

      protected List<PurchaseUnitInfo> buildPurchaseUnits(@NonNull @NonNull com.broadleafcommerce.paymentgateway.domain.ExternalFulfillmentCallbackInfo callbackInfo)
    • buildAmountWithBreakdown

      protected AmountWithBreakdown buildAmountWithBreakdown(@NonNull @NonNull com.broadleafcommerce.paymentgateway.domain.ExternalFulfillmentCallbackInfo callbackInfo)
    • convertToMoney

      protected Optional<Money> convertToMoney(@Nullable javax.money.MonetaryAmount amount)
    • convertToMonetaryAmount

      @Nullable protected javax.money.MonetaryAmount convertToMonetaryAmount(@NonNull @NonNull Money amount)
    • buildShippingOptions

      protected List<ShippingOption> buildShippingOptions(@NonNull @NonNull List<com.broadleafcommerce.paymentgateway.domain.FulfillmentOption> fulfillmentOptions)
    • convertToGatewayFulfillmentType

      protected String convertToGatewayFulfillmentType(String fulfillmentType)
    • validateShippingCallbackRequest

      protected void validateShippingCallbackRequest(ShippingCallbackRequest shippingCallbackRequest, Order updatedOrder, String tokenParam, @Nullable String tokenHmacKey) throws SignatureException
      Entry point for validation of the ShippingCallbackRequest.
      Parameters:
      shippingCallbackRequest - The ShippingCallbackRequest to validate
      updatedOrder - The updated PayPal Order
      tokenParam - The token received in the shipping callback URL params
      tokenHmacKey - The private HMAC key used to generate the token
      Throws:
      SignatureException - if there was a failure to generate the HMAC signature
    • validateToken

      protected void validateToken(String referenceId, String tokenParam, String tokenHmacKey) throws SignatureException, com.broadleafcommerce.paymentgateway.service.exception.ShippingCallbackValidationException
      Validates the token received in the shipping callback URL params. This is to ensure that the shipping callback is valid and initiated from PayPal, since we pass this token during PayPal Order creation.
      Parameters:
      referenceId - The reference ID for the PayPal order
      tokenParam - The token received in the shipping callback URL params
      tokenHmacKey - The private HMAC key used to generate the token
      Throws:
      SignatureException - if the key failed to generate an HMAC signature
      com.broadleafcommerce.paymentgateway.service.exception.ShippingCallbackValidationException - if the token is invalid
    • validateOrderStatus

      protected void validateOrderStatus(Order updatedOrder)
      Validates the status of the PayPal Order during the shipping callback.
      Parameters:
      updatedOrder - The current PayPal Order
      Throws:
      com.broadleafcommerce.paymentgateway.service.exception.ShippingCallbackValidationException - when the paypal order status is not valid
    • getGatewayType

      public String getGatewayType()
      Specified by:
      getGatewayType in interface com.broadleafcommerce.paymentgateway.service.PaymentGatewayTypeAware
    • getConfiguration

      protected PayPalGatewayConfiguration getConfiguration()
    • getTransactionService

      protected com.broadleafcommerce.paymentgateway.service.PaymentGatewayTransactionService getTransactionService()
    • getPayPalOrderService

      protected PayPalOrderService getPayPalOrderService()
    • setPayPalOrderService

      @Autowired public void setPayPalOrderService(PayPalOrderService payPalOrderService)
    • getObjectMapper

      protected com.fasterxml.jackson.databind.ObjectMapper getObjectMapper()
    • setObjectMapper

      @Autowired public void setObjectMapper(com.fasterxml.jackson.databind.ObjectMapper objectMapper)
    • getTypeFactory

      protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory()
    • setTypeFactory

      @Autowired public void setTypeFactory(com.broadleafcommerce.common.extension.TypeFactory typeFactory)