This commit is contained in:
Paul Schneider 2017-05-12 12:15:57 +02:00
commit 42c08797e3
44 changed files with 2798 additions and 350 deletions

View file

@ -14,6 +14,9 @@ namespace Yavsc.ApiControllers
using Services;
using Yavsc.Models.Haircut;
using Yavsc.Resources;
using System.Threading.Tasks;
using Yavsc.Helpers;
using Microsoft.Data.Entity;
[Route("api/haircut")]
public class HairCutController : Controller
@ -28,6 +31,7 @@ namespace Yavsc.ApiControllers
private SmtpSettings _smtpSettings;
private UserManager<ApplicationUser> _userManager;
PayPalSettings _paymentSettings;
public HairCutController(ApplicationDbContext context,
IOptions<GoogleAuthSettings> googleSettings,
IGoogleCloudMessageSender GCMSender,
@ -36,6 +40,7 @@ namespace Yavsc.ApiControllers
IEmailSender emailSender,
IOptions<SmtpSettings> smtpSettings,
IOptions<SiteSettings> siteSettings,
IOptions<PayPalSettings> payPalSettings,
ILoggerFactory loggerFactory)
{
_context = context;
@ -45,6 +50,7 @@ namespace Yavsc.ApiControllers
_userManager = userManager;
_smtpSettings = smtpSettings.Value;
_siteSettings = siteSettings.Value;
_paymentSettings = payPalSettings.Value;
_localizer = localizer;
_logger = loggerFactory.CreateLogger<HairCutController>();
}
@ -76,5 +82,14 @@ namespace Yavsc.ApiControllers
return Ok();
}
[HttpPost("createpayment/{id}")]
public async Task<IActionResult> CreatePayment(long id)
{
var apiContext = _paymentSettings.CreateAPIContext();
var query = await _context.HairCutQueries.Include(q=>q.Client).
Include(q=>q.Client.PostalAddress).SingleAsync(q=>q.Id == id);
var payment = apiContext.CreatePaiment(query,"sale",_logger);
return Json(payment);
}
}
}

View file

@ -1,12 +1,12 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNet.Mvc;
using Microsoft.Data.Entity;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.OptionsModel;
using PayPal.Api;
using Yavsc.Helpers;
using Yavsc.Models;
using Yavsc.ViewModels.PayPal;
namespace Yavsc.ApiControllers
{
@ -29,7 +29,19 @@ namespace Yavsc.ApiControllers
_logger = loggerFactory.CreateLogger<PaymentApiController>();
}
public async Task<IActionResult> Info(string paymentId)
{
var result = new PaymentInfo {
DbContent = await dbContext.PaypalPayments.SingleAsync(
p=>p.PaypalPaymentId==paymentId)
};
await Task.Run( () => {
var apiContext = paymentSettings.CreateAPIContext();
result.FromPaypal = Payment.Get(apiContext,paymentId);
});
return Ok(result);
}
[HttpPost("execute")]
public async Task<IActionResult> Execute(string paymentId, string payerId)
@ -43,63 +55,12 @@ namespace Yavsc.ApiControllers
execution.transactions = payment.transactions;
result = payment.Execute(apiContext,execution);
});
return Ok(result);
}
[HttpPost("create")]
public async Task<IActionResult> Create()
{
var apiContext = paymentSettings.CreateAPIContext();
var payment = Payment.Create(apiContext,
new Payment
{
intent = "authorize", // "sale", "order", "authorize"
payer = new Payer
{
payment_method = "paypal"
},
transactions = new List<Transaction>
{
new Transaction
{
description = "Transaction description.",
invoice_number = "001",
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<Item>
{
new Item
{
name = "nah",
currency = "EUR",
price = "0.02",
quantity = "4",
sku = "sku"
}
}
}
}
},
redirect_urls = new RedirectUrls
{
return_url = siteSettings.Audience+ "/Manage/Credit/Return",
cancel_url = siteSettings.Audience+ "/Manage/Credit/Cancel"
}
});
return Json(payment);
}
}
}