Ejemplo n.º 1
0
        public CheckoutOrder Build(CheckoutOrder checkoutOrderData, ICart cart, CheckoutConfiguration checkoutConfiguration)
        {
            if (checkoutConfiguration == null)
            {
                return(checkoutOrderData);
            }

            checkoutOrderData.ExternalPaymentMethods = new[]
            {
                new PaymentProvider {
                    Fee = 10, ImageUrl = "https://klarna.geta.no/Styles/Images/paypalpng", Name = "PayPal", RedirectUrl = "https://klarna.geta.no"
                }
            };

            if (checkoutConfiguration.PrefillAddress)
            {
                // Try to parse address into dutch address lines
                if (checkoutOrderData.ShippingCheckoutAddress != null && !string.IsNullOrEmpty(checkoutOrderData.ShippingCheckoutAddress.Country) && checkoutOrderData.ShippingCheckoutAddress.Country.Equals("NL"))
                {
                    var dutchAddress = ConvertToDutchAddress(checkoutOrderData.ShippingCheckoutAddress);
                    checkoutOrderData.ShippingCheckoutAddress = dutchAddress;
                }
            }
            UpdateOrderLines(checkoutOrderData.OrderLines, checkoutConfiguration);

            return(checkoutOrderData);
        }
Ejemplo n.º 2
0
 public AccountsClient(
     IApiClient apiClient,
     IApiClient filesApiClient,
     CheckoutConfiguration configuration)
     : base(apiClient, filesApiClient, configuration)
 {
 }
Ejemplo n.º 3
0
        public async Task <string> ApiDemo()
        {
            ApiClientAsync CheckoutClient;

            try
            {
                CheckoutConfiguration configuration = new CheckoutConfiguration()
                {
                    SecretKey = Environment.GetEnvironmentVariable("CKO_SECRET_KEY"),
                    DebugMode = true
                };

                CheckoutClient = new ApiClientAsync(configuration);

                CardTokenCharge cardTokenCharge = new CardTokenCharge()
                {
                    CardToken = Order.CardToken,
                    Currency  = Order.Currency,
                    Value     = (Order.Total * 100).ToString(),
                    Email     = Order.Cust.Email
                };
                HttpResponse <Charge> response = await CheckoutClient.ChargeServiceAsync.ChargeWithCardTokenAsync(cardTokenCharge);

                Charge charge = response.Model;
                return(charge.ResponseCode);
            }
            catch (Exception e)
            {
                Debug.WriteLine($"There was an exception: {e}");
                return("exception");
            }
        }
        public void SetConfiguration(CheckoutConfiguration configuration, PaymentMethodDto paymentMethod, string currentMarket)
        {
            var serialized = JsonConvert.SerializeObject(configuration);
            var languageId = paymentMethod.PaymentMethod.First().LanguageId;

            paymentMethod.SetParameter($"{currentMarket}_{languageId}_{Constants.SwedbankPaySerializedMarketOptions}", serialized);
        }
Ejemplo n.º 5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            _klarnaCheckoutService = ServiceLocator.Current.GetInstance <IKlarnaCheckoutService>();
            if (!base.IsPostBack && this._paymentMethodDto != null && this._paymentMethodDto.PaymentMethodParameter != null)
            {
                var markets = _paymentMethodDto.PaymentMethod.FirstOrDefault().GetMarketPaymentMethodsRows();

                if (markets != null)
                {
                    CheckoutConfiguration checkoutConfiguration = null;
                    try
                    {
                        checkoutConfiguration = _klarnaCheckoutService.GetConfiguration(markets.FirstOrDefault().MarketId);
                    }
                    catch
                    {
                        checkoutConfiguration = new CheckoutConfiguration();
                    }
                    BindData(checkoutConfiguration);

                    marketDropDownList.DataSource = markets.Select(m => m.MarketId);
                    marketDropDownList.DataBind();
                }
            }
        }
Ejemplo n.º 6
0
        public void Setup()
        {
            CheckoutConfiguration checkoutConfiguration = new CheckoutConfiguration("https://api.2checkout.com/rest/6.0/",
                                                                                    new CheckoutCredentials("XXXXX", "XXXXXX"));

            CheckoutApiClient = new CheckoutApiClient(checkoutConfiguration);
        }
