Class DefaultPayPalCheckoutTransactionService
- java.lang.Object
-
- com.broadleafcommerce.paypal.micro.gateway.service.DefaultPayPalCheckoutTransactionService
-
- All Implemented Interfaces:
com.broadleafcommerce.paymentgateway.service.PaymentGatewayTransactionService
,com.broadleafcommerce.paymentgateway.service.PaymentGatewayTypeAware
,PayPalCheckoutTransactionService
public class DefaultPayPalCheckoutTransactionService extends Object implements PayPalCheckoutTransactionService
- Author:
- Nathan Moore
-
-
Constructor Summary
Constructors Constructor Description DefaultPayPalCheckoutTransactionService(PayPalCheckoutProvider paypalCheckoutService, PayPalApiProvider apiProvider, PayPalOrderService payPalOrderService, PayPalCheckoutApiProperties properties, org.springframework.retry.support.RetryTemplate retryTemplate, PayPalUtils utils)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
addAssertionHeaderForRefundOnBehalfOf(@NonNull com.broadleafcommerce.paymentgateway.domain.PaymentRequest paymentRequest)
This is only needed when using the Marketplaces and Platforms solution from PayPal.com.broadleafcommerce.paymentgateway.domain.PaymentResponse
authorize(@NonNull com.broadleafcommerce.paymentgateway.domain.PaymentRequest paymentRequest)
com.broadleafcommerce.paymentgateway.domain.PaymentResponse
authorizeAndCapture(@NonNull com.broadleafcommerce.paymentgateway.domain.PaymentRequest paymentRequest)
protected PayPalAuthorizeResponse
authorizeOrder(@NonNull com.broadleafcommerce.paymentgateway.domain.PaymentRequest paymentRequest)
Executes anDefaultTransactionTypes.AUTHORIZE
transaction based on the providedPaymentRequest
com.broadleafcommerce.paymentgateway.domain.PaymentResponse
capture(@NonNull com.broadleafcommerce.paymentgateway.domain.PaymentRequest paymentRequest)
protected PayPalCaptureAuthResponse
captureAuthorization(@NonNull com.broadleafcommerce.paymentgateway.domain.PaymentRequest paymentRequest)
Executes aDefaultTransactionTypes.CAPTURE
for the providedAuthorization
protected PayPalCaptureOrderResponse
captureOrder(@NonNull com.broadleafcommerce.paymentgateway.domain.PaymentRequest paymentRequest)
Executes anDefaultTransactionTypes.AUTHORIZE_AND_CAPTURE
transaction based on the providedPaymentRequest
.protected PayPalApiProvider
getApiProvider()
String
getGatewayType()
protected PayPalCheckoutProvider
getPaypalCheckoutService()
protected PayPalOrderService
getPayPalOrderService()
protected PayPalCheckoutApiProperties
getProperties()
protected org.springframework.retry.support.RetryTemplate
getRetryTemplate()
protected PayPalUtils
getUtils()
protected boolean
isPaymentDecline(String errorCode)
Since PayPal uses a 400 HTTP response for many different types of failures, this method leverages the errorCode to determine if there was an error in the processing of the payment.protected boolean
isPaymentMethodDecline(String errorCode)
Since PayPal uses a 400 HTTP response for many different types of failures, this method leverages the errorCode to determine if there was an error in the processing of the payment method.protected void
processException(@NonNull Exception e, @NonNull com.broadleafcommerce.paymentgateway.domain.PaymentResponse paymentResponse, @NonNull com.broadleafcommerce.paymentgateway.domain.PaymentRequest paymentRequest)
This method is responsible for levering the exception, paymentRequest, & transactionType to populate the paymentResponse instead of allowing the exception to be thrown.com.broadleafcommerce.paymentgateway.domain.PaymentResponse
refund(@NonNull com.broadleafcommerce.paymentgateway.domain.PaymentRequest paymentRequest)
protected PayPalRefundResponse
refundPayment(@NonNull com.broadleafcommerce.paymentgateway.domain.PaymentRequest paymentRequest)
Executes aDefaultTransactionTypes.REFUND
for the captured payment.protected PayPalAuthorizationRetrievalResponse
retrieveAuthorization(@NonNull com.broadleafcommerce.paymentgateway.domain.PaymentRequest paymentRequest)
com.broadleafcommerce.paymentgateway.domain.PaymentResponse
reverseAuthorize(@NonNull com.broadleafcommerce.paymentgateway.domain.PaymentRequest paymentRequest)
protected PayPalVoidAuthResponse
voidAuthorization(@NonNull com.broadleafcommerce.paymentgateway.domain.PaymentRequest paymentRequest)
Executes aDefaultTransactionTypes.REVERSE_AUTH
for the providedAuthorization
object.protected com.broadleafcommerce.paymentgateway.domain.PaymentResponse
voidAuthorization(@NonNull com.broadleafcommerce.paymentgateway.domain.PaymentRequest paymentRequest, @NonNull com.broadleafcommerce.paymentgateway.domain.enums.TransactionType transactionType)
-
-
-
Constructor Detail
-
DefaultPayPalCheckoutTransactionService
public DefaultPayPalCheckoutTransactionService(PayPalCheckoutProvider paypalCheckoutService, PayPalApiProvider apiProvider, PayPalOrderService payPalOrderService, PayPalCheckoutApiProperties properties, org.springframework.retry.support.RetryTemplate retryTemplate, PayPalUtils utils)
-
-
Method Detail
-
authorize
public com.broadleafcommerce.paymentgateway.domain.PaymentResponse authorize(@NonNull @NonNull com.broadleafcommerce.paymentgateway.domain.PaymentRequest paymentRequest)
- Specified by:
authorize
in interfacecom.broadleafcommerce.paymentgateway.service.PaymentGatewayTransactionService
-
capture
public com.broadleafcommerce.paymentgateway.domain.PaymentResponse capture(@NonNull @NonNull com.broadleafcommerce.paymentgateway.domain.PaymentRequest paymentRequest)
- Specified by:
capture
in interfacecom.broadleafcommerce.paymentgateway.service.PaymentGatewayTransactionService
-
authorizeAndCapture
public com.broadleafcommerce.paymentgateway.domain.PaymentResponse authorizeAndCapture(@NonNull @NonNull com.broadleafcommerce.paymentgateway.domain.PaymentRequest paymentRequest)
- Specified by:
authorizeAndCapture
in interfacecom.broadleafcommerce.paymentgateway.service.PaymentGatewayTransactionService
-
reverseAuthorize
public com.broadleafcommerce.paymentgateway.domain.PaymentResponse reverseAuthorize(@NonNull @NonNull com.broadleafcommerce.paymentgateway.domain.PaymentRequest paymentRequest)
- Specified by:
reverseAuthorize
in interfacecom.broadleafcommerce.paymentgateway.service.PaymentGatewayTransactionService
-
refund
public com.broadleafcommerce.paymentgateway.domain.PaymentResponse refund(@NonNull @NonNull com.broadleafcommerce.paymentgateway.domain.PaymentRequest paymentRequest)
- Specified by:
refund
in interfacecom.broadleafcommerce.paymentgateway.service.PaymentGatewayTransactionService
-
addAssertionHeaderForRefundOnBehalfOf
protected void addAssertionHeaderForRefundOnBehalfOf(@NonNull @NonNull com.broadleafcommerce.paymentgateway.domain.PaymentRequest paymentRequest)
This is only needed when using the Marketplaces and Platforms solution from PayPal. Specifically, see Issuing a Refund.Adds the
PayPal-Auth-Assertion
header to thepaymentRequest
to ensure it's included for refund requests, otherwise, the request will be considered unauthorized when attempting to refund on behalf of a seller.- Parameters:
paymentRequest
-PaymentRequest
DTO.
-
voidAuthorization
protected com.broadleafcommerce.paymentgateway.domain.PaymentResponse voidAuthorization(@NonNull @NonNull com.broadleafcommerce.paymentgateway.domain.PaymentRequest paymentRequest, @NonNull @NonNull com.broadleafcommerce.paymentgateway.domain.enums.TransactionType transactionType)
-
captureAuthorization
protected PayPalCaptureAuthResponse captureAuthorization(@NonNull @NonNull com.broadleafcommerce.paymentgateway.domain.PaymentRequest paymentRequest)
Executes aDefaultTransactionTypes.CAPTURE
for the providedAuthorization
- Parameters:
paymentRequest
- The request payload that should be used to form the transaction- Returns:
- a
PayPalCaptureAuthResponse
-
authorizeOrder
protected PayPalAuthorizeResponse authorizeOrder(@NonNull @NonNull com.broadleafcommerce.paymentgateway.domain.PaymentRequest paymentRequest)
Executes anDefaultTransactionTypes.AUTHORIZE
transaction based on the providedPaymentRequest
- Parameters:
paymentRequest
- The request payload that should be used to form the transaction- Returns:
- an
PayPalAuthorizeResponse
representing the final state of the transaction
-
retrieveAuthorization
protected PayPalAuthorizationRetrievalResponse retrieveAuthorization(@NonNull @NonNull com.broadleafcommerce.paymentgateway.domain.PaymentRequest paymentRequest)
-
captureOrder
protected PayPalCaptureOrderResponse captureOrder(@NonNull @NonNull com.broadleafcommerce.paymentgateway.domain.PaymentRequest paymentRequest)
Executes anDefaultTransactionTypes.AUTHORIZE_AND_CAPTURE
transaction based on the providedPaymentRequest
. For PayPal, this captures theOrder
immediately with no authorization.- Parameters:
paymentRequest
- The request payload that should be used to form the transaction- Returns:
- a
PayPalCaptureOrderResponse
-
voidAuthorization
protected PayPalVoidAuthResponse voidAuthorization(@NonNull @NonNull com.broadleafcommerce.paymentgateway.domain.PaymentRequest paymentRequest)
Executes aDefaultTransactionTypes.REVERSE_AUTH
for the providedAuthorization
object. For PayPal, this means voiding the original authorization.- Parameters:
paymentRequest
- The request payload that should be used to form the transaction- Returns:
- the
PayPalVoidAuthResponse
-
refundPayment
protected PayPalRefundResponse refundPayment(@NonNull @NonNull com.broadleafcommerce.paymentgateway.domain.PaymentRequest paymentRequest)
Executes aDefaultTransactionTypes.REFUND
for the captured payment.- Parameters:
paymentRequest
- The request payload that should be used to form the transaction- Returns:
- a
PayPalRefundResponse
-
processException
protected void processException(@NonNull @NonNull Exception e, @NonNull @NonNull com.broadleafcommerce.paymentgateway.domain.PaymentResponse paymentResponse, @NonNull @NonNull com.broadleafcommerce.paymentgateway.domain.PaymentRequest paymentRequest)
This method is responsible for levering the exception, paymentRequest, & transactionType to populate the paymentResponse instead of allowing the exception to be thrown.- Parameters:
e
- the exception indicating a failed payment gateway transactionpaymentResponse
- the object that will hold the transaction resultspaymentRequest
- the request that was used to execute the transaction
-
isPaymentMethodDecline
protected boolean isPaymentMethodDecline(String errorCode)
Since PayPal uses a 400 HTTP response for many different types of failures, this method leverages the errorCode to determine if there was an error in the processing of the payment method. For example, an incorrect card number, expiration date, etc.- Parameters:
errorCode
- the error code returned by PayPal- Returns:
- whether or not the failure was due to the payment method being declined
- See Also:
DefaultTransactionFailureTypes.INVALID_PAYMENT_METHOD
-
isPaymentDecline
protected boolean isPaymentDecline(String errorCode)
Since PayPal uses a 400 HTTP response for many different types of failures, this method leverages the errorCode to determine if there was an error in the processing of the payment. For example, a credit card decline should be considered a processing failure, whereas a request validation issue would not.- Parameters:
errorCode
- the error code returned by PayPal- Returns:
- whether or not the failure was due to the payment method being declined
-
getGatewayType
public String getGatewayType()
- Specified by:
getGatewayType
in interfacecom.broadleafcommerce.paymentgateway.service.PaymentGatewayTypeAware
-
getPaypalCheckoutService
protected PayPalCheckoutProvider getPaypalCheckoutService()
-
getApiProvider
protected PayPalApiProvider getApiProvider()
-
getPayPalOrderService
protected PayPalOrderService getPayPalOrderService()
-
getProperties
protected PayPalCheckoutApiProperties getProperties()
-
getRetryTemplate
protected org.springframework.retry.support.RetryTemplate getRetryTemplate()
-
getUtils
protected PayPalUtils getUtils()
-
-