导航菜单

页面标题

页面副标题

Rilo v2.0.21 - ElementsSessionJsonParser.java 源代码

正在查看: Rilo v2.0.21 应用的 ElementsSessionJsonParser.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package com.stripe.android.model.parsers;

import com.stripe.android.core.model.StripeJsonUtils;
import com.stripe.android.core.model.parsers.ModelJsonParser;
import com.stripe.android.model.DeferredIntentParams;
import com.stripe.android.model.ElementsSession;
import com.stripe.android.model.ElementsSessionParams;
import com.stripe.android.model.StripeIntent;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import kotlin.Metadata;
import kotlin.NoWhenBranchMatchedException;
import kotlin.collections.CollectionsKt;
import kotlin.jvm.functions.Function0;
import kotlin.jvm.internal.DefaultConstructorMarker;
import kotlin.jvm.internal.Intrinsics;
import org.json.JSONArray;
import org.json.JSONObject;

@Metadata(d1 = {"\u0000H\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\u000e\n\u0000\n\u0002\u0018\u0002\n\u0002\u0010\t\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\u000b\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010 \n\u0002\b\u0004\b\u0000\u0018\u0000 \u001a2\b\u0012\u0004\u0012\u00020\u00020\u0001:\u0001\u001aB%\u0012\u0006\u0010\u0003\u001a\u00020\u0004\u0012\u0006\u0010\u0005\u001a\u00020\u0006\u0012\u000e\b\u0002\u0010\u0007\u001a\b\u0012\u0004\u0012\u00020\t0\b¢\u0006\u0002\u0010\nJ\u0012\u0010\u000b\u001a\u0004\u0018\u00010\u00022\u0006\u0010\f\u001a\u00020\rH\u0016J\u0010\u0010\u000e\u001a\u00020\u000f2\u0006\u0010\f\u001a\u00020\rH\u0002JH\u0010\u0010\u001a\u0004\u0018\u00010\u00112\b\u0010\u0012\u001a\u0004\u0018\u00010\u00062\b\u0010\u0013\u001a\u0004\u0018\u00010\r2\b\u0010\u0014\u001a\u0004\u0018\u00010\u00152\f\u0010\u0016\u001a\b\u0012\u0004\u0012\u00020\u00060\u00172\b\u0010\u0018\u001a\u0004\u0018\u00010\u00152\u0006\u0010\u0019\u001a\u00020\u0006H\u0002R\u000e\u0010\u0005\u001a\u00020\u0006X\u0082\u0004¢\u0006\u0002\n\u0000R\u000e\u0010\u0003\u001a\u00020\u0004X\u0082\u0004¢\u0006\u0002\n\u0000R\u0014\u0010\u0007\u001a\b\u0012\u0004\u0012\u00020\t0\bX\u0082\u0004¢\u0006\u0002\n\u0000¨\u0006\u001b"}, d2 = {"Lcom/stripe/android/model/parsers/ElementsSessionJsonParser;", "Lcom/stripe/android/core/model/parsers/ModelJsonParser;", "Lcom/stripe/android/model/ElementsSession;", "params", "Lcom/stripe/android/model/ElementsSessionParams;", "apiKey", "", "timeProvider", "Lkotlin/Function0;", "", "(Lcom/stripe/android/model/ElementsSessionParams;Ljava/lang/String;Lkotlin/jvm/functions/Function0;)V", "parse", "json", "Lorg/json/JSONObject;", "parseCardBrandChoiceEligibility", "", "parseStripeIntent", "Lcom/stripe/android/model/StripeIntent;", "elementsSessionId", "paymentMethodPreference", "orderedPaymentMethodTypes", "Lorg/json/JSONArray;", "unactivatedPaymentMethodTypes", "", "linkFundingSources", "countryCode", "Companion", "payments-core_release"}, k = 1, mv = {1, 8, 0}, xi = 48)
public final class ElementsSessionJsonParser implements ModelJsonParser<ElementsSession> {
    private static final String FIELD_CARD_BRAND_CHOICE = "card_brand_choice";
    private static final String FIELD_COUNTRY_CODE = "country_code";
    private static final String FIELD_ELEMENTS_SESSION_ID = "session_id";
    private static final String FIELD_ELIGIBLE = "eligible";
    public static final String FIELD_GOOGLE_PAY_PREFERENCE = "google_pay_preference";
    private static final String FIELD_LINK_FUNDING_SOURCES = "link_funding_sources";
    private static final String FIELD_LINK_PASSTHROUGH_MODE_ENABLED = "link_passthrough_mode_enabled";
    private static final String FIELD_LINK_SETTINGS = "link_settings";
    private static final String FIELD_MERCHANT_COUNTRY = "merchant_country";
    private static final String FIELD_OBJECT = "object";
    private static final String FIELD_ORDERED_PAYMENT_METHOD_TYPES = "ordered_payment_method_types";
    private static final String FIELD_PAYMENT_METHOD_PREFERENCE = "payment_method_preference";
    private static final String FIELD_PAYMENT_METHOD_SPECS = "payment_method_specs";
    private static final String FIELD_PAYMENT_METHOD_TYPES = "payment_method_types";
    private static final String FIELD_UNACTIVATED_PAYMENT_METHOD_TYPES = "unactivated_payment_method_types";
    private final String apiKey;
    private final ElementsSessionParams params;
    private final Function0<Long> timeProvider;