Ejemplo n.º 7
0
 public StateMachineContext(Customer customer, int storeId, ShoppingCart shoppingCart, CheckoutConfiguration configuration, CheckoutSelectionContext selections)
 {
     Customer      = customer;
     StoreId       = storeId;
     ShoppingCart  = shoppingCart;
     Configuration = configuration;
     Selections    = selections;
 }
 public CheckoutApiClient(CheckoutConfiguration checkoutConfiguration)
 {
     ApiEndpoint        = checkoutConfiguration.ApiEndpoint;
     MerchantCode       = checkoutConfiguration.CheckoutCredentials.MerchantCode;
     MerchantSecret     = checkoutConfiguration.CheckoutCredentials.MerchantSecret;
     this.Authenticator = new AuthenticatorHelper(MerchantCode, MerchantSecret);
     InitialInitizeClientCheckout();
 }
Ejemplo n.º 9
0
 public FilesClient(
     IApiClient apiClient,
     IApiClient filesApiClient,
     CheckoutConfiguration configuration) : base(apiClient, configuration,
                                                 SdkAuthorizationType.SecretKeyOrOAuth)
 {
     _filesApiClient = filesApiClient;
 }
        public void SaveChanges(object dto)
        {
            if (!Visible)
            {
                return;
            }

            var paymentMethod = dto as PaymentMethodDto;

            if (paymentMethod == null)
            {
                return;
            }
            var currentMarket = marketDropDownList.SelectedValue;

            List <string> selectedRestrictedCountries = new List <string>();

            foreach (ListItem countryListRightItem in CountryList.RightItems)
            {
                selectedRestrictedCountries.Add(countryListRightItem.Value);
            }

            var configuration = new CheckoutConfiguration
            {
                MarketId = currentMarket,

                Token                = txtToken.Text,
                ApiUrl               = !string.IsNullOrWhiteSpace(txtApiUrl.Text) ? new Uri(txtApiUrl.Text) : null,
                MerchantId           = txtMerchantId.Text,
                UseAnonymousCheckout = chkAnonymous.Checked,
                ShippingAddressRestrictedToCountries = selectedRestrictedCountries
            };

            try
            {
                configuration.HostUrls    = txtHostUrls.Text?.Split(';').Select(c => new Uri(c.Trim())).ToList();
                configuration.CompleteUrl = !string.IsNullOrWhiteSpace(txtCompletetUrl.Text)
                    ? new Uri(txtCompletetUrl.Text)
                    : null;
                configuration.CancelUrl =
                    !string.IsNullOrWhiteSpace(txtCancelUrl.Text) ? new Uri(txtCancelUrl.Text) : null;
                configuration.CallbackUrl = !string.IsNullOrWhiteSpace(txtCallbackUrl.Text)
                    ? new Uri(txtCallbackUrl.Text)
                    : null;
                configuration.TermsOfServiceUrl = !string.IsNullOrWhiteSpace(txtTermsOfServiceUrl.Text)
                    ? new Uri(txtTermsOfServiceUrl.Text)
                    : null;
                configuration.PaymentUrl =
                    !string.IsNullOrWhiteSpace(txtPaymentUrl.Text) ? new Uri(txtPaymentUrl.Text) : null;
            }
            catch (Exception)
            {
            }
            finally
            {
                _checkoutConfigurationLoader.SetConfiguration(configuration, paymentMethod, currentMarket);
            }
        }
