コード例 #1
0
 public PaymentStripeController(ISettingService settingService,
                                ILocalizationService localizationService, StripePaymentSettings stripePaymentSettings)
 {
     this._settingService        = settingService;
     this._localizationService   = localizationService;
     this._stripePaymentSettings = stripePaymentSettings;
 }
コード例 #2
0
 public PaymentStripeController(ISettingService settingService, 
     ILocalizationService localizationService, StripePaymentSettings stripePaymentSettings)
 {
     this._settingService = settingService;
     this._localizationService = localizationService;
     this._stripePaymentSettings = stripePaymentSettings;
 }
コード例 #3
0
 public PaymentStripeController(ISettingService settingService, IWorkContext workContext, ILocalizationService localizationService, StripePaymentSettings iDealPaymentSettings)
 {
     _workContext           = workContext;
     _settingService        = settingService;
     _localizationService   = localizationService;
     _stripePaymentSettings = iDealPaymentSettings;
 }
コード例 #4
0
 public PaymentStripeController(ILocalizationService localizationService,
                                IPermissionService permissionService,
                                ISettingService settingService,
                                INotificationService notificationService,
                                StripePaymentSettings stripePaymentSettings)
 {
     this._localizationService   = localizationService;
     this._permissionService     = permissionService;
     this._settingService        = settingService;
     this._notificationService   = notificationService;
     this._stripePaymentSettings = stripePaymentSettings;
 }
コード例 #5
0
 public static bool TryConnect(this StripePaymentSettings stripePaymentSettings)
 {
     try
     {
         var stripeService = new stripe.CustomerService(stripePaymentSettings.GetStripeClient());
         return(stripeService.List() != null);
     }
     catch (Exception ex)
     {
         return(false);
     }
 }
コード例 #6
0
 public PaymentStripeController(IWorkContext workContext,
                                Services.IPaymentStripeService stripeService,
                                IShoppingCartService shoppingCartService,
                                IStoreService storeService,
                                ISettingService settingService,
                                IOrderService orderService,
                                ICountryService countryService,
                                IStateProvinceService stateProvinceService,
                                IOrderProcessingService orderProcessingService,
                                IGenericAttributeService genericAttributeService,
                                ILocalizationService localizationService,
                                IStoreContext storeContext,
                                ILogger logger,
                                IWebHelper webHelper,
                                PaymentSettings paymentSettings,
                                StripePaymentSettings stripePaymentSettings,
                                ShoppingCartSettings shoppingCartSettings,
                                IPaymentStripeFactory paymentStripeFactory,
                                IOrderTotalCalculationService orderTotalCalculationService,
                                IPaymentStripeCheckoutService paymentStripeCheckoutService,
                                IPaymentStripeCheckoutPlaceOrderService paymentStripeCheckoutPlaceOrderService,
                                IPaymentStripeRedirectionService paymentStripeRedirectionService,
                                IPaymentStripeEventService paymentStripeEventService)
 {
     this._workContext             = workContext;
     this._countryService          = countryService;
     this._stateProvinceService    = stateProvinceService;
     this._paymentStripeService    = stripeService;
     this._storeService            = storeService;
     this._settingService          = settingService;
     this._orderService            = orderService;
     this._paymentStripeFactory    = paymentStripeFactory;
     this._orderProcessingService  = orderProcessingService;
     this._genericAttributeService = genericAttributeService;
     this._localizationService     = localizationService;
     this._storeContext            = storeContext;
     this._logger                                 = logger;
     this._webHelper                              = webHelper;
     this._paymentSettings                        = paymentSettings;
     this._stripePaymentSettings                  = stripePaymentSettings;
     this._shoppingCartSettings                   = shoppingCartSettings;
     this._orderTotalCalculationService           = orderTotalCalculationService;
     this._paymentStripeCheckoutService           = paymentStripeCheckoutService;
     this._paymentStripeCheckoutPlaceOrderService = paymentStripeCheckoutPlaceOrderService;
     this._paymentStripeRedirectionService        = paymentStripeRedirectionService;
     _paymentStripeEventService                   = paymentStripeEventService;
 }
 public PaymentStripeRedirectionService(ILogger logger,
                                        IWebHelper webHelper,
                                        IWorkContext workContext,
                                        ICustomerService customerService,
                                        HttpSessionStateBase session,
                                        IPaymentStripeService stripeService,
                                        IPaymentStripeCheckoutDetailsService stripeCheckoutDetailsService,
                                        StripePaymentSettings stripePaymentSettings)
 {
     _logger                       = logger;
     _webHelper                    = webHelper;
     _workContext                  = workContext;
     _customerService              = customerService;
     _session                      = session;
     _stripeService                = stripeService;
     _stripePaymentSettings        = stripePaymentSettings;
     _stripeCheckoutDetailsService = stripeCheckoutDetailsService;
 }
