diff --git a/src/Mollie.Api/Models/Subscription/Response/SubscriptionResponse.cs b/src/Mollie.Api/Models/Subscription/Response/SubscriptionResponse.cs
index 1bde5720..9310c169 100644
--- a/src/Mollie.Api/Models/Subscription/Response/SubscriptionResponse.cs
+++ b/src/Mollie.Api/Models/Subscription/Response/SubscriptionResponse.cs
@@ -91,6 +91,11 @@ public record SubscriptionResponse {
///
public string? WebhookUrl { get; set; }
+ ///
+ /// The customer this subscription belongs to.
+ ///
+ public required string CustomerId { get; init; }
+
///
/// The optional metadata you provided upon subscription creation. Metadata can for example be used to link a plan to a
/// subscription.
diff --git a/tests/Mollie.Tests.Integration/Api/SubscriptionTests.cs b/tests/Mollie.Tests.Integration/Api/SubscriptionTests.cs
index 42121da4..a4563087 100644
--- a/tests/Mollie.Tests.Integration/Api/SubscriptionTests.cs
+++ b/tests/Mollie.Tests.Integration/Api/SubscriptionTests.cs
@@ -109,17 +109,15 @@ public async Task CanCancelSubscription() {
[DefaultRetryFact]
public async Task CanUpdateSubscription() {
// Given
- string customerId = await GetFirstCustomerWithValidMandate();
- ListResponse subscriptions = await _subscriptionClient.GetSubscriptionListAsync(customerId);
+ var activeSubscription = await GetActiveSubscription();
// When
- SubscriptionResponse subscriptionToUpdate = subscriptions.Items
- .FirstOrDefault(s => s.Status != SubscriptionStatus.Canceled);
- if (subscriptionToUpdate != null) {
+ if (activeSubscription != null) {
+ var customerId = activeSubscription.CustomerId;
SubscriptionUpdateRequest request = new SubscriptionUpdateRequest() {
Description = $"Updated subscription {Guid.NewGuid()}"
};
- SubscriptionResponse response = await _subscriptionClient.UpdateSubscriptionAsync(customerId, subscriptionToUpdate.Id, request);
+ SubscriptionResponse response = await _subscriptionClient.UpdateSubscriptionAsync(customerId, activeSubscription.Id, request);
// Then
response.Description.Should().Be(request.Description);
@@ -163,6 +161,20 @@ private async Task GetFirstCustomerWithValidMandate() {
return null;
}
+ private async Task GetActiveSubscription() {
+ ListResponse customers = await _customerClient.GetCustomerListAsync();
+
+ foreach (CustomerResponse customer in customers.Items.OrderByDescending(x => x.CreatedAt)) {
+ ListResponse subscriptions = await _subscriptionClient.GetSubscriptionListAsync(customer.Id);
+ var activeSubscription = subscriptions.Items.FirstOrDefault(x => x.Status == SubscriptionStatus.Active);
+ if (activeSubscription != null) {
+ return activeSubscription;
+ }
+ }
+
+ return null;
+ }
+
public void Dispose()
{
_subscriptionClient?.Dispose();