Skip to content

Commit

Permalink
Fix: #207 인앱 결제 서비스 로직 수정4
Browse files Browse the repository at this point in the history
  • Loading branch information
LeeJae-H committed Dec 5, 2024
1 parent 23c22a4 commit b2f8aed
Showing 1 changed file with 12 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public Boolean validateReceipt(Long userId, PurchaseRequestDto purchaseRequestDt

JsonFactory JSON_FACTORY = GsonFactory.getDefaultInstance();

AndroidPublisher.Builder builder;
HttpTransport httpTransport;
try {
httpTransport = GoogleNetHttpTransport.newTrustedTransport();
Expand All @@ -57,27 +56,27 @@ public Boolean validateReceipt(Long userId, PurchaseRequestDto purchaseRequestDt
throw ExpectedException.withLogging(ResponseCode.AlreadyActivatedUser, e3);
}

builder = new AndroidPublisher.Builder(httpTransport, JSON_FACTORY, new HttpCredentialsAdapter(credentials));

AndroidPublisher publisher = builder.setApplicationName(purchaseRequestDto.getPackageName()).build();
AndroidPublisher.Builder builder = new AndroidPublisher.Builder(httpTransport, JSON_FACTORY, new HttpCredentialsAdapter(credentials));
AndroidPublisher publisher = builder.setApplicationName(googleApplicationPackageName).build();

AndroidPublisher.Purchases.Products.Get get = null;
try {
AndroidPublisher.Purchases.Products.Get get = publisher.purchases().products()
get = publisher.purchases().products()
.get(purchaseRequestDto.getPackageName(), purchaseRequestDto.getProductId(), purchaseRequestDto.getPurchaseToken());
ProductPurchase productPurchase = get.execute(); //검증 결과

// 인앱 상품의 소비 상태. 0 아직 소비 안됨(Yet to be consumed) / 1 소비됨(Consumed)
Integer consumptionState = productPurchase.getConsumptionState();
} catch (IOException e) {
throw ExpectedException.withLogging(ResponseCode.NotNullableEnum, e);
}

// 상품이 구매된 시각. 타임스탬프 형태
Long purchaseTimeMillis = productPurchase.getPurchaseTimeMillis();
try {
ProductPurchase productPurchase = get.execute();

// 구매 상태. 0 구매완료 / 1 취소됨
// 구매 상태 -> 0 : 구매완료 / 1 : 취소됨
Integer purchaseState = productPurchase.getPurchaseState();
if (purchaseState == 1) {
if (purchaseState != null && purchaseState == 1) {
return false;
}
return true;

} catch (IOException e5) {
throw ExpectedException.withLogging(ResponseCode.FileTypeNotProvided, e5);
}
Expand Down

0 comments on commit b2f8aed

Please sign in to comment.