Class ExternalPaymentProvider<P extends PaymentSummary>
java.lang.Object
com.broadleafcommerce.cartoperation.service.provider.external.AbstractExternalProvider
com.broadleafcommerce.cartoperation.service.provider.external.payments.ExternalPaymentProvider<P>
- All Implemented Interfaces:
PaymentProvider<P>
public class ExternalPaymentProvider<P extends PaymentSummary>
extends AbstractExternalProvider
implements PaymentProvider<P>
This particular implementation of
PaymentProvider is designed to interact with the
payment transaction service.- Author:
- Dima Myroniuk (dmyroniuk)
-
Field Summary
FieldsFields inherited from class com.broadleafcommerce.cartoperation.service.provider.external.AbstractExternalProvider
ENTITY_NOT_FOUND -
Constructor Summary
ConstructorsConstructorDescriptionExternalPaymentProvider(org.springframework.web.reactive.function.client.WebClient webClient, com.fasterxml.jackson.databind.ObjectMapper objectMapper, com.broadleafcommerce.common.extension.TypeFactory typeFactory, ExternalPaymentProperties properties) -
Method Summary
Modifier and TypeMethodDescriptionvoidarchivePayment(String paymentId, Integer version, String lockToken, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Archives the payment based on the provided id and version.blockCustomerMutabilityForPayments(@NonNull String cartId, Map<String, String> paymentLockTokens, boolean markTransactionsIneligibleForAutoReversal, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Blocks customer mutability for the cart's payments.claimTransactionsForRequest(@NonNull ClaimCheckoutTransactionsRequest request, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Updates the payment transaction request id with the new value, stores the previous value, clears transaction management state and management state reason.finalizePaymentsForCheckout(String cartId, Map<String, String> paymentLockTokens, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) The PaymentTransactionServices internally prepares and finalizes the payments for checkout.protected org.springframework.web.util.UriComponentsBuilderGets the base URI common to all requests this provider will make.Gets the type reference for a list of item list items.protected org.springframework.core.ParameterizedTypeReference<ResponsePageGenerator<P>>Gets the type reference for a page generator of item list items.protected ExternalPaymentPropertiesprotected Stringprotected org.springframework.core.ParameterizedTypeReference<P>getType()Gets the type reference for payment summary.lockAndRetrieveCartPayments(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Same functionality asPaymentProvider.lockCartPayments(Cart, ContextInfo)but this method also includes thePaymentSummariesin the response.protected LockPaymentsResponselockAndRetrievePayments(@NonNull LockPaymentRequest lockPaymentRequest, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Locks the payments based on the givenLockPaymentRequest.lockCartPayments(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Locks the cart's payments to ensure that all of the work done within theCheckoutWorkflowand checkout process in general is consistently interacting with payments that will not change.lockPayments(@NonNull LockPaymentRequest lockPaymentRequest, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Locks the payments based on the givenLockPaymentRequest.patchPayment(UpdatePaymentRequest updatePaymentRequest, Integer version, String lockToken, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Updates the payment based on the providedUpdatePaymentRequest.readAllByOwnerTypeAndOwnerId(@NonNull String ownerType, @NonNull String ownerId, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Retrieves a list ofPaymentSummariesthat belong to the given owner type and owner id.transferPaymentsToCSR(String cartId, Map<String, String> paymentLockTokens, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) The PaymentTransactionServices internally prepares and transfers the payments to the CSR user.transferPaymentsToCustomer(String cartId, Map<String, String> paymentLockTokens, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) The PaymentTransactionServices internally prepares and transfers the payments to the customer user.voidunlockCartPayments(Collection<String> lockTokens, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Unlocks the cart's payments, based on the lock tokens that were previously obtained viaPaymentProvider.lockCartPayments(Cart, ContextInfo).protected StringwritePaymentLockTokensAsHeaderString(Map<String, String> paymentLockTokens) Methods inherited from class com.broadleafcommerce.cartoperation.service.provider.external.AbstractExternalProvider
buildNotFoundException, executeRequest, getHeaders, getObjectMapper, getTypeFactory, getWebClient, isEntityNotFound, pageableToParams, uriVarsMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.broadleafcommerce.cartoperation.service.provider.PaymentProvider
archivePayment, claimTransactionsForRequest, patchPayment, readByCartId, transferPaymentsToCSR, transferPaymentsToCustomer
-
Field Details
-
DEFAULT_HEADER_PAYMENT_VERSION
- See Also:
-
DEFAULT_HEADER_PAYMENT_LOCK_TOKEN
- See Also:
-
DEFAULT_HEADER_PAYMENT_LOCK_TOKENS
- See Also:
-
-
Constructor Details
-
ExternalPaymentProvider
public ExternalPaymentProvider(org.springframework.web.reactive.function.client.WebClient webClient, com.fasterxml.jackson.databind.ObjectMapper objectMapper, com.broadleafcommerce.common.extension.TypeFactory typeFactory, ExternalPaymentProperties properties)
-
-
Method Details
-
readAllByOwnerTypeAndOwnerId
public List<P> readAllByOwnerTypeAndOwnerId(@NonNull @NonNull String ownerType, @NonNull @NonNull String ownerId, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Description copied from interface:PaymentProviderRetrieves a list ofPaymentSummariesthat belong to the given owner type and owner id.- Specified by:
readAllByOwnerTypeAndOwnerIdin interfacePaymentProvider<P extends PaymentSummary>- Parameters:
ownerType- the owner type of thePaymentSummariesto retrieveownerId- the owner id of thePaymentSummariesto retrievecontext- context information around sandbox and multitenant state.- Returns:
- a list of
PaymentSummariesbased on the given owner type and owner id
-
patchPayment
public PaymentSummary patchPayment(UpdatePaymentRequest updatePaymentRequest, Integer version, @Nullable String lockToken, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Description copied from interface:PaymentProviderUpdates the payment based on the providedUpdatePaymentRequest. This method can be used to partially update the payment. To do so provide only the fields you would like to update. The default implementation archives the payment ifUpdatePaymentRequest.getAmount()is equal to zero.- Specified by:
patchPaymentin interfacePaymentProvider<P extends PaymentSummary>- Parameters:
updatePaymentRequest- the request payload used to update the paymentversion- the payment versionlockToken- the token that owns the payment lockcontext- Context information related to multitenancy- Returns:
- the updated payment summary.
-
archivePayment
public void archivePayment(String paymentId, Integer version, @Nullable String lockToken, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Description copied from interface:PaymentProviderArchives the payment based on the provided id and version.- Specified by:
archivePaymentin interfacePaymentProvider<P extends PaymentSummary>- Parameters:
paymentId- the context id of the paymentversion- the payment versionlockToken- Token that can be used to unlock the cart's paymentcontext- context information related to multitenancy
-
lockCartPayments
public Map<String,String> lockCartPayments(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:PaymentProviderLocks the cart's payments to ensure that all of the work done within theCheckoutWorkflowand checkout process in general is consistently interacting with payments that will not change. With these locks in place, only this executing process will have access to modify the payments, until the lock TTL expires. Note: make sure that the checkout process can sufficiently be contained within the payment lock TTL. This can be configured in PaymentTransactionServices.- Specified by:
lockCartPaymentsin interfacePaymentProvider<P extends PaymentSummary>- Parameters:
cart- theCartwhose payments are to be locked.contextInfo- context information around sandbox and multitenant state.- Returns:
- A map of payment id to lock token.
-
lockAndRetrieveCartPayments
public LockPaymentsResponse lockAndRetrieveCartPayments(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:PaymentProviderSame functionality asPaymentProvider.lockCartPayments(Cart, ContextInfo)but this method also includes thePaymentSummariesin the response.This is useful to reduce the amount of network calls.
- Specified by:
lockAndRetrieveCartPaymentsin interfacePaymentProvider<P extends PaymentSummary>- Parameters:
cart- theCartwhose payments are to be locked.contextInfo- context information around sandbox and multitenant state.- Returns:
- A
LockPaymentsResponsecontaining the payment locks andPaymentSummaries
-
lockPayments
protected Map<String,String> lockPayments(@NonNull @NonNull LockPaymentRequest lockPaymentRequest, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Locks the payments based on the givenLockPaymentRequest.- Parameters:
lockPaymentRequest- theLockPaymentRequestcontextInfo- context information around sandbox and multitenant state- Returns:
- A map of payment id to lock token.
- Throws:
PaymentLockException- if a lock could not be obtained.
-
lockAndRetrievePayments
protected LockPaymentsResponse lockAndRetrievePayments(@NonNull @NonNull LockPaymentRequest lockPaymentRequest, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Locks the payments based on the givenLockPaymentRequest.- Parameters:
lockPaymentRequest- theLockPaymentRequestcontextInfo- context information around sandbox and multitenant state- Returns:
- A map of payment id to lock token.
- Throws:
PaymentLockException- if a lock could not be obtained.
-
unlockCartPayments
public void unlockCartPayments(Collection<String> lockTokens, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:PaymentProviderUnlocks the cart's payments, based on the lock tokens that were previously obtained viaPaymentProvider.lockCartPayments(Cart, ContextInfo).- Specified by:
unlockCartPaymentsin interfacePaymentProvider<P extends PaymentSummary>- Parameters:
lockTokens- Tokens that can be used to unlock the cart's payments
-
finalizePaymentsForCheckout
public UpdatePaymentsResponse finalizePaymentsForCheckout(String cartId, Map<String, String> paymentLockTokens, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:PaymentProviderThe PaymentTransactionServices internally prepares and finalizes the payments for checkout.- Specified by:
finalizePaymentsForCheckoutin interfacePaymentProvider<P extends PaymentSummary>- Parameters:
cartId- the owner id of thePaymentSummariesto finalizepaymentLockTokens- Tokens that can be used to unlock the cart's paymentscontextInfo- context information around sandbox and multitenant state.
-
blockCustomerMutabilityForPayments
public UpdatePaymentsResponse blockCustomerMutabilityForPayments(@NonNull @NonNull String cartId, Map<String, String> paymentLockTokens, boolean markTransactionsIneligibleForAutoReversal, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:PaymentProviderBlocks customer mutability for the cart's payments.- Specified by:
blockCustomerMutabilityForPaymentsin interfacePaymentProvider<P extends PaymentSummary>- Parameters:
cartId- the owner id of thePaymentSummariesto finalizepaymentLockTokens- Tokens that can be used to unlock the cart's paymentsmarkTransactionsIneligibleForAutoReversal- Determines if the payments' transactions should be marked ineligible for automatic reversalcontextInfo- context information around sandbox and multitenant state.
-
transferPaymentsToCSR
public UpdatePaymentsResponse transferPaymentsToCSR(String cartId, Map<String, String> paymentLockTokens, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:PaymentProviderThe PaymentTransactionServices internally prepares and transfers the payments to the CSR user. The expectation is that the payments will no longer be owned by the customer and cannot be accessed except by the CSR user.- Specified by:
transferPaymentsToCSRin interfacePaymentProvider<P extends PaymentSummary>- Parameters:
cartId- the owner id of thePaymentSummariesto transferpaymentLockTokens- Tokens that can be used to unlock the cart's paymentscontextInfo- context information around sandbox and multitenant state.
-
transferPaymentsToCustomer
public UpdatePaymentsResponse transferPaymentsToCustomer(String cartId, Map<String, String> paymentLockTokens, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:PaymentProviderThe PaymentTransactionServices internally prepares and transfers the payments to the customer user.- Specified by:
transferPaymentsToCustomerin interfacePaymentProvider<P extends PaymentSummary>- Parameters:
cartId- the owner id of thePaymentSummariesto transferpaymentLockTokens- Tokens that can be used to unlock the cart's paymentscontextInfo- context information around sandbox and multitenant state.
-
claimTransactionsForRequest
public PaymentSummary claimTransactionsForRequest(@NonNull @NonNull ClaimCheckoutTransactionsRequest request, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:PaymentProviderUpdates the payment transaction request id with the new value, stores the previous value, clears transaction management state and management state reason.- Specified by:
claimTransactionsForRequestin interfacePaymentProvider<P extends PaymentSummary>- Parameters:
request- theClaimCheckoutTransactionsRequestto claim the transactions for a checkout requestcontextInfo- context information related to multitenancy
-
getBaseUri
protected org.springframework.web.util.UriComponentsBuilder getBaseUri()Gets the base URI common to all requests this provider will make.- Returns:
- a URI components builder with the base URI set up
-
getType
Gets the type reference for payment summary.- Returns:
- type reference for payment summary
-
getPageType
protected org.springframework.core.ParameterizedTypeReference<ResponsePageGenerator<P>> getPageType()Gets the type reference for a page generator of item list items.- Returns:
- type reference for a page generator of item list items
-
getMapType
Gets the type reference for a list of item list items.- Returns:
- type reference for a list of item list items
-
writePaymentLockTokensAsHeaderString
-
getServiceClient
-
getProperties
-