package com.revenuecat.purchases.google;

import com.revenuecat.purchases.PurchasesError;
import com.revenuecat.purchases.PurchasesErrorCode;
import com.revenuecat.purchases.models.StoreTransaction;
import com.revenuecat.purchases.strings.PurchaseStrings;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import kotlin.jvm.internal.o;
import kotlin.jvm.internal.p;
import w4.C3137A;

/* JADX INFO: loaded from: classes3.dex */
public final class BillingWrapper$findPurchaseInPurchaseHistory$2$1 extends p implements J4.c {
    final /* synthetic */ J4.c $onCompletion;
    final /* synthetic */ J4.c $onError;
    final /* synthetic */ String $productId;

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public BillingWrapper$findPurchaseInPurchaseHistory$2$1(J4.c cVar, String str, J4.c cVar2) {
        super(1);
        this.$onCompletion = cVar;
        this.$productId = str;
        this.$onError = cVar2;
    }

    public final void invoke(List<StoreTransaction> purchasesList) {
        Object next;
        o.h(purchasesList, "purchasesList");
        String str = this.$productId;
        Iterator<T> it = purchasesList.iterator();
        while (true) {
            if (!it.hasNext()) {
                next = null;
                break;
            } else {
                next = it.next();
                if (((StoreTransaction) next).getProductIds().contains(str)) {
                    break;
                }
            }
        }
        StoreTransaction storeTransaction = (StoreTransaction) next;
        if (storeTransaction != null) {
            this.$onCompletion.invoke(storeTransaction);
            return;
        }
        this.$onError.invoke(new PurchasesError(PurchasesErrorCode.PurchaseInvalidError, String.format(PurchaseStrings.NO_EXISTING_PURCHASE, Arrays.copyOf(new Object[]{this.$productId}, 1))));
    }

    @Override // J4.c
    public /* bridge */ /* synthetic */ Object invoke(Object obj) {
        invoke((List<StoreTransaction>) obj);
        return C3137A.f25453a;
    }
}
