-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
YEL-176 [feat] google noti 로직 구현
- Loading branch information
Showing
23 changed files
with
478 additions
and
67 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
10 changes: 10 additions & 0 deletions
10
...in/java/com/yello/server/domain/purchase/dto/request/GooglePubSubNotificationRequest.java
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,10 @@ | ||
package com.yello.server.domain.purchase.dto.request; | ||
|
||
import com.yello.server.domain.purchase.dto.request.google.GooglePubSubMessage; | ||
|
||
public record GooglePubSubNotificationRequest( | ||
GooglePubSubMessage message, | ||
String subscription | ||
) { | ||
|
||
} |
42 changes: 42 additions & 0 deletions
42
src/main/java/com/yello/server/domain/purchase/dto/request/google/DeveloperNotification.java
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,42 @@ | ||
package com.yello.server.domain.purchase.dto.request.google; | ||
|
||
import static com.yello.server.global.common.util.ConstantUtil.GOOGLE_FIVE_TICKET_ID; | ||
import static com.yello.server.global.common.util.ConstantUtil.GOOGLE_ONE_TICKET_ID; | ||
import static com.yello.server.global.common.util.ConstantUtil.GOOGLE_TWO_TICKET_ID; | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.fasterxml.jackson.annotation.JsonInclude.Include; | ||
import com.yello.server.domain.purchase.entity.ProductType; | ||
import org.springframework.util.ObjectUtils; | ||
|
||
@JsonInclude(Include.NON_NULL) | ||
public record DeveloperNotification( | ||
String version, | ||
String packageName, | ||
Long eventTimeMillis, | ||
OneTimeProductNotification oneTimeProductNotification, | ||
SubscriptionNotification subscriptionNotification, | ||
TestNotification testNotification | ||
) { | ||
|
||
public ProductType getProductType() { | ||
if (ObjectUtils.isEmpty(testNotification)) { | ||
return ProductType.TEST; | ||
} else if (!ObjectUtils.isEmpty(subscriptionNotification)) { | ||
return ProductType.YELLO_PLUS; | ||
} else if (!ObjectUtils.isEmpty(oneTimeProductNotification)) { | ||
switch (oneTimeProductNotification.sku()) { | ||
case GOOGLE_ONE_TICKET_ID -> { | ||
return ProductType.ONE_TICKET; | ||
} | ||
case GOOGLE_TWO_TICKET_ID -> { | ||
return ProductType.TWO_TICKET; | ||
} | ||
case GOOGLE_FIVE_TICKET_ID -> { | ||
return ProductType.FIVE_TICKET; | ||
} | ||
} | ||
} | ||
return null; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/com/yello/server/domain/purchase/dto/request/google/GooglePubSubMessage.java
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,15 @@ | ||
package com.yello.server.domain.purchase.dto.request.google; | ||
|
||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
public record GooglePubSubMessage( | ||
Optional<Map<String, String>> attributes, | ||
String data, | ||
Long messageId, | ||
Optional<Long> message_id, | ||
Optional<String> publishTime, | ||
Optional<String> publish_time | ||
) { | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
.../java/com/yello/server/domain/purchase/dto/request/google/OneTimeProductNotification.java
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,10 @@ | ||
package com.yello.server.domain.purchase.dto.request.google; | ||
|
||
public record OneTimeProductNotification( | ||
String version, | ||
OneTimeProductNotificationType notificationType, | ||
String purchaseToken, | ||
String sku | ||
) { | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
...a/com/yello/server/domain/purchase/dto/request/google/OneTimeProductNotificationType.java
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,20 @@ | ||
package com.yello.server.domain.purchase.dto.request.google; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
public enum OneTimeProductNotificationType { | ||
ONE_TIME_PRODUCT_PURCHASED(1), | ||
ONE_TIME_PRODUCT_CANCELED(2); | ||
|
||
private final Long value; | ||
|
||
OneTimeProductNotificationType(long value) { | ||
this.value = value; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return this.name(); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...in/java/com/yello/server/domain/purchase/dto/request/google/SubscriptionNotification.java
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,10 @@ | ||
package com.yello.server.domain.purchase.dto.request.google; | ||
|
||
public record SubscriptionNotification( | ||
String version, | ||
SubscriptionNotificationType subscriptionNotificationType, | ||
String purchaseToken, | ||
String subscriptionId | ||
) { | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
...ava/com/yello/server/domain/purchase/dto/request/google/SubscriptionNotificationType.java
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 @@ | ||
package com.yello.server.domain.purchase.dto.request.google; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
public enum SubscriptionNotificationType { | ||
SUBSCRIPTION_RECOVERED(1), | ||
SUBSCRIPTION_RENEWED(2), | ||
SUBSCRIPTION_CANCELED(3), | ||
SUBSCRIPTION_PURCHASED(4), | ||
SUBSCRIPTION_ON_HOLD(5), | ||
SUBSCRIPTION_IN_GRACE_PERIOD(6), | ||
SUBSCRIPTION_RESTARTED(7), | ||
SUBSCRIPTION_PRICE_CHANGE_CONFIRMED(8), | ||
SUBSCRIPTION_DEFERRED(9), | ||
SUBSCRIPTION_PAUSED(10), | ||
SUBSCRIPTION_PAUSE_SCHEDULE_CHANGED(11), | ||
SUBSCRIPTION_REVOKED(12), | ||
SUBSCRIPTION_EXPIRED(13); | ||
|
||
private final Long value; | ||
|
||
SubscriptionNotificationType(long value) { | ||
this.value = value; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return this.name(); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/com/yello/server/domain/purchase/dto/request/google/TestNotification.java
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,7 @@ | ||
package com.yello.server.domain.purchase.dto.request.google; | ||
|
||
public record TestNotification( | ||
String version | ||
) { | ||
|
||
} |
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
29 changes: 29 additions & 0 deletions
29
src/main/java/com/yello/server/domain/purchase/entity/PurchaseState.java
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,29 @@ | ||
package com.yello.server.domain.purchase.entity; | ||
|
||
import java.text.MessageFormat; | ||
import java.util.Arrays; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Getter | ||
@RequiredArgsConstructor | ||
public enum PurchaseState { | ||
ACTIVE("ACTIVE"), | ||
CANCELED("CANCELED"), | ||
PAUSED("PAUSED"), | ||
INACTIVE("INACTIVE"); | ||
|
||
private final String intial; | ||
|
||
public static PurchaseState fromCode(String dbData) { | ||
return Arrays.stream(PurchaseState.values()) | ||
.filter(v -> v.getIntial().equals(dbData)) | ||
.findAny() | ||
.orElseThrow(() -> new IllegalArgumentException( | ||
MessageFormat.format("존재하지 않는 결제 상태입니다. {0}", dbData))); | ||
} | ||
|
||
public String intial() { | ||
return intial; | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/main/java/com/yello/server/domain/purchase/entity/PurchaseStateConverter.java
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,32 @@ | ||
package com.yello.server.domain.purchase.entity; | ||
|
||
import javax.persistence.AttributeConverter; | ||
import javax.persistence.Converter; | ||
import lombok.extern.log4j.Log4j2; | ||
|
||
@Converter | ||
@Log4j2 | ||
public class PurchaseStateConverter implements AttributeConverter<PurchaseState, String> { | ||
|
||
@Override | ||
public String convertToDatabaseColumn(PurchaseState purchaseState) { | ||
if (purchaseState == null) { | ||
return null; | ||
} | ||
return purchaseState.getIntial(); | ||
} | ||
|
||
@Override | ||
public PurchaseState convertToEntityAttribute(String dbData) { | ||
if (dbData == null) { | ||
return null; | ||
} | ||
try { | ||
return PurchaseState.fromCode(dbData); | ||
} catch (IllegalArgumentException exception) { | ||
log.error("failure to convert cause unexpected code" + dbData + exception); | ||
throw exception; | ||
} | ||
} | ||
|
||
} |
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
Oops, something went wrong.