    public ElementsSessionJsonParser(ElementsSessionParams elementsSessionParams, String str, Function0<Long> function0) {
        Intrinsics.checkNotNullParameter(elementsSessionParams, "params");
        Intrinsics.checkNotNullParameter(str, "apiKey");
        Intrinsics.checkNotNullParameter(function0, "timeProvider");
        this.params = elementsSessionParams;
        this.apiKey = str;
        this.timeProvider = function0;
    }

    public ElementsSessionJsonParser(ElementsSessionParams elementsSessionParams, String str, AnonymousClass1 anonymousClass1, int i2, DefaultConstructorMarker defaultConstructorMarker) {
        this(elementsSessionParams, str, (i2 & 4) != 0 ? new Function0<Long>() {
            public final Long m19invoke() {
                return Long.valueOf(System.currentTimeMillis());
            }
        } : anonymousClass1);
    }

    public ElementsSession parse(JSONObject json) {
        Intrinsics.checkNotNullParameter(json, "json");
        JSONObject mapToJsonObject = StripeJsonUtils.INSTANCE.mapToJsonObject(StripeJsonUtils.INSTANCE.optMap(json, FIELD_PAYMENT_METHOD_PREFERENCE));
        String optString = StripeJsonUtils.optString(mapToJsonObject, FIELD_OBJECT);
        if (mapToJsonObject == null || !Intrinsics.areEqual(FIELD_PAYMENT_METHOD_PREFERENCE, optString)) {
            return null;
        }
        String optString2 = mapToJsonObject.optString(FIELD_COUNTRY_CODE);
        List jsonArrayToList = ModelJsonParser.Companion.jsonArrayToList(json.optJSONArray(FIELD_UNACTIVATED_PAYMENT_METHOD_TYPES));
        ArrayList arrayList = new ArrayList(CollectionsKt.collectionSizeOrDefault(jsonArrayToList, 10));
        Iterator it2 = jsonArrayToList.iterator();
        while (it2.hasNext()) {
            String lowerCase = ((String) it2.next()).toLowerCase(Locale.ROOT);
            Intrinsics.checkNotNullExpressionValue(lowerCase, "this as java.lang.String).toLowerCase(Locale.ROOT)");
            arrayList.add(lowerCase);
        }
        ArrayList arrayList2 = arrayList;
        JSONArray optJSONArray = json.optJSONArray(FIELD_PAYMENT_METHOD_SPECS);
        String jSONArray = optJSONArray != null ? optJSONArray.toString() : null;
        JSONObject optJSONObject = json.optJSONObject(FIELD_LINK_SETTINGS);
        JSONArray optJSONArray2 = optJSONObject != null ? optJSONObject.optJSONArray(FIELD_LINK_FUNDING_SOURCES) : null;
        JSONObject optJSONObject2 = json.optJSONObject(FIELD_LINK_SETTINGS);
        boolean optBoolean = optJSONObject2 != null ? optJSONObject2.optBoolean(FIELD_LINK_PASSTHROUGH_MODE_ENABLED) : false;
        JSONArray optJSONArray3 = mapToJsonObject.optJSONArray(FIELD_ORDERED_PAYMENT_METHOD_TYPES);
        String optString3 = json.optString(FIELD_ELEMENTS_SESSION_ID);
        Intrinsics.checkNotNullExpressionValue(optString2, "countryCode");
        StripeIntent parseStripeIntent = parseStripeIntent(optString3, mapToJsonObject, optJSONArray3, arrayList2, optJSONArray2, optString2);
        String optString4 = json.optString(FIELD_MERCHANT_COUNTRY);
        boolean parseCardBrandChoiceEligibility = parseCardBrandChoiceEligibility(json);
        String optString5 = json.optString(FIELD_GOOGLE_PAY_PREFERENCE);
        if (parseStripeIntent != null) {
            return new ElementsSession(new ElementsSession.LinkSettings(ModelJsonParser.Companion.jsonArrayToList(optJSONArray2), optBoolean), jSONArray, parseStripeIntent, optString4, parseCardBrandChoiceEligibility, !Intrinsics.areEqual(optString5, "disabled"), null, 64, null);
        }
        return null;
    }