Ejemplo n.º 11
0
        public void SaveChanges(object dto)
        {
            if (!Visible)
            {
                return;
            }

            var paymentMethod = dto as PaymentMethodDto;

            if (paymentMethod == null)
            {
                return;
            }
            var currentMarket = marketDropDownList.SelectedValue;

            var configuration = new CheckoutConfiguration();

            configuration.Username = txtUsername.Text;
            configuration.Password = txtPassword.Text;
            configuration.ApiUrl   = txtApiUrl.Text;

            configuration.WidgetButtonColor            = txtColorButton.Text;
            configuration.WidgetButtonTextColor        = txtColorButtonText.Text;
            configuration.WidgetCheckboxColor          = txtColorCheckbox.Text;
            configuration.WidgetHeaderColor            = txtColorHeader.Text;
            configuration.WidgetLinkColor              = txtColorLink.Text;
            configuration.WidgetBorderRadius           = txtRadiusBorder.Text;
            configuration.WidgetCheckboxCheckmarkColor = txtColorCheckboxCheckmark.Text;
            configuration.ShippingOptionsInIFrame      = shippingOptionsInIFrameCheckBox.Checked;
            configuration.AllowSeparateShippingAddress = allowSeparateShippingAddressCheckBox.Checked;
            configuration.DateOfBirthMandatory         = dateOfBirthMandatoryCheckBox.Checked;
            configuration.ShippingDetailsText          = txtShippingDetails.Text;
            configuration.TitleMandatory     = titleMandatoryCheckBox.Checked;
            configuration.ShowSubtotalDetail = showSubtotalDetailCheckBox.Checked;

            configuration.SendShippingCountries             = sendShippingCountriesCheckBox.Checked;
            configuration.PrefillAddress                    = prefillAddressCheckBox.Checked;
            configuration.SendShippingOptionsPriorAddresses = SendShippingOptionsPriorAddressesCheckBox.Checked;
            configuration.SendProductAndImageUrl            = SendProductAndImageUrlCheckBox.Checked;

            configuration.AdditionalCheckboxText           = additionalCheckboxTextTextBox.Text;
            configuration.AdditionalCheckboxDefaultChecked = additionalCheckboxDefaultCheckedCheckBox.Checked;
            configuration.AdditionalCheckboxRequired       = additionalCheckboxRequiredCheckBox.Checked;

            configuration.ConfirmationUrl      = txtConfirmationUrl.Text;
            configuration.TermsUrl             = txtTermsUrl.Text;
            configuration.CancellationTermsUrl = txtCancellationTermsUrl.Text;
            configuration.CheckoutUrl          = txtCheckoutUrl.Text;
            configuration.PushUrl                        = txtPushUrl.Text;
            configuration.NotificationUrl                = txtNotificationUrl.Text;
            configuration.ShippingOptionUpdateUrl        = txtShippingOptionUpdateUrl.Text;
            configuration.AddressUpdateUrl               = txtAddressUpdateUrl.Text;
            configuration.OrderValidationUrl             = txtOrderValidationUrl.Text;
            configuration.RequireValidateCallbackSuccess = requireValidateCallbackSuccessCheckBox.Checked;
            configuration.MarketId                       = currentMarket;

            paymentMethod.SetParameter($"{currentMarket}_{Common.Constants.KlarnaSerializedMarketOptions}", Newtonsoft.Json.JsonConvert.SerializeObject(configuration));
        }
        protected AbstractCheckoutApmApi(CheckoutConfiguration configuration)
        {
            var apiClient = new ApiClient(configuration.HttpClientFactory,
                                          configuration.Environment.GetAttribute <EnvironmentAttribute>().ApiUri);

            _idealClient  = new IdealClient(apiClient, configuration);
            _klarnaClient = new KlarnaClient(apiClient, configuration);
            _sepaClient   = new SepaClient(apiClient, configuration);
        }
Ejemplo n.º 13
0
 protected AbstractClient(
     IApiClient apiClient,
     CheckoutConfiguration configuration,
     SdkAuthorizationType sdkAuthorizationType)
 {
     ApiClient             = apiClient;
     _configuration        = configuration;
     _sdkAuthorizationType = sdkAuthorizationType;
 }
Ejemplo n.º 14
0
        public PaymentsClient(IApiClient apiClient, CheckoutConfiguration configuration)
        {
            _apiClient = apiClient ?? throw new ArgumentNullException(nameof(apiClient));
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            _credentials = new SecretKeyCredentials(configuration);
        }
Ejemplo n.º 15
0
        public static IServiceProvider Configure()
        {
            var serviceCollection = new ServiceCollection();

            // can be added any standard dependencies
            serviceCollection.AddLogging();
            serviceCollection.AddAutoMapper(c => c.AddProfile(typeof(EntityMapper)));
            DataAccessConfiguration.Configure(serviceCollection);
            CheckoutConfiguration.Configure(serviceCollection);

            return(serviceCollection.BuildServiceProvider());
        }
