diff --git a/Yavsc/ApiControllers/HairCut/HairCutController.cs b/Yavsc/ApiControllers/HairCut/HairCutController.cs index 5fae9db6..e3980323 100644 --- a/Yavsc/ApiControllers/HairCut/HairCutController.cs +++ b/Yavsc/ApiControllers/HairCut/HairCutController.cs @@ -2,7 +2,6 @@ using Microsoft.AspNet.Identity; using Microsoft.AspNet.Mvc; using Microsoft.Extensions.OptionsModel; using Microsoft.Extensions.Localization; -using PayPal.Api; namespace Yavsc.ApiControllers @@ -20,8 +19,10 @@ namespace Yavsc.ApiControllers using Helpers; using Microsoft.Data.Entity; using Models.Payment; - using Models.Relationship; using Newtonsoft.Json; + using PayPal.PayPalAPIInterfaceService.Model; + using Yavsc.Models.Haircut.Views; + using Microsoft.AspNet.Http; [Route("api/haircut")] public class HairCutController : Controller @@ -67,79 +68,185 @@ namespace Yavsc.ApiControllers { var uid = User.GetUserId(); var now = DateTime.Now; - var result = _context.HairCutQueries.Where( + var result = _context.HairCutQueries + .Include(q => q.Prestation) + .Include(q => q.Client) + .Include(q => q.PerformerProfile) + .Include(q => q.Location) + .Where( q => q.ClientId == uid - && q.EventDate > now + && ( q.EventDate > now || q.EventDate == null ) && q.Status == QueryStatus.Inserted - ); + ).Select(q => new HaircutQueryClientInfo(q)); return Ok(result); } + // GET: api/HairCutQueriesApi/5 + [HttpGet("{id}", Name = "GetHairCutQuery")] + public async Task GetHairCutQuery([FromRoute] long id) + { + if (!ModelState.IsValid) + { + return HttpBadRequest(ModelState); + } + + HairCutQuery hairCutQuery = await _context.HairCutQueries.SingleAsync(m => m.Id == id); + + if (hairCutQuery == null) + { + return HttpNotFound(); + } + + return Ok(hairCutQuery); + } + + // PUT: api/HairCutQueriesApi/5 + [HttpPut("{id}")] + public async Task PutHairCutQuery([FromRoute] long id, [FromBody] HairCutQuery hairCutQuery) + { + if (!ModelState.IsValid) + { + return HttpBadRequest(ModelState); + } + + if (id != hairCutQuery.Id) + { + return HttpBadRequest(); + } + + _context.Entry(hairCutQuery).State = EntityState.Modified; + + try + { + await _context.SaveChangesAsync(); + } + catch (DbUpdateConcurrencyException) + { + if (!HairCutQueryExists(id)) + { + return HttpNotFound(); + } + else + { + throw; + } + } + + return new HttpStatusCodeResult(StatusCodes.Status204NoContent); + } + [HttpPost] - public IActionResult PostQuery(HairCutQuery query) + public async Task PostQuery(HairCutQuery hairCutQuery) { var uid = User.GetUserId(); if (!ModelState.IsValid) { return new BadRequestObjectResult(ModelState); } - _context.HairCutQueries.Add(query); - _context.Update(uid); - return Ok(); + if (!ModelState.IsValid) + { + return HttpBadRequest(ModelState); + } + + _context.HairCutQueries.Add(hairCutQuery); + try + { + await _context.SaveChangesAsync(uid); + } + catch (DbUpdateException) + { + if (HairCutQueryExists(hairCutQuery.Id)) + { + return new HttpStatusCodeResult(StatusCodes.Status409Conflict); + } + else + { + throw; + } + } + + return CreatedAtRoute("GetHairCutQuery", new { id = hairCutQuery.Id }, hairCutQuery); + } [HttpPost("createpayment/{id}")] public async Task CreatePayment(long id) { - APIContext apiContext = null; + HairCutQuery query = await _context.HairCutQueries.Include(q => q.Client). Include(q => q.Client.PostalAddress).Include(q => q.Prestation).Include(q=>q.Regularisation) .SingleAsync(q => q.Id == id); if (query.PaymentId!=null) return new BadRequestObjectResult(new { error = "An existing payment process already exists" }); query.SelectedProfile = _context.BrusherProfile.Single(p => p.UserId == query.PerformerId); - + SetExpressCheckoutResponseType payment = null; try { - apiContext = PayPalHelpers.CreateAPIContext(); + payment = Request.CreatePayment("HairCutCommand", query, "sale", _logger); } - catch (PayPal.IdentityException ex) { - _logger.LogError(ex.Response); + catch (Exception ex) { + _logger.LogError(ex.Message); + return new HttpStatusCodeResult(500); } - if (apiContext==null) { + if (payment==null) { + _logger.LogError("Error doing SetExpressCheckout, aborting."); _logger.LogError(JsonConvert.SerializeObject(Startup.PayPalSettings)); - throw new Exception("No PayPal Api context"); + return new HttpStatusCodeResult(500); } - var payment = Request.CreatePayment("HairCutCommand",apiContext, query, "sale", _logger); - switch (payment.state) + switch (payment.Ack) { - case "created": - case "approved": + case AckCodeType.SUCCESS: + case AckCodeType.SUCCESSWITHWARNING: { - var dbinfo = new PaypalPayment + var dbinfo = new PayPalPayment { ExecutorId = User.GetUserId(), - PaypalPayerId = payment.payer.payer_info?.payer_id, - PaypalPaymentId = payment.id, - State = payment.state + PaypalPayerId = payment.Token, + CreationToken = null, + State = "inserted" }; - var links = payment.links.Select - ( - l=> new Link { - HRef = l.href, - Rel = l.rel, - Method = l.method - }); - _context.PaypalPayments.Add(dbinfo); - query.PaymentId = payment.id; await _context.SaveChangesAsync(User.GetUserId()); } break; - case "failed": + + default: + _logger.LogError(JsonConvert.SerializeObject(payment)); return new BadRequestObjectResult(payment); - default: throw new NotImplementedException(); } - return Json(payment); + return Json(new { token = payment.Token }); + } + + [HttpDelete("{id}")] + public async Task DeleteHairCutQuery([FromRoute] long id) + { + if (!ModelState.IsValid) + { + return HttpBadRequest(ModelState); + } + + HairCutQuery hairCutQuery = await _context.HairCutQueries.SingleAsync(m => m.Id == id); + if (hairCutQuery == null) + { + return HttpNotFound(); + } + + _context.HairCutQueries.Remove(hairCutQuery); + await _context.SaveChangesAsync(); + + return Ok(hairCutQuery); + } + + private bool HairCutQueryExists(long id) + { + return _context.HairCutQueries.Count(e => e.Id == id) > 0; + } + protected override void Dispose(bool disposing) + { + if (disposing) + { + _context.Dispose(); + } + base.Dispose(disposing); } } } diff --git a/Yavsc/ApiControllers/HairCut/HairCutQueriesApiController.cs b/Yavsc/ApiControllers/HairCut/HairCutQueriesApiController.cs deleted file mode 100644 index dcf739f1..00000000 --- a/Yavsc/ApiControllers/HairCut/HairCutQueriesApiController.cs +++ /dev/null @@ -1,173 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Security.Claims; -using System.Threading.Tasks; -using Microsoft.AspNet.Http; -using Microsoft.AspNet.Mvc; -using Microsoft.Data.Entity; -using Yavsc.Models; -using Yavsc.Models.Haircut; -using Yavsc.Models.Haircut.Views; - -namespace Yavsc.Controllers -{ - [Produces("application/json")] - [Route("api/haircutquery")] - public class HairCutQueriesApiController : Controller - { - private ApplicationDbContext _context; - - public HairCutQueriesApiController(ApplicationDbContext context) - { - _context = context; - } - - - // GET: api/HairCutQueriesApi - // Get the active queries for current - // user, as a client - [HttpGet] - public async Task GetHairCutQueries() - { - IEnumerable info = null; - await Task.Run( - () => - { - var bi = DateTime.Now.AddDays(-15); - - var uid = User.GetUserId(); - - var dat = _context.HairCutQueries - .Include(q => q.Prestation) - .Include(q => q.Client) - .Include(q => q.PerformerProfile) - .Include(q => q.Location) - .Where(q => q.ClientId == uid - && (q.EventDate == null || q.EventDate > bi)) - ; - info = dat.ToArray().Select(q => new HaircutQueryClientInfo(q)); - }); - - return Ok(info); - } - - // GET: api/HairCutQueriesApi/5 - [HttpGet("{id}", Name = "GetHairCutQuery")] - public async Task GetHairCutQuery([FromRoute] long id) - { - if (!ModelState.IsValid) - { - return HttpBadRequest(ModelState); - } - - HairCutQuery hairCutQuery = await _context.HairCutQueries.SingleAsync(m => m.Id == id); - - if (hairCutQuery == null) - { - return HttpNotFound(); - } - - return Ok(hairCutQuery); - } - - // PUT: api/HairCutQueriesApi/5 - [HttpPut("{id}")] - public async Task PutHairCutQuery([FromRoute] long id, [FromBody] HairCutQuery hairCutQuery) - { - if (!ModelState.IsValid) - { - return HttpBadRequest(ModelState); - } - - if (id != hairCutQuery.Id) - { - return HttpBadRequest(); - } - - _context.Entry(hairCutQuery).State = EntityState.Modified; - - try - { - await _context.SaveChangesAsync(); - } - catch (DbUpdateConcurrencyException) - { - if (!HairCutQueryExists(id)) - { - return HttpNotFound(); - } - else - { - throw; - } - } - - return new HttpStatusCodeResult(StatusCodes.Status204NoContent); - } - - // POST: api/HairCutQueriesApi - [HttpPost] - public async Task PostHairCutQuery([FromBody] HairCutQuery hairCutQuery) - { - if (!ModelState.IsValid) - { - return HttpBadRequest(ModelState); - } - - _context.HairCutQueries.Add(hairCutQuery); - try - { - await _context.SaveChangesAsync(); - } - catch (DbUpdateException) - { - if (HairCutQueryExists(hairCutQuery.Id)) - { - return new HttpStatusCodeResult(StatusCodes.Status409Conflict); - } - else - { - throw; - } - } - - return CreatedAtRoute("GetHairCutQuery", new { id = hairCutQuery.Id }, hairCutQuery); - } - - // DELETE: api/HairCutQueriesApi/5 - [HttpDelete("{id}")] - public async Task DeleteHairCutQuery([FromRoute] long id) - { - if (!ModelState.IsValid) - { - return HttpBadRequest(ModelState); - } - - HairCutQuery hairCutQuery = await _context.HairCutQueries.SingleAsync(m => m.Id == id); - if (hairCutQuery == null) - { - return HttpNotFound(); - } - - _context.HairCutQueries.Remove(hairCutQuery); - await _context.SaveChangesAsync(); - - return Ok(hairCutQuery); - } - - protected override void Dispose(bool disposing) - { - if (disposing) - { - _context.Dispose(); - } - base.Dispose(disposing); - } - - private bool HairCutQueryExists(long id) - { - return _context.HairCutQueries.Count(e => e.Id == id) > 0; - } - } -} diff --git a/Yavsc/ApiControllers/PaymentApiController.cs b/Yavsc/ApiControllers/PaymentApiController.cs index 0d6850ca..71c3ba4c 100644 --- a/Yavsc/ApiControllers/PaymentApiController.cs +++ b/Yavsc/ApiControllers/PaymentApiController.cs @@ -1,14 +1,10 @@ using System.Threading.Tasks; -using Microsoft.AspNet.Authorization; using Microsoft.AspNet.Mvc; -using Microsoft.Data.Entity; using Microsoft.Extensions.Logging; using Microsoft.Extensions.OptionsModel; -using PayPal.Api; +using Newtonsoft.Json; using Yavsc.Helpers; using Yavsc.Models; -using Yavsc.Models.Billing; -using Yavsc.ViewModels.PayPal; namespace Yavsc.ApiControllers { @@ -16,57 +12,23 @@ namespace Yavsc.ApiControllers public class PaymentApiController : Controller { private ApplicationDbContext dbContext; - PayPalSettings paymentSettings; private SiteSettings siteSettings; private readonly ILogger _logger; public PaymentApiController( ApplicationDbContext dbContext, - IOptions paypalSettingsReceiver, IOptions siteSettingsReceiver, ILoggerFactory loggerFactory) { this.dbContext = dbContext; - paymentSettings = paypalSettingsReceiver.Value; siteSettings = siteSettingsReceiver.Value; _logger = loggerFactory.CreateLogger(); } - public async Task Info(string paymentId) + public async Task Info(string paymentId, string token) { - var result = new PaymentInfo { - DbContent = await dbContext.PaypalPayments.SingleAsync( - p=>p.PaypalPaymentId==paymentId) - }; - await Task.Run( () => { - var apiContext = PayPalHelpers.CreateAPIContext(); - result.FromPaypal = Payment.Get(apiContext,paymentId); - }); - - return Ok(result); - } - - [HttpPost("execute")] - public async Task Execute(string paymentId, string payerId) - { - Payment result=null; - await Task.Run( () => { - var apiContext = PayPalHelpers.CreateAPIContext(); - var payment = Payment.Get(apiContext,paymentId); - var execution = new PaymentExecution(); - execution.payer_id = payerId; - execution.transactions = payment.transactions; - result = payment.Execute(apiContext,execution); - }); - - return Ok(result); - } - - [HttpPost("create"),AllowAnonymous] - public IActionResult Create() - { - var apiContext = PayPalHelpers.CreateAPIContext(); - Payment result= Request.CreatePayment("Command",apiContext,new Estimate()); - return Ok(Payment.Create(apiContext,result)); + var details = await dbContext.GetCheckoutInfo(token); + _logger.LogInformation(JsonConvert.SerializeObject(details)); + return Ok(details); } } diff --git a/Yavsc/Controllers/Haircut/HairCutCommandController.cs b/Yavsc/Controllers/Haircut/HairCutCommandController.cs index f51f5712..aa805009 100644 --- a/Yavsc/Controllers/Haircut/HairCutCommandController.cs +++ b/Yavsc/Controllers/Haircut/HairCutCommandController.cs @@ -24,7 +24,6 @@ namespace Yavsc.Controllers using System.Globalization; using Microsoft.AspNet.Mvc.Rendering; using System.Collections.Generic; - using PayPal.Api; public class HairCutCommandController : CommandController { @@ -62,12 +61,27 @@ namespace Yavsc.Controllers { return HttpNotFound(); } - ViewBag.CreatePaymentUrl = Request.ToAbsolute("api/haircut/createpayment/"+id); - ViewBag.ExecutePaymentUrl = Request.ToAbsolute("api/payment/execute"); - ViewBag.Urls=Request.GetPaymentUrls("HairCutCommand",id.ToString()); - + SetViewBagPaymentUrls(id); return View (command); } + public async Task Confirmation([FromRoute] long id, string token, string PayerID) + { + HairCutQuery command = await GetQuery(id); + if (command == null) + { + return HttpNotFound(); + } + SetViewBagPaymentUrls(id); + var paymentinfo = await _context.ConfirmPayment( User.GetUserId(), PayerID, token ); + return View (paymentinfo); + } + + private void SetViewBagPaymentUrls(long id) + { + ViewBag.CreatePaymentUrl = Request.ToAbsolute("api/haircut/createpayment/"+id); + ViewBag.ExecutePaymentUrl = Request.ToAbsolute("api/payment/execute"); + ViewBag.Urls=Request.GetPaymentUrls("HairCutCommand",id.ToString()); + } public async Task ClientCancelConfirm(long id) { var query = await GetQuery(id);if (query == null) @@ -97,7 +111,7 @@ namespace Yavsc.Controllers .ToListAsync()); } - public async Task Details(long id, string paymentId, string token, string PayerID) + public async Task Details(long id) { HairCutQuery command = await _context.HairCutQueries @@ -106,40 +120,16 @@ namespace Yavsc.Controllers .Include(x => x.Prestation) .Include(x => x.PerformerProfile.Performer) .Include(x => x.Regularisation) - .SingleAsync(m => m.Id == id); + .SingleOrDefaultAsync(m => m.Id == id); if (command == null) { return HttpNotFound(); } - ViewBag.CreatePaymentUrl = Request.ToAbsolute("api/haircut/createpayment/"+id); - ViewBag.ExecutePaymentUrl = Request.ToAbsolute("api/payment/execute"); - ViewBag.Urls=Request.GetPaymentUrls("HairCutCommand",id.ToString()); + SetViewBagPaymentUrls(id); return View(command); } - public async Task Execute(long id, string paymentId, string token, string PayerID) - { - HairCutQuery command = await _context.HairCutQueries - .Include(x => x.Location) - .Include(x => x.PerformerProfile) - .Include(x => x.Prestation) - .Include(x => x.PerformerProfile.Performer) - .Include(x => x.Regularisation) - .SingleAsync(m => m.Id == id); - if (command == null) - { - return HttpNotFound(); - } - var context = PayPalHelpers.CreateAPIContext(); - var payment = Payment.Get(context,paymentId); - - var execution = new PaymentExecution{ transactions = payment.transactions, - payer_id = PayerID }; - var result = payment.Execute(context,execution); - - return View(command); - } /// /// Crée une requête en coiffure à domicile /// @@ -244,9 +234,6 @@ namespace Yavsc.Controllers var items = model.GetBillItems(); var addition = items.Addition(); ViewBag.Addition = addition.ToString("C",CultureInfo.CurrentUICulture); - ViewBag.CreatePaymentUrl = Request.ToAbsolute("api/haircut/createpayment/"+model.Id); - ViewBag.ExecutePaymentUrl = Request.ToAbsolute("api/payment/execute"); - ViewBag.Urls=Request.GetPaymentUrls("HairCutCommand",model.Id.ToString()); return View("CommandConfirmation",model); } @@ -256,6 +243,7 @@ namespace Yavsc.Controllers return View("HairCut",model); } + public async Task HairCut(string performerId, string activityCode) { HairPrestation pPrestation=null; diff --git a/Yavsc/Controllers/ManageController.cs b/Yavsc/Controllers/ManageController.cs index a3fc87c1..29e7cb6c 100644 --- a/Yavsc/Controllers/ManageController.cs +++ b/Yavsc/Controllers/ManageController.cs @@ -23,7 +23,6 @@ using Yavsc.Models.Identity; namespace Yavsc.Controllers { using Models.Relationship; - using PayPal.Api; using Yavsc.Models.Bank; [Authorize] @@ -716,13 +715,18 @@ namespace Yavsc.Controllers ViewBag.GoogleSettings = _googleSettings; return View(model); } - - public IActionResult PaymentInfo(string id) + public IActionResult PaymentInfo (string id) { - var context = PayPalHelpers.CreateAPIContext(); - var payment = Payment.Get(context,id); - return View (payment); + ViewData["id"] = id; + var info = PayPalHelpers.GetCheckoutInfo(_dbContext,id); + return View(info); } + public IActionResult PaymentError (string id, string error) + { + ViewData["error"] = error; + ViewData["id"] = id; + return View(); + } } } diff --git a/Yavsc/Helpers/PayPalHelpers.cs b/Yavsc/Helpers/PayPalHelpers.cs index a03bb98f..8718436e 100644 --- a/Yavsc/Helpers/PayPalHelpers.cs +++ b/Yavsc/Helpers/PayPalHelpers.cs @@ -1,188 +1,249 @@ using System.Collections.Generic; using Microsoft.Extensions.Logging; -using PayPal.Api; using PayPal.Exception; using Yavsc.Models.Billing; using Microsoft.AspNet.Http; +using System.Threading.Tasks; +using System.Net.Http; +using System; +using System.Text; +using Newtonsoft.Json; +using PayPal.PayPalAPIInterfaceService.Model; +using PayPal.PayPalAPIInterfaceService; +using Yavsc.ViewModels.PayPal; +using Yavsc.Models; +using Microsoft.Data.Entity; +using System.Linq; +using Yavsc.Models.Payment; namespace Yavsc.Helpers { public static class PayPalHelpers { - private static OAuthTokenCredential payPaylCredential=null; - public static OAuthTokenCredential PayPaylCredential - { - get - { - if (payPaylCredential==null) - { - Dictionary config = new Dictionary(); - // config.Add("mode",Startup.PayPalSettings.Mode); - // config.Add("clientId",Startup.PayPalSettings.ClientId); - // config.Add("clientSecret",Startup.PayPalSettings.Secret); - // config.Add("user",Startup.PayPalSettings.APIUserId); - // https://api-3t.paypal.com/nvp - config.Add("USER",Startup.PayPalSettings.APIUserId); - config.Add("SIGNATURE",Startup.PayPalSettings.APISignature); - config.Add("PWD",Startup.PayPalSettings.APIPassword); - payPaylCredential = new OAuthTokenCredential(config); + private static Dictionary payPalProperties = null; + public static Dictionary GetPayPalProperties() { + if (payPalProperties==null) { + + payPalProperties = new Dictionary(); + // Don't do: + // payPalProperties.Add("mode", Startup.PayPalSettings.Mode); + // Instead, set the endpoint parameter. + if (Startup.PayPalSettings.Mode == "production") { + // use nvp end point: https://api-3t.paypal.com/nvp + payPalProperties.Add("endpoint", "https://api-3t.paypal.com/nvp"); + + } else { + payPalProperties.Add("endpoint", "https://api-3t.sandbox.paypal.com/nvp"); + } + payPalProperties.Add("clientId", Startup.PayPalSettings.ClientId); + payPalProperties.Add("clientSecret", Startup.PayPalSettings.ClientSecret); + + int numClient = 0; + if (Startup.PayPalSettings.Accounts!=null) + foreach (var account in Startup.PayPalSettings.Accounts) { + numClient++; + payPalProperties.Add ($"account{numClient}.apiUsername",account.ApiUsername); + payPalProperties.Add ($"account{numClient}.apiPassword",account.ApiPassword); + payPalProperties.Add ($"account{numClient}.apiSignature",account.Signature); } - return payPaylCredential; } + return payPalProperties; } - public static APIContext CreateAPIContext() + public class PayPalOAuth2Token { - var accessToken = PayPaylCredential.GetAccessToken(); - var apiContext = new APIContext(accessToken); - return apiContext; - } + public string scope; + public string nonce; + public string access_token; + public string token_type; - public class PaymentUrls { - public string Details { get; set; } - public string Cancel { get; set; } + public string app_id; + public string expires_in; - public string CGV { get; set; } } - public static PaymentUrls GetPaymentUrls(this HttpRequest request, string controllerName, string id ) + private static PayPalOAuth2Token token = null; + private static PayPalAPIInterfaceServiceService payPalService = null; + public static PayPalAPIInterfaceServiceService PayPalService { + get { + if (payPalService==null) + payPalService = new PayPal.PayPalAPIInterfaceService.PayPalAPIInterfaceServiceService(GetPayPalProperties()); + return payPalService; + }} + + [Obsolete("use the PayPalService property")] + internal static async Task GetAccessToken() { - var result =new PaymentUrls { - Details = request.ToAbsolute($"{controllerName}/Details/{id}") , - Cancel = request.ToAbsolute($"{controllerName}/ClientCancel/{id}"), - CGV = request.ToAbsolute($"{controllerName}/CGV") - }; + + + if (token == null) + { + token = new PayPalOAuth2Token(); + + using (HttpClient client = new HttpClient()) + { + + var uriString = Startup.PayPalSettings.Mode == "production" ? + "https://api.paypal.com/v1/oauth2/token" : "https://api.sandbox.paypal.com/v1/oauth2/token"; + + client.DefaultRequestHeaders.Add("Accept", "application/json"); + client.DefaultRequestHeaders.Add("Accept-Language", "en_US"); + + + string oAuthCredentials = Convert.ToBase64String(Encoding.Default.GetBytes(Startup.PayPalSettings.ClientId + ":" + Startup.PayPalSettings.ClientSecret)); + + var h_request = new HttpRequestMessage(HttpMethod.Post, uriString); + + h_request.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", oAuthCredentials); + var keyValues = new List>(); + keyValues.Add(new KeyValuePair("grant_type", "client_credentials")); + h_request.Content = new FormUrlEncodedContent(keyValues); + + using (var response = await client.SendAsync(h_request)) + { + if (response.IsSuccessStatusCode) + { + var content = await response.Content.ReadAsStringAsync(); + Console.WriteLine(content); + token = JsonConvert.DeserializeObject(content); + } + else + { + throw new PayPalException($"{response.StatusCode}"); + } + } + + } + } + return token?.access_token ?? null; + //return PayPalCredential.GetAccessToken(); + + } + + public class PaymentUrls + { + public string ReturnUrl { get; set; } + public string CancelUrl { get; set; } + public string CGVUrl { get; set; } + } + public static PaymentUrls GetPaymentUrls(this HttpRequest request, string controllerName, string id) + { + var result = new PaymentUrls + { + ReturnUrl = request.ToAbsolute($"{controllerName}/Confirmation/{id}"), + CancelUrl = request.ToAbsolute($"{controllerName}/ClientCancel/{id}"), + CGVUrl = request.ToAbsolute($"{controllerName}/CGV") + }; return result; } - public static Payment CreatePayment(this HttpRequest request, string controllerName, APIContext apiContext, NominativeServiceCommand query, string intent = "sale", ILogger logger=null) + private static string MerchantUserId { get { + return Startup.PayPalSettings.Accounts[0].ApiUsername; + }} + public static SetExpressCheckoutResponseType CreatePayment(this HttpRequest request, string controllerName, NominativeServiceCommand query, string intent = "sale", ILogger logger = null) { + var items = query.GetBillItems(); + var total = items.Addition().ToString("F2"); var queryType = query.GetType().Name; - var transaction = new Transaction - { - description = query.Description, - invoice_number = query.Id.ToString(), - custom = query.GetType().Name + "/"+ query.Id.ToString() + var coreq = new SetExpressCheckoutReq {}; + var urls = request.GetPaymentUrls(controllerName, query.Id.ToString()); + coreq.SetExpressCheckoutRequest = new SetExpressCheckoutRequestType{ + DetailLevel = new List { DetailLevelCodeType.RETURNALL }, + SetExpressCheckoutRequestDetails = new SetExpressCheckoutRequestDetailsType + { + PaymentDetails = items.Select(i => new PaymentDetailsType{ + OrderTotal = new BasicAmountType { + currencyID = CurrencyCodeType.EUR, + value = (i.Count * i.UnitaryCost).ToString("F2") + }, + OrderDescription = i.Description + }).ToList(), + InvoiceID = queryType + "/" + query.Id.ToString(), +OrderDescription = query.Description, CancelURL = urls.CancelUrl, ReturnURL = urls.ReturnUrl + } }; - - var urls = request.GetPaymentUrls(controllerName, query.Id.ToString() ); - - transaction.order_url = urls.Details; + var response = PayPalService.SetExpressCheckout( coreq, MerchantUserId ); // transaction.item_list.shipping_address.city // country_code default_address id // line1 line2 preferred_address recipient_name state status type - /* transaction.item_list = new ItemList(); - if (query.Client.PostalAddress!=null) { - var address = query.Client.PostalAddress?.Address; - if (address!=null) { - var parts = new Stack ( address.Split(',') ); - var country = parts.Pop().Trim(); - var city = parts.Pop().Trim().Split(' '); - var line1 = parts.First().Trim(); - var line2 = string.Join(" - ",parts.Skip(1)); - transaction.item_list.shipping_address = new ShippingAddress { - line1 = line1, - line2 = line2, - city = city[1], - postal_code = city[0], - country_code = country == "France" ? "fr" : country - }; - } - } - transaction.item_list.shipping_phone_number = query.Client.PhoneNumber; - var items = query.GetBillItems(); - transaction.item_list.items = items.Select(i => new Item { - name = i.Name, - description = i.Description, - quantity = i.Count.ToString(), - price = i.UnitaryCost.ToString("F2"), - currency = "EUR", - sku = "sku" - // postback_data= - // supplementary_data= - }).ToList(); -*/ var total = query.GetBillItems().Addition().ToString("F2"); - transaction.amount = new Amount { - currency = "EUR", - total = total - }; - var payment = new Payment - { - intent = intent, // "sale", "order", "authorize" - payer = new Payer - { - payment_method = "paypal" - }, - transactions = new List { transaction }, - redirect_urls = new RedirectUrls - { - return_url = urls.Details, - cancel_url = urls.Cancel - } - }; - Payment result = null; - try { - result = Payment.Create(apiContext,payment); - } - catch (PaymentsException ex) { - logger.LogError (ex.Message); - } - return result; + /* transaction.item_list = new ItemList(); + if (query.Client.PostalAddress!=null) { + var address = query.Client.PostalAddress?.Address; + if (address!=null) { + var parts = new Stack ( address.Split(',') ); + var country = parts.Pop().Trim(); + var city = parts.Pop().Trim().Split(' '); + var line1 = parts.First().Trim(); + var line2 = string.Join(" - ",parts.Skip(1)); + transaction.item_list.shipping_address = new ShippingAddress { + line1 = line1, + line2 = line2, + city = city[1], + postal_code = city[0], + country_code = country == "France" ? "fr" : country + }; + } + } + transaction.item_list.shipping_phone_number = query.Client.PhoneNumber; + var items = query.GetBillItems(); + transaction.item_list.items = items.Select(i => new Item { + name = i.Name, + description = i.Description, + quantity = i.Count.ToString(), + price = i.UnitaryCost.ToString("F2"), + currency = "EUR", + sku = "sku" + // postback_data= + // supplementary_data= + }).ToList(); + */ + + return response; } - public static Payment CreatePayment(this HttpRequest request, string controllerName, APIContext apiContext, Estimate estimation) + public static async Task GetCheckoutInfo( + this ApplicationDbContext context, + string token) { - var urls = request.GetPaymentUrls( controllerName, estimation.Id.ToString() ); - var payment = Payment.Create(apiContext, - new Payment - { - intent = "order", // "sale", "order", "authorize" - payer = new Payer - { - payment_method = "paypal" - }, - transactions = new List - { - new Transaction - { - description = "Transaction description.", - invoice_number = estimation.Id.ToString(), - amount = new Amount - { - currency = "EUR", - total = "0.11", - details = new Details - { - tax = "0.01", - shipping = "0.02", - subtotal = "0.08" - } - }, - item_list = new ItemList - { - items = new List - { - new Item - { - name = "nah", - currency = "EUR", - price = "0.02", - quantity = "4", - sku = "sku" - } - } - } + return await CreatePaymentViewModel(context,token,GetExpressCheckoutDetails(token)); + } + private static GetExpressCheckoutDetailsResponseType GetExpressCheckoutDetails(string token) + { + GetExpressCheckoutDetailsReq req = new GetExpressCheckoutDetailsReq{ + GetExpressCheckoutDetailsRequest = new GetExpressCheckoutDetailsRequestType { + Token = token + } + }; + return PayPalService.GetExpressCheckoutDetails(req,Startup.PayPalSettings.Accounts[0].ApiUsername); + } + public static async Task ConfirmPayment( + this ApplicationDbContext context, + string userId, + string payerId, + string token) + { + var details = GetExpressCheckoutDetails(token); + var payment = new PayPalPayment{ + ExecutorId = userId, + PaypalPayerId = payerId, + CreationToken = token + }; + context.PayPalPayments.Add(payment); + await context.SaveChangesAsync(userId); + // GetCheckoutInfo(,token); + return new PaymentInfo { DbContent = payment, DetailsFromPayPal = details }; + } + public static async Task CreatePaymentViewModel ( + this ApplicationDbContext context, + string token, GetExpressCheckoutDetailsResponseType fromPayPal) + { + return new PaymentInfo { + DbContent = await context.PayPalPayments.SingleOrDefaultAsync( + p=>p.CreationToken==token), + DetailsFromPayPal = fromPayPal + }; } - }, - redirect_urls = new RedirectUrls - { - return_url = urls.Details, - cancel_url = urls.Cancel - } - }); - return payment; - } } } diff --git a/Yavsc/Migrations/20170524210924_paypalToDeprecated.Designer.cs b/Yavsc/Migrations/20170524210924_paypalToDeprecated.Designer.cs new file mode 100644 index 00000000..6db894e6 --- /dev/null +++ b/Yavsc/Migrations/20170524210924_paypalToDeprecated.Designer.cs @@ -0,0 +1,1540 @@ +using System; +using Microsoft.Data.Entity; +using Microsoft.Data.Entity.Infrastructure; +using Microsoft.Data.Entity.Metadata; +using Microsoft.Data.Entity.Migrations; +using Yavsc.Models; + +namespace Yavsc.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("20170524210924_paypalToDeprecated")] + partial class paypalToDeprecated + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { + modelBuilder + .HasAnnotation("ProductVersion", "7.0.0-rc1-16348"); + + modelBuilder.Entity("Microsoft.AspNet.Identity.EntityFramework.IdentityRole", b => + { + b.Property("Id"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken(); + + b.Property("Name") + .HasAnnotation("MaxLength", 256); + + b.Property("NormalizedName") + .HasAnnotation("MaxLength", 256); + + b.HasKey("Id"); + + b.HasIndex("NormalizedName") + .HasAnnotation("Relational:Name", "RoleNameIndex"); + + b.HasAnnotation("Relational:TableName", "AspNetRoles"); + }); + + modelBuilder.Entity("Microsoft.AspNet.Identity.EntityFramework.IdentityRoleClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ClaimType"); + + b.Property("ClaimValue"); + + b.Property("RoleId") + .IsRequired(); + + b.HasKey("Id"); + + b.HasAnnotation("Relational:TableName", "AspNetRoleClaims"); + }); + + modelBuilder.Entity("Microsoft.AspNet.Identity.EntityFramework.IdentityUserClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ClaimType"); + + b.Property("ClaimValue"); + + b.Property("UserId") + .IsRequired(); + + b.HasKey("Id"); + + b.HasAnnotation("Relational:TableName", "AspNetUserClaims"); + }); + + modelBuilder.Entity("Microsoft.AspNet.Identity.EntityFramework.IdentityUserLogin", b => + { + b.Property("LoginProvider"); + + b.Property("ProviderKey"); + + b.Property("ProviderDisplayName"); + + b.Property("UserId") + .IsRequired(); + + b.HasKey("LoginProvider", "ProviderKey"); + + b.HasAnnotation("Relational:TableName", "AspNetUserLogins"); + }); + + modelBuilder.Entity("Microsoft.AspNet.Identity.EntityFramework.IdentityUserRole", b => + { + b.Property("UserId"); + + b.Property("RoleId"); + + b.HasKey("UserId", "RoleId"); + + b.HasAnnotation("Relational:TableName", "AspNetUserRoles"); + }); + + modelBuilder.Entity("Yavsc.Models.Access.Ban", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("DateCreated"); + + b.Property("DateModified"); + + b.Property("UserCreated"); + + b.Property("UserModified"); + + b.HasKey("Id"); + }); + + modelBuilder.Entity("Yavsc.Models.Access.BlackListed", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("OwnerId") + .IsRequired(); + + b.Property("UserId") + .IsRequired(); + + b.HasKey("Id"); + }); + + modelBuilder.Entity("Yavsc.Models.Access.CircleAuthorizationToBlogPost", b => + { + b.Property("CircleId"); + + b.Property("BlogPostId"); + + b.HasKey("CircleId", "BlogPostId"); + }); + + modelBuilder.Entity("Yavsc.Models.AccountBalance", b => + { + b.Property("UserId"); + + b.Property("ContactCredits"); + + b.Property("Credits"); + + b.HasKey("UserId"); + }); + + modelBuilder.Entity("Yavsc.Models.ApplicationUser", b => + { + b.Property("Id"); + + b.Property("AccessFailedCount"); + + b.Property("Avatar") + .HasAnnotation("MaxLength", 512) + .HasAnnotation("Relational:DefaultValue", "/images/Users/icon_user.png") + .HasAnnotation("Relational:DefaultValueType", "System.String"); + + b.Property("BankInfoId"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken(); + + b.Property("DedicatedGoogleCalendar"); + + b.Property("DiskQuota") + .HasAnnotation("Relational:DefaultValue", "524288000") + .HasAnnotation("Relational:DefaultValueType", "System.Int64"); + + b.Property("DiskUsage"); + + b.Property("Email") + .HasAnnotation("MaxLength", 256); + + b.Property("EmailConfirmed"); + + b.Property("FullName") + .HasAnnotation("MaxLength", 512); + + b.Property("LockoutEnabled"); + + b.Property("LockoutEnd"); + + b.Property("NormalizedEmail") + .HasAnnotation("MaxLength", 256); + + b.Property("NormalizedUserName") + .HasAnnotation("MaxLength", 256); + + b.Property("PasswordHash"); + + b.Property("PhoneNumber"); + + b.Property("PhoneNumberConfirmed"); + + b.Property("PostalAddressId"); + + b.Property("SecurityStamp"); + + b.Property("TwoFactorEnabled"); + + b.Property("UserName") + .HasAnnotation("MaxLength", 256); + + b.HasKey("Id"); + + b.HasIndex("NormalizedEmail") + .HasAnnotation("Relational:Name", "EmailIndex"); + + b.HasIndex("NormalizedUserName") + .HasAnnotation("Relational:Name", "UserNameIndex"); + + b.HasAnnotation("Relational:TableName", "AspNetUsers"); + }); + + modelBuilder.Entity("Yavsc.Models.Auth.Client", b => + { + b.Property("Id"); + + b.Property("Active"); + + b.Property("DisplayName"); + + b.Property("LogoutRedirectUri") + .HasAnnotation("MaxLength", 100); + + b.Property("RedirectUri"); + + b.Property("RefreshTokenLifeTime"); + + b.Property("Secret"); + + b.Property("Type"); + + b.HasKey("Id"); + }); + + modelBuilder.Entity("Yavsc.Models.Auth.RefreshToken", b => + { + b.Property("Id"); + + b.Property("ClientId") + .IsRequired() + .HasAnnotation("MaxLength", 50); + + b.Property("ExpiresUtc"); + + b.Property("IssuedUtc"); + + b.Property("ProtectedTicket") + .IsRequired(); + + b.Property("Subject") + .IsRequired() + .HasAnnotation("MaxLength", 50); + + b.HasKey("Id"); + }); + + modelBuilder.Entity("Yavsc.Models.BalanceImpact", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("BalanceId") + .IsRequired(); + + b.Property("ExecDate"); + + b.Property("Impact"); + + b.Property("Reason") + .IsRequired(); + + b.HasKey("Id"); + }); + + modelBuilder.Entity("Yavsc.Models.Bank.BankIdentity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("AccountNumber") + .HasAnnotation("MaxLength", 15); + + b.Property("BIC") + .HasAnnotation("MaxLength", 15); + + b.Property("BankCode") + .HasAnnotation("MaxLength", 5); + + b.Property("BankedKey"); + + b.Property("IBAN") + .HasAnnotation("MaxLength", 33); + + b.Property("WicketCode") + .HasAnnotation("MaxLength", 5); + + b.HasKey("Id"); + }); + + modelBuilder.Entity("Yavsc.Models.Billing.CommandLine", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Count"); + + b.Property("Currency"); + + b.Property("Description") + .IsRequired() + .HasAnnotation("MaxLength", 512); + + b.Property("EstimateId"); + + b.Property("EstimateTemplateId"); + + b.Property("Name") + .IsRequired() + .HasAnnotation("MaxLength", 256); + + b.Property("UnitaryCost"); + + b.HasKey("Id"); + }); + + modelBuilder.Entity("Yavsc.Models.Billing.Estimate", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("AttachedFilesString"); + + b.Property("AttachedGraphicsString"); + + b.Property("ClientId") + .IsRequired(); + + b.Property("ClientValidationDate"); + + b.Property("CommandId"); + + b.Property("CommandType") + .IsRequired(); + + b.Property("Description"); + + b.Property("OwnerId") + .IsRequired(); + + b.Property("ProviderValidationDate"); + + b.Property("Title"); + + b.HasKey("Id"); + }); + + modelBuilder.Entity("Yavsc.Models.Billing.EstimateTemplate", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Description"); + + b.Property("OwnerId") + .IsRequired(); + + b.Property("Title"); + + b.HasKey("Id"); + }); + + modelBuilder.Entity("Yavsc.Models.Billing.ExceptionSIREN", b => + { + b.Property("SIREN"); + + b.HasKey("SIREN"); + }); + + modelBuilder.Entity("Yavsc.Models.Blog", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("AuthorId"); + + b.Property("Content"); + + b.Property("DateCreated"); + + b.Property("DateModified"); + + b.Property("Photo"); + + b.Property("Rate"); + + b.Property("Title"); + + b.Property("UserCreated"); + + b.Property("UserModified"); + + b.Property("Visible"); + + b.HasKey("Id"); + }); + + modelBuilder.Entity("Yavsc.Models.Chat.Connection", b => + { + b.Property("ConnectionId"); + + b.Property("ApplicationUserId") + .IsRequired(); + + b.Property("Connected"); + + b.Property("UserAgent"); + + b.HasKey("ConnectionId"); + }); + + modelBuilder.Entity("Yavsc.Models.Drawing.Color", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Blue"); + + b.Property("Green"); + + b.Property("Name"); + + b.Property("Red"); + + b.HasKey("Id"); + }); + + modelBuilder.Entity("Yavsc.Models.Forms.Form", b => + { + b.Property("Id"); + + b.Property("Summary"); + + b.HasKey("Id"); + }); + + modelBuilder.Entity("Yavsc.Models.Haircut.BrusherProfile", b => + { + b.Property("UserId"); + + b.Property("ActionDistance"); + + b.Property("CarePrice"); + + b.Property("EndOfTheDay"); + + b.Property("FlatFeeDiscount"); + + b.Property("HalfBalayagePrice"); + + b.Property("HalfBrushingPrice"); + + b.Property("HalfColorPrice"); + + b.Property("HalfDefrisPrice"); + + b.Property("HalfFoldingPrice"); + + b.Property("HalfMechPrice"); + + b.Property("HalfMultiColorPrice"); + + b.Property("HalfPermanentPrice"); + + b.Property("KidCutPrice"); + + b.Property("LongBalayagePrice"); + + b.Property("LongBrushingPrice"); + + b.Property("LongColorPrice"); + + b.Property("LongDefrisPrice"); + + b.Property("LongFoldingPrice"); + + b.Property("LongMechPrice"); + + b.Property("LongMultiColorPrice"); + + b.Property("LongPermanentPrice"); + + b.Property("ManBrushPrice"); + + b.Property("ManCutPrice"); + + b.Property("ShampooPrice"); + + b.Property("ShortBalayagePrice"); + + b.Property("ShortBrushingPrice"); + + b.Property("ShortColorPrice"); + + b.Property("ShortDefrisPrice"); + + b.Property("ShortFoldingPrice"); + + b.Property("ShortMechPrice"); + + b.Property("ShortMultiColorPrice"); + + b.Property("ShortPermanentPrice"); + + b.Property("StartOfTheDay"); + + b.Property("WomenHalfCutPrice"); + + b.Property("WomenLongCutPrice"); + + b.Property("WomenShortCutPrice"); + + b.HasKey("UserId"); + }); + + modelBuilder.Entity("Yavsc.Models.Haircut.HairCutQuery", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ActivityCode") + .IsRequired(); + + b.Property("AdditionalInfo") + .HasAnnotation("MaxLength", 512); + + b.Property("ClientId") + .IsRequired(); + + b.Property("Consent"); + + b.Property("DateCreated"); + + b.Property("DateModified"); + + b.Property("Description"); + + b.Property("EventDate"); + + b.Property("LocationId"); + + b.Property("PaymentId"); + + b.Property("PerformerId") + .IsRequired(); + + b.Property("PrestationId"); + + b.Property("Previsional"); + + b.Property("SelectedProfileUserId"); + + b.Property("Status"); + + b.Property("UserCreated"); + + b.Property("UserModified"); + + b.Property("ValidationDate"); + + b.HasKey("Id"); + }); + + modelBuilder.Entity("Yavsc.Models.Haircut.HairMultiCutQuery", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ActivityCode") + .IsRequired(); + + b.Property("ClientId") + .IsRequired(); + + b.Property("Consent"); + + b.Property("DateCreated"); + + b.Property("DateModified"); + + b.Property("Description"); + + b.Property("EventDate"); + + b.Property("LocationId"); + + b.Property("PaymentId"); + + b.Property("PerformerId") + .IsRequired(); + + b.Property("Previsional"); + + b.Property("Status"); + + b.Property("UserCreated"); + + b.Property("UserModified"); + + b.Property("ValidationDate"); + + b.HasKey("Id"); + }); + + modelBuilder.Entity("Yavsc.Models.Haircut.HairPrestation", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Cares"); + + b.Property("Cut"); + + b.Property("Dressing"); + + b.Property("Gender"); + + b.Property("Length"); + + b.Property("Shampoo"); + + b.Property("Tech"); + + b.HasKey("Id"); + }); + + modelBuilder.Entity("Yavsc.Models.Haircut.HairPrestationCollectionItem", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("PrestationId"); + + b.Property("QueryId"); + + b.HasKey("Id"); + }); + + modelBuilder.Entity("Yavsc.Models.Haircut.HairTaint", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Brand"); + + b.Property("ColorId"); + + b.HasKey("Id"); + }); + + modelBuilder.Entity("Yavsc.Models.Haircut.HairTaintInstance", b => + { + b.Property("TaintId"); + + b.Property("PrestationId"); + + b.HasKey("TaintId", "PrestationId"); + }); + + modelBuilder.Entity("Yavsc.Models.Identity.GoogleCloudMobileDeclaration", b => + { + b.Property("DeviceId"); + + b.Property("DeclarationDate") + .ValueGeneratedOnAdd() + .HasAnnotation("Relational:GeneratedValueSql", "LOCALTIMESTAMP"); + + b.Property("DeviceOwnerId"); + + b.Property("GCMRegistrationId") + .IsRequired(); + + b.Property("Model"); + + b.Property("Platform"); + + b.Property("Version"); + + b.HasKey("DeviceId"); + }); + + modelBuilder.Entity("Yavsc.Models.Market.Product", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Depth"); + + b.Property("Description"); + + b.Property("Height"); + + b.Property("Name"); + + b.Property("Price"); + + b.Property("Public"); + + b.Property("Weight"); + + b.Property("Width"); + + b.HasKey("Id"); + }); + + modelBuilder.Entity("Yavsc.Models.Market.Service", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ContextId"); + + b.Property("Description"); + + b.Property("Name"); + + b.Property("Public"); + + b.HasKey("Id"); + }); + + modelBuilder.Entity("Yavsc.Models.Messaging.ClientProviderInfo", b => + { + b.Property("UserId"); + + b.Property("Avatar"); + + b.Property("BillingAddressId"); + + b.Property("EMail"); + + b.Property("Phone"); + + b.Property("UserName"); + + b.HasKey("UserId"); + }); + + modelBuilder.Entity("Yavsc.Models.Messaging.DimissClicked", b => + { + b.Property("UserId"); + + b.Property("NotificationId"); + + b.HasKey("UserId", "NotificationId"); + }); + + modelBuilder.Entity("Yavsc.Models.Messaging.Notification", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Target"); + + b.Property("body") + .IsRequired(); + + b.Property("click_action") + .IsRequired(); + + b.Property("color"); + + b.Property("icon"); + + b.Property("sound"); + + b.Property("tag"); + + b.Property("title") + .IsRequired(); + + b.HasKey("Id"); + }); + + modelBuilder.Entity("Yavsc.Models.Musical.Instrument", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Name") + .IsRequired() + .HasAnnotation("MaxLength", 255); + + b.HasKey("Id"); + }); + + modelBuilder.Entity("Yavsc.Models.Musical.MusicalPreference", b => + { + b.Property("OwnerProfileId"); + + b.Property("DjSettingsUserId"); + + b.Property("GeneralSettingsUserId"); + + b.Property("Rate"); + + b.Property("TendencyId"); + + b.HasKey("OwnerProfileId"); + }); + + modelBuilder.Entity("Yavsc.Models.Musical.MusicalTendency", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Name") + .IsRequired() + .HasAnnotation("MaxLength", 255); + + b.HasKey("Id"); + }); + + modelBuilder.Entity("Yavsc.Models.Musical.Profiles.DjSettings", b => + { + b.Property("UserId"); + + b.Property("SoundCloudId"); + + b.HasKey("UserId"); + }); + + modelBuilder.Entity("Yavsc.Models.Musical.Profiles.GeneralSettings", b => + { + b.Property("UserId"); + + b.HasKey("UserId"); + }); + + modelBuilder.Entity("Yavsc.Models.Musical.Profiles.Instrumentation", b => + { + b.Property("InstrumentId"); + + b.Property("UserId"); + + b.HasKey("InstrumentId", "UserId"); + }); + + modelBuilder.Entity("Yavsc.Models.OAuth.OAuth2Tokens", b => + { + b.Property("UserId"); + + b.Property("AccessToken"); + + b.Property("Expiration"); + + b.Property("ExpiresIn"); + + b.Property("RefreshToken"); + + b.Property("TokenType"); + + b.HasKey("UserId"); + }); + + modelBuilder.Entity("Yavsc.Models.Payment.PayPalPayment", b => + { + b.Property("CreationToken"); + + b.Property("DateCreated"); + + b.Property("DateModified"); + + b.Property("ExecutorId") + .IsRequired(); + + b.Property("OrderReference"); + + b.Property("PaypalPayerId"); + + b.Property("State"); + + b.Property("UserCreated"); + + b.Property("UserModified"); + + b.HasKey("CreationToken"); + }); + + modelBuilder.Entity("Yavsc.Models.Relationship.Circle", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ApplicationUserId"); + + b.Property("Name"); + + b.Property("OwnerId"); + + b.HasKey("Id"); + }); + + modelBuilder.Entity("Yavsc.Models.Relationship.CircleMember", b => + { + b.Property("MemberId"); + + b.Property("CircleId"); + + b.HasKey("MemberId", "CircleId"); + }); + + modelBuilder.Entity("Yavsc.Models.Relationship.Contact", b => + { + b.Property("OwnerId"); + + b.Property("UserId"); + + b.Property("ApplicationUserId"); + + b.HasKey("OwnerId", "UserId"); + }); + + modelBuilder.Entity("Yavsc.Models.Relationship.Link", b => + { + b.Property("HRef"); + + b.Property("Method"); + + b.Property("PayPalPaymentCreationToken"); + + b.Property("Rel"); + + b.HasKey("HRef", "Method"); + }); + + modelBuilder.Entity("Yavsc.Models.Relationship.Location", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Address") + .IsRequired() + .HasAnnotation("MaxLength", 512); + + b.Property("Latitude"); + + b.Property("Longitude"); + + b.HasKey("Id"); + }); + + modelBuilder.Entity("Yavsc.Models.Relationship.LocationType", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Name"); + + b.HasKey("Id"); + }); + + modelBuilder.Entity("Yavsc.Models.Relationship.PostTag", b => + { + b.Property("PostId"); + + b.Property("TagId"); + + b.HasKey("PostId", "TagId"); + }); + + modelBuilder.Entity("Yavsc.Models.Relationship.Tag", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Name") + .IsRequired(); + + b.HasKey("Id"); + }); + + modelBuilder.Entity("Yavsc.Models.Skill", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Name"); + + b.Property("Rate"); + + b.HasKey("Id"); + }); + + modelBuilder.Entity("Yavsc.Models.Workflow.Activity", b => + { + b.Property("Code") + .HasAnnotation("MaxLength", 512); + + b.Property("DateCreated"); + + b.Property("DateModified"); + + b.Property("Description"); + + b.Property("Hidden"); + + b.Property("ModeratorGroupName"); + + b.Property("Name") + .IsRequired() + .HasAnnotation("MaxLength", 512); + + b.Property("ParentCode") + .HasAnnotation("MaxLength", 512); + + b.Property("Photo"); + + b.Property("Rate"); + + b.Property("SettingsClassName"); + + b.Property("UserCreated"); + + b.Property("UserModified"); + + b.HasKey("Code"); + }); + + modelBuilder.Entity("Yavsc.Models.Workflow.CommandForm", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ActionName"); + + b.Property("ActivityCode") + .IsRequired(); + + b.Property("Title"); + + b.HasKey("Id"); + }); + + modelBuilder.Entity("Yavsc.Models.Workflow.CoWorking", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("FormationSettingsUserId"); + + b.Property("PerformerId"); + + b.Property("WorkingForId"); + + b.HasKey("Id"); + }); + + modelBuilder.Entity("Yavsc.Models.Workflow.PerformerProfile", b => + { + b.Property("PerformerId"); + + b.Property("AcceptNotifications"); + + b.Property("AcceptPublicContact"); + + b.Property("Active"); + + b.Property("MaxDailyCost"); + + b.Property("MinDailyCost"); + + b.Property("OrganizationAddressId"); + + b.Property("Rate"); + + b.Property("SIREN") + .IsRequired() + .HasAnnotation("MaxLength", 14); + + b.Property("UseGeoLocalizationToReduceDistanceWithClients"); + + b.Property("WebSite"); + + b.HasKey("PerformerId"); + }); + + modelBuilder.Entity("Yavsc.Models.Workflow.Profiles.FormationSettings", b => + { + b.Property("UserId"); + + b.HasKey("UserId"); + }); + + modelBuilder.Entity("Yavsc.Models.Workflow.RdvQuery", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ActivityCode") + .IsRequired(); + + b.Property("ClientId") + .IsRequired(); + + b.Property("Consent"); + + b.Property("DateCreated"); + + b.Property("DateModified"); + + b.Property("Description"); + + b.Property("EventDate"); + + b.Property("LocationId"); + + b.Property("LocationTypeId"); + + b.Property("PaymentId"); + + b.Property("PerformerId") + .IsRequired(); + + b.Property("Previsional"); + + b.Property("Reason"); + + b.Property("Status"); + + b.Property("UserCreated"); + + b.Property("UserModified"); + + b.Property("ValidationDate"); + + b.HasKey("Id"); + }); + + modelBuilder.Entity("Yavsc.Models.Workflow.UserActivity", b => + { + b.Property("DoesCode"); + + b.Property("UserId"); + + b.Property("Weight"); + + b.HasKey("DoesCode", "UserId"); + }); + + modelBuilder.Entity("Microsoft.AspNet.Identity.EntityFramework.IdentityRoleClaim", b => + { + b.HasOne("Microsoft.AspNet.Identity.EntityFramework.IdentityRole") + .WithMany() + .HasForeignKey("RoleId"); + }); + + modelBuilder.Entity("Microsoft.AspNet.Identity.EntityFramework.IdentityUserClaim", b => + { + b.HasOne("Yavsc.Models.ApplicationUser") + .WithMany() + .HasForeignKey("UserId"); + }); + + modelBuilder.Entity("Microsoft.AspNet.Identity.EntityFramework.IdentityUserLogin", b => + { + b.HasOne("Yavsc.Models.ApplicationUser") + .WithMany() + .HasForeignKey("UserId"); + }); + + modelBuilder.Entity("Microsoft.AspNet.Identity.EntityFramework.IdentityUserRole", b => + { + b.HasOne("Microsoft.AspNet.Identity.EntityFramework.IdentityRole") + .WithMany() + .HasForeignKey("RoleId"); + + b.HasOne("Yavsc.Models.ApplicationUser") + .WithMany() + .HasForeignKey("UserId"); + }); + + modelBuilder.Entity("Yavsc.Models.Access.BlackListed", b => + { + b.HasOne("Yavsc.Models.ApplicationUser") + .WithMany() + .HasForeignKey("OwnerId"); + }); + + modelBuilder.Entity("Yavsc.Models.Access.CircleAuthorizationToBlogPost", b => + { + b.HasOne("Yavsc.Models.Blog") + .WithMany() + .HasForeignKey("BlogPostId"); + + b.HasOne("Yavsc.Models.Relationship.Circle") + .WithMany() + .HasForeignKey("CircleId"); + }); + + modelBuilder.Entity("Yavsc.Models.AccountBalance", b => + { + b.HasOne("Yavsc.Models.ApplicationUser") + .WithOne() + .HasForeignKey("Yavsc.Models.AccountBalance", "UserId"); + }); + + modelBuilder.Entity("Yavsc.Models.ApplicationUser", b => + { + b.HasOne("Yavsc.Models.Bank.BankIdentity") + .WithMany() + .HasForeignKey("BankInfoId"); + + b.HasOne("Yavsc.Models.Relationship.Location") + .WithMany() + .HasForeignKey("PostalAddressId"); + }); + + modelBuilder.Entity("Yavsc.Models.BalanceImpact", b => + { + b.HasOne("Yavsc.Models.AccountBalance") + .WithMany() + .HasForeignKey("BalanceId"); + }); + + modelBuilder.Entity("Yavsc.Models.Billing.CommandLine", b => + { + b.HasOne("Yavsc.Models.Billing.Estimate") + .WithMany() + .HasForeignKey("EstimateId"); + + b.HasOne("Yavsc.Models.Billing.EstimateTemplate") + .WithMany() + .HasForeignKey("EstimateTemplateId"); + }); + + modelBuilder.Entity("Yavsc.Models.Billing.Estimate", b => + { + b.HasOne("Yavsc.Models.ApplicationUser") + .WithMany() + .HasForeignKey("ClientId"); + + b.HasOne("Yavsc.Models.Workflow.RdvQuery") + .WithMany() + .HasForeignKey("CommandId"); + + b.HasOne("Yavsc.Models.Workflow.PerformerProfile") + .WithMany() + .HasForeignKey("OwnerId"); + }); + + modelBuilder.Entity("Yavsc.Models.Blog", b => + { + b.HasOne("Yavsc.Models.ApplicationUser") + .WithMany() + .HasForeignKey("AuthorId"); + }); + + modelBuilder.Entity("Yavsc.Models.Chat.Connection", b => + { + b.HasOne("Yavsc.Models.ApplicationUser") + .WithMany() + .HasForeignKey("ApplicationUserId"); + }); + + modelBuilder.Entity("Yavsc.Models.Haircut.BrusherProfile", b => + { + b.HasOne("Yavsc.Models.Workflow.PerformerProfile") + .WithMany() + .HasForeignKey("UserId"); + }); + + modelBuilder.Entity("Yavsc.Models.Haircut.HairCutQuery", b => + { + b.HasOne("Yavsc.Models.Workflow.Activity") + .WithMany() + .HasForeignKey("ActivityCode"); + + b.HasOne("Yavsc.Models.ApplicationUser") + .WithMany() + .HasForeignKey("ClientId"); + + b.HasOne("Yavsc.Models.Relationship.Location") + .WithMany() + .HasForeignKey("LocationId"); + + b.HasOne("Yavsc.Models.Payment.PayPalPayment") + .WithMany() + .HasForeignKey("PaymentId"); + + b.HasOne("Yavsc.Models.Workflow.PerformerProfile") + .WithMany() + .HasForeignKey("PerformerId"); + + b.HasOne("Yavsc.Models.Haircut.HairPrestation") + .WithMany() + .HasForeignKey("PrestationId"); + + b.HasOne("Yavsc.Models.Haircut.BrusherProfile") + .WithMany() + .HasForeignKey("SelectedProfileUserId"); + }); + + modelBuilder.Entity("Yavsc.Models.Haircut.HairMultiCutQuery", b => + { + b.HasOne("Yavsc.Models.Workflow.Activity") + .WithMany() + .HasForeignKey("ActivityCode"); + + b.HasOne("Yavsc.Models.ApplicationUser") + .WithMany() + .HasForeignKey("ClientId"); + + b.HasOne("Yavsc.Models.Relationship.Location") + .WithMany() + .HasForeignKey("LocationId"); + + b.HasOne("Yavsc.Models.Payment.PayPalPayment") + .WithMany() + .HasForeignKey("PaymentId"); + + b.HasOne("Yavsc.Models.Workflow.PerformerProfile") + .WithMany() + .HasForeignKey("PerformerId"); + }); + + modelBuilder.Entity("Yavsc.Models.Haircut.HairPrestationCollectionItem", b => + { + b.HasOne("Yavsc.Models.Haircut.HairPrestation") + .WithMany() + .HasForeignKey("PrestationId"); + + b.HasOne("Yavsc.Models.Haircut.HairMultiCutQuery") + .WithMany() + .HasForeignKey("QueryId"); + }); + + modelBuilder.Entity("Yavsc.Models.Haircut.HairTaint", b => + { + b.HasOne("Yavsc.Models.Drawing.Color") + .WithMany() + .HasForeignKey("ColorId"); + }); + + modelBuilder.Entity("Yavsc.Models.Haircut.HairTaintInstance", b => + { + b.HasOne("Yavsc.Models.Haircut.HairPrestation") + .WithMany() + .HasForeignKey("PrestationId"); + + b.HasOne("Yavsc.Models.Haircut.HairTaint") + .WithMany() + .HasForeignKey("TaintId"); + }); + + modelBuilder.Entity("Yavsc.Models.Identity.GoogleCloudMobileDeclaration", b => + { + b.HasOne("Yavsc.Models.ApplicationUser") + .WithMany() + .HasForeignKey("DeviceOwnerId"); + }); + + modelBuilder.Entity("Yavsc.Models.Market.Service", b => + { + b.HasOne("Yavsc.Models.Workflow.Activity") + .WithMany() + .HasForeignKey("ContextId"); + }); + + modelBuilder.Entity("Yavsc.Models.Messaging.ClientProviderInfo", b => + { + b.HasOne("Yavsc.Models.Relationship.Location") + .WithMany() + .HasForeignKey("BillingAddressId"); + }); + + modelBuilder.Entity("Yavsc.Models.Messaging.DimissClicked", b => + { + b.HasOne("Yavsc.Models.Messaging.Notification") + .WithMany() + .HasForeignKey("NotificationId"); + + b.HasOne("Yavsc.Models.ApplicationUser") + .WithMany() + .HasForeignKey("UserId"); + }); + + modelBuilder.Entity("Yavsc.Models.Musical.MusicalPreference", b => + { + b.HasOne("Yavsc.Models.Musical.Profiles.DjSettings") + .WithMany() + .HasForeignKey("DjSettingsUserId"); + + b.HasOne("Yavsc.Models.Musical.Profiles.GeneralSettings") + .WithMany() + .HasForeignKey("GeneralSettingsUserId"); + }); + + modelBuilder.Entity("Yavsc.Models.Musical.Profiles.Instrumentation", b => + { + b.HasOne("Yavsc.Models.Musical.Instrument") + .WithMany() + .HasForeignKey("InstrumentId"); + + b.HasOne("Yavsc.Models.Workflow.PerformerProfile") + .WithMany() + .HasForeignKey("UserId"); + }); + + modelBuilder.Entity("Yavsc.Models.Payment.PayPalPayment", b => + { + b.HasOne("Yavsc.Models.ApplicationUser") + .WithMany() + .HasForeignKey("ExecutorId"); + }); + + modelBuilder.Entity("Yavsc.Models.Relationship.Circle", b => + { + b.HasOne("Yavsc.Models.ApplicationUser") + .WithMany() + .HasForeignKey("ApplicationUserId"); + }); + + modelBuilder.Entity("Yavsc.Models.Relationship.CircleMember", b => + { + b.HasOne("Yavsc.Models.Relationship.Circle") + .WithMany() + .HasForeignKey("CircleId"); + + b.HasOne("Yavsc.Models.ApplicationUser") + .WithMany() + .HasForeignKey("MemberId"); + }); + + modelBuilder.Entity("Yavsc.Models.Relationship.Contact", b => + { + b.HasOne("Yavsc.Models.ApplicationUser") + .WithMany() + .HasForeignKey("ApplicationUserId"); + }); + + modelBuilder.Entity("Yavsc.Models.Relationship.Link", b => + { + b.HasOne("Yavsc.Models.Payment.PayPalPayment") + .WithMany() + .HasForeignKey("PayPalPaymentCreationToken"); + }); + + modelBuilder.Entity("Yavsc.Models.Relationship.PostTag", b => + { + b.HasOne("Yavsc.Models.Blog") + .WithMany() + .HasForeignKey("PostId"); + }); + + modelBuilder.Entity("Yavsc.Models.Workflow.Activity", b => + { + b.HasOne("Yavsc.Models.Workflow.Activity") + .WithMany() + .HasForeignKey("ParentCode"); + }); + + modelBuilder.Entity("Yavsc.Models.Workflow.CommandForm", b => + { + b.HasOne("Yavsc.Models.Workflow.Activity") + .WithMany() + .HasForeignKey("ActivityCode"); + }); + + modelBuilder.Entity("Yavsc.Models.Workflow.CoWorking", b => + { + b.HasOne("Yavsc.Models.Workflow.Profiles.FormationSettings") + .WithMany() + .HasForeignKey("FormationSettingsUserId"); + + b.HasOne("Yavsc.Models.Workflow.PerformerProfile") + .WithMany() + .HasForeignKey("PerformerId"); + + b.HasOne("Yavsc.Models.ApplicationUser") + .WithMany() + .HasForeignKey("WorkingForId"); + }); + + modelBuilder.Entity("Yavsc.Models.Workflow.PerformerProfile", b => + { + b.HasOne("Yavsc.Models.Relationship.Location") + .WithMany() + .HasForeignKey("OrganizationAddressId"); + + b.HasOne("Yavsc.Models.ApplicationUser") + .WithMany() + .HasForeignKey("PerformerId"); + }); + + modelBuilder.Entity("Yavsc.Models.Workflow.RdvQuery", b => + { + b.HasOne("Yavsc.Models.Workflow.Activity") + .WithMany() + .HasForeignKey("ActivityCode"); + + b.HasOne("Yavsc.Models.ApplicationUser") + .WithMany() + .HasForeignKey("ClientId"); + + b.HasOne("Yavsc.Models.Relationship.Location") + .WithMany() + .HasForeignKey("LocationId"); + + b.HasOne("Yavsc.Models.Relationship.LocationType") + .WithMany() + .HasForeignKey("LocationTypeId"); + + b.HasOne("Yavsc.Models.Payment.PayPalPayment") + .WithMany() + .HasForeignKey("PaymentId"); + + b.HasOne("Yavsc.Models.Workflow.PerformerProfile") + .WithMany() + .HasForeignKey("PerformerId"); + }); + + modelBuilder.Entity("Yavsc.Models.Workflow.UserActivity", b => + { + b.HasOne("Yavsc.Models.Workflow.Activity") + .WithMany() + .HasForeignKey("DoesCode"); + + b.HasOne("Yavsc.Models.Workflow.PerformerProfile") + .WithMany() + .HasForeignKey("UserId"); + }); + } + } +} diff --git a/Yavsc/Migrations/20170524210924_paypalToDeprecated.cs b/Yavsc/Migrations/20170524210924_paypalToDeprecated.cs new file mode 100644 index 00000000..dc882fda --- /dev/null +++ b/Yavsc/Migrations/20170524210924_paypalToDeprecated.cs @@ -0,0 +1,19 @@ +using Microsoft.Data.Entity.Migrations; + +namespace Yavsc.Migrations +{ + public partial class paypalToDeprecated : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.RenameTable( name: "PaypalPayment", newName: "PayPalPayment"); + migrationBuilder.RenameColumn ( name:"PaypalPaymentId", table: "PayPalPayment", newName:"CreationToken" ); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.RenameColumn ( newName :"PaypalPaymentId", table: "PayPalPayment", name:"CreationToken" ); + migrationBuilder.RenameTable( newName: "PaypalPayment", name: "PayPalPayment"); + } + } +} diff --git a/Yavsc/Migrations/ApplicationDbContextModelSnapshot.cs b/Yavsc/Migrations/ApplicationDbContextModelSnapshot.cs index 1ddf7af2..ad395ad5 100644 --- a/Yavsc/Migrations/ApplicationDbContextModelSnapshot.cs +++ b/Yavsc/Migrations/ApplicationDbContextModelSnapshot.cs @@ -1,6 +1,8 @@ using System; using Microsoft.Data.Entity; using Microsoft.Data.Entity.Infrastructure; +using Microsoft.Data.Entity.Metadata; +using Microsoft.Data.Entity.Migrations; using Yavsc.Models; namespace Yavsc.Migrations @@ -596,6 +598,8 @@ namespace Yavsc.Migrations b.Property("LocationId"); + b.Property("PaymentId"); + b.Property("PerformerId") .IsRequired(); @@ -863,9 +867,9 @@ namespace Yavsc.Migrations b.HasKey("UserId"); }); - modelBuilder.Entity("Yavsc.Models.Payment.PaypalPayment", b => + modelBuilder.Entity("Yavsc.Models.Payment.PayPalPayment", b => { - b.Property("PaypalPaymentId"); + b.Property("CreationToken"); b.Property("DateCreated"); @@ -884,7 +888,7 @@ namespace Yavsc.Migrations b.Property("UserModified"); - b.HasKey("PaypalPaymentId"); + b.HasKey("CreationToken"); }); modelBuilder.Entity("Yavsc.Models.Relationship.Circle", b => @@ -927,7 +931,7 @@ namespace Yavsc.Migrations b.Property("Method"); - b.Property("PaypalPaymentPaypalPaymentId"); + b.Property("PayPalPaymentCreationToken"); b.Property("Rel"); @@ -1117,6 +1121,8 @@ namespace Yavsc.Migrations b.Property("LocationTypeId"); + b.Property("PaymentId"); + b.Property("PerformerId") .IsRequired(); @@ -1282,7 +1288,7 @@ namespace Yavsc.Migrations .WithMany() .HasForeignKey("LocationId"); - b.HasOne("Yavsc.Models.Payment.PaypalPayment") + b.HasOne("Yavsc.Models.Payment.PayPalPayment") .WithMany() .HasForeignKey("PaymentId"); @@ -1313,6 +1319,10 @@ namespace Yavsc.Migrations .WithMany() .HasForeignKey("LocationId"); + b.HasOne("Yavsc.Models.Payment.PayPalPayment") + .WithMany() + .HasForeignKey("PaymentId"); + b.HasOne("Yavsc.Models.Workflow.PerformerProfile") .WithMany() .HasForeignKey("PerformerId"); @@ -1401,7 +1411,7 @@ namespace Yavsc.Migrations .HasForeignKey("UserId"); }); - modelBuilder.Entity("Yavsc.Models.Payment.PaypalPayment", b => + modelBuilder.Entity("Yavsc.Models.Payment.PayPalPayment", b => { b.HasOne("Yavsc.Models.ApplicationUser") .WithMany() @@ -1435,9 +1445,9 @@ namespace Yavsc.Migrations modelBuilder.Entity("Yavsc.Models.Relationship.Link", b => { - b.HasOne("Yavsc.Models.Payment.PaypalPayment") + b.HasOne("Yavsc.Models.Payment.PayPalPayment") .WithMany() - .HasForeignKey("PaypalPaymentPaypalPaymentId"); + .HasForeignKey("PayPalPaymentCreationToken"); }); modelBuilder.Entity("Yavsc.Models.Relationship.PostTag", b => @@ -1505,6 +1515,10 @@ namespace Yavsc.Migrations .WithMany() .HasForeignKey("LocationTypeId"); + b.HasOne("Yavsc.Models.Payment.PayPalPayment") + .WithMany() + .HasForeignKey("PaymentId"); + b.HasOne("Yavsc.Models.Workflow.PerformerProfile") .WithMany() .HasForeignKey("PerformerId"); diff --git a/Yavsc/Models/ApplicationDbContext.cs b/Yavsc/Models/ApplicationDbContext.cs index d4fd6ec4..a1e0e4ed 100644 --- a/Yavsc/Models/ApplicationDbContext.cs +++ b/Yavsc/Models/ApplicationDbContext.cs @@ -309,7 +309,7 @@ namespace Yavsc.Models public DbSet BankIdentity { get; set; } - public DbSet PaypalPayments { get; set; } + public DbSet PayPalPayments { get; set; } public DbSet Links { get; set; } } diff --git a/Yavsc/Models/Billing/NominativeServiceCommand.cs b/Yavsc/Models/Billing/NominativeServiceCommand.cs index 38713068..e5b9b1e9 100644 --- a/Yavsc/Models/Billing/NominativeServiceCommand.cs +++ b/Yavsc/Models/Billing/NominativeServiceCommand.cs @@ -79,6 +79,6 @@ namespace Yavsc.Models.Billing public string PaymentId { get; set; } [ForeignKey("PaymentId"), Display(Name = "Acquittement de la facture")] - public virtual PaypalPayment Regularisation { get; set; } + public virtual PayPalPayment Regularisation { get; set; } } } diff --git a/Yavsc/Models/HairCut/HairCutQuery.cs b/Yavsc/Models/HairCut/HairCutQuery.cs index 61d18a7d..9a4da247 100644 --- a/Yavsc/Models/HairCut/HairCutQuery.cs +++ b/Yavsc/Models/HairCut/HairCutQuery.cs @@ -4,7 +4,6 @@ using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using Yavsc.Models.Billing; -using Yavsc.Models.Payment; using Yavsc.Models.Relationship; using YavscLib.Billing; @@ -56,10 +55,7 @@ namespace Yavsc.Models.Haircut [DisplayFormat(ConvertEmptyStringToNull = true, NullDisplayText = "[pas d'informations complémentaires]")] public string AdditionalInfo { get; set; } - public string PaymentId { get; set; } - [ForeignKey("PaymentId"), Display(Name = "Acquittement de la facture")] - public virtual PaypalPayment Regularisation { get; set; } public override List GetBillItems() { diff --git a/Yavsc/Models/Payment/PaypalPayment.cs b/Yavsc/Models/Payment/PaypalPayment.cs index ae28ccbd..0af725f3 100644 --- a/Yavsc/Models/Payment/PaypalPayment.cs +++ b/Yavsc/Models/Payment/PaypalPayment.cs @@ -7,10 +7,10 @@ namespace Yavsc.Models.Payment { using YavscLib; using Relationship; - public class PaypalPayment : IBaseTrackedEntity + public class PayPalPayment : IBaseTrackedEntity { [Required,Key] - public string PaypalPaymentId { get; set; } + public string CreationToken { get; set; } [Required] public string ExecutorId { get; set; } diff --git a/Yavsc/Services/IBankInterface.cs b/Yavsc/Services/IBankInterface.cs new file mode 100644 index 00000000..3194d3e5 --- /dev/null +++ b/Yavsc/Services/IBankInterface.cs @@ -0,0 +1,7 @@ +namespace Yavsc.Services +{ + public interface IBankInterface + { + + } +} diff --git a/Yavsc/Settings/PayPalSettings.cs b/Yavsc/Settings/PayPalSettings.cs index 045221b9..88396709 100644 --- a/Yavsc/Settings/PayPalSettings.cs +++ b/Yavsc/Settings/PayPalSettings.cs @@ -1,14 +1,30 @@ namespace Yavsc { + /// + /// PayPal NV/SOAP API Credentials + /// public class PayPalSettings { - + /// + /// supported values: sandbox or production + /// + /// public string Mode { get; set; } - public string Secret { get; set; } + /// + /// + /// public string ClientId { get; set; } + /// + /// For sandbox only? + /// + /// + public string ClientSecret { get; set; } + public string ApplicationId { get; set; } + public class ClassicPayPalAccountApiCredential { + public string Signature { get; set; } + public string ApiUsername { get; set; } + public string ApiPassword { get; set; } - // NV/SOAP Api - Signature - public string UserId { get; set; } - public string Password { get; set; } - public string Signature { get; set; } + } + public ClassicPayPalAccountApiCredential[] Accounts { get; set; } } } diff --git a/Yavsc/Startup/Startup.cs b/Yavsc/Startup/Startup.cs index 4aa35a7b..83321c4e 100755 --- a/Yavsc/Startup/Startup.cs +++ b/Yavsc/Startup/Startup.cs @@ -25,8 +25,11 @@ using Microsoft.Net.Http.Headers; namespace Yavsc { + using System.Net; using Formatters; using Models; + using Newtonsoft.Json; + using PayPal.Manager; using Services; using ViewModels.Auth.Handlers; public partial class Startup @@ -320,6 +323,12 @@ namespace Yavsc else throw ex; } } + // before fixing the security protocol, let beleive our lib it's done with it. + var cxmgr = ConnectionManager.Instance; + // then, fix it. + ServicePointManager.SecurityProtocol = (SecurityProtocolType) 0xC00; + + logger.LogInformation($"ServicePointManager.SecurityProtocol: {ServicePointManager.SecurityProtocol}"); app.UseIISPlatformHandler(options => { @@ -341,6 +350,8 @@ namespace Yavsc template: "{controller=Home}/{action=Index}/{id?}"); }); + logger.LogInformation(JsonConvert.SerializeObject(Startup.PayPalSettings)); + } // Entry point for the application. diff --git a/Yavsc/ViewComponents/PayPalButtonComponent.cs b/Yavsc/ViewComponents/PayPalButtonComponent.cs new file mode 100644 index 00000000..2f207af4 --- /dev/null +++ b/Yavsc/ViewComponents/PayPalButtonComponent.cs @@ -0,0 +1,18 @@ +using Microsoft.AspNet.Mvc; +using Yavsc.Helpers; +using Yavsc.Models.Billing; + +namespace Yavsc.ViewComponents +{ + public class PayPalButtonViewComponent : ViewComponent + { + public IViewComponentResult Invoke(NominativeServiceCommand command, string apiControllerName , string controllerName) + { + ViewBag.CreatePaymentUrl = Request.ToAbsolute($"api/{apiControllerName}/createpayment/"+command.Id); + ViewBag.ExecutePaymentUrl = Request.ToAbsolute("api/payment/execute"); + ViewBag.Urls=Request.GetPaymentUrls(controllerName,command.Id.ToString()); + return View ( command); + } + + } +} diff --git a/Yavsc/ViewModels/PayPal/PaymentInfo.cs b/Yavsc/ViewModels/PayPal/PaymentInfo.cs index b5146024..66611e79 100644 --- a/Yavsc/ViewModels/PayPal/PaymentInfo.cs +++ b/Yavsc/ViewModels/PayPal/PaymentInfo.cs @@ -1,11 +1,14 @@ -using PayPal.Api; + + +using PayPal.PayPalAPIInterfaceService.Model; using Yavsc.Models.Payment; namespace Yavsc.ViewModels.PayPal { public class PaymentInfo { - public PaypalPayment DbContent { get; set; } - public Payment FromPaypal { get; set; } + public PayPalPayment DbContent { get; set; } + + public virtual GetExpressCheckoutDetailsResponseType DetailsFromPayPal { get; set; } } } diff --git a/Yavsc/Views/HairCutCommand/ClientCancel.cshtml b/Yavsc/Views/HairCutCommand/ClientCancel.cshtml index b4fdeb8b..cf1ed280 100644 --- a/Yavsc/Views/HairCutCommand/ClientCancel.cshtml +++ b/Yavsc/Views/HairCutCommand/ClientCancel.cshtml @@ -1,4 +1,7 @@ @model HairCutQuery +@section header { + +} @{ ViewData["Title"] = @SR["Annuler votre commande"]; diff --git a/Yavsc/Views/HairCutCommand/CommandConfirmation.cshtml b/Yavsc/Views/HairCutCommand/CommandConfirmation.cshtml index 50bb0493..c48d68a6 100644 --- a/Yavsc/Views/HairCutCommand/CommandConfirmation.cshtml +++ b/Yavsc/Views/HairCutCommand/CommandConfirmation.cshtml @@ -2,6 +2,10 @@ @{ ViewData["Title"] = SR["Command confirmation"]+" "+ViewBag.Activity.Name; } +@section header { + +} +

