Skip to content

Commit

Permalink
fixes bug subscription_offer_details=null
Browse files Browse the repository at this point in the history
  • Loading branch information
PickleJesus123 committed Oct 31, 2023
1 parent 265e78c commit 117e484
Showing 1 changed file with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,33 +76,35 @@ public static Dictionary convertProductDetailsToDictionary(ProductDetails detail
}

List<ProductDetails.SubscriptionOfferDetails> subscriptionOfferDetailsList = details.getSubscriptionOfferDetails();

if (subscriptionOfferDetailsList != null && !subscriptionOfferDetailsList.isEmpty()) {
ArrayList<Dictionary> subscriptionOfferDetailsDictionaryList = new ArrayList<>();
Dictionary subscriptionOfferDetailsDictionaryContainer = new Dictionary();

int subscriptionOfferIndex = 1;
for (ProductDetails.SubscriptionOfferDetails subscriptionOfferDetails : subscriptionOfferDetailsList) {
Dictionary subscriptionOfferDetailsDictionary = new Dictionary();
subscriptionOfferDetailsDictionary.put("offer_token", subscriptionOfferDetails.getOfferToken());
subscriptionOfferDetailsDictionary.put("offer_tags", subscriptionOfferDetails.getOfferTags());

ArrayList<Dictionary> pricingPhasesDictionaryList = new ArrayList<>();
for (ProductDetails.PricingPhase pricingPhase : subscriptionOfferDetails.getPricingPhases().getPricingPhaseList()) {
Dictionary pricingPhasesDictionaryContainer = new Dictionary();
List<ProductDetails.PricingPhase> pricingPhasesList = subscriptionOfferDetails.getPricingPhases().getPricingPhaseList();
for (int i = 0; i < pricingPhasesList.size(); i++) {
ProductDetails.PricingPhase pricingPhase = pricingPhasesList.get(i);
Dictionary pricingPhasesDictionary = new Dictionary();
pricingPhasesDictionary.put("billing_cycle_count", pricingPhase.getBillingCycleCount());
pricingPhasesDictionary.put("billing_period", pricingPhase.getBillingPeriod());
pricingPhasesDictionary.put("formatted_price", pricingPhase.getFormattedPrice());
pricingPhasesDictionary.put("price_amount_micros", pricingPhase.getPriceAmountMicros());
pricingPhasesDictionary.put("price_currency_code", pricingPhase.getPriceCurrencyCode());
pricingPhasesDictionary.put("recurrence_mode", pricingPhase.getRecurrenceMode());
pricingPhasesDictionaryList.add(pricingPhasesDictionary);
pricingPhasesDictionaryContainer.put("pricingPhase_" + (i + 1), pricingPhasesDictionary);
}

subscriptionOfferDetailsDictionary.put("pricing_phases", pricingPhasesDictionaryList);

subscriptionOfferDetailsDictionaryList.add(subscriptionOfferDetailsDictionary);
subscriptionOfferDetailsDictionary.put("pricing_phases", pricingPhasesDictionaryContainer);
subscriptionOfferDetailsDictionaryContainer.put("subscriptionOffer_" + subscriptionOfferIndex, subscriptionOfferDetailsDictionary);
subscriptionOfferIndex++;
}

dictionary.put("subscription_offer_details", subscriptionOfferDetailsDictionaryList);
dictionary.put("subscription_offer_details", subscriptionOfferDetailsDictionaryContainer);
}

return dictionary;
Expand Down

0 comments on commit 117e484

Please sign in to comment.