Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

External Interface Access Control #1155

Merged
merged 5 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ package com.braintreepayments.api.americanexpress

import android.content.Context
import android.net.Uri
import androidx.annotation.RestrictTo
import com.braintreepayments.api.core.ApiClient.Companion.versionedPath
import com.braintreepayments.api.core.BraintreeClient
import org.json.JSONException

/**
* Used to integrate with Braintree's American Express API
*/
class AmericanExpressClient @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) constructor(
class AmericanExpressClient internal constructor(
private val braintreeClient: BraintreeClient
) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ sealed class AmericanExpressResult {
/**
* The [rewardsBalance] was successfully fetched
*/
class Success(val rewardsBalance: AmericanExpressRewardsBalance) : AmericanExpressResult()
class Success internal constructor(
val rewardsBalance: AmericanExpressRewardsBalance
) : AmericanExpressResult()

/**
* There was an [error] fetching rewards balance
*/
class Failure(val error: Exception) : AmericanExpressResult()
class Failure internal constructor(val error: Exception) : AmericanExpressResult()
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.braintreepayments.api.americanexpress

import android.os.Parcelable
import androidx.annotation.RestrictTo
import com.braintreepayments.api.sharedutils.Json
import kotlinx.parcelize.Parcelize
import org.json.JSONException
Expand Down Expand Up @@ -49,10 +48,8 @@ data class AmericanExpressRewardsBalance @JvmOverloads constructor(
* @return The [AmericanExpressRewardsBalance] with rewards balance data.
* @throws JSONException when parsing fails.
*/
@JvmStatic
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
@Throws(JSONException::class)
fun fromJson(jsonString: String): AmericanExpressRewardsBalance {
internal fun fromJson(jsonString: String): AmericanExpressRewardsBalance {
val json = JSONObject(jsonString)

val rewardsBalance = AmericanExpressRewardsBalance()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import androidx.room.PrimaryKey
* at the JSON level. JSON encoded events can be sent directly to the analytics server.
*/
@Entity(tableName = "analytics_event_blob")
data class AnalyticsEventBlob(
internal data class AnalyticsEventBlob(
@PrimaryKey(autoGenerate = true) @ColumnInfo(name = "_id") val id: Long = 0L,
@ColumnInfo(name = "json_string") val jsonString: String,
@ColumnInfo(defaultValue = "") val sessionId: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ class BraintreeClient @VisibleForTesting internal constructor(
/**
* @suppress
*/
@JvmOverloads
constructor (
context: Context,
authorization: String,
Expand Down Expand Up @@ -129,7 +128,6 @@ class BraintreeClient @VisibleForTesting internal constructor(
/**
* @suppress
*/
@JvmOverloads
fun sendAnalyticsEvent(
eventName: String,
params: AnalyticsEventParams = AnalyticsEventParams()
Expand Down Expand Up @@ -308,7 +306,7 @@ class BraintreeClient @VisibleForTesting internal constructor(
/**
* @suppress
*/
fun reportCrash() =
internal fun reportCrash() =
getConfiguration { configuration, _ ->
analyticsClient.reportCrash(
applicationContext,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.braintreepayments.api.core

import android.os.Parcelable
import androidx.annotation.RestrictTo
import com.braintreepayments.api.core.GraphQLConstants.ErrorTypes
import com.braintreepayments.api.sharedutils.Json
import kotlinx.parcelize.Parcelize
Expand Down Expand Up @@ -64,12 +63,7 @@ class BraintreeError internal constructor(
return errors
}

/**
* @suppress
*/
@JvmStatic
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
fun fromGraphQLJsonArray(graphQLErrors: JSONArray?): List<BraintreeError> {
internal fun fromGraphQLJsonArray(graphQLErrors: JSONArray?): List<BraintreeError> {
val errors = mutableListOf<BraintreeError>()
if (graphQLErrors == null) {
return errors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import android.util.Base64
import androidx.annotation.RestrictTo
import org.json.JSONException
import org.json.JSONObject
import java.lang.NullPointerException
import kotlin.jvm.Throws

/**
* A class containing the configuration url and authorization for the current Braintree environment.
Expand All @@ -24,8 +22,8 @@ class ClientToken @Throws(InvalidArgumentException::class) internal constructor(
override val configUrl: String
override val bearer: String

@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) internal val authorizationFingerprint: String
val customerId: String?
internal val authorizationFingerprint: String
internal val customerId: String?

init {
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.braintreepayments.api.core

import androidx.annotation.RestrictTo

/**
* Callback for receiving result of [BraintreeClient.getConfiguration].
*/
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
fun interface ConfigurationCallback {
/**
* @param configuration [Configuration]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import androidx.annotation.RestrictTo
/**
* Error class thrown when a configuration value is invalid
*/
class ConfigurationException @JvmOverloads @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) constructor(
class ConfigurationException @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) constructor(
message: String?,
cause: Throwable? = null
) : BraintreeException(message, cause)
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import android.util.Base64
import com.braintreepayments.api.sharedutils.HttpClient
import org.json.JSONException

internal class ConfigurationLoader internal constructor(
internal class ConfigurationLoader(
private val httpClient: BraintreeHttpClient,
private val configurationCache: ConfigurationCache
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.os.Build
import androidx.annotation.VisibleForTesting
import com.braintreepayments.api.sharedutils.AppHelper
import com.braintreepayments.api.sharedutils.SignatureVerifier

Expand Down Expand Up @@ -123,7 +122,6 @@ internal class DeviceInspector(
private const val VENMO_APP_PACKAGE = "com.venmo"
private const val VENMO_APP_SWITCH_ACTIVITY = "controller.SetupMerchantActivity"

@VisibleForTesting
const val VENMO_BASE_64_ENCODED_SIGNATURE = "x34mMawEUcCG8l95riWCOK+kAJYejVmdt44l6tzcyUc=\n"
private val venmoIntent: Intent
get() = Intent().setComponent(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ data class ErrorWithResponse internal constructor(
*/
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
@Throws(JSONException::class)
@JvmStatic
fun fromJson(json: String?) = ErrorWithResponse(errorResponse = json).apply {
parseJson(json)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ object GraphQLConstants {
}

object ErrorMessages {
const val UNKNOWN = "An unknown error occurred."
const val USER = "Input is invalid."
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ enum class IntegrationType(val stringValue: String) {
DROP_IN("dropin");

companion object {
fun fromString(stringValue: String?): IntegrationType? {
internal fun fromString(stringValue: String?): IntegrationType? {
return values().firstOrNull { it.stringValue == stringValue }
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ object PostalAddressParser {
private const val VENMO_GQL_LOCALITY_KEY = "adminArea2"
private const val VENMO_GQL_REGION_KEY = "adminArea1"

@JvmStatic
fun fromJson(accountAddress: JSONObject?): PostalAddress =
// If we don't have an account address, return an empty PostalAddress.
accountAddress?.let {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.braintreepayments.api.core

import android.content.Context
import androidx.annotation.RestrictTo
import androidx.annotation.VisibleForTesting
import com.braintreepayments.api.sharedutils.BraintreeSharedPreferences
import java.util.*

Expand All @@ -12,32 +11,13 @@ import java.util.*
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
class UUIDHelper {

/**
* @param context Android Context
* @return A persistent UUID for this application install.
*/
fun getPersistentUUID(context: Context?): String? {
return getPersistentUUID(BraintreeSharedPreferences.getInstance(context))
}

@VisibleForTesting
internal fun getPersistentUUID(braintreeSharedPreferences: BraintreeSharedPreferences): String? {
var uuid = braintreeSharedPreferences.getString(BRAINTREE_UUID_KEY, null)
if (uuid == null) {
uuid = formattedUUID
braintreeSharedPreferences.putString(BRAINTREE_UUID_KEY, uuid)
}
return uuid
}

val formattedUUID: String
get() = UUID.randomUUID().toString().replace("-", "")

fun getInstallationGUID(context: Context?): String {
return getInstallationGUID(BraintreeSharedPreferences.getInstance(context))
}

@VisibleForTesting
internal fun getInstallationGUID(braintreeSharedPreferences: BraintreeSharedPreferences): String {
var installationGUID = braintreeSharedPreferences.getString(INSTALL_GUID, null)
if (installationGUID == null) {
Expand All @@ -48,7 +28,6 @@ class UUIDHelper {
}

companion object {
private const val BRAINTREE_UUID_KEY = "braintreeUUID"
private const val INSTALL_GUID = "InstallationGUID"
}
}
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@
* ThreeDSecure
* Make `ThreeDSecureParams` internal
* Make `ThreeDSecurePaymentAuthResult` parameters internal
* LocalPayment
* Remove `ThreeDSecurePaymentAuthResultInfo`
* LocalPayment
* Remove `LocalPaymentAuthResultInfo`
* Make `LocalPaymentAuthRequestParams` internal

## 5.0.0-beta2 (2024-08-28)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.braintreepayments.api.card

import android.os.Parcelable
import androidx.annotation.RestrictTo
import com.braintreepayments.api.sharedutils.Json
import kotlinx.parcelize.Parcelize
import org.json.JSONObject
Expand All @@ -13,13 +14,16 @@ import org.json.JSONObject
* v4#authentication-insight">Documentation</a> for possible values.
*/
@Parcelize
data class AuthenticationInsight(val regulationEnvironment: String) : Parcelable {
data class AuthenticationInsight internal constructor(
val regulationEnvironment: String
) : Parcelable {

companion object {

private const val GRAPHQL_REGULATION_ENVIRONMENT_KEY = "customerAuthenticationRegulationEnvironment"
private const val REST_REGULATION_ENVIRONMENT_KEY = "regulationEnvironment"

@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
@JvmStatic
fun fromJson(json: JSONObject?): AuthenticationInsight? {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ enum class BinType {
Unknown;

companion object {
fun fromString(string: String): BinType {
internal fun fromString(string: String): BinType {
return when (string.lowercase()) {
Yes.name.lowercase() -> Yes
No.name.lowercase() -> No
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ data class Card @JvmOverloads constructor(
private const val AUTHENTICATION_INSIGHT_INPUT_KEY = "authenticationInsightInput"
}

@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
private fun buildMetadataJSON(): JSONObject {
return MetadataBuilder()
.sessionId(sessionId)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.braintreepayments.api.card

import android.content.Context
import androidx.annotation.VisibleForTesting
import com.braintreepayments.api.card.CardNonce.Companion.fromJSON
import com.braintreepayments.api.core.AnalyticsParamRepository
import com.braintreepayments.api.core.ApiClient
Expand All @@ -16,7 +15,7 @@ import org.json.JSONObject
* Used to tokenize credit or debit cards using a [Card]. For more information see the
* [documentation](https://developer.paypal.com/braintree/docs/guides/credit-cards/overview)
*/
class CardClient @VisibleForTesting @JvmOverloads internal constructor(
class CardClient internal constructor(
private val braintreeClient: BraintreeClient,
private val apiClient: ApiClient = ApiClient(braintreeClient),
private val analyticsParamRepository: AnalyticsParamRepository = AnalyticsParamRepository.instance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,9 @@ constructor(
}
}

@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
const val API_RESOURCE_KEY: String = "creditCards"
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
const val DATA_KEY: String = "data"

private const val PAYMENT_METHOD_NONCE_KEY = "nonce"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ sealed class CardResult {
/**
* The card tokenization completed successfully. This [nonce] should be sent to your server.
*/
class Success(val nonce: CardNonce) : CardResult()
class Success internal constructor(val nonce: CardNonce) : CardResult()

/**
* There was an [error] during card tokenization.
*/
class Failure(val error: Exception) : CardResult()
class Failure internal constructor(val error: Exception) : CardResult()
}
Original file line number Diff line number Diff line change
Expand Up @@ -241,22 +241,6 @@ class CardUnitTest {
@Throws(JSONException::class)
fun buildJSON_doesNotIncludeEmptyStrings() {
val card = Card()
// card.number = ""
// card.expirationDate = ""
// card.expirationMonth = ""
// card.expirationYear = ""
// card.cvv = ""
// card.postalCode = ""
// card.cardholderName = ""
// card.firstName = ""
// card.lastName = ""
// card.company = ""
// card.streetAddress = ""
// card.extendedAddress = ""
// card.locality = ""
// card.postalCode = ""
// card.region = ""
// card.countryCode = ""
Comment on lines -244 to -259
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a typo that snuck in

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

➕ 1

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a comment that was removed in this PR. I think it was a stale comment that ended up getting merged in.


assertEquals(1, card.buildJSON().getJSONObject(CREDIT_CARD_KEY).length())
assertTrue(card.buildJSON().getJSONObject(CREDIT_CARD_KEY).has("options"))
Expand Down
Loading
Loading