diff --git a/src/main/java/com/trynoice/api/subscription/SubscriptionService.java b/src/main/java/com/trynoice/api/subscription/SubscriptionService.java index 20bd002..c16e4c2 100644 --- a/src/main/java/com/trynoice/api/subscription/SubscriptionService.java +++ b/src/main/java/com/trynoice/api/subscription/SubscriptionService.java @@ -737,7 +737,7 @@ public SubscriptionResponse redeemGiftCard( Subscription.builder() .customer(giftCard.getCustomer()) .plan(giftCard.getPlan()) - .providerSubscriptionId(String.valueOf(giftCard.getId())) + .providerSubscriptionId(giftCardCode) .isPaymentPending(false) .isAutoRenewing(false) .isRefunded(false) @@ -797,6 +797,10 @@ private static SubscriptionResponse buildSubscriptionResponse(@NonNull Subscript .googlePlayPurchaseToken( subscription.isActive() && subscription.getPlan().getProvider() == SubscriptionPlan.Provider.GOOGLE_PLAY ? subscription.getProviderSubscriptionId() : null) + .giftCardCode( + subscription.getPlan().getProvider() == SubscriptionPlan.Provider.GIFT_CARD + ? subscription.getProviderSubscriptionId() + : null) .build(); } diff --git a/src/main/java/com/trynoice/api/subscription/payload/SubscriptionResponse.java b/src/main/java/com/trynoice/api/subscription/payload/SubscriptionResponse.java index de007f4..f6ced83 100644 --- a/src/main/java/com/trynoice/api/subscription/payload/SubscriptionResponse.java +++ b/src/main/java/com/trynoice/api/subscription/payload/SubscriptionResponse.java @@ -57,4 +57,7 @@ public class SubscriptionResponse { @Schema(description = "purchase token corresponding to this subscription purchase. only present when the " + "subscription is active and provided by Google Play") private String googlePlayPurchaseToken; + + @Schema(description = "the gift card code if this subscription was activated using a gift card.") + private String giftCardCode; } diff --git a/src/test/java/com/trynoice/api/subscription/SubscriptionServiceTest.java b/src/test/java/com/trynoice/api/subscription/SubscriptionServiceTest.java index c48f4b5..d42dfb8 100644 --- a/src/test/java/com/trynoice/api/subscription/SubscriptionServiceTest.java +++ b/src/test/java/com/trynoice/api/subscription/SubscriptionServiceTest.java @@ -401,7 +401,8 @@ void redeemGiftCard_withValidCode() { val card = buildGiftCard(code, 1L); when(giftCardRepository.findByCode(code)).thenReturn(Optional.of(card)); when(subscriptionRepository.save(any())).thenAnswer(i -> i.getArgument(0)); - assertDoesNotThrow(() -> service.redeemGiftCard(1L, code)); + val response = assertDoesNotThrow(() -> service.redeemGiftCard(1L, code)); + assertEquals(card.getCode(), response.getGiftCardCode()); } @Test