Class StripeServiceImpl

  • All Implemented Interfaces:
    StripeService

    @Service
    public class StripeServiceImpl
    extends java.lang.Object
    implements StripeService
    • Constructor Detail

      • StripeServiceImpl

        public StripeServiceImpl()
    • 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 interface StripeService
        Returns:
        value as boolean
      • getCurrency

        public java.lang.String getCurrency()
        Description copied from interface: StripeService
        This method returns currency name
        Specified by:
        getCurrency in interface StripeService
        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: StripeService
        Creates payment intent for current seller by payment method and amount.
        Specified by:
        createIntent in interface StripeService
        Parameters:
        orderId - id of the order for metadata
        stripeConnectId - id of the stripe connect account for vendor
        paymentMethodId - 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: StripeService
        This method cancel created payment intent in Stripe
        Specified by:
        cancelIntent in interface StripeService
        Parameters:
        paymentIntentId - identification from payment intent in Stripe
        Returns:
        stripe payment intent entity
      • 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 interface StripeService
        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 interface StripeService
        Parameters:
        paymentIntentId - id of intent
        paymentMethodId - 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: StripeService
        Moves funds from stripe account to bank/card.
        Specified by:
        payoutToVendor in interface StripeService
        Parameters:
        vendor - seller
        orderId - identification of order
        amount - 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 interface StripeService
        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 interface StripeService
        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 interface StripeService
        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 interface StripeService
        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 interface StripeService
        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 interface StripeService
        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 interface StripeService
        Parameters:
        createdDate - from which can extracted time
        pattern - 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 interface StripeService
        Parameters:
        created - from which can extracted time
        pattern - 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 interface StripeService
        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 interface StripeService
        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 interface StripeService
        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 interface StripeService
        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 interface StripeService
        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 interface StripeService
        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 interface StripeService
        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 interface StripeService
        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 interface StripeService
        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 interface StripeService
        Parameters:
        amount - from this amount will be calculated a tax value
        countryIsoCode - 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 interface StripeService
        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)