Exemplo n.º 1
0
        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));
        }
Exemplo n.º 2
0
 public Card(MyContext db, UserManager <Customer> userManager, ICartItem cartItemRepository, IOptions <PaypalSettings> settings)
 {
     _db                 = db;
     _userManager        = userManager;
     _cartItemRepository = cartItemRepository;
     _configSettings     = settings.Value;
 }
Exemplo n.º 3
0
        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."));
                }
            }));
        }
Exemplo n.º 4
0
        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()
            };
        }
Exemplo n.º 5
0
 public Card(UserManager <Customer> Manager, ICartItem cart, IOptions <PaypalSettings> settings, DBcontext bcontext)
 {
     context       = bcontext;
     userManager   = Manager;
     cartItem      = cart;
     configsetting = settings.Value;
 }
Exemplo n.º 6
0
        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."));
            }
        }
Exemplo n.º 7
0
        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)));
        }
Exemplo n.º 8
0
        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));
        }
Exemplo n.º 9
0
        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);
        }
Exemplo n.º 10
0
 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();
        }
Exemplo n.º 12
0
        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();
        }
Exemplo n.º 13
0
        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);
        }
Exemplo n.º 14
0
        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));
        }
Exemplo n.º 15
0
 public PaypalService(IUserService userService)
 {
     _userService      = userService;
     _payPalApiService = new PayPalAPIInterfaceServiceService();
     _settings         = PaypalSettings.ParseConfiguration();
 }
Exemplo n.º 16
0
 private Task <AccessToken> CreateTokenAsync(PaypalSettings Settings)
 {
     return(CreateTokenAsync(Settings.ClientId, Settings.ClientSecret, Settings.UseSandbox));
 }
Exemplo n.º 17
0
 public PaypalService(IUserService userService)
 {
     _userService = userService;
     _payPalApiService = new PayPalAPIInterfaceServiceService();
     _settings = PaypalSettings.ParseConfiguration();
 }
Exemplo n.º 18
0
 public PaypalManager(IOptions <PaypalSettings> paypalSettings)
 {
     _paypalSettings = paypalSettings.Value;
 }