|
13 | 13 | import com.google.api.services.androidpublisher.AndroidPublisherRequest; |
14 | 14 | import com.google.api.services.androidpublisher.AndroidPublisherScopes; |
15 | 15 | import com.google.api.services.androidpublisher.model.AutoRenewingPlan; |
16 | | -import com.google.api.services.androidpublisher.model.BasePlan; |
| 16 | +import com.google.api.services.androidpublisher.model.Money; |
17 | 17 | import com.google.api.services.androidpublisher.model.OfferDetails; |
18 | | -import com.google.api.services.androidpublisher.model.RegionalBasePlanConfig; |
19 | | -import com.google.api.services.androidpublisher.model.Subscription; |
20 | 18 | import com.google.api.services.androidpublisher.model.SubscriptionPurchaseLineItem; |
21 | 19 | import com.google.api.services.androidpublisher.model.SubscriptionPurchaseV2; |
22 | 20 | import com.google.api.services.androidpublisher.model.SubscriptionPurchasesAcknowledgeRequest; |
|
37 | 35 | import java.util.List; |
38 | 36 | import java.util.Locale; |
39 | 37 | import java.util.Map; |
40 | | -import java.util.Objects; |
41 | 38 | import java.util.Optional; |
42 | 39 | import java.util.stream.Collectors; |
43 | 40 | import org.apache.commons.lang3.StringUtils; |
@@ -130,7 +127,6 @@ public class ValidatedToken { |
130 | 127 | * Acknowledge the purchase to the play billing server. If a purchase is never acknowledged, it will eventually be |
131 | 128 | * refunded. |
132 | 129 | * |
133 | | - * @return A stage that completes when the purchase has been successfully acknowledged |
134 | 130 | */ |
135 | 131 | public void acknowledgePurchase() |
136 | 132 | throws RateLimitExceededException, SubscriptionNotFoundException { |
@@ -269,32 +265,16 @@ public SubscriptionInformation getSubscriptionInformation(final String purchaseT |
269 | 265 | } |
270 | 266 |
|
271 | 267 | private SubscriptionPrice getSubscriptionPrice(final SubscriptionPurchaseV2 subscriptionPurchase) { |
272 | | - |
273 | 268 | final SubscriptionPurchaseLineItem lineItem = getLineItem(subscriptionPurchase); |
274 | | - final OfferDetails offerDetails = lineItem.getOfferDetails(); |
275 | | - final String basePlanId = offerDetails.getBasePlanId(); |
276 | 269 |
|
277 | | - try { |
278 | | - final Subscription subscription = this.androidPublisher.monetization().subscriptions() |
279 | | - .get(packageName, lineItem.getProductId()).execute(); |
280 | | - |
281 | | - final BasePlan basePlan = subscription.getBasePlans().stream() |
282 | | - .filter(bp -> bp.getBasePlanId().equals(basePlanId)) |
283 | | - .findFirst() |
284 | | - .orElseThrow(() -> new UncheckedIOException(new IOException("unknown basePlanId " + basePlanId))); |
285 | | - final String region = subscriptionPurchase.getRegionCode(); |
286 | | - final RegionalBasePlanConfig basePlanConfig = basePlan.getRegionalConfigs() |
287 | | - .stream() |
288 | | - .filter(rbpc -> Objects.equals(region, rbpc.getRegionCode())) |
289 | | - .findFirst() |
290 | | - .orElseThrow(() -> new UncheckedIOException(new IOException("unknown subscription region " + region))); |
291 | | - |
292 | | - return new SubscriptionPrice( |
293 | | - basePlanConfig.getPrice().getCurrencyCode().toUpperCase(Locale.ROOT), |
294 | | - SubscriptionCurrencyUtil.convertGoogleMoneyToApiAmount(basePlanConfig.getPrice())); |
295 | | - } catch (IOException e) { |
296 | | - throw new UncheckedIOException(e); |
| 270 | + // We don't offer pre-paid plans, so autoRenewingPlan must be nonnull |
| 271 | + if (lineItem.getAutoRenewingPlan() == null) { |
| 272 | + throw new UncheckedIOException(new IOException("Subscription purchases must be auto-renewing plans")); |
297 | 273 | } |
| 274 | + final Money price = lineItem.getAutoRenewingPlan().getRecurringPrice(); |
| 275 | + return new SubscriptionPrice( |
| 276 | + price.getCurrencyCode().toUpperCase(Locale.ROOT), |
| 277 | + SubscriptionCurrencyUtil.convertGoogleMoneyToApiAmount(price)); |
298 | 278 | } |
299 | 279 |
|
300 | 280 | @Override |
|
0 commit comments