Class StripeServiceImpl
- java.lang.Object
-
- co.mastermindcms.modules.services.StripeServiceImpl
-
- All Implemented Interfaces:
StripeService
@Service public class StripeServiceImpl extends java.lang.Object implements StripeService
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
CARD_TYPE
private CommerceProperties
commerceProperties
private EmailProperties
emailProperties
private EmailSenderService
emailSenderService
private static com.fasterxml.jackson.databind.ObjectMapper
mapper
private OrderRepository
orderRepository
private ProfileManagementService
profileManagementService
private SellerRegistrationService
sellerRegistrationService
private SellerRepository
sellerRepository
static java.lang.String
SEPA_DEBIT_TYPE
private TranslationService
translationService
private UserRepository
userRepository
-
Constructor Summary
Constructors Constructor Description StripeServiceImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.math.BigDecimal
calculateServiceFee(java.math.BigDecimal amount)
Calculates service fee for given amount.java.util.Map<java.lang.String,java.lang.Object>
calculateTaxRate(java.lang.String amount, java.lang.String countryIsoCode)
This method returns data as object.com.stripe.model.PaymentIntent
cancelIntent(java.lang.String paymentIntentId)
This method cancel created payment intent in Stripeprivate void
cancelSubscription(java.lang.String sellerId)
java.lang.String
cancelSubscriptionAfterActivePeriod(java.lang.String sellerId)
This method cancels a stripe subscription after expired stripe contract period.java.lang.String
cancelSubscriptionImmediately(java.lang.String sellerId)
This method cancels a stripe subscription immediately.boolean
changePaymentMethod(java.lang.String paymentIntentId, java.lang.String paymentMethodId)
Changes the payment method for the given payment intent.java.lang.String
chargeCreditCard(java.util.LinkedHashMap<java.lang.String,java.lang.Object> chargeRequestAsMap)
This method creates a charge for payment.PaymentStatus
chargeIntent(java.lang.String paymentIntentId)
Charges payment intent.java.lang.String
chargeSepa(java.util.LinkedHashMap<java.lang.String,java.lang.Object> chargeRequestAsMap)
This method creates a stripe charge entity.void
chargeTariffCreditCard(java.util.LinkedHashMap<java.lang.String,java.lang.Object> chargeRequestAsMap)
This method creates a charge tariff for payment.(package private) void
chargeTariffCreditCardAsync(ChargeRequest chargeRequest)
void
chargeTariffSepa(java.util.LinkedHashMap<java.lang.String,java.lang.Object> chargeRequestAsMap)
This method creates a stripe charge tariff.(package private) void
chargeTariffSepaAsync(ChargeRequest chargeRequest)
java.lang.String
createIntent(java.lang.String orderId, java.lang.String stripeConnectId, java.lang.String paymentMethodId, java.lang.Long bruttoAmount, java.lang.Long nettoAmount)
Creates payment intent for current seller by payment method and amount.java.util.Map<java.lang.String,java.lang.Object>
createPaymentMethod(java.util.LinkedHashMap<java.lang.String,java.lang.Object> paymentMethodMap)
Creates payment method and - if needed - customer for Stripe.private java.util.Optional<com.stripe.model.PaymentMethod>
duplicatedPaymentMethod(com.stripe.model.PaymentMethod newPm)
private com.stripe.model.PaymentMethod
executeAttachPaymentMethod(com.stripe.model.PaymentMethod paymentMethod, java.lang.String customerId)
private void
executeConfirmSepaPaymentMethod(java.lang.String paymentMethodId, java.lang.String customerId)
private com.stripe.model.PaymentMethod
executeCreatePaymentMethod(java.util.LinkedHashMap<java.lang.String,java.lang.Object> paymentMethodMap)
java.util.Map<java.lang.String,java.lang.String>
getAmountByTariff(java.lang.String tariff)
This method returns data as map.java.util.Map<java.lang.String,java.lang.Object>
getContractEndDate(java.lang.String createdDate, java.lang.String pattern)
This method does return time.java.util.Map<java.lang.String,java.lang.Object>
getContractEndDateFromTimestamp(java.lang.String created, java.lang.String pattern)
This method does return time.java.lang.String
getCurrency()
This method returns currency namejava.util.List<com.stripe.model.Invoice>
getInvoices()
This method returns data as list.java.util.Map<java.lang.String,java.lang.Object>
getPaymentMethod(java.lang.String paymentMethodId)
This method returns data as map.java.util.List<com.stripe.model.PaymentMethod>
getPaymentMethods(java.lang.String type)
This method returns data as list.java.util.List<com.stripe.model.Product>
getProducts()
This method returns data as list.java.math.BigDecimal
getServiceFee()
Service fee coefficient.java.util.Map<java.lang.String,java.lang.Object>
getSubscription()
This method returns data as object.private java.util.List<java.lang.String>
getTaxRatesIds()
void
init()
private boolean
isAllowsToCharge(java.lang.String email)
boolean
isStripeKeysDefined()
This method does return boolean result.boolean
isTariffEquals(java.lang.String tariff)
This method does return boolean result.java.lang.String
obtain3DSecureLink(java.lang.String paymentIntentId)
Obtains link for payment intent authorization.java.util.Map<java.lang.String,com.stripe.model.TaxRate>
obtainAllTaxRates()
Obtains all tax rates from Stripe api.com.stripe.model.Payout
payoutToVendor(Seller vendor, long amount)
Moves funds from stripe account to bank/card.void
removePaymentMethod(java.lang.String paymentMethodId)
This method returns data as object.private void
sendConfirmationEmail(User user)
java.lang.String
transferToVendor(Order order, long amount)
Attempts to execute aTransfer
from the service to given order seller'sAccount
.private PaymentStatus
translatePaymentStatus(java.lang.String status)
private java.lang.String
updateSubscription(java.lang.String subscriptionId, java.lang.String tariff, long amount)
-
-
-
Field Detail
-
sellerRepository
@Autowired private SellerRepository sellerRepository
-
userRepository
@Autowired private UserRepository userRepository
-
orderRepository
@Autowired private OrderRepository orderRepository
-
commerceProperties
@Autowired private CommerceProperties commerceProperties
-
sellerRegistrationService
@Autowired private SellerRegistrationService sellerRegistrationService
-
profileManagementService
@Autowired private ProfileManagementService profileManagementService
-
translationService
@Autowired private TranslationService translationService
-
emailSenderService
@Autowired private EmailSenderService emailSenderService
-
emailProperties
@Autowired private EmailProperties emailProperties
-
SEPA_DEBIT_TYPE
public static final java.lang.String SEPA_DEBIT_TYPE
- See Also:
- Constant Field Values
-
CARD_TYPE
public static final java.lang.String CARD_TYPE
- See Also:
- Constant Field Values
-
mapper
private static final com.fasterxml.jackson.databind.ObjectMapper mapper
-
-
Method Detail
-
init
@PostConstruct public void init()
-
isStripeKeysDefined
public boolean isStripeKeysDefined()
Description copied from interface:StripeService
This method does return boolean result.- Specified by:
isStripeKeysDefined
in interfaceStripeService
- Returns:
- value as boolean
-
getCurrency
public java.lang.String getCurrency()
Description copied from interface:StripeService
This method returns currency name- Specified by:
getCurrency
in interfaceStripeService
- Returns:
- value as string
-
getServiceFee
public java.math.BigDecimal getServiceFee()
Description copied from interface:StripeService
Service fee coefficient.- Specified by:
getServiceFee
in interfaceStripeService
- Returns:
- coefficient
-
calculateServiceFee
public java.math.BigDecimal calculateServiceFee(java.math.BigDecimal amount)
Description copied from interface:StripeService
Calculates service fee for given amount.- Specified by:
calculateServiceFee
in interfaceStripeService
- Parameters:
amount
- amount- Returns:
- service fee
-
createIntent
public java.lang.String createIntent(java.lang.String orderId, java.lang.String stripeConnectId, java.lang.String paymentMethodId, java.lang.Long bruttoAmount, java.lang.Long nettoAmount)
Description copied from interface:StripeService
Creates payment intent for current seller by payment method and amount.- Specified by:
createIntent
in interfaceStripeService
- Parameters:
orderId
- id of the order for metadatastripeConnectId
- id of the stripe connect account for vendorpaymentMethodId
- payment method ID.bruttoAmount
- amount with tax in the smallest currency unit, e.g. for 100$ expected value would be 10000 (that means to be cents).nettoAmount
- net amount in the smallest currency unit, e.g. for 100$ expected value would be 10000 (that means to be cents).- Returns:
- created intent ID
-
cancelIntent
public com.stripe.model.PaymentIntent cancelIntent(java.lang.String paymentIntentId)
Description copied from interface:StripeService
This method cancel created payment intent in Stripe- Specified by:
cancelIntent
in interfaceStripeService
- Parameters:
paymentIntentId
- identification from payment intent in Stripe- Returns:
- stripe payment intent entity
-
chargeIntent
public PaymentStatus chargeIntent(java.lang.String paymentIntentId)
Description copied from interface:StripeService
Charges payment intent.- Specified by:
chargeIntent
in interfaceStripeService
- Parameters:
paymentIntentId
- id- Returns:
PaymentStatus
of the payment
-
translatePaymentStatus
private PaymentStatus translatePaymentStatus(java.lang.String status)
-
obtain3DSecureLink
public java.lang.String obtain3DSecureLink(java.lang.String paymentIntentId)
Description copied from interface:StripeService
Obtains link for payment intent authorization.- Specified by:
obtain3DSecureLink
in interfaceStripeService
- Parameters:
paymentIntentId
- intent id- Returns:
- link
-
changePaymentMethod
public boolean changePaymentMethod(java.lang.String paymentIntentId, java.lang.String paymentMethodId)
Description copied from interface:StripeService
Changes the payment method for the given payment intent.- Specified by:
changePaymentMethod
in interfaceStripeService
- Parameters:
paymentIntentId
- id of intentpaymentMethodId
- id of a new using in the intent payment method- Returns:
- true if successful
-
transferToVendor
public java.lang.String transferToVendor(Order order, long amount)
Description copied from interface:StripeService
Attempts to execute aTransfer
from the service to given order seller'sAccount
.- Specified by:
transferToVendor
in interfaceStripeService
- Parameters:
order
- orderamount
- amount- Returns:
- ID of created
Transfer
-
payoutToVendor
public com.stripe.model.Payout payoutToVendor(Seller vendor, long amount) throws com.stripe.exception.StripeException
Description copied from interface:StripeService
Moves funds from stripe account to bank/card.- Specified by:
payoutToVendor
in interfaceStripeService
- Parameters:
vendor
- selleramount
- amount- Returns:
- stripe payout
- Throws:
com.stripe.exception.StripeException
- in create token and customer
-
chargeSepa
public java.lang.String chargeSepa(java.util.LinkedHashMap<java.lang.String,java.lang.Object> chargeRequestAsMap)
Description copied from interface:StripeService
This method creates a stripe charge entity.- Specified by:
chargeSepa
in interfaceStripeService
- Parameters:
chargeRequestAsMap
- map-representation of database entity- Returns:
- optional value to externally interaction
-
chargeCreditCard
public java.lang.String chargeCreditCard(java.util.LinkedHashMap<java.lang.String,java.lang.Object> chargeRequestAsMap)
Description copied from interface:StripeService
This method creates a charge for payment.- Specified by:
chargeCreditCard
in interfaceStripeService
- Parameters:
chargeRequestAsMap
- map-representation of charge request- Returns:
- value as text
-
chargeTariffSepa
public void chargeTariffSepa(java.util.LinkedHashMap<java.lang.String,java.lang.Object> chargeRequestAsMap)
Description copied from interface:StripeService
This method creates a stripe charge tariff.- Specified by:
chargeTariffSepa
in interfaceStripeService
- Parameters:
chargeRequestAsMap
- map-representation of database entity
-
chargeTariffCreditCard
public void chargeTariffCreditCard(java.util.LinkedHashMap<java.lang.String,java.lang.Object> chargeRequestAsMap)
Description copied from interface:StripeService
This method creates a charge tariff for payment.- Specified by:
chargeTariffCreditCard
in interfaceStripeService
- Parameters:
chargeRequestAsMap
- map-representation of charge request
-
cancelSubscriptionAfterActivePeriod
public java.lang.String cancelSubscriptionAfterActivePeriod(java.lang.String sellerId)
Description copied from interface:StripeService
This method cancels a stripe subscription after expired stripe contract period.- Specified by:
cancelSubscriptionAfterActivePeriod
in interfaceStripeService
- Parameters:
sellerId
- identification bean which will be find database entity- Returns:
- value as text
-
cancelSubscriptionImmediately
public java.lang.String cancelSubscriptionImmediately(java.lang.String sellerId)
Description copied from interface:StripeService
This method cancels a stripe subscription immediately.- Specified by:
cancelSubscriptionImmediately
in interfaceStripeService
- Parameters:
sellerId
- identification bean which will be find database entity- Returns:
- value as text
-
getContractEndDate
public java.util.Map<java.lang.String,java.lang.Object> getContractEndDate(java.lang.String createdDate, java.lang.String pattern)
Description copied from interface:StripeService
This method does return time.- Specified by:
getContractEndDate
in interfaceStripeService
- Parameters:
createdDate
- from which can extracted timepattern
- pattern for formatting a date- Returns:
- data as map
-
getContractEndDateFromTimestamp
public java.util.Map<java.lang.String,java.lang.Object> getContractEndDateFromTimestamp(java.lang.String created, java.lang.String pattern)
Description copied from interface:StripeService
This method does return time.- Specified by:
getContractEndDateFromTimestamp
in interfaceStripeService
- Parameters:
created
- from which can extracted timepattern
- pattern for formatting a date- Returns:
- data as map
-
isTariffEquals
public boolean isTariffEquals(java.lang.String tariff)
Description copied from interface:StripeService
This method does return boolean result.- Specified by:
isTariffEquals
in interfaceStripeService
- Parameters:
tariff
- value to check- Returns:
- value as boolean
-
getAmountByTariff
public java.util.Map<java.lang.String,java.lang.String> getAmountByTariff(java.lang.String tariff)
Description copied from interface:StripeService
This method returns data as map.- Specified by:
getAmountByTariff
in interfaceStripeService
- Parameters:
tariff
- field for filter and return data- Returns:
- data as map
-
getInvoices
public java.util.List<com.stripe.model.Invoice> getInvoices()
Description copied from interface:StripeService
This method returns data as list.- Specified by:
getInvoices
in interfaceStripeService
- Returns:
- data as list
-
getProducts
public java.util.List<com.stripe.model.Product> getProducts()
Description copied from interface:StripeService
This method returns data as list.- Specified by:
getProducts
in interfaceStripeService
- Returns:
- data as list
-
createPaymentMethod
public java.util.Map<java.lang.String,java.lang.Object> createPaymentMethod(java.util.LinkedHashMap<java.lang.String,java.lang.Object> paymentMethodMap)
Description copied from interface:StripeService
Creates payment method and - if needed - customer for Stripe.- Specified by:
createPaymentMethod
in interfaceStripeService
- Parameters:
paymentMethodMap
- data- Returns:
- map as object
-
duplicatedPaymentMethod
private java.util.Optional<com.stripe.model.PaymentMethod> duplicatedPaymentMethod(com.stripe.model.PaymentMethod newPm)
-
removePaymentMethod
public void removePaymentMethod(java.lang.String paymentMethodId)
Description copied from interface:StripeService
This method returns data as object.- Specified by:
removePaymentMethod
in interfaceStripeService
- Parameters:
paymentMethodId
- field for filter and return data
-
getPaymentMethods
public java.util.List<com.stripe.model.PaymentMethod> getPaymentMethods(java.lang.String type)
Description copied from interface:StripeService
This method returns data as list.- Specified by:
getPaymentMethods
in interfaceStripeService
- Parameters:
type
- field for filter and return data- Returns:
- data as list
-
getPaymentMethod
public java.util.Map<java.lang.String,java.lang.Object> getPaymentMethod(java.lang.String paymentMethodId)
Description copied from interface:StripeService
This method returns data as map.- Specified by:
getPaymentMethod
in interfaceStripeService
- Parameters:
paymentMethodId
- field for filter and return data- Returns:
- data as map
-
getSubscription
public java.util.Map<java.lang.String,java.lang.Object> getSubscription()
Description copied from interface:StripeService
This method returns data as object.- Specified by:
getSubscription
in interfaceStripeService
- Returns:
- map as object
-
calculateTaxRate
public java.util.Map<java.lang.String,java.lang.Object> calculateTaxRate(java.lang.String amount, java.lang.String countryIsoCode)
Description copied from interface:StripeService
This method returns data as object.- Specified by:
calculateTaxRate
in interfaceStripeService
- Parameters:
amount
- from this amount will be calculated a tax valuecountryIsoCode
- field for filter and return data- Returns:
- map as object
-
obtainAllTaxRates
public java.util.Map<java.lang.String,com.stripe.model.TaxRate> obtainAllTaxRates()
Description copied from interface:StripeService
Obtains all tax rates from Stripe api.- Specified by:
obtainAllTaxRates
in interfaceStripeService
- Returns:
- map of country iso codes to tax rate
-
isAllowsToCharge
private boolean isAllowsToCharge(java.lang.String email)
-
chargeTariffCreditCardAsync
@Async("asyncTaskExecutor") void chargeTariffCreditCardAsync(ChargeRequest chargeRequest)
-
chargeTariffSepaAsync
@Async("asyncTaskExecutor") void chargeTariffSepaAsync(ChargeRequest chargeRequest)
-
executeConfirmSepaPaymentMethod
private void executeConfirmSepaPaymentMethod(java.lang.String paymentMethodId, java.lang.String customerId) throws com.stripe.exception.StripeException
- Throws:
com.stripe.exception.StripeException
-
updateSubscription
private java.lang.String updateSubscription(java.lang.String subscriptionId, java.lang.String tariff, long amount) throws com.stripe.exception.StripeException
- Throws:
com.stripe.exception.StripeException
-
cancelSubscription
private void cancelSubscription(java.lang.String sellerId)
-
getTaxRatesIds
private java.util.List<java.lang.String> getTaxRatesIds()
-
executeCreatePaymentMethod
private com.stripe.model.PaymentMethod executeCreatePaymentMethod(java.util.LinkedHashMap<java.lang.String,java.lang.Object> paymentMethodMap) throws com.stripe.exception.StripeException
- Throws:
com.stripe.exception.StripeException
-
executeAttachPaymentMethod
private com.stripe.model.PaymentMethod executeAttachPaymentMethod(com.stripe.model.PaymentMethod paymentMethod, java.lang.String customerId) throws com.stripe.exception.StripeException
- Throws:
com.stripe.exception.StripeException
-
sendConfirmationEmail
private void sendConfirmationEmail(User user)
-
-