Files
yavsc/Yavsc/Views/Shared/DisplayTemplates/PaypalPayment.cshtml
2017-05-16 20:58:52 +02:00

55 lines
1.8 KiB
Plaintext

@model PaypalPayment
@inject IOptions<PayPalSettings> PayPalSettings
@if (Model!=null && Model.PaypalPaymentId!=null) {
@if (Model.Executor.Id == User.GetUserId()) {
<text>
Votre paiment
</text>
} else {
<text>
Le paiment de @Html.DisplayFor(m=>m.Executor.UserName)
</text>
}
<text> :
</text><a asp-controller="Manage" asp-action="PaymentInfo" asp-route-id="@Model.PaypalPaymentId">@Model.PaypalPaymentId</a>
} else {
<div id="paypal-button"></div>
<script src="https://www.paypalobjects.com/api/checkout.js"></script>
<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
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;
/* Go to an error page */ });
}
}, '#paypal-button');
</script>
}