@ViewData["Title"]

@SR["Your book query"]

@@ -84,10 +88,9 @@ - -
@Html.DisplayNameFor(m=>m.Regularisation)
-
@Html.DisplayFor(m=>m.Regularisation,new { - PaymentUrl = "/api/haircut/createpayment/"+Model.Id.ToString(), - SuccessUrl = "/HairCutCommand/Details/"+Model.Id.ToString() })
+
@Html.DisplayNameFor(m=>m.Regularisation)
+
@Component.Invoke("PayPalButton", Model, "haircut", "HairCutCommand" ) +
+
diff --git a/Yavsc/Views/HairCutCommand/Details.cshtml b/Yavsc/Views/HairCutCommand/Details.cshtml index 3db3003d..0df3562a 100644 --- a/Yavsc/Views/HairCutCommand/Details.cshtml +++ b/Yavsc/Views/HairCutCommand/Details.cshtml @@ -1,4 +1,7 @@ @model HairCutQuery +@section header { + +} @{ ViewData["Title"] = @SR["Le detail de votre commande de prestation en coiffure à domicile"]; diff --git a/Yavsc/Views/HairCutCommand/HairCut.cshtml b/Yavsc/Views/HairCutCommand/HairCut.cshtml index 95987df1..87c7db21 100644 --- a/Yavsc/Views/HairCutCommand/HairCut.cshtml +++ b/Yavsc/Views/HairCutCommand/HairCut.cshtml @@ -233,7 +233,7 @@ Conditions générales de vente liées à cette commande de service. - + PayPal Acceptance diff --git a/Yavsc/Views/Manage/PaymentError.cshtml b/Yavsc/Views/Manage/PaymentError.cshtml new file mode 100644 index 00000000..28881ce7 --- /dev/null +++ b/Yavsc/Views/Manage/PaymentError.cshtml @@ -0,0 +1,8 @@ + + +
+
Le paiment @ViewData["id"] a échoué +
+
@ViewData["error"] +
+
\ No newline at end of file diff --git a/Yavsc/Views/Manage/PaymentInfo.cshtml b/Yavsc/Views/Manage/PaymentInfo.cshtml deleted file mode 100644 index 4669b13e..00000000 --- a/Yavsc/Views/Manage/PaymentInfo.cshtml +++ /dev/null @@ -1,20 +0,0 @@ -@using PayPal.Api -@model Payment - -
-
État du paiment -
-
@SR[Model.state] @Model.failure_reason -
-
-
-
@Model.payment_instruction -
-
-@if (Model.state=="created") { - Autoriser le paiement -} -@{ var refundUrl = Model.GetHateoasLink("refund"); } -@if (refundUrl!=null) { - Rembourser ce paiement -} \ No newline at end of file diff --git a/Yavsc/Views/Shared/Components/PayPalButton/Default.cshtml b/Yavsc/Views/Shared/Components/PayPalButton/Default.cshtml new file mode 100644 index 00000000..9848413d --- /dev/null +++ b/Yavsc/Views/Shared/Components/PayPalButton/Default.cshtml @@ -0,0 +1,43 @@ +@model NominativeServiceCommand +@inject IOptions PayPalSettings +@Model.PaymentId +@if (Model!=null && Model.PaymentId!=null) { + + @if (Model.Regularisation.Executor.Id == User.GetUserId()) { + + Votre paiment + + } else { + + Le paiment de @Html.DisplayFor(m=>m.Regularisation.Executor.UserName) + + } + : + @Model.Regularisation.PaypalPaymentId + +} else { +
+ +} diff --git a/Yavsc/Views/Shared/DisplayTemplates/HairCutQuery.cshtml b/Yavsc/Views/Shared/DisplayTemplates/HairCutQuery.cshtml index 1d6e9307..02d62a60 100644 --- a/Yavsc/Views/Shared/DisplayTemplates/HairCutQuery.cshtml +++ b/Yavsc/Views/Shared/DisplayTemplates/HairCutQuery.cshtml @@ -21,7 +21,8 @@
@Html.DisplayFor(m=>m.AdditionalInfo)
@Html.DisplayNameFor(m=>m.Regularisation)
-
@Html.DisplayFor(m=>m.Regularisation) +
+ @Component.Invoke("PayPalButton", Model, "haircut", "HairCutCommand" )
diff --git a/Yavsc/Views/Shared/DisplayTemplates/PaypalPayment.cshtml b/Yavsc/Views/Shared/DisplayTemplates/PaypalPayment.cshtml deleted file mode 100644 index 3aa4aa73..00000000 --- a/Yavsc/Views/Shared/DisplayTemplates/PaypalPayment.cshtml +++ /dev/null @@ -1,55 +0,0 @@ -@model PaypalPayment -@inject IOptions PayPalSettings -@if (Model!=null && Model.PaypalPaymentId!=null) { - - @if (Model.Executor.Id == User.GetUserId()) { - - Votre paiment - - } else { - - Le paiment de @Html.DisplayFor(m=>m.Executor.UserName) - - } - : - @Model.PaypalPaymentId - -} else { - -
- - - -} \ No newline at end of file diff --git a/Yavsc/gulpfile.js b/Yavsc/gulpfile.js index e68de750..965faa1b 100755 --- a/Yavsc/gulpfile.js +++ b/Yavsc/gulpfile.js @@ -2,31 +2,31 @@ "use strict"; var gulp = require("gulp"), - rimraf = require("rimraf"), -// concat = require("gulp-concat"), - cssmin = require("gulp-cssmin"), - uglify = require("gulp-uglify"), - shell = require("gulp-shell"), - rename = require('gulp-rename'); + rimraf = require("rimraf"), + // concat = require("gulp-concat"), + cssmin = require("gulp-cssmin"), + uglify = require("gulp-uglify"), + shell = require("gulp-shell"), + rename = require('gulp-rename'); var webroot = "./wwwroot/"; var paths = { - bower: "./bower_components/", - js: webroot + "js/**/*.js", - minJs: webroot + "js/**/*.min.js", - css: webroot + "css/**/*.css", - minCss: webroot + "css/**/*.min.css", - concatJsDest: webroot + "js/site.min.js", - concatCssDest: webroot + "css/site.min.css" + bower: "./bower_components/", + js: webroot + "js/**/*.js", + minJs: webroot + "js/**/*.min.js", + css: webroot + "css/**/*.css", + minCss: webroot + "css/**/*.min.css", + concatJsDest: webroot + "js/site.min.js", + concatCssDest: webroot + "css/site.min.css" }; -gulp.task("clean:js", function (cb) { - rimraf(paths.concatJsDest, cb); +gulp.task("clean:js", function(cb) { + rimraf(paths.concatJsDest, cb); }); -gulp.task("clean:css", function (cb) { - rimraf(paths.concatCssDest, cb); +gulp.task("clean:css", function(cb) { + rimraf(paths.concatCssDest, cb); }); gulp.task("clean", ["clean:js", "clean:css"]); @@ -34,21 +34,20 @@ gulp.task("clean", ["clean:js", "clean:css"]); gulp.task('watch', shell.task(['ASPNET_ENV=Development dnx-watch web --configuration=Debug'])); -gulp.task('watchlua', shell.task(['ASPNET_ENV=Lua dnx-watch luatest --configuration=Debug'])); +gulp.task('watchlua', shell.task(['ASPNET_ENV=lua dnx-watch luatest --configuration=Debug'])); +gulp.task('watchpre', shell.task(['ASPNET_ENV=yavscpre dnx-watch web --configuration=Debug'])); - - -gulp.task("min:css", function () { +gulp.task("min:css", function() { gulp.src([paths.css, "!" + paths.minCss, '!site.css']) .pipe(cssmin()) - .pipe(rename({suffix: '.min'})) + .pipe(rename({ suffix: '.min' })) .pipe(gulp.dest('wwwroot/css')); }); -gulp.task("min:js", function () { - return gulp.src([paths.js, "!" + paths.minJs, '!site.js']) - .pipe(uglify()) - .pipe(rename({suffix: '.min'})) +gulp.task("min:js", function() { + return gulp.src([paths.js, "!" + paths.minJs, '!site.js']) + .pipe(uglify()) + .pipe(rename({ suffix: '.min' })) .pipe(gulp.dest('wwwroot/js')); }); @@ -60,5 +59,4 @@ gulp.task('buildrelease', shell.task(['dnu build --configuration=Release'])); gulp.task('publish', shell.task(['dnu publish --configuration=Release'])); gulp.task('postpublish', shell.task(['contrib/rsync-to-pre.sh'])); -gulp.task("default", ["watch"]); - +gulp.task("default", ["watch"]); \ No newline at end of file diff --git a/Yavsc/project.json b/Yavsc/project.json index 516413a0..776afbca 100755 --- a/Yavsc/project.json +++ b/Yavsc/project.json @@ -107,7 +107,6 @@ "Microsoft.AspNet.DataProtection": "1.0.0-rc1-final", "Microsoft.AspNet.DataProtection.SystemWeb": "1.0.0-rc1-final", "Microsoft.AspNet.Authentication.JwtBearer": "1.0.0-rc1-final", - "PayPalCoreSDK": "1.7.1", "Microsoft.AspNet.Authentication.OAuth": "1.0.0-rc1-final", "Microsoft.AspNet.Mvc.Formatters.Json": "6.0.0-rc1-final", "Microsoft.AspNet.OWin": "1.0.0-rc1-final", @@ -119,7 +118,7 @@ "Extensions.AspNet.Authentication.Instagram": "1.0.0-t150809211713", "Microsoft.AspNet.Http.Extensions": "1.0.0-rc1-final", "Microsoft.DiaSymReader.Native": "1.5.0", - "PayPal": "1.8.0" + "MyPayPalMerchantSDK": "1.0.0" }, "commands": { "web": "Microsoft.AspNet.Server.Kestrel --server.urls http://*:5000", diff --git a/Yavsc/project.lock.json b/Yavsc/project.lock.json index 20dcbf36..5937d0f6 100644 --- a/Yavsc/project.lock.json +++ b/Yavsc/project.lock.json @@ -2514,6 +2514,18 @@ "lib/net451/MimeKit.dll": {} } }, + "MyPayPalMerchantSDK/1.0.0": { + "type": "package", + "dependencies": { + "PayPalCoreSDK": "1.7.1" + }, + "compile": { + "lib/net451/PayPalMerchantSDK.dll": {} + }, + "runtime": { + "lib/net451/PayPalMerchantSDK.dll": {} + } + }, "Newtonsoft.Json/10.0.2": { "type": "package", "compile": { @@ -2547,18 +2559,6 @@ "lib/net40/Owin.dll": {} } }, - "PayPal/1.8.0": { - "type": "package", - "dependencies": { - "Newtonsoft.Json": "7.0.1" - }, - "compile": { - "lib/net451/PayPal.dll": {} - }, - "runtime": { - "lib/net451/PayPal.dll": {} - } - }, "PayPalCoreSDK/1.7.1": { "type": "package", "dependencies": { @@ -5383,6 +5383,18 @@ "lib/net451/MimeKit.dll": {} } }, + "MyPayPalMerchantSDK/1.0.0": { + "type": "package", + "dependencies": { + "PayPalCoreSDK": "1.7.1" + }, + "compile": { + "lib/net451/PayPalMerchantSDK.dll": {} + }, + "runtime": { + "lib/net451/PayPalMerchantSDK.dll": {} + } + }, "Newtonsoft.Json/10.0.2": { "type": "package", "compile": { @@ -5416,18 +5428,6 @@ "lib/net40/Owin.dll": {} } }, - "PayPal/1.8.0": { - "type": "package", - "dependencies": { - "Newtonsoft.Json": "7.0.1" - }, - "compile": { - "lib/net451/PayPal.dll": {} - }, - "runtime": { - "lib/net451/PayPal.dll": {} - } - }, "PayPalCoreSDK/1.7.1": { "type": "package", "dependencies": { @@ -8252,6 +8252,18 @@ "lib/net451/MimeKit.dll": {} } }, + "MyPayPalMerchantSDK/1.0.0": { + "type": "package", + "dependencies": { + "PayPalCoreSDK": "1.7.1" + }, + "compile": { + "lib/net451/PayPalMerchantSDK.dll": {} + }, + "runtime": { + "lib/net451/PayPalMerchantSDK.dll": {} + } + }, "Newtonsoft.Json/10.0.2": { "type": "package", "compile": { @@ -8285,18 +8297,6 @@ "lib/net40/Owin.dll": {} } }, - "PayPal/1.8.0": { - "type": "package", - "dependencies": { - "Newtonsoft.Json": "7.0.1" - }, - "compile": { - "lib/net451/PayPal.dll": {} - }, - "runtime": { - "lib/net451/PayPal.dll": {} - } - }, "PayPalCoreSDK/1.7.1": { "type": "package", "dependencies": { @@ -10632,6 +10632,16 @@ "MimeKit.nuspec" ] }, + "MyPayPalMerchantSDK/1.0.0": { + "type": "package", + "sha512": "T/4NVweMlULqGurtG0EuXE2WebtMiD4M0QPpJxx/AAHS33eJiXjWb/CZRcEvJKE9REgWctK7RALuMQqzPt9DEg==", + "files": [ + "lib/net451/PayPalMerchantSDK.dll", + "MyPayPalMerchantSDK.1.0.0.nupkg", + "MyPayPalMerchantSDK.1.0.0.nupkg.sha512", + "MyPayPalMerchantSDK.nuspec" + ] + }, "Newtonsoft.Json/10.0.2": { "type": "package", "sha512": "iwElSU2IXmwGvytJsezyDML2ZWDkG2JzTYzlU/BNlmzMdlmRvbnwITsGGY74gwVEpDli1UdOLkMT7/3jxWvXzA==", @@ -10689,21 +10699,6 @@ "Owin.nuspec" ] }, - "PayPal/1.8.0": { - "type": "package", - "sha512": "r59EIEePqy0yLRbGgJ1Ul86rXGtogC/8ofn9qTdKozN/CsTsotxGZMCzzDIFgnZRAm3zO6xz8tZGAWmKxDFX/Q==", - "files": [ - "lib/net40/PayPal.dll", - "lib/net40/PayPal.xml", - "lib/net45/PayPal.dll", - "lib/net45/PayPal.xml", - "lib/net451/PayPal.dll", - "lib/net451/PayPal.xml", - "PayPal.1.8.0.nupkg", - "PayPal.1.8.0.nupkg.sha512", - "PayPal.nuspec" - ] - }, "PayPalCoreSDK/1.7.1": { "type": "package", "sha512": "hGOLo3X2vgOpOWJI91+vlBgr/Dchk3xZAF0bdIpKiAwjlRKMjzSC4zuT1eGwmQ8uVL1IaGBZwNGklyRHDniYlQ==", @@ -11623,7 +11618,6 @@ "Microsoft.AspNet.DataProtection >= 1.0.0-rc1-final", "Microsoft.AspNet.DataProtection.SystemWeb >= 1.0.0-rc1-final", "Microsoft.AspNet.Authentication.JwtBearer >= 1.0.0-rc1-final", - "PayPalCoreSDK >= 1.7.1", "Microsoft.AspNet.Authentication.OAuth >= 1.0.0-rc1-final", "Microsoft.AspNet.Mvc.Formatters.Json >= 6.0.0-rc1-final", "Microsoft.AspNet.OWin >= 1.0.0-rc1-final", @@ -11632,7 +11626,7 @@ "Extensions.AspNet.Authentication.Instagram >= 1.0.0-t150809211713", "Microsoft.AspNet.Http.Extensions >= 1.0.0-rc1-final", "Microsoft.DiaSymReader.Native >= 1.5.0", - "PayPal >= 1.8.0" + "MyPayPalMerchantSDK >= 1.0.0" ], "DNX,Version=v4.5.1": [ "fx/System.Drawing >= 4.0.0", diff --git a/Yavsc/wwwroot/images/haircut/coiffure.svg b/Yavsc/wwwroot/images/haircut/coiffure.svg new file mode 100644 index 00000000..8dee8c53 --- /dev/null +++ b/Yavsc/wwwroot/images/haircut/coiffure.svg @@ -0,0 +1,167 @@ + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Yavsc/wwwroot/js/paypalbutton.js b/Yavsc/wwwroot/js/paypalbutton.js new file mode 100644 index 00000000..40724134 --- /dev/null +++ b/Yavsc/wwwroot/js/paypalbutton.js @@ -0,0 +1,33 @@ ++(function($, paypal, PAYPAL_ENV, CREATE_PAYMENT_URL, EXECUTE_PAYMENT_URL) { + $(document).ready(function() { + + paypal.Button.render({ + + env: PAYPAL_ENV, // 'production', Optional: specify 'sandbox' environment + commit: true, + payment: function(resolve, reject) { + + return paypal.request.post(CREATE_PAYMENT_URL) + .then(function(data) { resolve(data.id); }) + .catch(function(err) { reject(err); }); + }, + + onAuthorize: function(data) { + + // Note: you can display a confirmation page before executing + + return paypal.request.post(EXECUTE_PAYMENT_URL, { paymentID: data.paymentID, payerID: data.payerID }) + + .then(function(data) { + document.location = '@ViewBag.Urls.Details'; + /* Go to a success page */ + }) + .catch(function(err) { + document.location = '/Manage/PaymentInfo/' + data.paymentID + '/?error=' + err; + /* Go to an error page */ + }); + } + + }, '#paypal-button'); + }) +})(jQuery); \ No newline at end of file diff --git a/Yavsc/wwwroot/js/paypalbutton.min.js b/Yavsc/wwwroot/js/paypalbutton.min.js new file mode 100644 index 00000000..0a4d2040 --- /dev/null +++ b/Yavsc/wwwroot/js/paypalbutton.min.js @@ -0,0 +1 @@ ++function(n,t,e,o,u){n(document).ready(function(){t.Button.render({env:e,commit:!0,payment:function(n,e){return t.request.post(o).then(function(t){n(t.id)})["catch"](function(n){e(n)})},onAuthorize:function(n){return t.request.post(u,{paymentID:n.paymentID,payerID:n.payerID}).then(function(n){document.location="@ViewBag.Urls.Details"})["catch"](function(t){document.location="/Manage/PaymentInfo/"+n.paymentID+"/?error="+t})}},"#paypal-button")})}(jQuery); \ No newline at end of file