コード例 #8
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);
        }
コード例 #9
0
        private int _cacheExpirationInMinutes = 43200; //30 days

        public StripeController(IWorkContext workContext,
                                IStoreService storeService,
                                ISettingService settingService,
                                PaymentSettings paymentSettings,
                                ILocalizationService localizationService,
                                IPluginFinder pluginFinder,
                                StripePaymentSettings stripePaymentSettings,
                                ICountryService countryService,
                                IStateProvinceService stateProvinceService,
                                ICacheManager cacheManager)
        {
            this._workContext           = workContext;
            this._storeService          = storeService;
            this._settingService        = settingService;
            this._paymentSettings       = paymentSettings;
            this._localizationService   = localizationService;
            this._stripePaymentSettings = stripePaymentSettings;
            this._pluginFinder          = pluginFinder;
            this._countryService        = countryService;
            this._stateProvinceService  = stateProvinceService;
            this._cacheManager          = cacheManager;
        }
コード例 #10
0
        public static stripe.Charge CreateCapture(this CapturePaymentRequest capturePaymentRequest, StripePaymentSettings stripePaymentSettings, Store store)
        {
            var chargesService = new stripe.ChargeService(stripePaymentSettings.GetStripeClient());

            var chargeId = capturePaymentRequest.Order.AuthorizationTransactionId;

            stripe.Charge charge = chargesService.Capture(chargeId, new stripe.ChargeCaptureOptions()
            {
                StatementDescriptor = $"{store.Name.ToStripeDescriptor()}"
            });

            return(charge);
        }
コード例 #11
0
        public static stripe.Refund CreateRefund(this RefundPaymentRequest refundPaymentRequest, StripePaymentSettings stripePaymentSettings, CurrencySettings currencySettings, ICurrencyService currencyService)
        {
            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 refundService = new stripe.RefundService(stripePaymentSettings.GetStripeClient());

            stripe.Refund refund = refundService.Create(new stripe.RefundCreateOptions()
            {
                Amount = (int)(refundPaymentRequest.AmountToRefund * 100),
                Charge = refundPaymentRequest.Order.CaptureTransactionId
            });

            return(refund);
        }
コード例 #12
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);
            }
        }
コード例 #13
0
 public static stripe.Customer GetOrCreateCustomer(this stripe.CustomerService customerService, Core.Domain.Customers.Customer customer, string stripeCustomerId, StripePaymentSettings paymentSettings)
 {
     if (!string.IsNullOrEmpty(stripeCustomerId))
     {
         return(customerService.Get(stripeCustomerId));
     }
     else
     {
         return(customerService.Create(customer.CreateCustomerOptions(paymentSettings)));
     }
 }
コード例 #14
0
        public static stripe.Customer GetOrCreateCustomer(this stripe.CustomerService customerService, Core.Domain.Customers.Customer customer, IGenericAttributeService genericAttributeService, StripePaymentSettings paymentSettings)
        {
            string stripeCustomerId = genericAttributeService.GetAttribute <string>(customer, paymentSettings.GetCustomerIdKey());

            stripe.Customer result = customerService.GetOrCreateCustomer(customer, stripeCustomerId, paymentSettings);

            if (string.IsNullOrEmpty(stripeCustomerId))
            {
                genericAttributeService.SaveAttribute(customer, paymentSettings.GetCustomerIdKey(), result.Id);
            }

            return(result);
        }
コード例 #15
0
        public static stripe.CustomerCreateOptions CreateCustomerOptions(this Core.Domain.Customers.Customer customer, StripePaymentSettings paymentSettings)
        {
            var customerCreateOptions = new stripe.CustomerCreateOptions()
            {
                Email = customer.Email,
            };

            customerCreateOptions.Metadata = new Dictionary <string, string>()
            {
                { paymentSettings.GetCustomerIdKey(), customer.Id.ToString() }
            };

            return(customerCreateOptions);
        }
コード例 #16
0
 public PaymentStripeViewComponent(StripePaymentSettings iDealPaymentSettings)
 {
     this._stripePaymentSettings = iDealPaymentSettings;
 }