Ejemplo n.º 16
0
        public void Init()
        {
            // Configure this to switch between Sandbox and Live
            CheckoutConfiguration configuration = new CheckoutConfiguration()
            {
                SecretKey = Environment.GetEnvironmentVariable("CKO_SECRET_KEY"),
                PublicKey = Environment.GetEnvironmentVariable("CKO_PUBLIC_KEY"),
                DebugMode = true
            };

            CheckoutClient = new ApiClient(configuration);
        }
 public ConfigurationSet(System.Configuration.Configuration config)
 {
     _locale = config.AppSettings.Settings["Locale"].Value;
     _paymentsConfiguration         = PaymentsConfiguration.GetConfiguration(config);
     _addressingConfiguration       = AddressingConfiguration.GetConfiguration(config);
     _APFConfiguration              = APFConfiguration.GetConfiguration(config);
     _checkoutConfiguration         = CheckoutConfiguration.GetConfiguration(config);
     _DOConfiguration               = DOConfiguration.GetConfiguration(config);
     _paymentsConfiguration         = PaymentsConfiguration.GetConfiguration(config);
     _shoppingCartConfiguration     = ShoppingCartConfiguration.GetConfiguration(config);
     _rulesConfiguration            = RulesConfiguration.GetConfiguration(config);
     _pickupOrDeliveryConfiguration = PickupOrDeliveryConfiguration.GetConfiguration(config);
     ValidateState();
 }
 public void BindConfigurationData(CheckoutConfiguration checkoutConfiguration)
 {
     txtToken.Text             = checkoutConfiguration.Token;
     txtApiUrl.Text            = checkoutConfiguration.ApiUrl?.ToString();
     txtMerchantId.Text        = checkoutConfiguration.MerchantId;
     txtHostUrls.Text          = checkoutConfiguration.HostUrls != null && checkoutConfiguration.HostUrls.Any() ? string.Join("; ", checkoutConfiguration.HostUrls) : null;
     txtCompletetUrl.Text      = checkoutConfiguration.CompleteUrl?.ToString();
     txtCancelUrl.Text         = checkoutConfiguration.CancelUrl?.ToString();
     txtCallbackUrl.Text       = checkoutConfiguration.CallbackUrl?.ToString();
     txtTermsOfServiceUrl.Text = checkoutConfiguration.TermsOfServiceUrl?.ToString();
     chkAnonymous.Checked      = checkoutConfiguration.UseAnonymousCheckout;
     txtPaymentUrl.Text        = checkoutConfiguration.PaymentUrl?.ToString();
     BindCountries(checkoutConfiguration.ShippingAddressRestrictedToCountries);
 }
Ejemplo n.º 19
0
        protected void marketDropDownList_OnSelectedIndexChanged(object sender, EventArgs e)
        {
            CheckoutConfiguration checkoutConfiguration = null;

            try
            {
                checkoutConfiguration = _klarnaCheckoutService.GetConfiguration(new MarketId(marketDropDownList.SelectedValue));
            }
            catch
            {
                checkoutConfiguration = new CheckoutConfiguration();
            }
            BindData(checkoutConfiguration);

            ConfigureUpdatePanelContentPanel.Update();
        }
Ejemplo n.º 20
0
        public void CanResolveCheckoutApi()
        {
            var services      = new ServiceCollection();
            var configuration = new CheckoutConfiguration("sk_xxx", true);

            services.AddCheckoutSdk(configuration);

            var serviceProvider = services.BuildServiceProvider();

            var checkoutApi = serviceProvider.GetService <ICheckoutApi>();

            checkoutApi.ShouldNotBeNull();

            var ckoConfig = serviceProvider.GetService <CheckoutConfiguration>();

            ckoConfig.ShouldBeSameAs(configuration);
        }
