-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OFFI-126: Adding several Stripe API endpoints and basics of Subscript…
…ion (#510) * WIP: Stripe headless * Fix reference * Make stripe workflow possible on headless * Fixing possible NRE * Deleting not used viewmodels * Fixing folder typo * Code cleanup * Code cleanup * More cleanup * Adding changes so order creation is easy through minimal api * Adding subscription elements * Adding stripe product part * Adding logic for subscription and stripe checkout * Separating and adding logic supporting stripe subscription * Code refactoring and drying * Using actual function * Fixing null issue * Drying and refactoring * Drying and refactoring and documenting * Start date should not be overriden every time * Should be datetime not date * Added permissions * Adding new part of the subscription update logic * Use the actual start date * Making populate function public * Removing update step * Refactoring and documenting * Adding search * Moving stripe services to use DI * Adding get subscription endpoint * Mocking services * Adding testing possibility * Simple textfield * Creating new event data for everything * Deleting not needed using * Fixing altering * Small refactoring * Fixing spelling stuff * Adding reference * Adding version * Adding newest version * Update Directory.Packages.props Co-authored-by: Sára El-Saig <[email protected]> * Abstracting logic so it is not that stripe related * Renaming * Sorting out endpoint paths * Adding breaking changes * Not needed using * Removing not needed usings * Using list style --------- Co-authored-by: Sára El-Saig <[email protected]>
- Loading branch information
1 parent
16bedc4
commit 2786470
Showing
105 changed files
with
2,679 additions
and
397 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
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
16 changes: 16 additions & 0 deletions
16
...dules/OrchardCore.Commerce.Payment.Stripe/Abstractions/IStripeConfirmationTokenService.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,16 @@ | ||
using Stripe; | ||
using System.Threading.Tasks; | ||
|
||
namespace OrchardCore.Commerce.Payment.Stripe.Abstractions; | ||
|
||
/// <summary> | ||
/// Service for managing Stripe confirmation tokens. | ||
/// </summary> | ||
public interface IStripeConfirmationTokenService | ||
{ | ||
/// <summary> | ||
/// Gets the Stripe confirmation token with an Id of <paramref name="confirmationTokenId"/>. | ||
/// </summary> | ||
/// <returns>The Stripe <see cref="ConfirmationToken"/>.</returns> | ||
Task<ConfirmationToken> GetConfirmationTokenAsync(string confirmationTokenId); | ||
} |
73 changes: 73 additions & 0 deletions
73
src/Modules/OrchardCore.Commerce.Payment.Stripe/Abstractions/IStripeCustomerService.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,73 @@ | ||
using Stripe; | ||
using System.Threading.Tasks; | ||
using Address = OrchardCore.Commerce.AddressDataType.Address; | ||
|
||
namespace OrchardCore.Commerce.Payment.Stripe.Abstractions; | ||
|
||
/// <summary> | ||
/// Stripe customer related services. | ||
/// </summary> | ||
public interface IStripeCustomerService | ||
{ | ||
/// <summary> | ||
/// Search for customers in Stripe with the given <paramref name="options"/>. | ||
/// </summary> | ||
Task<StripeSearchResult<Customer>> SearchCustomersAsync(CustomerSearchOptions options); | ||
|
||
/// <summary> | ||
/// Get the first customer with the given email in Stripe. | ||
/// </summary> | ||
Task<Customer> GetFirstCustomerByEmailAsync(string customerEmail); | ||
|
||
/// <summary> | ||
/// Returns <see cref="Customer"/> with the given Id in Stripe. | ||
/// </summary> | ||
Task<Customer> GetCustomerByIdAsync(string customerId); | ||
|
||
/// <summary> | ||
/// Returns <see cref="Customer"/> with the given email in Stripe. If not found, create a new customer. | ||
/// </summary> | ||
/// <param name="email">If not provided the current user's email will be used.</param> | ||
Task<Customer> GetAndUpdateOrCreateCustomerAsync( | ||
Address billingAddress, | ||
Address shippingAddress, | ||
string email, | ||
string phone); | ||
|
||
/// <summary> | ||
/// Create a new customer in Stripe with the given <paramref name="customerCreateOptions"/>. | ||
/// </summary> | ||
/// <returns>The created Stripe <see cref="Customer"/>.</returns> | ||
Task<Customer> CreateCustomerAsync(CustomerCreateOptions customerCreateOptions); | ||
|
||
/// <summary> | ||
/// Create the customer in Stripe with the given details which will be used to create the | ||
/// <see cref="CustomerCreateOptions"/>. | ||
/// </summary> | ||
/// <returns>The created Stripe <see cref="Customer"/>.</returns> | ||
Task<Customer> CreateCustomerAsync( | ||
Address billingAddress, | ||
Address shippingAddress, | ||
string email, | ||
string phone); | ||
|
||
/// <summary> | ||
/// Update the customer in Stripe with the given details. | ||
/// </summary> | ||
/// <returns>The updated Stripe <see cref="Customer"/>.</returns> | ||
Task<Customer> UpdateCustomerAsync( | ||
string customerId, | ||
Address billingAddress, | ||
Address shippingAddress, | ||
string email, | ||
string phone); | ||
|
||
/// <summary> | ||
/// Populate the returned <see cref="CustomerCreateOptions"/> with the given details. | ||
/// </summary> | ||
CustomerCreateOptions PopulateCustomerCreateOptions( | ||
Address billingAddress, | ||
Address shippingAddress, | ||
string email, | ||
string phone); | ||
} |
31 changes: 31 additions & 0 deletions
31
src/Modules/OrchardCore.Commerce.Payment.Stripe/Abstractions/IStripeHelperService.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,31 @@ | ||
using Stripe; | ||
|
||
namespace OrchardCore.Commerce.Payment.Stripe.Abstractions; | ||
|
||
/// <summary> | ||
/// Stripe helping services, needed so we can mock this part of Stripe also. | ||
/// </summary> | ||
public interface IStripeHelperService | ||
{ | ||
/// <summary> | ||
/// Parses a JSON string from a Stripe webhook into a <see cref="Event"/> object, while | ||
/// verifying the <a href="https://stripe.com/docs/webhooks/signatures">webhook's | ||
/// signature</a>. | ||
/// </summary> | ||
/// <param name="json">The JSON string to parse.</param> | ||
/// <param name="stripeSignatureHeader"> | ||
/// The value of the <c>Stripe-Signature</c> header from the webhook request. | ||
/// </param> | ||
/// <param name="secret">The webhook endpoint's signing secret.</param> | ||
/// <param name="throwOnApiVersionMismatch"> | ||
/// If <see langword="true"/> (default), the method will throw a <see cref="StripeException"/> if the | ||
/// API version of the event doesn't match Stripe.net's default API version (see | ||
/// <see cref="StripeConfiguration.ApiVersion"/>). | ||
/// </param> | ||
/// <returns>The deserialized <see cref="Event"/>.</returns> | ||
/// <exception cref="StripeException"> | ||
/// Thrown if the signature verification fails for any reason, of if the API version of the | ||
/// event doesn't match Stripe.net's default API version. | ||
/// </exception> | ||
Event PrepareStripeEvent(string json, string stripeSignatureHeader, string secret, bool throwOnApiVersionMismatch); | ||
} |
41 changes: 41 additions & 0 deletions
41
src/Modules/OrchardCore.Commerce.Payment.Stripe/Abstractions/IStripePaymentIntentService.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,41 @@ | ||
using OrchardCore.Commerce.MoneyDataType; | ||
using OrchardCore.Commerce.Payment.Stripe.Constants; | ||
using Stripe; | ||
using System.Threading.Tasks; | ||
|
||
namespace OrchardCore.Commerce.Payment.Stripe.Abstractions; | ||
|
||
/// <summary> | ||
/// Service for managing Stripe Payment Intents. | ||
/// </summary> | ||
public interface IStripePaymentIntentService | ||
{ | ||
/// <summary> | ||
/// Gets a PaymentIntent by its Stripe Id. | ||
/// </summary> | ||
/// <returns>Stripe <see cref="PaymentIntent"/> model.</returns> | ||
Task<PaymentIntent> GetPaymentIntentAsync(string paymentIntentId); | ||
|
||
/// <summary> | ||
/// Gets the PaymentIntent by its Stripe Id if it is <see cref="PaymentIntentStatuses.Succeeded"/> or | ||
/// <see cref="PaymentIntentStatuses.Processing"/>. Otherwise, updates it with the provided | ||
/// <paramref name="defaultTotal"/>. | ||
/// </summary> | ||
/// <returns>Updated or original Stripe <see cref="PaymentIntent"/> model.</returns> | ||
Task<PaymentIntent> GetOrUpdatePaymentIntentAsync( | ||
string paymentIntentId, | ||
Amount defaultTotal); | ||
|
||
/// <summary> | ||
/// Creates a PaymentIntent with the provided <paramref name="total"/>. And adds description and other values to | ||
/// the payment intent. Check the implementation for more details. | ||
/// </summary> | ||
/// <returns>Created Stripe <see cref="PaymentIntent"/>.</returns> | ||
Task<PaymentIntent> CreatePaymentIntentAsync(Amount total); | ||
|
||
/// <summary> | ||
/// Creates a PaymentIntent with the provided <paramref name="options"/>. | ||
/// </summary> | ||
/// <returns>Created Stripe <see cref="PaymentIntent"/> model.</returns> | ||
Task<PaymentIntent> CreatePaymentIntentAsync(PaymentIntentCreateOptions options); | ||
} |
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
22 changes: 22 additions & 0 deletions
22
src/Modules/OrchardCore.Commerce.Payment.Stripe/Abstractions/IStripeSessionEventHandler.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,22 @@ | ||
using Stripe.Checkout; | ||
using System.Threading.Tasks; | ||
|
||
namespace OrchardCore.Commerce.Payment.Stripe.Abstractions; | ||
|
||
/// <summary> | ||
/// Event handler for Stripe sessions. | ||
/// </summary> | ||
public interface IStripeSessionEventHandler | ||
{ | ||
/// <summary> | ||
/// Called before a Stripe session is created with a pre-populated <see cref="SessionCreateOptions"/> | ||
/// <paramref name="options"/>. Here you can modify the options before the session is created. | ||
/// </summary> | ||
Task StripeSessionCreatingAsync(SessionCreateOptions options) => Task.CompletedTask; | ||
|
||
/// <summary> | ||
/// Called after a Stripe session is created with the created <paramref name="session"/> and the | ||
/// <paramref name="options"/> used during creation. | ||
/// </summary> | ||
Task StripeSessionCreatedAsync(Session session, SessionCreateOptions options) => Task.CompletedTask; | ||
} |
16 changes: 16 additions & 0 deletions
16
src/Modules/OrchardCore.Commerce.Payment.Stripe/Abstractions/IStripeSessionService.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,16 @@ | ||
using Stripe.Checkout; | ||
using System.Threading.Tasks; | ||
|
||
namespace OrchardCore.Commerce.Payment.Stripe.Abstractions; | ||
|
||
/// <summary> | ||
/// Service for managing Stripe sessions. | ||
/// </summary> | ||
public interface IStripeSessionService | ||
{ | ||
/// <summary> | ||
/// Creates a Stripe session using the given <paramref name="options"/>. | ||
/// </summary> | ||
/// <returns>The created Stripe <see cref="Session"/>.</returns> | ||
Task<Session> CreateSessionAsync(SessionCreateOptions options); | ||
} |
Oops, something went wrong.