Skip to content

Commit

Permalink
use gift card code as provider id & return it with subscription response
Browse files Browse the repository at this point in the history
  • Loading branch information
ashutoshgngwr committed Jun 26, 2022
1 parent 4a19b81 commit 83ca60c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 83ca60c

Please sign in to comment.