-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
506 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
...Modules/OrchardCore.Commerce.Payment.Stripe/Endpoints/Api/StripeConfirmPaymentEndpoint.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#nullable enable | ||
using Lombiq.HelpfulLibraries.AspNetCore.Extensions; | ||
using Lombiq.HelpfulLibraries.OrchardCore.Mvc; | ||
using Microsoft.AspNetCore.Authorization; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.Routing; | ||
using OrchardCore.Commerce.Payment.Stripe.Abstractions; | ||
using OrchardCore.Commerce.Payment.Stripe.Endpoints.Permissions; | ||
using System; | ||
using System.Threading.Tasks; | ||
using static OrchardCore.Commerce.Payment.Stripe.Endpoints.Constants.Endpoints; | ||
|
||
namespace OrchardCore.Commerce.Payment.Stripe.Endpoints.Api; | ||
public static class StripeConfirmPaymentEndpoint | ||
{ | ||
[Obsolete("This endpoint is obsolete and will be removed in a future version. Use checkout/stripe/middleware instead.")] | ||
public static IEndpointRouteBuilder AddStripeMiddlewareEndpoint(this IEndpointRouteBuilder builder) | ||
{ | ||
builder.MapPostWithDefaultSettings($"{StripePaymentApiPath}/middleware", AddStripeMiddlewareAsync); | ||
return builder; | ||
} | ||
|
||
[Obsolete("This endpoint is obsolete and will be removed in a future version. Use checkout/stripe/middleware instead.")] | ||
private static async Task<IResult> AddStripeMiddlewareAsync( | ||
[FromQuery] string? shoppingCartId, | ||
[FromServices] IStripePaymentService stripePaymentService, | ||
[FromServices] IAuthorizationService authorizationService, | ||
HttpContext httpContext, | ||
[FromQuery(Name = "payment_intent")] string? paymentIntentId = null) | ||
{ | ||
var result = await StripePaymentOrderConfirmationAsync( | ||
shoppingCartId, | ||
stripePaymentService, | ||
authorizationService, | ||
httpContext, | ||
paymentIntentId); | ||
return TypedResults.Ok(result); | ||
} | ||
|
||
public static IEndpointRouteBuilder AddStripePaymentOrderConfirmationEndpoint(this IEndpointRouteBuilder builder) | ||
{ | ||
builder.MapPostWithDefaultSettings($"{StripePaymentApiPath}", StripePaymentOrderConfirmationAsync); | ||
return builder; | ||
} | ||
|
||
private static async Task<IResult> StripePaymentOrderConfirmationAsync( | ||
[FromQuery] string? shoppingCartId, | ||
[FromServices] IStripePaymentService stripePaymentService, | ||
[FromServices] IAuthorizationService authorizationService, | ||
HttpContext httpContext, | ||
[FromQuery(Name = "payment_intent")] string? paymentIntentId = null) | ||
{ | ||
if (!await authorizationService.AuthorizeAsync(httpContext.User, ApiPermissions.CommerceApiStripePayment)) | ||
{ | ||
return httpContext.ChallengeOrForbidApi(); | ||
} | ||
|
||
var result = await stripePaymentService.PaymentConfirmationAsync( | ||
paymentIntentId, | ||
shoppingCartId, | ||
paymentIntentId == null); | ||
|
||
return TypedResults.Ok(result); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...ules/OrchardCore.Commerce.Payment.Stripe/Endpoints/Api/StripeConfirmationTokenEndpoint.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#nullable enable | ||
using Lombiq.HelpfulLibraries.AspNetCore.Extensions; | ||
using Lombiq.HelpfulLibraries.OrchardCore.Mvc; | ||
using Microsoft.AspNetCore.Authorization; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.Routing; | ||
using OrchardCore.Commerce.Payment.Stripe.Abstractions; | ||
using OrchardCore.Commerce.Payment.Stripe.Endpoints.Permissions; | ||
using System.Threading.Tasks; | ||
using static OrchardCore.Commerce.Payment.Stripe.Endpoints.Constants.Endpoints; | ||
|
||
namespace OrchardCore.Commerce.Payment.Stripe.Endpoints.Api; | ||
public static class StripeConfirmationTokenEndpoint | ||
{ | ||
public static IEndpointRouteBuilder AddStripeConfirmationTokenEndpoint(this IEndpointRouteBuilder builder) | ||
{ | ||
builder.MapGetWithDefaultSettings($"{StripePaymentApiPath}/confirmation-token", GetStripeConfirmationTokenAsync); | ||
return builder; | ||
} | ||
|
||
private static async Task<IResult> GetStripeConfirmationTokenAsync( | ||
[FromQuery] string? confirmationTokenId, | ||
[FromServices] IStripePaymentService stripePaymentService, | ||
[FromServices] IAuthorizationService authorizationService, | ||
HttpContext httpContext) | ||
{ | ||
if (!await authorizationService.AuthorizeAsync(httpContext.User, ApiPermissions.CommerceApiStripePayment)) | ||
{ | ||
return httpContext.ChallengeOrForbidApi(); | ||
} | ||
|
||
var confirmationToken = await stripePaymentService.GetConfirmationTokenAsync(confirmationTokenId); | ||
return TypedResults.Ok(confirmationToken); | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
src/Modules/OrchardCore.Commerce.Payment.Stripe/Endpoints/Api/StripeCustomerEndpoint.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#nullable enable | ||
using Lombiq.HelpfulLibraries.AspNetCore.Extensions; | ||
using Lombiq.HelpfulLibraries.OrchardCore.Mvc; | ||
using Microsoft.AspNetCore.Authorization; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.Routing; | ||
using OrchardCore.Commerce.Payment.Stripe.Abstractions; | ||
using OrchardCore.Commerce.Payment.Stripe.Endpoints.Permissions; | ||
using Stripe; | ||
using System.Threading.Tasks; | ||
using static OrchardCore.Commerce.Payment.Stripe.Endpoints.Constants.Endpoints; | ||
|
||
namespace OrchardCore.Commerce.Payment.Stripe.Endpoints.Api; | ||
public static class StripeCustomerEndpoint | ||
{ | ||
public static IEndpointRouteBuilder AddStripeGetCustomerEndpoint(this IEndpointRouteBuilder builder) | ||
{ | ||
builder.MapGetWithDefaultSettings($"{StripePaymentApiPath}/customer", GetStripeCustomerAsync); | ||
return builder; | ||
} | ||
|
||
private static async Task<IResult> GetStripeCustomerAsync( | ||
[FromQuery] string? customerId, | ||
[FromServices] IStripePaymentService stripePaymentService, | ||
[FromServices] IAuthorizationService authorizationService, | ||
HttpContext httpContext) | ||
{ | ||
if (!await authorizationService.AuthorizeAsync(httpContext.User, ApiPermissions.CommerceApiStripePayment)) | ||
{ | ||
return httpContext.ChallengeOrForbidApi(); | ||
} | ||
|
||
var customer = await stripePaymentService.GetCustomerAsync(customerId); | ||
return TypedResults.Ok(customer); | ||
} | ||
|
||
public static IEndpointRouteBuilder AddStripeCreateCustomerEndpoint(this IEndpointRouteBuilder builder) | ||
{ | ||
builder.MapGetWithDefaultSettings($"{StripePaymentApiPath}/customer", GetStripeCreateCustomerAsync); | ||
return builder; | ||
} | ||
|
||
private static async Task<IResult> GetStripeCreateCustomerAsync( | ||
[FromBody] CustomerCreateOptions customerCreateOptions, | ||
[FromServices] IStripePaymentService stripePaymentService, | ||
[FromServices] IAuthorizationService authorizationService, | ||
HttpContext httpContext) | ||
{ | ||
if (!await authorizationService.AuthorizeAsync(httpContext.User, ApiPermissions.CommerceApiStripePayment)) | ||
{ | ||
return httpContext.ChallengeOrForbidApi(); | ||
} | ||
|
||
var customer = await stripePaymentService.CreateCustomerAsync(customerCreateOptions); | ||
return TypedResults.Ok(customer); | ||
} | ||
} |
Oops, something went wrong.