public static IServiceCollection AddPayPalExpressCheckout( this IServiceCollection services, string sectionName = nameof(PayPalExpressCheckoutOptions), Action <PayPalExpressCheckoutOptions>?configureOptions = default) { services.AddChangeTokenOptions <PayPalExpressCheckoutOptions>(sectionName, configureAction: o => configureOptions?.Invoke(o)); services.AddTransient <PayPalHttp.HttpClient>(sp => { PayPalEnvironment environment; var options = sp.GetRequiredService <IOptionsMonitor <PayPalExpressCheckoutOptions> >().CurrentValue; if (options.IsSandBox) { environment = new SandboxEnvironment(options.ClientId, options.ClientSecret); } else { environment = new LiveEnvironment(options.ClientId, options.ClientSecret); } return(new PayPalHttpClient(environment)); }); return(services); }
public async Task <Payment> CreatePaymentAsync(PaypalTransaction transaction) { PayPalEnvironment environment; if (isSandboxMode) { environment = new SandboxEnvironment(clientId, clientSecret); } else { environment = new LiveEnvironment(clientId, clientSecret); } var client = new PayPalHttpClient(environment); try { var payment = CreatePayment(transaction); var request = new PaymentCreateRequest().RequestBody(payment); var response = await client.Execute(request); var statusCode = response.StatusCode; var result = response.Result <Payment>(); return(result); } catch (HttpException httpException) { var statusCode = httpException.StatusCode; var debugId = httpException.Headers.GetValues("PayPal-Debug-Id").FirstOrDefault(); return(null); } }
public PaymentPaypalService() { string SiteUrl = "http://www.appzero.com/api/payments/"; var environment = new LiveEnvironment(ClientId, ClientSecret); m_PayPalHttpClient = new PayPalHttpClient(environment); m_ApplicationContext = new ApplicationContext { BrandName = "Naobiz", ReturnUrl = SiteUrl + "comporder", CancelUrl = SiteUrl + "canorder" }; m_TaxRate = 5.5M; }
public PayPalClient(IConfigurationKeys configurationKeys) { if (configurationKeys.PayPal.IsDevelop) { var environment = new SandboxEnvironment( configurationKeys.PayPal.ClientId, configurationKeys.PayPal.ClientSecret); _client = new PayPalHttpClient(environment); } else { var environment = new LiveEnvironment( configurationKeys.PayPal.ClientId, configurationKeys.PayPal.ClientSecret); _client = new PayPalHttpClient(environment); } }
public static HttpClient client() { // Creating a sandbox environment if (ObjectFactory.instanceName == "Live") { LiveEnvironment environment = new LiveEnvironment("AbsLlwBzsLwTvG-6awsiklgFPeDNWlGctQ9MukFQl-VimUpPwBtTLpR5SX8Wyu0U_R8pg6mGxgrpzYiA", "EIFw-teU8tWyH7UBXgI7UftSXuJoB1aG51jkZMiRb23x39OaTd9kLOcKSVtb6FWK5vj1sSypW1kC9xUB"); // Creating a client for the environment PayPalHttpClient client = new PayPalHttpClient(environment); return(client); } else { SandboxEnvironment environment = new SandboxEnvironment("ARXuDzN7ArL3ZiTG0_ebn-4u53kqetWWQSkM5UoVk5KZ_ClhTjSueiVJTnDuFvYtf4TnPxxJDRSJryWJ", "EL6FuAA6ocMA6rFtSWg7Ck-mZYMCq4W-G-huZPVsiOIT9zyI9z2Wh_-_Elv9GiiWP00S8fn28I5G-NFm"); // Creating a client for the environment PayPalHttpClient client = new PayPalHttpClient(environment); return(client); } }
public static PayPalClient Create(Mode mode, string clientId, string clientSecret) { PayPalEnvironment env = null; switch (mode) { case Mode.live: env = new LiveEnvironment(clientId, clientSecret); break; case Mode.sandbox: env = new SandboxEnvironment(clientId, clientSecret); break; } PayPalHttpClient client = new PayPalHttpClient(env); return(new PayPalClient(client)); }
private async Task <PayPal.v1.Payments.Payment> ProcessPayment(PaymentModel model) { var mode = _configuration["Service:Paypal:Mode"]; PayPalHttpClient client = null; switch (mode) { case "production": { var environment = new LiveEnvironment(_configuration["Service:Paypal:ClientId"], _configuration["Service:Paypal:ClientSecret"]); client = new PayPalHttpClient(environment); break; } case "sandbox": { var environment = new SandboxEnvironment(_configuration["Service:Paypal:ClientId"], _configuration["Service:Paypal:ClientSecret"]); client = new PayPalHttpClient(environment); break; } } var payment = new PayPal.v1.Payments.Payment() { Intent = "sale", Transactions = new List <Transaction>() { new Transaction() { Amount = new Amount() { Total = string.Format(CultureInfo.InvariantCulture, "{0:0.00}", model.TotalTTc) .Replace(CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator, "."), Details = new AmountDetails { Subtotal = string.Format(CultureInfo.InvariantCulture, "{0:0.00}", model.SubTotal), Tax = string.Format(CultureInfo.InvariantCulture, "{0:0.00}", model.TotalTax) }, Currency = "EUR" } } }, RedirectUrls = new RedirectUrls() { CancelUrl = $"{_configuration["Service:FrontOffice:Url"].TrimEnd('/')}/api/paypal/cancel", ReturnUrl = $"{_configuration["Service:FrontOffice:Url"].TrimEnd('/')}/api/paypal/success" }, Payer = new Payer() { PaymentMethod = "paypal" } }; PaymentCreateRequest request = new PaymentCreateRequest(); request.RequestBody(payment); try { HttpResponse response = await client.Execute(request); var statusCode = response.StatusCode; PayPal.v1.Payments.Payment result = response.Result <PayPal.v1.Payments.Payment>(); model.PaymentReference = result.Id; await _functionalUnitOfWork.PaymentRepository.Update(model); return(result); } catch (HttpException httpException) { var statusCode = httpException.StatusCode; var debugId = httpException.Headers.GetValues("PayPal-Debug-Id").FirstOrDefault(); throw; } }