package y9;

import android.app.Application;
import com.google.android.gms.wallet.PaymentsClient;
import com.google.android.gms.wallet.Wallet;
import com.google.firebase.remoteconfig.RemoteConfigConstants;
import java.math.BigDecimal;
import java.util.Collection;
import kotlin.jvm.internal.t;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import rm.n0;

/* loaded from: classes.dex */
public final class f {

    /* renamed from: a, reason: collision with root package name */
    public static final f f52063a = new f();

    /* renamed from: b, reason: collision with root package name */
    private static final BigDecimal f52064b = new BigDecimal(1000000.0d);

    /* renamed from: c, reason: collision with root package name */
    private static final JSONObject f52065c;

    /* renamed from: d, reason: collision with root package name */
    private static final JSONArray f52066d;

    /* renamed from: e, reason: collision with root package name */
    private static final JSONArray f52067e;

    static {
        JSONObject jSONObject = new JSONObject();
        jSONObject.put("apiVersion", 2);
        jSONObject.put("apiVersionMinor", 0);
        f52065c = jSONObject;
        a aVar = a.f52040a;
        f52066d = new JSONArray((Collection) aVar.e());
        f52067e = new JSONArray((Collection) aVar.d());
    }

    private f() {
    }

    private final JSONObject a() {
        JSONObject jSONObject = new JSONObject();
        JSONObject jSONObject2 = new JSONObject();
        jSONObject2.put("allowedAuthMethods", f52067e);
        jSONObject2.put("allowedCardNetworks", f52066d);
        jSONObject2.put("billingAddressRequired", true);
        JSONObject jSONObject3 = new JSONObject();
        jSONObject3.put("format", "FULL");
        n0 n0Var = n0.f34904a;
        jSONObject2.put("billingAddressParameters", jSONObject3);
        jSONObject.put("type", "CARD");
        jSONObject.put("parameters", jSONObject2);
        return jSONObject;
    }

    private final JSONObject b() {
        JSONObject a10 = a();
        a10.put("tokenizationSpecification", d());
        return a10;
    }

    private final JSONObject d() {
        a aVar = a.f52040a;
        if (aVar.b().isEmpty()) {
            throw new RuntimeException("Please edit the Constants.java file to add gateway name and other parameters your processor requires");
        }
        JSONObject jSONObject = new JSONObject();
        jSONObject.put("type", "PAYMENT_GATEWAY");
        jSONObject.put("parameters", new JSONObject(aVar.b()));
        return jSONObject;
    }

    private final JSONObject e() {
        JSONObject put = new JSONObject().put("merchantName", "Example Merchant");
        t.f(put, "put(...)");
        return put;
    }

    private final JSONObject g(String str) {
        JSONObject jSONObject = new JSONObject();
        jSONObject.put("totalPrice", str);
        jSONObject.put("totalPriceStatus", "FINAL");
        jSONObject.put(RemoteConfigConstants.RequestFieldKey.COUNTRY_CODE, "CA");
        jSONObject.put("currencyCode", "CAD");
        return jSONObject;
    }

    public final PaymentsClient c(Application application) {
        t.g(application, "application");
        Wallet.WalletOptions build = new Wallet.WalletOptions.Builder().setEnvironment(a.f52040a.a()).build();
        t.f(build, "build(...)");
        PaymentsClient paymentsClient = Wallet.getPaymentsClient(application, build);
        t.f(paymentsClient, "getPaymentsClient(...)");
        return paymentsClient;
    }

    public final JSONObject f(String price) {
        t.g(price, "price");
        try {
            JSONObject jSONObject = new JSONObject(f52065c.toString());
            JSONArray jSONArray = new JSONArray();
            f fVar = f52063a;
            jSONObject.put("allowedPaymentMethods", jSONArray.put(fVar.b()));
            jSONObject.put("transactionInfo", fVar.g(price));
            jSONObject.put("merchantInfo", fVar.e());
            jSONObject.put("emailRequired", true);
            JSONObject jSONObject2 = new JSONObject();
            jSONObject2.put("phoneNumberRequired", false);
            jSONObject2.put("allowedCountryCodes", new JSONArray((Collection) a.f52040a.c()));
            jSONObject.put("shippingAddressParameters", jSONObject2);
            return jSONObject;
        } catch (JSONException unused) {
            return null;
        }
    }

    public final JSONObject h(boolean z10) {
        try {
            JSONObject jSONObject = new JSONObject(f52065c.toString());
            jSONObject.put("allowedPaymentMethods", new JSONArray().put(a()));
            if (!z10) {
                return jSONObject;
            }
            jSONObject.put("existingPaymentMethodRequired", true);
            return jSONObject;
        } catch (JSONException unused) {
            return null;
        }
    }
}
