Building successfull urls

This commit is contained in:
2017-05-16 02:16:09 +02:00
parent 3ea7f3e933
commit 60c81070c0
10 changed files with 51 additions and 37 deletions

View File

@ -95,8 +95,7 @@ namespace Yavsc.ApiControllers
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);
var payment = apiContext.CreatePayment(query, "HairCutCommand", "sale", _logger);
var payment = Request.CreatePayment("HairCutCommand",apiContext, query, "sale", _logger);
switch (payment.state)
{
case "created":

View File

@ -65,7 +65,7 @@ namespace Yavsc.ApiControllers
public IActionResult Create()
{
var apiContext = paymentSettings.CreateAPIContext();
Payment result=apiContext.CreatePayment(new Estimate());
Payment result= Request.CreatePayment("Command",apiContext,new Estimate());
return Ok(Payment.Create(apiContext,result));
}

View File

@ -106,7 +106,9 @@ 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());
return View(command);
}

View File

@ -76,11 +76,7 @@ namespace Yavsc.Controllers
.Include(a=>a.Forms).Include(a=>a.Children)
.Where(a=>!a.Hidden)
.Where(a=> a.ParentCode==id).OrderByDescending(a=>a.Rate));
}
}
public IActionResult About()
{

View File

@ -1,4 +1,5 @@
using System;
using Microsoft.AspNet.Http;
using Microsoft.AspNet.Mvc.Rendering;
using Yavsc.Models.Drawing;
@ -11,5 +12,11 @@ namespace Yavsc.Helpers
if (c==null) return new HtmlString("#000");
return new HtmlString(String.Format("#{0:X2}{1:X2}{2:X2}", c.Red, c.Green, c.Blue));
}
public static string ToAbsolute(this HttpRequest request, string url)
{
var host = request.Host;
var isSecure = request.Headers[Constants.SshHeaderKey]=="on";
return (isSecure ? "https" : "http") + $"://{host}/{url}";
}
}
}
}

View File

@ -1,8 +1,10 @@
using System.Collections.Generic;
using Microsoft.Extensions.Logging;
using PayPal.Api;
using PayPal.Exception;
using Yavsc.Models.Billing;
using Microsoft.AspNet.Http;
namespace Yavsc.Helpers
{
@ -18,8 +20,20 @@ namespace Yavsc.Helpers
var apiContext = new APIContext(accessToken);
return apiContext;
}
public class PaymentUrls {
public string Details { get; set; }
public string Cancel { get; set; }
}
public static PaymentUrls GetPaymentUrls(this HttpRequest request, string controllerName, string id )
{
var result =new PaymentUrls {
Details = request.ToAbsolute($"{controllerName}/Details/{id}") ,
Cancel = request.ToAbsolute($"{controllerName}/ClientCancel/{id}")
};
return result;
}
public static Payment CreatePayment(this APIContext apiContext, NominativeServiceCommand query, string controllerName, string intent = "sale", ILogger logger=null)
public static Payment CreatePayment(this HttpRequest request, string controllerName, APIContext apiContext, NominativeServiceCommand query, string intent = "sale", ILogger logger=null)
{
var queryType = query.GetType().Name;
var transaction = new Transaction
@ -28,7 +42,10 @@ namespace Yavsc.Helpers
invoice_number = query.Id.ToString(),
custom = query.GetType().Name + "/"+ query.Id.ToString()
};
transaction.order_url = Startup.Audience + "/" +controllerName + "/Details/" + query.Id;
var urls = request.GetPaymentUrls(controllerName, query.Id.ToString() );
transaction.order_url = urls.Details;
// transaction.item_list.shipping_address.city
// country_code default_address id
@ -78,8 +95,8 @@ namespace Yavsc.Helpers
transactions = new List<Transaction> { transaction },
redirect_urls = new RedirectUrls
{
return_url = Startup.Audience+ $"/{controllerName}/Details/"+query.Id.ToString(),
cancel_url = Startup.Audience+ $"/{controllerName}/ClientCancel/"+query.Id.ToString()
return_url = urls.Details,
cancel_url = urls.Cancel
}
};
Payment result = null;
@ -92,8 +109,9 @@ namespace Yavsc.Helpers
return result;
}
public static Payment CreatePayment(this APIContext apiContext, Estimate estimation)
public static Payment CreatePayment(this HttpRequest request, string controllerName, APIContext apiContext, Estimate estimation)
{
var urls = request.GetPaymentUrls( controllerName, estimation.Id.ToString() );
var payment = Payment.Create(apiContext,
new Payment
{
@ -137,10 +155,11 @@ namespace Yavsc.Helpers
},
redirect_urls = new RedirectUrls
{
return_url = Startup.Audience+ "/Manage/Credit/Return",
cancel_url = Startup.Audience+ "/Manage/Credit/Cancel"
return_url = urls.Details,
cancel_url = urls.Cancel
}
});
return payment;
}
}