Ejemplo n.º 21
0
        public CheckoutApi(CheckoutConfiguration configuration) : base(configuration)
        {
            var apiClient = new ApiClient(configuration.HttpClientFactory,
                                          configuration.Environment.GetAttribute <EnvironmentAttribute>().ApiUri);

            _tokensClient         = new TokensClient(apiClient, configuration);
            _customersClient      = new CustomersClient(apiClient, configuration);
            _sourcesClient        = new SourcesClient(apiClient, configuration);
            _paymentsClient       = new PaymentsClient(apiClient, configuration);
            _instrumentsClient    = new InstrumentsClient(apiClient, configuration);
            _disputesClient       = new DisputesClient(apiClient, configuration);
            _webhooksClient       = new WebhooksClient(apiClient, configuration);
            _eventsClient         = new EventsClient(apiClient, configuration);
            _riskClient           = new RiskClient(apiClient, configuration);
            _paymentLinksClient   = new PaymentLinksClient(apiClient, configuration);
            _reconciliationClient = new ReconciliationClient(apiClient, configuration);
            _hostedPaymentsClient = new HostedPaymentsClient(apiClient, configuration);
        }
Ejemplo n.º 22
0
        public void BindConfigurationData(CheckoutConfiguration checkoutConfiguration)
        {
            txtUsername.Text = checkoutConfiguration.Username;
            txtPassword.Text = checkoutConfiguration.Password;
            txtApiUrl.Text   = checkoutConfiguration.ApiUrl;

            txtColorButton.Text            = checkoutConfiguration.WidgetButtonColor;
            txtColorButtonText.Text        = checkoutConfiguration.WidgetButtonTextColor;
            txtColorCheckbox.Text          = checkoutConfiguration.WidgetCheckboxColor;
            txtColorHeader.Text            = checkoutConfiguration.WidgetHeaderColor;
            txtColorLink.Text              = checkoutConfiguration.WidgetLinkColor;
            txtRadiusBorder.Text           = checkoutConfiguration.WidgetBorderRadius;
            txtColorCheckboxCheckmark.Text = checkoutConfiguration.WidgetCheckboxCheckmarkColor;

            shippingOptionsInIFrameCheckBox.Checked      = checkoutConfiguration.ShippingOptionsInIFrame;
            allowSeparateShippingAddressCheckBox.Checked = checkoutConfiguration.AllowSeparateShippingAddress;
            dateOfBirthMandatoryCheckBox.Checked         = checkoutConfiguration.DateOfBirthMandatory;
            txtShippingDetails.Text            = checkoutConfiguration.ShippingDetailsText;
            titleMandatoryCheckBox.Checked     = checkoutConfiguration.TitleMandatory;
            showSubtotalDetailCheckBox.Checked = checkoutConfiguration.ShowSubtotalDetail;

            sendShippingCountriesCheckBox.Checked             = checkoutConfiguration.SendShippingCountries;
            prefillAddressCheckBox.Checked                    = checkoutConfiguration.PrefillAddress;
            SendShippingOptionsPriorAddressesCheckBox.Checked = checkoutConfiguration.SendShippingOptionsPriorAddresses;
            SendProductAndImageUrlCheckBox.Checked            = checkoutConfiguration.SendProductAndImageUrl;

            additionalCheckboxTextTextBox.Text = checkoutConfiguration.AdditionalCheckboxText;
            additionalCheckboxDefaultCheckedCheckBox.Checked = checkoutConfiguration.AdditionalCheckboxDefaultChecked;
            additionalCheckboxRequiredCheckBox.Checked       = checkoutConfiguration.AdditionalCheckboxRequired;

            txtConfirmationUrl.Text      = checkoutConfiguration.ConfirmationUrl;
            txtTermsUrl.Text             = checkoutConfiguration.TermsUrl;
            txtCancellationTermsUrl.Text = checkoutConfiguration.CancellationTermsUrl;
            txtCheckoutUrl.Text          = checkoutConfiguration.CheckoutUrl;
            txtPushUrl.Text                 = checkoutConfiguration.PushUrl;
            txtNotificationUrl.Text         = checkoutConfiguration.NotificationUrl;
            txtShippingOptionUpdateUrl.Text = checkoutConfiguration.ShippingOptionUpdateUrl;
            txtAddressUpdateUrl.Text        = checkoutConfiguration.AddressUpdateUrl;
            txtOrderValidationUrl.Text      = checkoutConfiguration.OrderValidationUrl;
            requireValidateCallbackSuccessCheckBox.Checked = checkoutConfiguration.RequireValidateCallbackSuccess;
        }
