Ejemplo n.º 1
0
        public static stripe.Charge CreateCharge(this ProcessPaymentRequest processPaymentRequest, StripePaymentSettings stripePaymentSettings, CurrencySettings currencySettings, Store store,
                                                 ICustomerService customerService, ICurrencyService currencyService, IGenericAttributeService genericAttributeService)
        {
            int substep = 0;

            try
            {
                var customer = customerService.GetCustomerById(processPaymentRequest.CustomerId);
                if (customer == null)
                {
                    throw new NopException("Customer cannot be loaded");
                }
                substep = 1;
                var currency = currencyService.GetCurrencyById(currencySettings.PrimaryStoreCurrencyId);
                if (currency == null)
                {
                    throw new NopException("Primary store currency cannot be loaded");
                }
                substep = 2;
                if (!Enum.TryParse(currency.CurrencyCode, out StripeCurrency stripeCurrency))
                {
                    throw new NopException($"The {currency.CurrencyCode} currency is not supported by Stripe");
                }
                substep = 3;

                var stripeCustomerService = new stripe.CustomerService(stripePaymentSettings.GetStripeClient());
                var chargeService         = new stripe.ChargeService(stripePaymentSettings.GetStripeClient());
                var tokenService          = new stripe.TokenService(stripePaymentSettings.GetStripeClient());
                substep = 4;
                var stripeCustomer = stripeCustomerService.GetOrCreateCustomer(customer, genericAttributeService, stripePaymentSettings);
                substep = 5;
                var tokenOptions = processPaymentRequest.CreateTokenOptions(customer, stripeCurrency);
                substep = 6;
                var token = tokenService.Create(tokenOptions);
                substep = 7;
                var chargeOptions = processPaymentRequest.CreateChargeOptions(store, token, stripePaymentSettings.TransactionMode, stripeCurrency);
                substep = 8;

                var charge = chargeService.Create(chargeOptions);
                substep = 9;
                return(charge);
            }
            catch (Exception ex)
            {
                throw new Exception($"Failed at substep {substep}", ex);
            }
        }
Ejemplo n.º 2
0
        public static stripe.Charge CreateCharge(this ProcessPaymentRequest processPaymentRequest,
                                                 StripePaymentSettings stripePaymentSettings,
                                                 CurrencySettings currencySettings,
                                                 Store store,
                                                 ICustomerService customerService,
                                                 IStateProvinceService stateProvinceService,
                                                 ICountryService countryService,
                                                 ICurrencyService currencyService,
                                                 IGenericAttributeService genericAttributeService)
        {
            var customer = customerService.GetCustomerById(processPaymentRequest.CustomerId);

            if (customer == null)
            {
                throw new NopException("Customer cannot be loaded");
            }

            var currency = currencyService.GetCurrencyById(currencySettings.PrimaryStoreCurrencyId);

            if (currency == null)
            {
                throw new NopException("Primary store currency cannot be loaded");
            }

            if (!Enum.TryParse(currency.CurrencyCode, out StripeCurrency stripeCurrency))
            {
                throw new NopException($"The {currency.CurrencyCode} currency is not supported by Stripe");
            }


            var stripeCustomerService = new stripe.CustomerService(stripePaymentSettings.GetStripeClient());
            var chargeService         = new stripe.ChargeService(stripePaymentSettings.GetStripeClient());
            var tokenService          = new stripe.TokenService(stripePaymentSettings.GetStripeClient());

            var stripeCustomer = stripeCustomerService.GetOrCreateCustomer(customer, genericAttributeService, stripePaymentSettings);

            var tokenOptions  = processPaymentRequest.CreateTokenOptions(customerService, stateProvinceService, countryService, stripeCurrency);
            var token         = tokenService.Create(tokenOptions);
            var chargeOptions = processPaymentRequest.CreateChargeOptions(store, token, stripePaymentSettings.TransactionMode, stripeCurrency);

            var charge = chargeService.Create(chargeOptions);

            return(charge);
        }