public async Task <ActionResult> SettingsValidate(PaypalSettings model) { if (!Services.Authorizer.Authorize(OShopPermissions.ManageShopSettings, T("Not allowed to manage Shop Settings"))) { return(new HttpUnauthorizedResult()); } if (TryUpdateModel(model)) { if (await _apiService.ValidateCredentialsAsync(model)) { Services.Notifier.Information(T("Valid credentials.")); } else { Services.Notifier.Warning(T("Invalid credentials.")); } } else { Services.Notifier.Error(T("Could not validate credentials.")); } return(View(model)); }
public Card(MyContext db, UserManager <Customer> userManager, ICartItem cartItemRepository, IOptions <PaypalSettings> settings) { _db = db; _userManager = userManager; _cartItemRepository = cartItemRepository; _configSettings = settings.Value; }
public Task <HttpClient> CreateClientAsync(PaypalSettings Settings) { return(Task.Run(() => _cacheManager.Get(Settings, true, async ctx => { var createdToken = await CreateTokenAsync(Settings); if (createdToken != null) { // Acquire new token if it expires in less than 5 minutes. ctx.Monitor(_clock.WhenUtc(_clock.UtcNow.AddSeconds(createdToken.ExpiresIn - 300))); } return createdToken; })).ContinueWith <HttpClient>((getTokenTask) => { if (getTokenTask.Result != null) { var token = getTokenTask.Result; var client = new HttpClient(); client.BaseAddress = new Uri(Settings.UseSandbox ? PaypalConnectionManager.SandboxEndpoint : PaypalConnectionManager.LiveEndpoint); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(token.TokenType, token.Token); return client; } else { throw new OrchardException(T("Unable to obtain Access Token from PayPal API.")); } })); }
public void Init() { //ToDo: Please add here your own Sandbox credentials _settings = new PaypalSettings { ClientId = "Your ClientId", ClientSecret = "Your Client Secret" }; _payment = new Payment { CardDetails = new CardDetails { CardFirstname = "Firstname", CardLastname = "Lastname", CardNumber = "1234567894567896", Cvv = "123", ExpiryDateMonth = 10, ExpiryDateYear = 2025, Type = "mastercard" }, Created = DateTime.Now, Details = "Payment Test", PaymentId = Guid.NewGuid(), Price = new Price { Amount = 100, Currency = "EUR" }, ProductId = "123ABC_TEST1", ProductName = "Product Test", UserId = Guid.NewGuid() }; }
public Card(UserManager <Customer> Manager, ICartItem cart, IOptions <PaypalSettings> settings, DBcontext bcontext) { context = bcontext; userManager = Manager; cartItem = cart; configsetting = settings.Value; }
private async Task <AccessToken> GetAccessTokenAsync(HttpClient Client, PaypalSettings Settings) { Client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String( ASCIIEncoding.ASCII.GetBytes(Settings.ClientId + ":" + Settings.ClientSecret) )); var response = await Client.PostAsync("v1/oauth2/token", new FormUrlEncodedContent(new KeyValuePair <string, string>[] { new KeyValuePair <string, string>("grant_type", "client_credentials") })); if (response.IsSuccessStatusCode) { var token = await response.Content.ReadAsAsync <AccessToken>(); if (token != null) { // Set authorization header for further requests Client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(token.TokenType, token.Token); } return(token); } else { throw new OrchardException(T("Unable to obtain Access Token from PayPal API.")); } }
public void SetSettings(PaypalSettings Settings) { var settingsPart = Services.WorkContext.CurrentSite.As <OShopPaypalSettingsPart>(); settingsPart.UseSandbox = Settings.UseSandbox; settingsPart.ClientId = Settings.ClientId; settingsPart.ClientSecret = Convert.ToBase64String(_encryptionService.Encode(Encoding.UTF8.GetBytes(Settings.ClientSecret))); }
public PayPalHttpClient CreateClient(PaypalSettings paypalSettings) { PayPalEnvironment environment = paypalSettings.Mode == "sandbox" ? new SandboxEnvironment(paypalSettings.ClientId, paypalSettings.ClientSecret) : new LiveEnvironment(paypalSettings.ClientId, paypalSettings.ClientSecret); return(new PayPalHttpClient(environment)); }
public PaymentService(IOptions <PaypalSettings> paypalSettings, IPaypalClientFactory paypalClientFactory, IOrderTransactionService orderTransactionService, IDatabase database, IHttpContextReader httpContextReader) { this.paypalSettings = paypalSettings.Value; this.orderTransactionService = orderTransactionService; this.database = database; this.httpContextReader = httpContextReader; this.paypalClient = paypalClientFactory.CreateClient(this.paypalSettings); }
public async Task <bool> ValidateCredentialsAsync(PaypalSettings Settings) { using (var client = CreateClient(Settings.UseSandbox)) { try { return(await GetAccessTokenAsync(client, Settings) != null); } catch { return(false); } } }
public PaypalPaymentService(IOptions <PaypalSettings> jwtsettings) { _paypalSettings = jwtsettings.Value; var ClientId = _paypalSettings.ClientId; var Secret = _paypalSettings.ClientSecret; accessToken = new OAuthTokenCredential(ClientId, Secret, new Dictionary <string, string>() { { "mode", "sandbox" } }).GetAccessToken(); }
public E2ETestBase() { var configJson = File.ReadAllText("testsettings.json"); var settings = JsonConvert.DeserializeObject <TestSettings>(configJson); PaypalSettings = JsonConvert.DeserializeObject <PaypalSettings>(File.ReadAllText(PaypalSettingsPath)); _connectionString = settings.ConnectionString; BaseUrl = settings.BaseUrl; Helper = new EndToEndTestHelper(_connectionString); Driver = new ChromeDriver(); Driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5); Driver.Manage().Window.Maximize(); }
public PaypalSettings GetSettings() { var settingsPart = Services.WorkContext.CurrentSite.As <OShopPaypalSettingsPart>(); var settings = new PaypalSettings() { UseSandbox = settingsPart.UseSandbox, ClientId = settingsPart.ClientId, }; if (!string.IsNullOrEmpty(settingsPart.ClientSecret)) { settings.ClientSecret = Encoding.UTF8.GetString(_encryptionService.Decode(Convert.FromBase64String(settingsPart.ClientSecret))); } return(settings); }
public ActionResult SettingsSave(PaypalSettings model) { if (!Services.Authorizer.Authorize(OShopPermissions.ManageShopSettings, T("Not allowed to manage Shop Settings"))) { return(new HttpUnauthorizedResult()); } if (TryUpdateModel(model)) { _settingsService.SetSettings(model); Services.Notifier.Information(T("PayPal Settings saved successfully.")); } else { Services.Notifier.Error(T("Could not save PayPal Settings.")); } return(View(model)); }
public PaypalService(IUserService userService) { _userService = userService; _payPalApiService = new PayPalAPIInterfaceServiceService(); _settings = PaypalSettings.ParseConfiguration(); }
private Task <AccessToken> CreateTokenAsync(PaypalSettings Settings) { return(CreateTokenAsync(Settings.ClientId, Settings.ClientSecret, Settings.UseSandbox)); }
public PaypalManager(IOptions <PaypalSettings> paypalSettings) { _paypalSettings = paypalSettings.Value; }