com.badlogic.gdx.pay.android.googleplay.billing.converter.GetPurchasesResponseConverter Maven / Gradle / Ivy
package com.badlogic.gdx.pay.android.googleplay.billing.converter;
import android.os.Bundle;
import com.badlogic.gdx.pay.Transaction;
import org.json.JSONException;
import java.util.ArrayList;
import java.util.List;
import static com.badlogic.gdx.pay.android.googleplay.GoogleBillingConstants.INAPP_PURCHASE_DATA_LIST;
import static com.badlogic.gdx.pay.android.googleplay.billing.converter.InAppPurchaseDataToTransactionConverter.convertJSONPurchaseToTransaction;
import static com.badlogic.gdx.pay.android.googleplay.billing.converter.ResponseConverters.assertResponseOk;
public class GetPurchasesResponseConverter {
public static List convertPurchasesResponseToTransactions(Bundle purchasesResponseBundle) {
assertResponseOk(purchasesResponseBundle);
ArrayList jsonPurchases = purchasesResponseBundle.getStringArrayList(INAPP_PURCHASE_DATA_LIST);
return convertPurchasesToTransactions(jsonPurchases);
}
private static List convertPurchasesToTransactions(ArrayList jsonPurchases) {
List transactions = new ArrayList<>();
for(String jsonPurchase : jsonPurchases) {
try {
transactions.add(convertJSONPurchaseToTransaction(jsonPurchase));
// Do not add price from Information.java: price might have changes since purchase.
} catch (JSONException e) {
throw new IllegalArgumentException("JSON operation failed for json: " + jsonPurchase, e);
}
}
return transactions;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy