private static String formatExtendedUserAddress(JSONObject address) { String extendedAddress = "" + Json.optString(address, USER_ADDRESS_ADDRESS_2_KEY, "") + "\n" + Json.optString(address, USER_ADDRESS_ADDRESS_3_KEY, "") + "\n" + Json.optString(address, USER_ADDRESS_ADDRESS_4_KEY, "") + "\n" + Json.optString(address, USER_ADDRESS_ADDRESS_5_KEY, ""); return extendedAddress.trim(); } }
public static BraintreeApiError fromJson(JSONObject json) { BraintreeApiError error = new BraintreeApiError(); error.mCode = Json.optString(json, "code", null); error.mMessage = Json.optString(json, "developer_message", null); error.mIn = Json.optString(json, "in", null); error.mAt = Json.optString(json, "at", null); return error; }
public static VisaCheckoutUserData fromJson(JSONObject json) { if (json == null) { json = new JSONObject(); } VisaCheckoutUserData visaCheckoutUserData = new VisaCheckoutUserData(); visaCheckoutUserData.mUserFirstName = Json.optString(json, "userFirstName", ""); visaCheckoutUserData.mUserLastName = Json.optString(json, "userLastName", ""); visaCheckoutUserData.mUserFullName = Json.optString(json, "userFullName", ""); visaCheckoutUserData.mUsername = Json.optString(json, "userName", ""); visaCheckoutUserData.mUserEmail = Json.optString(json, "userEmail", ""); return visaCheckoutUserData; }
public static VisaCheckoutAddress fromJson(JSONObject json) { if (json == null) { json = new JSONObject(); } VisaCheckoutAddress visaCheckoutAddress = new VisaCheckoutAddress(); visaCheckoutAddress.mFirstName = Json.optString(json, "firstName", ""); visaCheckoutAddress.mLastName = Json.optString(json, "lastName", ""); visaCheckoutAddress.mStreetAddress = Json.optString(json, "streetAddress", ""); visaCheckoutAddress.mExtendedAddress = Json.optString(json, "extendedAddress", ""); visaCheckoutAddress.mLocality = Json.optString(json, "locality", ""); visaCheckoutAddress.mRegion = Json.optString(json, "region", ""); visaCheckoutAddress.mPostalCode = Json.optString(json, "postalCode", ""); visaCheckoutAddress.mCountryCode = Json.optString(json, "countryCode", ""); visaCheckoutAddress.mPhoneNumber = Json.optString(json, "phoneNumber", ""); return visaCheckoutAddress; }
public static PayPalCreditFinancingAmount fromJson(JSONObject amount) { PayPalCreditFinancingAmount result = new PayPalCreditFinancingAmount(); if (amount == null) { return result; } result.mCurrency = Json.optString(amount, CURRENCY_KEY, null); result.mValue = Json.optString(amount, VALUE_KEY, null); return result; }
static BraintreeApiConfiguration fromJson(JSONObject json) { if (json == null) { json = new JSONObject(); } BraintreeApiConfiguration braintreeApiConfiguration = new BraintreeApiConfiguration(); braintreeApiConfiguration.mAccessToken = Json.optString(json, ACCESS_TOKEN_KEY, ""); braintreeApiConfiguration.mUrl = Json.optString(json, URL_KEY, ""); return braintreeApiConfiguration; }
static IdealConfiguration fromJson(JSONObject json) { if (json == null) { json = new JSONObject(); } IdealConfiguration configuration = new IdealConfiguration(); configuration.mRouteId = Json.optString(json, ROUTE_ID_KEY, ""); configuration.mAssetsUrl = Json.optString(json, ASSETS_URL_KEY, ""); return configuration; }
/** * Parse an {@link PayPalConfiguration} from json. * * @param json The {@link JSONObject} to parse. * @return An {@link PayPalConfiguration} instance with data that was able to be parsed from * the {@link JSONObject}. */ public static PayPalConfiguration fromJson(JSONObject json) { if (json == null) { json = new JSONObject(); } PayPalConfiguration payPalConfiguration = new PayPalConfiguration(); payPalConfiguration.mDisplayName = Json.optString(json, DISPLAY_NAME_KEY, null); payPalConfiguration.mClientId = Json.optString(json, CLIENT_ID_KEY, null); payPalConfiguration.mPrivacyUrl = Json.optString(json, PRIVACY_URL_KEY, null); payPalConfiguration.mUserAgreementUrl = Json.optString(json, USER_AGREEMENT_URL_KEY, null); payPalConfiguration.mDirectBaseUrl = Json.optString(json, DIRECT_BASE_URL_KEY, null); payPalConfiguration.mEnvironment = Json.optString(json, ENVIRONMENT_KEY, null); payPalConfiguration.mTouchDisabled = json.optBoolean(TOUCH_DISABLED_KEY, true); payPalConfiguration.mCurrencyIsoCode = Json.optString(json, CURRENCY_ISO_CODE_KEY, null); payPalConfiguration.mUseBillingAgreement = json.optBoolean(BILLING_AGREEMENT_KEY, false); return payPalConfiguration; }
/** * Parses the Venmo configuration from json. * * @param json The json to parse. * @return A {@link VenmoConfiguration} instance with data that was able to be parsed from the * {@link JSONObject}. */ static VenmoConfiguration fromJson(JSONObject json) { if (json == null) { json = new JSONObject(); } VenmoConfiguration venmoConfiguration = new VenmoConfiguration(); venmoConfiguration.mAccessToken = Json.optString(json, ACCESS_TOKEN_KEY, ""); venmoConfiguration.mEnvironment = Json.optString(json, ENVIRONMENT_KEY, ""); venmoConfiguration.mMerchantId = Json.optString(json, MERCHANT_ID_KEY, ""); return venmoConfiguration; }
static SamsungPayConfiguration fromJson(JSONObject json) { SamsungPayConfiguration configuration = new SamsungPayConfiguration(); if (json == null) { json = new JSONObject(); } configuration.mMerchantDisplayName = Json.optString(json, DISPLAY_NAME_KEY, ""); configuration.mServiceId = Json.optString(json, SERVICE_ID_KEY, ""); try { JSONArray supportedCardBrands = json.getJSONArray(SUPPORTED_CARD_BRANDS_KEY); for (int i = 0; i < supportedCardBrands.length(); i++) { configuration.mSupportedCardBrands.add(supportedCardBrands.getString(i)); } } catch (JSONException ignored) {} configuration.mSamsungAuthorization = Json.optString(json, SAMSUNG_AUTHORIZATION_KEY, ""); configuration.mEnvironment = Json.optString(json, ENVIRONMENT, ""); return configuration; }
/** * Used to parse a response from the Braintree Gateway to be used for American Express rewards balance. * * @param jsonString The json response from the Braintree Gateway American Express rewards balance route. * @return The {@link com.braintreepayments.api.models.AmericanExpressRewardsBalance} with rewards balance data. * @throws JSONException when parsing fails. */ public static AmericanExpressRewardsBalance fromJson(String jsonString) throws JSONException { JSONObject json = new JSONObject(jsonString); AmericanExpressRewardsBalance rewardsBalance = new AmericanExpressRewardsBalance(); if (json.has(ERROR_KEY)) { JSONObject errorJson = json.getJSONObject(ERROR_KEY); rewardsBalance.mErrorMessage = errorJson.getString(ERROR_MESSAGE_KEY); rewardsBalance.mErrorCode = errorJson.getString(ERROR_CODE_KEY); } rewardsBalance.mConversionRate = Json.optString(json, CONVERSION_RATE_KEY, null); rewardsBalance.mCurrencyAmount = Json.optString(json, CURRENCY_AMOUNT_KEY, null); rewardsBalance.mCurrencyIsoCode = Json.optString(json, CURRENCY_ISO_CODE_KEY, null); rewardsBalance.mRequestId = Json.optString(json, REQUEST_ID_KEY, null); rewardsBalance.mRewardsAmount = Json.optString(json, REWARDS_AMOUNT_KEY, null); rewardsBalance.mRewardsUnit = Json.optString(json, REWARDS_UNIT_KEY, null); return rewardsBalance; }
protected static BinData fromJson(JSONObject json) { if (json == null) { json = new JSONObject(); } BinData binData = new BinData(); binData.mPrepaid = Json.optString(json, PREPAID_KEY, UNKNOWN); binData.mHealthcare = Json.optString(json, HEALTHCARE_KEY, UNKNOWN); binData.mDebit = Json.optString(json, DEBIT_KEY, UNKNOWN); binData.mDurbinRegulated = Json.optString(json, DURBIN_REGULATED_KEY, UNKNOWN); binData.mCommercial = Json.optString(json, COMMERCIAL_KEY, UNKNOWN); binData.mPayroll = Json.optString(json, PAYROLL_KEY, UNKNOWN); binData.mIssuingBank = convertNullToUnknown(json, ISSUING_BANK_KEY); binData.mCountryOfIssuance = convertNullToUnknown(json, COUNTRY_OF_ISSUANCE_KEY); binData.mProductId = convertNullToUnknown(json, PRODUCT_ID_KEY); return binData; }
public BraintreeApiErrorResponse(String jsonString) { mOriginalResponse = jsonString; try { JSONObject json = new JSONObject(jsonString); JSONObject error = json.getJSONObject("error"); mMessage = Json.optString(error, "developer_message", "No message was returned"); mErrors = BraintreeApiError.fromJsonArray(error.optJSONArray("details")); } catch (JSONException e) { mMessage = "Parsing error response failed"; } }
public static BraintreeError fromJson(JSONObject json) { BraintreeError error = new BraintreeError(); error.mField = Json.optString(json, FIELD_KEY, null); error.mMessage = Json.optString(json, MESSAGE_KEY, null); error.mFieldErrors = BraintreeError.fromJsonArray(json.optJSONArray(FIELD_ERRORS_KEY)); return error; }
private static String convertNullToUnknown(JSONObject json, String key) { if (json.has(key) && json.isNull(key)) { return UNKNOWN; } else { return Json.optString(json, key, ""); } }
/** * Parse a {@link KountConfiguration} from json. * * @param json The {@link JSONObject} to parse. * @return a {@link KountConfiguration} instance with the data that was able to be parsed from * the {@link JSONObject}. */ public static KountConfiguration fromJson(JSONObject json) { if (json == null) { json = new JSONObject(); } KountConfiguration kountConfiguration = new KountConfiguration(); kountConfiguration.mKountMerchantId = Json.optString(json, KOUNT_MERCHANT_ID_KEY, ""); return kountConfiguration; }
/** * Parse an {@link AnalyticsConfiguration} from json. * * @param json The {@link JSONObject} to parse. * @return An {@link AnalyticsConfiguration} instance with data that was able to be parsed from * the {@link JSONObject}. */ public static AnalyticsConfiguration fromJson(JSONObject json) { if (json == null) { json = new JSONObject(); } AnalyticsConfiguration analyticsConfiguration = new AnalyticsConfiguration(); analyticsConfiguration.mUrl = Json.optString(json, URL_KEY, null); return analyticsConfiguration; }
/** * Parse an {@link AndroidPayConfiguration} from json. * * @param json The {@link JSONObject} to parse. * @return An {@link AndroidPayConfiguration} instance with data that was able to be parsed from * the {@link JSONObject}. */ public static GooglePaymentConfiguration fromJson(JSONObject json) { if (json == null) { json = new JSONObject(); } GooglePaymentConfiguration googlePaymentConfiguration = new GooglePaymentConfiguration(); googlePaymentConfiguration.mEnabled = json.optBoolean(ENABLED_KEY, false); googlePaymentConfiguration.mGoogleAuthorizationFingerprint = Json.optString(json, GOOGLE_AUTHORIZATION_FINGERPRINT_KEY, null); googlePaymentConfiguration.mEnvironment = Json.optString(json, ENVIRONMENT_KEY, null); googlePaymentConfiguration.mDisplayName = Json.optString(json, DISPLAY_NAME_KEY, ""); JSONArray supportedNetworks = json.optJSONArray(SUPPORTED_NETWORKS_KEY); if (supportedNetworks != null) { googlePaymentConfiguration.mSupportedNetworks = new String[supportedNetworks.length()]; for (int i = 0; i < supportedNetworks.length(); i++) { try { googlePaymentConfiguration.mSupportedNetworks[i] = supportedNetworks.getString(i); } catch (JSONException ignored) {} } } else { googlePaymentConfiguration.mSupportedNetworks = new String[0]; } return googlePaymentConfiguration; }
public static PostalAddress fromUserAddressJson(JSONObject json) { PostalAddress address = new PostalAddress(); address .recipientName(Json.optString(json, USER_ADDRESS_NAME_KEY, "")) .phoneNumber(Json.optString(json, USER_ADDRESS_PHONE_NUMBER_KEY, "")) .streetAddress(Json.optString(json, USER_ADDRESS_ADDRESS_1_KEY, "")) .extendedAddress(formatExtendedUserAddress(json)) .locality(Json.optString(json, USER_ADDRESS_LOCALITY_KEY, "")) .region(Json.optString(json, USER_ADDRESS_ADMINISTRATIVE_AREA_KEY, "")) .countryCodeAlpha2(Json.optString(json, USER_ADDRESS_COUNTRY_CODE_KEY, "")) .postalCode(Json.optString(json, USER_ADDRESS_POSTAL_CODE_KEY, "")) .sortingCode(Json.optString(json, USER_ADDRESS_SORTING_CODE_KEY, "")); return address; }
private void fromGraphQLJson(JSONObject json) throws JSONException { JSONObject data = json.getJSONObject(DATA_KEY); if (data.has(GRAPHQL_TOKENIZE_CREDIT_CARD_KEY)) { JSONObject payload = data.getJSONObject(GRAPHQL_TOKENIZE_CREDIT_CARD_KEY); JSONObject creditCard = payload.getJSONObject(GRAPHQL_CREDIT_CARD_KEY); mLastFour = Json.optString(creditCard, GRAPHQL_LAST_FOUR_KEY, ""); mLastTwo = mLastFour.length() < 4 ? "" : mLastFour.substring(2); mCardType = Json.optString(creditCard, GRAPHQL_BRAND_KEY, "Unknown"); mThreeDSecureInfo = ThreeDSecureInfo.fromJson(null); mBinData = BinData.fromJson(creditCard.optJSONObject(BIN_DATA_KEY)); mNonce = payload.getString(TOKEN_KEY); mDescription = TextUtils.isEmpty(mLastTwo) ? "" : "ending in ••" + mLastTwo; mDefault = false; } else { throw new JSONException("Failed to parse GraphQL response JSON"); } }