Plus de clarté à l'erreur

main
Paul Schneider 9 years ago
parent 7b33a83298
commit a78c7c58e4
1 changed files with 15 additions and 3 deletions

@ -2,6 +2,8 @@ using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Mvc; using Microsoft.AspNet.Mvc;
using Microsoft.Extensions.OptionsModel; using Microsoft.Extensions.OptionsModel;
using Microsoft.Extensions.Localization; using Microsoft.Extensions.Localization;
using PayPal.Api;
namespace Yavsc.ApiControllers namespace Yavsc.ApiControllers
{ {
@ -19,6 +21,7 @@ namespace Yavsc.ApiControllers
using Microsoft.Data.Entity; using Microsoft.Data.Entity;
using Models.Payment; using Models.Payment;
using Models.Relationship; using Models.Relationship;
using Newtonsoft.Json;
[Route("api/haircut")] [Route("api/haircut")]
public class HairCutController : Controller public class HairCutController : Controller
@ -88,15 +91,24 @@ namespace Yavsc.ApiControllers
[HttpPost("createpayment/{id}")] [HttpPost("createpayment/{id}")]
public async Task<IActionResult> CreatePayment(long id) public async Task<IActionResult> CreatePayment(long id)
{ {
var apiContext = PayPalHelpers.CreateAPIContext(); APIContext apiContext = null;
HairCutQuery query = await _context.HairCutQueries.Include(q => q.Client).
var query = await _context.HairCutQueries.Include(q => q.Client).
Include(q => q.Client.PostalAddress).Include(q => q.Prestation).Include(q=>q.Regularisation) Include(q => q.Client.PostalAddress).Include(q => q.Prestation).Include(q=>q.Regularisation)
.SingleAsync(q => q.Id == id); .SingleAsync(q => q.Id == id);
if (query.PaymentId!=null) if (query.PaymentId!=null)
return new BadRequestObjectResult(new { error = "An existing payment process already exists" }); return new BadRequestObjectResult(new { error = "An existing payment process already exists" });
query.SelectedProfile = _context.BrusherProfile.Single(p => p.UserId == query.PerformerId); query.SelectedProfile = _context.BrusherProfile.Single(p => p.UserId == query.PerformerId);
try {
apiContext = PayPalHelpers.CreateAPIContext();
}
catch (PayPal.IdentityException ex) {
_logger.LogError(ex.Response);
}
if (apiContext==null) {
_logger.LogError(JsonConvert.SerializeObject(Startup.PayPalSettings));
throw new Exception("No PayPal Api context");
}
var payment = Request.CreatePayment("HairCutCommand",apiContext, query, "sale", _logger); var payment = Request.CreatePayment("HairCutCommand",apiContext, query, "sale", _logger);
switch (payment.state) switch (payment.state)
{ {

Loading…