    private final StripeIntent parseStripeIntent(String elementsSessionId, JSONObject paymentMethodPreference, JSONArray orderedPaymentMethodTypes, List<String> unactivatedPaymentMethodTypes, JSONArray linkFundingSources, String countryCode) {
        JSONObject optJSONObject = paymentMethodPreference != null ? paymentMethodPreference.optJSONObject(this.params.getType()) : null;
        if (optJSONObject == null) {
            optJSONObject = new JSONObject();
        }
        if (orderedPaymentMethodTypes != null) {
            optJSONObject.put(FIELD_PAYMENT_METHOD_TYPES, orderedPaymentMethodTypes);
        }
        optJSONObject.put(FIELD_UNACTIVATED_PAYMENT_METHOD_TYPES, unactivatedPaymentMethodTypes);
        optJSONObject.put(FIELD_LINK_FUNDING_SOURCES, linkFundingSources);
        optJSONObject.put(FIELD_COUNTRY_CODE, countryCode);
        ElementsSessionParams elementsSessionParams = this.params;
        if (elementsSessionParams instanceof ElementsSessionParams.PaymentIntentType) {
            return new PaymentIntentJsonParser(null, 1, null).parse(optJSONObject);
        }
        if (elementsSessionParams instanceof ElementsSessionParams.SetupIntentType) {
            return new SetupIntentJsonParser().parse(optJSONObject);
        }
        if (!(elementsSessionParams instanceof ElementsSessionParams.DeferredIntentType)) {
            throw new NoWhenBranchMatchedException();
        }
        DeferredIntentParams.Mode mode = ((ElementsSessionParams.DeferredIntentType) elementsSessionParams).getDeferredIntentParams().getMode();
        if (mode instanceof DeferredIntentParams.Mode.Payment) {
            return new DeferredPaymentIntentJsonParser(elementsSessionId, (DeferredIntentParams.Mode.Payment) ((ElementsSessionParams.DeferredIntentType) this.params).getDeferredIntentParams().getMode(), this.apiKey, this.timeProvider).parse(optJSONObject);
        }
        if (mode instanceof DeferredIntentParams.Mode.Setup) {
            return new DeferredSetupIntentJsonParser(elementsSessionId, (DeferredIntentParams.Mode.Setup) ((ElementsSessionParams.DeferredIntentType) this.params).getDeferredIntentParams().getMode(), this.apiKey, this.timeProvider).parse(optJSONObject);
        }
        throw new NoWhenBranchMatchedException();
    }

    private final boolean parseCardBrandChoiceEligibility(JSONObject json) {
        JSONObject optJSONObject = json.optJSONObject("card_brand_choice");
        if (optJSONObject == null) {
            return false;
        }
        return optJSONObject.optBoolean("eligible", false);
    }
}