Class DefaultStripeExternalCallService<T>

java.lang.Object
com.broadleafcommerce.paymentgateway.service.AbstractExternalPaymentGatewayCall<StripePaymentRequest,com.stripe.model.StripeObject>
com.broadleafcommerce.payment.service.gateway.DefaultStripeExternalCallService<T>
All Implemented Interfaces:
StripeExternalCallService, com.broadleafcommerce.paymentgateway.service.FailureCountExposable, com.broadleafcommerce.paymentgateway.vendor.service.monitor.ServiceStatusDetectable<StripePaymentRequest>

public class DefaultStripeExternalCallService<T> extends com.broadleafcommerce.paymentgateway.service.AbstractExternalPaymentGatewayCall<StripePaymentRequest,com.stripe.model.StripeObject> implements StripeExternalCallService
  • Field Details

  • Constructor Details

  • Method Details

    • call

      public com.stripe.model.StripeObject call(@NonNull @NonNull StripePaymentRequest paymentRequest)
      Specified by:
      call in interface StripeExternalCallService
    • communicateWithVendor

      public com.stripe.model.StripeObject communicateWithVendor(@NonNull @NonNull StripePaymentRequest stripePaymentRequest) throws Exception
      Specified by:
      communicateWithVendor in class com.broadleafcommerce.paymentgateway.service.AbstractExternalPaymentGatewayCall<StripePaymentRequest,com.stripe.model.StripeObject>
      Throws:
      Exception
    • communicateWithVendorChargesAPI

      @Deprecated(forRemoval=true) protected com.stripe.model.StripeObject communicateWithVendorChargesAPI(@NonNull @NonNull StripePaymentRequest stripePaymentRequest, @NonNull @NonNull com.stripe.net.RequestOptions requestOptions) throws Exception
      Deprecated, for removal: This API element is subject to removal in a future version.
      The usage of the Charges API is not compliant with SCA, so high rates of declines are likely in EEA. Related documentation https://stripe.com/docs/strong-customer-authentication#preparing
      Throws:
      Exception
    • communicateWithVendorPaymentIntentsAPI

      protected com.stripe.model.StripeObject communicateWithVendorPaymentIntentsAPI(@NonNull @NonNull StripePaymentRequest stripePaymentRequest, @NonNull @NonNull com.stripe.net.RequestOptions requestOptions) throws Exception
      Throws:
      Exception
    • communicateWithVendorCustomerAPI

      protected com.stripe.model.StripeObject communicateWithVendorCustomerAPI(@NonNull @NonNull StripePaymentRequest stripePaymentRequest, @NonNull @NonNull com.stripe.net.RequestOptions requestOptions) throws Exception
      Throws:
      Exception
    • createCharge

      @Deprecated(forRemoval=true) protected com.stripe.model.StripeObject createCharge(@NonNull @NonNull StripePaymentRequest stripePaymentRequest, @NonNull @NonNull com.stripe.net.RequestOptions requestOptions) throws Exception
      Deprecated, for removal: This API element is subject to removal in a future version.
      The usage of the Charges API is not compliant with SCA, so high rates of declines are likely in EEA. Related documentation https://stripe.com/docs/strong-customer-authentication#preparing
      Throws:
      Exception
    • populateCustomCreateChargeParams

      protected void populateCustomCreateChargeParams(Map<String,Object> params, @NonNull @NonNull StripePaymentRequest stripePaymentRequest)
    • captureCharge

      @Deprecated(forRemoval=true) protected com.stripe.model.StripeObject captureCharge(@NonNull @NonNull StripePaymentRequest stripePaymentRequest, @NonNull @NonNull com.stripe.net.RequestOptions requestOptions) throws Exception
      Deprecated, for removal: This API element is subject to removal in a future version.
      The usage of the Charges API is not compliant with SCA, so high rates of declines are likely in EEA. Related documentation https://stripe.com/docs/strong-customer-authentication#preparing
      Throws:
      Exception
    • populateCustomCaptureChargeParams

      protected void populateCustomCaptureChargeParams(Map<String,Object> params, @NonNull @NonNull StripePaymentRequest stripePaymentRequest)
    • refundCharge

      @Deprecated(forRemoval=true) protected com.stripe.model.StripeObject refundCharge(@NonNull @NonNull StripePaymentRequest stripePaymentRequest, @NonNull @NonNull com.stripe.net.RequestOptions requestOptions) throws Exception
      Deprecated, for removal: This API element is subject to removal in a future version.
      The usage of the Charges API is not compliant with SCA, so high rates of declines are likely in EEA. Related documentation https://stripe.com/docs/strong-customer-authentication#preparing
      Throws:
      Exception
    • populateCustomRefundChargeParams

      protected void populateCustomRefundChargeParams(Map<String,Object> params, @NonNull @NonNull StripePaymentRequest stripePaymentRequest)
    • handleCustomVendorChargeOperation

      protected com.stripe.model.StripeObject handleCustomVendorChargeOperation(@NonNull @NonNull StripePaymentRequest stripePaymentRequest, @NonNull @NonNull com.stripe.net.RequestOptions requestOptions, @NonNull @NonNull StripeMethodType methodType) throws Exception
      Throws:
      Exception
    • createPaymentIntent

      protected com.stripe.model.StripeObject createPaymentIntent(@NonNull @NonNull StripePaymentRequest stripePaymentRequest, @NonNull @NonNull com.stripe.net.RequestOptions requestOptions) throws Exception
      Throws:
      Exception
    • confirmPaymentIntent

      protected com.stripe.model.StripeObject confirmPaymentIntent(@NonNull @NonNull StripePaymentRequest stripePaymentRequest, @NonNull @NonNull com.stripe.net.RequestOptions requestOptions) throws Exception
      Throws:
      Exception
    • isAch

      protected boolean isAch(@NonNull @NonNull StripePaymentRequest stripePaymentRequest)
    • confirmPaymentIntentForAch

      protected com.stripe.model.StripeObject confirmPaymentIntentForAch(@NonNull @NonNull StripePaymentRequest stripePaymentRequest, @NonNull @NonNull com.stripe.net.RequestOptions requestOptions) throws Exception
      Throws:
      Exception
    • retrievePaymentIntent

      protected com.stripe.model.StripeObject retrievePaymentIntent(@NonNull @NonNull StripePaymentRequest stripePaymentRequest, @NonNull @NonNull com.stripe.net.RequestOptions requestOptions) throws Exception
      Throws:
      Exception
    • updatePaymentIntent

      protected com.stripe.model.PaymentIntent updatePaymentIntent(@NonNull @NonNull StripePaymentRequest stripePaymentRequest, @NonNull @NonNull com.stripe.model.PaymentIntent paymentIntent) throws com.stripe.exception.StripeException
      Throws:
      com.stripe.exception.StripeException
    • buildPaymentIntentConfirmationParams

      protected Map<String,Object> buildPaymentIntentConfirmationParams(@NonNull @NonNull com.stripe.model.PaymentIntent paymentIntent, @NonNull @NonNull StripePaymentRequest stripePaymentRequest)
    • populateCustomConfirmIntentParams

      protected Map<String,Object> populateCustomConfirmIntentParams(Map<String,Object> params, @NonNull @NonNull StripePaymentRequest stripePaymentRequest)
    • createChargeFromPaymentIntent

      @Deprecated(forRemoval=true) protected com.stripe.model.StripeObject createChargeFromPaymentIntent(@NonNull @NonNull StripePaymentRequest stripePaymentRequest, @NonNull @NonNull com.stripe.net.RequestOptions requestOptions) throws Exception
      Deprecated, for removal: This API element is subject to removal in a future version.
      The usage of the Charges API is not compliant with SCA, so high rates of declines are likely in EEA. Related documentation https://stripe.com/docs/strong-customer-authentication#preparing
      Throws:
      Exception
    • populateCustomCreateChargeFromIntentParams

      protected void populateCustomCreateChargeFromIntentParams(Map<String,Object> params, @NonNull @NonNull StripePaymentRequest stripePaymentRequest)
    • capturePaymentIntent

      protected com.stripe.model.StripeObject capturePaymentIntent(@NonNull @NonNull StripePaymentRequest stripePaymentRequest, @NonNull @NonNull com.stripe.net.RequestOptions requestOptions) throws Exception
      Throws:
      Exception
    • populateCustomCaptureIntentParams

      protected void populateCustomCaptureIntentParams(Map<String,Object> params, @NonNull @NonNull StripePaymentRequest stripePaymentRequest)
    • refundPaymentIntent

      protected com.stripe.model.StripeObject refundPaymentIntent(@NonNull @NonNull StripePaymentRequest stripePaymentRequest, @NonNull @NonNull com.stripe.net.RequestOptions requestOptions) throws Exception
      Throws:
      Exception
    • populateCustomRefundIntentParams

      protected void populateCustomRefundIntentParams(Map<String,Object> params, @NonNull @NonNull StripePaymentRequest stripePaymentRequest)
    • handleCustomPaymentIntentOperation

      protected com.stripe.model.StripeObject handleCustomPaymentIntentOperation(@NonNull @NonNull StripePaymentRequest stripePaymentRequest, @NonNull @NonNull com.stripe.net.RequestOptions requestOptions, @NonNull @NonNull StripeMethodType methodType) throws Exception
      Throws:
      Exception
    • createCustomer

      protected com.stripe.model.StripeObject createCustomer(@NonNull @NonNull StripePaymentRequest stripePaymentRequest, @NonNull @NonNull com.stripe.net.RequestOptions requestOptions) throws Exception
      Throws:
      Exception
    • buildCustomerShippingData

      protected Map<String,Object> buildCustomerShippingData(@NonNull @NonNull StripePaymentRequest stripePaymentRequest)
    • buildCustomerShippingAddress

      protected Map<String,Object> buildCustomerShippingAddress(@NonNull @NonNull com.broadleafcommerce.paymentgateway.domain.Address<com.broadleafcommerce.paymentgateway.domain.PaymentRequest> shipTo)
    • getShippingCustomerName

      @Nullable protected String getShippingCustomerName(@NonNull @NonNull com.broadleafcommerce.paymentgateway.domain.Address<com.broadleafcommerce.paymentgateway.domain.PaymentRequest> shipTo)
    • buildCustomerAddress

      @Nullable protected com.stripe.param.CustomerCreateParams.Address buildCustomerAddress(@NonNull @NonNull StripePaymentRequest stripePaymentRequest)
    • updateCustomer

      protected com.stripe.model.StripeObject updateCustomer(@NonNull @NonNull StripePaymentRequest stripePaymentRequest, @NonNull @NonNull com.stripe.net.RequestOptions requestOptions) throws Exception
      Throws:
      Exception
    • buildUpdateCustomerShippingPayload

      @Nullable protected com.stripe.param.CustomerUpdateParams.Shipping buildUpdateCustomerShippingPayload(@NonNull @NonNull StripePaymentRequest stripePaymentRequest)
    • buildUpdateCustomerShippingAddressPayload

      protected com.stripe.param.CustomerUpdateParams.Shipping.Address buildUpdateCustomerShippingAddressPayload(@NonNull @NonNull com.broadleafcommerce.paymentgateway.domain.Address<com.broadleafcommerce.paymentgateway.domain.PaymentRequest> shipTo)
    • buildUpdateCustomerAddressPayload

      @Nullable protected com.stripe.param.CustomerUpdateParams.Address buildUpdateCustomerAddressPayload(@NonNull @NonNull StripePaymentRequest stripePaymentRequest)
    • deleteCustomer

      protected com.stripe.model.StripeObject deleteCustomer(@NonNull @NonNull StripePaymentRequest stripePaymentRequest, @NonNull @NonNull com.stripe.net.RequestOptions requestOptions) throws Exception
      Throws:
      Exception
    • handleCustomCustomerOperation

      protected com.stripe.model.StripeObject handleCustomCustomerOperation(@NonNull @NonNull StripePaymentRequest stripePaymentRequest, @NonNull @NonNull com.stripe.net.RequestOptions requestOptions, @NonNull @NonNull StripeMethodType methodType) throws Exception
      Throws:
      Exception
    • determineCustomerEmail

      protected String determineCustomerEmail(@NonNull @NonNull StripePaymentRequest stripePaymentRequest)
    • determineCustomerName

      @Nullable protected String determineCustomerName(@NonNull @NonNull StripePaymentRequest stripePaymentRequest)
    • determineCustomerPhone

      @Nullable protected String determineCustomerPhone(@NonNull @NonNull StripePaymentRequest stripePaymentRequest)
    • populatePaymentIntentCreateParams

      protected com.stripe.param.PaymentIntentCreateParams populatePaymentIntentCreateParams(@NonNull @NonNull StripePaymentRequest stripePaymentRequest, @NonNull @NonNull String paymentMethodId)
    • isACHPaymentRequest

      protected boolean isACHPaymentRequest(@NonNull @NonNull com.broadleafcommerce.paymentgateway.domain.PaymentRequest paymentRequest)
    • buildPaymentIntentShipping

      @Nullable protected com.stripe.param.PaymentIntentCreateParams.Shipping buildPaymentIntentShipping(@NonNull @NonNull StripePaymentRequest stripePaymentRequest)
    • buildPaymentIntentShippingAddress

      protected com.stripe.param.PaymentIntentCreateParams.Shipping.Address buildPaymentIntentShippingAddress(@NonNull @NonNull com.broadleafcommerce.paymentgateway.domain.Address<com.broadleafcommerce.paymentgateway.domain.PaymentRequest> shipTo)
    • getTransactionTotalInMinorUnits

      public Long getTransactionTotalInMinorUnits(@NonNull @NonNull com.broadleafcommerce.paymentgateway.domain.PaymentRequest paymentRequest)
      Specified by:
      getTransactionTotalInMinorUnits in interface StripeExternalCallService
    • getSubtotalInMinorUnits

      protected Long getSubtotalInMinorUnits(@NonNull @NonNull com.broadleafcommerce.paymentgateway.domain.PaymentRequest paymentRequest)
    • getShippingTotalInMinorUnits

      protected Long getShippingTotalInMinorUnits(@NonNull @NonNull com.broadleafcommerce.paymentgateway.domain.PaymentRequest paymentRequest)
    • getTaxTotalInMinorUnits

      protected Long getTaxTotalInMinorUnits(@NonNull @NonNull com.broadleafcommerce.paymentgateway.domain.PaymentRequest paymentRequest)
    • getAmountInMinorUnits

      protected Long getAmountInMinorUnits(@NonNull @NonNull javax.money.MonetaryAmount amount)
    • getAmountInMajorUnits

      public javax.money.MonetaryAmount getAmountInMajorUnits(@NonNull @NonNull Long amount, @NonNull @NonNull String currencyCode)
      Specified by:
      getAmountInMajorUnits in interface StripeExternalCallService
    • processStripeException

      public void processStripeException(@NonNull @NonNull Exception e, @NonNull @NonNull com.broadleafcommerce.paymentgateway.domain.PaymentResponse paymentResponse, @NonNull @NonNull com.broadleafcommerce.paymentgateway.domain.PaymentRequest paymentRequest)
      Specified by:
      processStripeException in interface StripeExternalCallService
    • addRawResponse

      protected void addRawResponse(@NonNull @NonNull com.broadleafcommerce.paymentgateway.domain.PaymentResponse paymentResponse, @Nullable com.stripe.model.StripeError stripeError)
    • determineFailureTypeForCardException

      protected String determineFailureTypeForCardException(com.stripe.exception.CardException cardException)
    • isInvalidPaymentMethodFailureType

      protected boolean isInvalidPaymentMethodFailureType(String declineCode)
    • determineDeclineType

      protected String determineDeclineType(String responseCode)
      Determine whether the decline code should be considered a hard or soft decline.
      Parameters:
      responseCode - Stripe's reason for declining the transaction
      Returns:
      Whether the decline code should be considered a hard or soft decline.
    • isStripeCustomerRequest

      protected boolean isStripeCustomerRequest(@NonNull @NonNull StripeMethodType stripeMethodType)
    • populateCustomerMetadata

      protected Map<String,Object> populateCustomerMetadata(@NonNull @NonNull StripePaymentRequest stripePaymentRequest)
    • populateLevel3Data

      @Nullable protected Map<String,Object> populateLevel3Data(@NonNull @NonNull StripePaymentRequest stripePaymentRequest)
      {@link 'https://stripe.com/guides/3d-secure-2'}
    • isLevel3DataEnabled

      protected boolean isLevel3DataEnabled(@NonNull @NonNull StripePaymentRequest stripePaymentRequest)
    • getSetupFutureUsage

      protected com.stripe.param.PaymentIntentCreateParams.SetupFutureUsage getSetupFutureUsage(@NonNull @NonNull com.broadleafcommerce.paymentgateway.domain.PaymentRequest paymentRequest)
    • maxLength

      protected String maxLength(@NonNull @NonNull String attributeValue, int maxLength)
    • populateLineItemData

      protected Map<String,Object> populateLineItemData(@NonNull @NonNull StripePaymentRequest stripePaymentRequest)
    • determineProductDescription

      protected String determineProductDescription(@NonNull @NonNull com.broadleafcommerce.paymentgateway.domain.LineItem lineItem)
    • determineLineItemProductCode

      protected String determineLineItemProductCode(@NonNull @NonNull com.broadleafcommerce.paymentgateway.domain.LineItem lineItem)
    • determineLineItemDiscountAmount

      protected Long determineLineItemDiscountAmount(@NonNull @NonNull com.broadleafcommerce.paymentgateway.domain.PaymentRequest paymentRequest, @NonNull @NonNull com.broadleafcommerce.paymentgateway.domain.LineItem lineItem)
    • populateCustomMetadata

      protected void populateCustomMetadata(@NonNull @NonNull StripePaymentRequest stripePaymentRequest, @NonNull @NonNull Map<String,Object> params)
      Hookpoint for populating metadata on stripe requests that support it in their params.
      Parameters:
      stripePaymentRequest - the request that will be sent to Stripe
      params - The request parameter map
      See Also:
    • getCustomMetadata

      protected Map<String,String> getCustomMetadata(@NonNull @NonNull StripePaymentRequest stripePaymentRequest)
      Add the transactionReferenceId to the custom metadata so that we can link Stripe's record of the transaction to our record of the transaction
      Parameters:
      stripePaymentRequest - the request that will be sent to Stripe
      Returns:
      the map of custom metadata
      See Also:
    • populateCustomerAdditionalAttributes

      protected void populateCustomerAdditionalAttributes(@NonNull @NonNull StripePaymentRequest stripePaymentRequest, @NonNull @NonNull Map<String,Object> params)
    • isPaymentIntentRequest

      public boolean isPaymentIntentRequest(@NonNull @NonNull StripePaymentRequest stripePaymentRequest)
      Specified by:
      isPaymentIntentRequest in interface StripeExternalCallService
    • buildRequestOptions

      protected com.stripe.net.RequestOptions buildRequestOptions(@NonNull @NonNull StripePaymentRequest stripePaymentRequest)
      Builds a RequestOptions object including API credentials & an idempotencyKey
      Parameters:
      stripePaymentRequest - the request that will be sent to Stripe
      Returns:
      the configured request options
    • buildRequestOptionsForUpdatePaymentIntent

      protected com.stripe.net.RequestOptions buildRequestOptionsForUpdatePaymentIntent(@NonNull @NonNull StripePaymentRequest stripePaymentRequest)
    • buildIdempotencyKey

      protected String buildIdempotencyKey(@NonNull @NonNull StripePaymentRequest stripePaymentRequest)
      Builds or gathers the idempotencyKey for the request. This value will guarantee that the request cannot be processed twice & that if the request is made twice, that the second response will be the same as the first response. Note: this value must be unique for each TransactionType. For example, if we want to authorize & later capture a Stripe Payment, the capture request's idempotencyKey must be different than the authorization request's idempotencyKey.
      Parameters:
      stripePaymentRequest - the request that will be sent to Stripe
      Returns:
      the idempotencyKey
    • getStripeAccount

      @Nullable protected String getStripeAccount(@NonNull @NonNull StripePaymentRequest stripePaymentRequest)
      When integrating with Stripe Connect functionality such as for a marketplace implementation, this will retrieve the the Stripe Account ID for the connected account so that it can be added to the request.
      Parameters:
      stripePaymentRequest - the request that will be sent to Stripe
      Returns:
      the connected Stripe Account ID
    • getFailureReportingThreshold

      public Integer getFailureReportingThreshold()
      Specified by:
      getFailureReportingThreshold in interface com.broadleafcommerce.paymentgateway.service.FailureCountExposable
      Specified by:
      getFailureReportingThreshold in class com.broadleafcommerce.paymentgateway.service.AbstractExternalPaymentGatewayCall<StripePaymentRequest,com.stripe.model.StripeObject>
    • getServiceName

      public String getServiceName()
      Specified by:
      getServiceName in interface com.broadleafcommerce.paymentgateway.vendor.service.monitor.ServiceStatusDetectable<T>
    • buildAddressForStripeUser

      protected Map<String,Object> buildAddressForStripeUser(@NonNull @NonNull StripePaymentRequest stripePaymentRequest)
    • getConfiguration

      protected StripeConfiguration getConfiguration()
    • getRestConfigurationProperties

      protected StripeRestConfigurationProperties getRestConfigurationProperties()
    • getRetryTemplate

      protected org.springframework.retry.support.RetryTemplate getRetryTemplate()