Class StripeServiceImpl
- java.lang.Object
-
- co.mastermindcms.modules.services.stripe.StripeServiceImpl
-
- All Implemented Interfaces:
StripeService
@Service public class StripeServiceImpl extends java.lang.Object implements StripeService
-
-
Field Summary
Fields Modifier and Type Field Description private BillingServicebillingServicestatic java.lang.StringCARD_TYPEprivate CommercePropertiescommercePropertiesprivate EmailPropertiesemailPropertiesprivate EmailSenderServiceemailSenderServiceprivate static com.fasterxml.jackson.databind.ObjectMappermapperprivate OrderRepositoryorderRepositoryprivate ProfileManagementServiceprofileManagementServiceprivate SellerRegistrationServicesellerRegistrationServiceprivate SellerRepositorysellerRepositorystatic java.lang.StringSEPA_DEBIT_TYPEprivate TranslationServicetranslationServiceprivate UserRepositoryuserRepository
-
Constructor Summary
Constructors Constructor Description StripeServiceImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Order.TaxcalculateTax(Seller buyer, Seller seller, java.util.Map<java.lang.String,com.stripe.model.TaxRate> taxRates)Calculates the tax for an order based on the buyer, seller, and tax rates.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.PaymentIntentcancelIntent(java.lang.String paymentIntentId)This method cancel created payment intent in Stripeprivate voidcancelSubscription(java.lang.String sellerId)java.lang.StringcancelSubscriptionAfterActivePeriod(java.lang.String sellerId)This method cancels a stripe subscription after expired stripe contract period.java.lang.StringcancelSubscriptionImmediately(java.lang.String sellerId)This method cancels a stripe subscription immediately.booleanchangePaymentMethod(java.lang.String paymentIntentId, java.lang.String paymentMethodId)Changes the payment method for the given payment intent.java.lang.StringchargeCreditCard(java.util.LinkedHashMap<java.lang.String,java.lang.Object> chargeRequestAsMap)This method creates a charge for payment.PaymentStatuschargeIntent(java.lang.String paymentIntentId)Charges payment intent.java.lang.StringchargeSepa(java.util.LinkedHashMap<java.lang.String,java.lang.Object> chargeRequestAsMap)This method creates a stripe charge entity.voidchargeTariffCreditCard(java.util.LinkedHashMap<java.lang.String,java.lang.Object> chargeRequestAsMap)This method creates a charge tariff for payment.(package private) voidchargeTariffCreditCardAsync(ChargeRequest chargeRequest)voidchargeTariffSepa(java.util.LinkedHashMap<java.lang.String,java.lang.Object> chargeRequestAsMap)This method creates a stripe charge tariff.(package private) voidchargeTariffSepaAsync(ChargeRequest chargeRequest)java.lang.StringcreateIntent(java.lang.String orderId, java.lang.String stripeConnectId, java.lang.String paymentMethodId, java.math.BigDecimal nettoAmount, Order.Tax tax)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.PaymentMethodexecuteAttachPaymentMethod(com.stripe.model.PaymentMethod paymentMethod, java.lang.String customerId)private voidexecuteConfirmSepaPaymentMethod(java.lang.String paymentMethodId, java.lang.String customerId)private com.stripe.model.PaymentMethodexecuteCreatePaymentMethod(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.StringgetCurrency()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.util.Map<java.lang.String,java.lang.Object>getSubscription()This method returns data as object.private java.util.List<java.lang.String>getTaxRatesIds()voidinit()private booleanisAllowsToCharge(java.lang.String email)booleanisStripeKeysDefined()This method does return boolean result.booleanisTariffEquals(java.lang.String tariff)This method does return boolean result.java.lang.Stringobtain3DSecureLink(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.PayoutpayoutToVendor(Seller vendor, java.lang.String orderId, long amount)Moves funds from stripe account to bank/card.voidremovePaymentMethod(java.lang.String paymentMethodId)This method returns data as object.private voidsendConfirmationEmail(User user)private PaymentStatustranslatePaymentStatus(java.lang.String status)private java.lang.StringupdateSubscription(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
-
billingService
@Autowired private BillingService billingService
-
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:StripeServiceThis method does return boolean result.- Specified by:
isStripeKeysDefinedin interfaceStripeService- Returns:
- value as boolean
-
getCurrency
public java.lang.String getCurrency()
Description copied from interface:StripeServiceThis method returns currency name- Specified by:
getCurrencyin interfaceStripeService- Returns:
- value as string
-
createIntent
public java.lang.String createIntent(java.lang.String orderId, java.lang.String stripeConnectId, java.lang.String paymentMethodId, java.math.BigDecimal nettoAmount, Order.Tax tax)Description copied from interface:StripeServiceCreates payment intent for current seller by payment method and amount.- Specified by:
createIntentin interfaceStripeService- Parameters:
orderId- id of the order for metadatastripeConnectId- id of the stripe connect account for vendorpaymentMethodId- payment method ID.nettoAmount- net amount in the smallest currency unit, e.g. for 100$ expected value would be 10000 (that means to be cents).tax- tax object- Returns:
- created intent ID
-
cancelIntent
public com.stripe.model.PaymentIntent cancelIntent(java.lang.String paymentIntentId)
Description copied from interface:StripeServiceThis method cancel created payment intent in Stripe- Specified by:
cancelIntentin 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:StripeServiceCharges payment intent.- Specified by:
chargeIntentin interfaceStripeService- Parameters:
paymentIntentId- id- Returns:
PaymentStatusof the payment
-
translatePaymentStatus
private PaymentStatus translatePaymentStatus(java.lang.String status)
-
obtain3DSecureLink
public java.lang.String obtain3DSecureLink(java.lang.String paymentIntentId)
Description copied from interface:StripeServiceObtains link for payment intent authorization.- Specified by:
obtain3DSecureLinkin interfaceStripeService- Parameters:
paymentIntentId- intent id- Returns:
- link
-
changePaymentMethod
public boolean changePaymentMethod(java.lang.String paymentIntentId, java.lang.String paymentMethodId)Description copied from interface:StripeServiceChanges the payment method for the given payment intent.- Specified by:
changePaymentMethodin interfaceStripeService- Parameters:
paymentIntentId- id of intentpaymentMethodId- id of a new using in the intent payment method- Returns:
- true if successful
-
payoutToVendor
public com.stripe.model.Payout payoutToVendor(Seller vendor, java.lang.String orderId, long amount) throws com.stripe.exception.StripeException
Description copied from interface:StripeServiceMoves funds from stripe account to bank/card.- Specified by:
payoutToVendorin interfaceStripeService- Parameters:
vendor- sellerorderId- identification of orderamount- 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:StripeServiceThis method creates a stripe charge entity.- Specified by:
chargeSepain 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:StripeServiceThis method creates a charge for payment.- Specified by:
chargeCreditCardin 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:StripeServiceThis method creates a stripe charge tariff.- Specified by:
chargeTariffSepain 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:StripeServiceThis method creates a charge tariff for payment.- Specified by:
chargeTariffCreditCardin interfaceStripeService- Parameters:
chargeRequestAsMap- map-representation of charge request
-
cancelSubscriptionAfterActivePeriod
public java.lang.String cancelSubscriptionAfterActivePeriod(java.lang.String sellerId)
Description copied from interface:StripeServiceThis method cancels a stripe subscription after expired stripe contract period.- Specified by:
cancelSubscriptionAfterActivePeriodin 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:StripeServiceThis method cancels a stripe subscription immediately.- Specified by:
cancelSubscriptionImmediatelyin 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:StripeServiceThis method does return time.- Specified by:
getContractEndDatein 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:StripeServiceThis method does return time.- Specified by:
getContractEndDateFromTimestampin 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:StripeServiceThis method does return boolean result.- Specified by:
isTariffEqualsin 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:StripeServiceThis method returns data as map.- Specified by:
getAmountByTariffin 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:StripeServiceThis method returns data as list.- Specified by:
getInvoicesin interfaceStripeService- Returns:
- data as list
-
getProducts
public java.util.List<com.stripe.model.Product> getProducts()
Description copied from interface:StripeServiceThis method returns data as list.- Specified by:
getProductsin 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:StripeServiceCreates payment method and - if needed - customer for Stripe.- Specified by:
createPaymentMethodin 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:StripeServiceThis method returns data as object.- Specified by:
removePaymentMethodin 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:StripeServiceThis method returns data as list.- Specified by:
getPaymentMethodsin 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:StripeServiceThis method returns data as map.- Specified by:
getPaymentMethodin 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:StripeServiceThis method returns data as object.- Specified by:
getSubscriptionin 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:StripeServiceThis method returns data as object.- Specified by:
calculateTaxRatein 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:StripeServiceObtains all tax rates from Stripe api.- Specified by:
obtainAllTaxRatesin interfaceStripeService- Returns:
- map of country iso codes to tax rate
-
calculateTax
public Order.Tax calculateTax(Seller buyer, Seller seller, java.util.Map<java.lang.String,com.stripe.model.TaxRate> taxRates)
Description copied from interface:StripeServiceCalculates the tax for an order based on the buyer, seller, and tax rates.- Specified by:
calculateTaxin interfaceStripeService- Parameters:
buyer- the user who is buying the orderseller- the user who is selling the ordertaxRates- a map containing the tax rates for different products- Returns:
- the tax amount for the order
-
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)
-
-