Skip to content

Commit

Permalink
Adding stripe product part
Browse files Browse the repository at this point in the history
  • Loading branch information
wAsnk committed Oct 24, 2024
1 parent 93b90fa commit c6c2b01
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace OrchardCore.Commerce.Payment.Stripe.Abstractions;
/// </summary>
public interface IStripePaymentService
{
Task<SubscriptionCreateResponse> CreateSubscriptionAsync(StripeCreateSubscriptionViewModel stripeCreateSubscriptionViewModel);
Task<SubscriptionCreateResponse> CreateSubscriptionAsync(StripeCreateSubscriptionViewModel viewModel);

Task<Customer> GetCustomerAsync(string customerId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,21 @@ await SchemaBuilder
.Column<string>(nameof(OrderPaymentIndex.OrderId), column => column.WithCommonUniqueIdLength())
.Column<string>(nameof(OrderPaymentIndex.PaymentIntentId)));

await _contentDefinitionManager
.AlterPartDefinitionAsync<StripeProductPart>(builder => builder
.Configure(part => part.Attachable())
.WithField(part => part.StripeProductId, field => field.WithDisplayName("Stripe Product ID")));

return 1;
}

public async Task<int> UpdateFrom1Async()
{
await _contentDefinitionManager
.AlterPartDefinitionAsync<StripeProductPart>(builder => builder
.Configure(part => part.Attachable())
.WithField(part => part.StripeProductId, field => field.WithDisplayName("Stripe Product ID")));

return 2;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using OrchardCore.ContentFields.Fields;
using OrchardCore.ContentManagement;
using System.Collections.Generic;

namespace OrchardCore.Commerce.Payment.Stripe.Models;

public class StripeProductPart : ContentPart
{
public TextField StripeProductId { get; set; } = new();
public IList<TextField> StripePriceIds { get; } = new List<TextField>();
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public StripePaymentService(
_httpContextAccessor = httpContextAccessor;
}

public async Task<SubscriptionCreateResponse> CreateSubscriptionAsync(StripeCreateSubscriptionViewModel stripeCreateSubscriptionViewModel)
public async Task<SubscriptionCreateResponse> CreateSubscriptionAsync(StripeCreateSubscriptionViewModel viewModel)
{
// Automatically save the payment method to the subscription
// when the first payment is successful.
Expand All @@ -81,12 +81,12 @@ public async Task<SubscriptionCreateResponse> CreateSubscriptionAsync(StripeCrea

var subscriptionOptions = new SubscriptionCreateOptions
{
Customer = stripeCreateSubscriptionViewModel.CustomerId,
Customer = viewModel.CustomerId,
PaymentSettings = paymentSettings,
PaymentBehavior = "default_incomplete",
};

foreach (var priceId in stripeCreateSubscriptionViewModel.PriceIds)
foreach (var priceId in viewModel.PriceIds)
{
subscriptionOptions.Items.Add(new SubscriptionItemOptions { Price = priceId });
}
Expand Down
2 changes: 2 additions & 0 deletions src/Modules/OrchardCore.Commerce.Payment.Stripe/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public override void ConfigureServices(IServiceCollection services)
services.AddTransient<IConfigureOptions<StripeApiSettings>, StripeApiSettingsConfiguration>();

services.AddContentPart<StripePaymentPart>().WithMigration<StripeMigrations>().WithIndex<OrderPaymentIndexProvider>();
services.AddContentPart<StripeProductPart>();

services.AddScoped<IDisplayDriver<ISite>, StripeApiSettingsDisplayDriver>();

services.AddScoped<IOrderContentTypeDefinitionExclusionProvider, StripeOrderContentTypeDefinitionExclusionProvider>();
Expand Down

0 comments on commit c6c2b01

Please sign in to comment.