Ejemplo n.º 23
0
        private void UpdateOrderLines(IList <OrderLine> orderLines, CheckoutConfiguration checkoutConfiguration)
        {
            foreach (var lineItem in orderLines)
            {
                if (lineItem != null && lineItem.Type.Equals("physical"))
                {
                    EntryContentBase entryContent = null;
                    FashionProduct   product      = null;
                    if (!string.IsNullOrEmpty(lineItem.Reference))
                    {
                        var contentLink = _referenceConverter.Service.GetContentLink(lineItem.Reference);
                        if (!ContentReference.IsNullOrEmpty(contentLink))
                        {
                            entryContent = _contentRepository.Service.Get <EntryContentBase>(contentLink);

                            var parentLink =
                                entryContent.GetParentProducts(_relationRepository.Service).SingleOrDefault();
                            product = _contentRepository.Service.Get <FashionProduct>(parentLink);
                        }
                    }

                    var patchedOrderLine = (PatchedOrderLine)lineItem;
                    if (patchedOrderLine.ProductIdentifiers == null)
                    {
                        patchedOrderLine.ProductIdentifiers = new PatchedProductIdentifiers();
                    }


                    patchedOrderLine.ProductIdentifiers.Brand = product?.Brand;
                    patchedOrderLine.ProductIdentifiers.GlobalTradeItemNumber  = "GlobalTradeItemNumber test";
                    patchedOrderLine.ProductIdentifiers.ManuFacturerPartNumber = "ManuFacturerPartNumber test";
                    patchedOrderLine.ProductIdentifiers.CategoryPath           = "test / test";

                    if (checkoutConfiguration.SendProductAndImageUrl && entryContent != null)
                    {
                        ((PatchedOrderLine)lineItem).ProductUrl = SiteUrlHelper.GetAbsoluteUrl()
                                                                  + entryContent.GetUrl(_relationRepository.Service, _urlResolver.Service);
                    }
                }
            }
        }
Ejemplo n.º 24
0
        public CheckoutEvaluationResult EvaluateCheckout(CheckoutConfiguration configuration, PersistedCheckoutContext persistedCheckoutContext, CheckoutSelectionContext checkoutSelectionContext, Customer customer, int storeId, CartContext cartContext)
        {
            // Build the evaluation context
            var stateMachineContext = new StateMachineContext(
                customer: customer,
                storeId: storeId,
                shoppingCart: cartContext.Cart,
                configuration: configuration,
                selections: checkoutSelectionContext);

            // Run the state machine
            var stateEvaluationResult = EvaluateStateMachine(stateMachineContext);

            // Put together a result
            var checkoutEvaluationResult = new CheckoutEvaluationResult(
                state: stateEvaluationResult.State,
                checkoutStageContext: stateEvaluationResult.CheckoutStageContext,
                selections: stateEvaluationResult.Selections);

            return(checkoutEvaluationResult);
        }
Ejemplo n.º 25
0
 public EventsClient(IApiClient apiClient,
                     CheckoutConfiguration configuration) : base(apiClient, configuration, SdkAuthorizationType.SecretKey)
 {
 }
Ejemplo n.º 26
0
 public LookupsService(IApiHttpClient apiHttpclient, CheckoutConfiguration configuration)
 {
     _lookupsServiceAsync = new LookupsServiceAsync(apiHttpclient, configuration);
 }
Ejemplo n.º 27
0
 public CustomerService(IApiHttpClient apiHttpclient, CheckoutConfiguration configuration)
 {
     _customerServiceAsync = new CustomerServiceAsync(apiHttpclient, configuration);
 }
Ejemplo n.º 28
0
 public ReportingServiceAsync(IApiHttpClient apiHttpclient, CheckoutConfiguration configuration)
 {
     _apiHttpClient = apiHttpclient;
     _configuration = configuration;
 }
Ejemplo n.º 29
0
 public SessionsClient(IApiClient apiClient, CheckoutConfiguration configuration)
     : base(apiClient, configuration, SdkAuthorizationType.OAuth)
 {
 }
Ejemplo n.º 30
0
 public PayoutsService(IApiHttpClient apiHttpclient, CheckoutConfiguration configuration)
 {
     _payoutsServiceAsync = new PayoutsServiceAsync(apiHttpclient, configuration);
 }