View File

@ -21,10 +21,8 @@
<dd>@Html.DisplayFor(m=>m.AdditionalInfo)
</dd>
<dt>@Html.DisplayNameFor(m=>m.Regularisation)</dt>
<dd>@Html.DisplayFor(m=>m.Regularisation,new {
PaymentUrl = "/api/haircut/createpayment/"+Model.Id.ToString(),
SuccessUrl = "/HairCutCommand/Details/"+Model.Id.ToString()
})</dd>
<dd>@Html.DisplayFor(m=>m.Regularisation)
</dd>
</dl>

View File

@ -1,5 +1,5 @@
@model PaypalPayment
@inject IOptions<PayPalSettings> PayPalSettings
@if (Model!=null && Model.PaypalPaymentId!=null) {
@if (Model.Executor.Id == User.GetUserId()) {
@ -18,21 +18,11 @@
<div id="paypal-button"></div>
<script src="https://www.paypalobjects.com/api/checkout.js"></script>
<environement names="lua,coiffure,zicmoove,yavsc,yavscpre">
<script>
var CREATE_PAYMENT_URL = '@(ViewData["PaymentUrl"])';
var EXECUTE_PAYMENT_URL = '@(SiteSettings.Value.Audience)/api/payment/execute';
var PAYPAL_ENV = 'production';
</script>
</environement>
<environement names="Development">
<script>
var CREATE_PAYMENT_URL = '@(ViewData["PaymentUrl"])';
var EXECUTE_PAYMENT_URL = '@(SiteSettings.Value.Audience)/api/payment/execute';
var PAYPAL_ENV = 'sandbox';
</script>
</environement>
<script>
var CREATE_PAYMENT_URL = '@ViewBag.CreatePaymentUrl';
var EXECUTE_PAYMENT_URL = '@ViewBag.ExecutePaymentUrl';
var PAYPAL_ENV = '@PayPalSettings.Value.Mode';
paypal.Button.render({
env: PAYPAL_ENV, // 'production', Optional: specify 'sandbox' environment
@ -52,7 +42,7 @@
{ paymentID: data.paymentID, payerID: data.payerID })
.then(function(data) {
document.location = '@(ViewData["SuccessUrl"])';
document.location = '@ViewBag.Urls.Details';
/* Go to a success page */ })
.catch(function(err) {
document.location = '/Manage/PaymentInfo/'+data.paymentID;

View File

@ -32,6 +32,8 @@
@using Yavsc.ViewModels.Relationship;
@using Yavsc.ViewModels.Workflow;
@using Yavsc.ViewModels.Blogspot;
@using Microsoft.AspNet.Hosting;
@using Microsoft.Extensions.PlatformAbstractions;
@inject IViewLocalizer LocString
@addTagHelper "*, Microsoft.AspNet.Mvc.TagHelpers"
@ -41,3 +43,4 @@
@inject IAuthorizationService AuthorizationService
@inject IOptions<GoogleAuthSettings> GoogleSettings
@inject IOptions<SiteSettings> SiteSettings
@inject IHostingEnvironment HostingEnvironment

View File

@ -1 +1 @@
.discussion,.notif,.pv{font-family:monospace}.smalltofhol,tr.visiblepost,tr.visiblepost img{max-height:3em}.blog a:active,.blog a:hover,a:active,a:hover{outline:0}#discussion,.blogphoto{float:left}.badge img{height:2em}.performer{padding-left:1em;background-repeat:no-repeat;background-image:url(/images/lis.svg);background-attachment:local;background-size:contain}.performer ul{margin-left:2.5em}.smalltofhol{max-width:3em;float:left;margin:.5em}.price,.total{font-weight:700;padding:.2em;margin:.2em}.price{font-size:x-large}.total{font-size:xx-large;background-color:#f8f;border:3px solid #000;border-radius:1em}.blog,.panel{padding:1em}.blog a{font-weight:900}.discussion{color:#000}.notif{color:#006}.pv{color:#251;font-style:bold}#targets{display:block}tr.hiddenpost{max-height:2em;background-color:#888;font-size:smaller}tr.hiddenpost img{max-height:3em}a.bloglink{font-weight:700;text-shadow:0 0 8px #000}a{font-weight:900}.panel{display:inline-block;margin:1em;color:#000;background-color:inherit;border:1px solid #000}button,input,select,textarea{background-color:#bbb;color:#000}.jumbotron{padding:.5em}.carousel .item .btn{-webkit-transition:-webkit-transform 2s;transition:transform 2s background-color 1s color 1s;transform:scale3d(0,0,0);-webkit-transform:scale3d(0,0,0)}.carousel .active .btn{-webkit-transform:inherit;transform:inherit}.container{-webkit-transition:background-color 2s color 1s;-moz-transition:background-color 2s color 1s;transition:background-color 2s color 1s}.disabled{color:#999;background-color:#555}.carousel-caption-s p{-webkit-text-shadow:3px 3px 7px #000;margin:.5em;padding:.5em;animation:mymove 4s infinite;font-family:Arial;font-weight:800;font-size:x-large;text-shadow:3px 3px 7px #000;color:#fff}.carousel-caption-s{right:3em;top:1em;left:3em;z-index:10;padding-top:20px;padding-bottom:20px;text-align:center;min-height:16em;overflow:auto}.carousel-inner .item{padding-left:15%;padding-right:15%}.carousel-indicators{position:absolute;z-index:15;padding:0;text-align:center;list-style:none;top:.1em;height:1em}main.container{padding-right:1em;padding-left:1em;margin-left:1em;margin-right:1em}@media (max-width:767px){main.container{padding-right:.3em;padding-left:.3em;margin-left:.3em;margin-right:.3em}.navbar-brand{float:left;height:50px;padding:5px;font-size:16px;line-height:18px}.carousel-caption-s p{margin:.2em;padding:.2em}}@-webkit-keyframes mymove{from,to{text-decoration-color:red}50%{text-decoration-color:#00f}}@keyframes mymove{from,to{text-decoration-color:red}50%{text-decoration-color:#00f}}ul.actiongroup li{display:inline}ul.actiongroup li a:hover{background-color:rgba(200,200,200,.6);color:#400}footer{vertical-align:bottom;padding:1.5em}.display-field{font-kerning:none;display:inline-flex;color:#008}.display-label{font-family:'Lucida Sans','Lucida Sans Regular','Lucida Grande','Lucida Sans Unicode',Geneva,Verdana,sans-serif;font-stretch:condensed;display:inline-flex;color:#ff8;padding:.1em;border-radius:.5em;background-color:#210912}footer{color:grey;font-weight:bolder;font-size:x-small}.meta{color:#444;font-style:italic;font-size:smaller}.activity{font-family:fantasy}.blogtitle{display:inline-block;font-size:x-large}.blogphoto{margin:1em}.dl-horizontal dd{margin-left:20%}
.discussion,.notif,.pv{font-family:monospace}.smalltofhol,tr.visiblepost,tr.visiblepost img{max-height:3em}.blog a:active,.blog a:hover,a:active,a:hover{outline:0}#discussion,.blogphoto{float:left}.badge img{height:2em}.performer{padding-left:1em;background-repeat:no-repeat;background-image:url(/images/lis.svg);background-attachment:local;background-size:contain}.performer ul{margin-left:2.5em}.smalltofhol{max-width:3em;float:left;margin:.5em}.price,.total{font-weight:700;padding:.2em;margin:.2em}.price{font-size:large}.total{font-size:xx-large;background-color:#f8f;border:3px solid #000;border-radius:1em}.blog,.panel{padding:1em}.blog a{font-weight:900}.discussion{color:#000}.notif{color:#006}.pv{color:#251;font-style:bold}#targets{display:block}tr.hiddenpost{max-height:2em;background-color:#888;font-size:smaller}tr.hiddenpost img{max-height:3em}a.bloglink{font-weight:700;text-shadow:0 0 8px #000}a{font-weight:900}.panel{display:inline-block;margin:1em;color:#000;background-color:inherit;border:1px solid #000}button,input,select,textarea{background-color:#bbb;color:#000}.jumbotron{padding:.5em}.carousel .item .btn{-webkit-transition:-webkit-transform 2s background-color 1s color 1s;-moz-transition:transform 2s background-color 2s color 2s;transition:transform 2s;transform:scale3d(0,0,0);-webkit-transform:scale3d(0,0,0)}.carousel .active .btn{-webkit-transform:inherit;transform:inherit}.disabled{color:#999;background-color:#555}.carousel-caption-s p{-webkit-text-shadow:3px 3px 7px #000;animation:mymove 4s infinite;font-family:Arial;font-weight:800;font-size:x-large;text-shadow:3px 3px 7px #00003c;color:#fff;background-color:rgba(94,24,194,.15);border-radius:.5em}.carousel-caption-s{right:3em;top:1em;left:3em;z-index:10;padding-top:20px;padding-bottom:20px;text-align:center;min-height:16em;overflow:auto}.carousel-inner .item{padding-left:15%;padding-right:15%}.carousel-indicators{position:absolute;z-index:15;padding:0;text-align:center;list-style:none;top:.1em;height:1em}main.container{padding-right:1em;padding-left:1em;margin-left:1em;margin-right:1em}@media (max-width:767px){main.container{padding-right:.3em;padding-left:.3em;margin-left:.3em;margin-right:.3em}.navbar-brand{float:left;height:50px;padding:5px;font-size:16px;line-height:18px}.carousel-caption-s p{margin:.2em;padding:.2em}}@-webkit-keyframes mymove{from,to{text-decoration-color:red}50%{text-decoration-color:#00f}}@keyframes mymove{from,to{text-decoration-color:red}50%{text-decoration-color:#00f}}ul.actiongroup li{display:inline}ul.actiongroup li a:hover{background-color:rgba(200,200,200,.6);color:#400}footer{vertical-align:bottom;padding:1.5em}.display-field{font-kerning:none;display:inline-flex;color:#008}.display-label{font-family:'Lucida Sans','Lucida Sans Regular','Lucida Grande','Lucida Sans Unicode',Geneva,Verdana,sans-serif;font-stretch:condensed;display:inline-flex;color:#ff8;padding:.1em;border-radius:.5em;background-color:#210912}footer{color:grey;font-weight:bolder;font-size:x-small}.meta{color:#444;font-style:italic;font-size:smaller}.activity{font-family:fantasy}.blogtitle{display:inline-block;font-size:x-large}.blogphoto{margin:1em}.dl-horizontal dd{margin-left:20%}