Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

YEL-177 [hotfix] apple pay column fix #383

Merged
merged 3 commits into from
Oct 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public class Purchase extends AuditingTimeEntity {
@Convert(converter = PurchaseStateConverter.class)
private PurchaseState state;

@Column
@Column(length = 15000)
private String rawData;

@Column(nullable = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.yello.server.global.common.util.ConstantUtil;
import com.yello.server.infrastructure.slack.dto.response.SlackAppleNotificationResponse;
import java.util.Map;
import java.util.Optional;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
Expand Down Expand Up @@ -112,35 +113,47 @@ public Purchase decodeAppleNotificationData(String signedTransactionInfo) {
public void changeSubscriptionStatus(AppleNotificationPayloadVO payloadVO) {

ApplePurchaseVO purchaseData = getPurchaseData(payloadVO);
Purchase purchase =
purchaseRepository.findByTransactionId(purchaseData.transactionId())
.orElseThrow(() -> new PurchaseNotFoundException(NOT_FOUND_TRANSACTION_EXCEPTION));
User user = purchaseData.purchase().getUser();

if (payloadVO.subtype().equals(ConstantUtil.APPLE_SUBTYPE_AUTO_RENEW_DISABLED)
&& !user.getSubscribe().equals(Subscribe.NORMAL)) {
user.setSubscribe(Subscribe.CANCELED);
purchase.setPurchaseState(PurchaseState.CANCELED);
}

if (payloadVO.subtype().equals(ConstantUtil.APPLE_SUBTYPE_VOLUNTARY)) {
user.setSubscribe(Subscribe.NORMAL);
purchase.setPurchaseState(PurchaseState.PAUSED);
}
}

@Override
public void refundAppleInApp(AppleNotificationPayloadVO payloadVO) {
ApplePurchaseVO purchaseData = getPurchaseData(payloadVO);
Purchase purchase =
purchaseRepository.findByTransactionId(purchaseData.transactionId())
.orElseThrow(() -> new PurchaseNotFoundException(NOT_FOUND_TRANSACTION_EXCEPTION));
User user = purchaseData.purchase().getUser();

switch (purchaseData.purchase().getProductType()) {
case YELLO_PLUS -> {
user.setSubscribe(Subscribe.NORMAL);
purchase.setPurchaseState(PurchaseState.INACTIVE);
}
case ONE_TICKET -> {
validateTicketCount(REFUND_ONE_TICKET, user);
purchase.setPurchaseState(PurchaseState.INACTIVE);
}
case TWO_TICKET -> {
validateTicketCount(REFUND_TWO_TICKET, user);
purchase.setPurchaseState(PurchaseState.INACTIVE);
}
case FIVE_TICKET -> {
validateTicketCount(REFUND_FIVE_TICKET, user);
purchase.setPurchaseState(PurchaseState.INACTIVE);
}
}
}
Expand Down Expand Up @@ -171,6 +184,9 @@ public void reSubscribeApple(AppleNotificationPayloadVO payloadVO) {
createSubscribe(purchase.getUser(), Gateway.APPLE, appleJwtDecode.transactionId(), null,
PurchaseState.ACTIVE, appleJwtDecode.toString());

purchase.setPurchaseState(PurchaseState.INACTIVE);
reSubscribePurchase.setPurchaseState(PurchaseState.ACTIVE);

purchaseRepository.save(reSubscribePurchase);
}

Expand Down
Loading