Skip to content

Commit

Permalink
Merge branch 'main' into shipping-callback-feature
Browse files Browse the repository at this point in the history
# Conflicts:
#	CHANGELOG.md
  • Loading branch information
jaxdesmarais committed Dec 16, 2024
2 parents 182f599 + 8c181f1 commit 8849562
Show file tree
Hide file tree
Showing 1,267 changed files with 9,037 additions and 3,176 deletions.
1 change: 1 addition & 0 deletions .github/PULL_REQUEST_TEMPLATE.MD
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Thank you for your contribution to Braintree.

- [ ] Added a changelog entry
- [ ] Relevant test coverage
- [ ] Tested and confirmed payment flows affected by this change are functioning as expected

### Authors
> List GitHub usernames for everyone who contributed to this pull request.
Expand Down
7 changes: 4 additions & 3 deletions APP_LINK_SETUP.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ Before using this feature, you must register your App Link domain in the Braintr

1. Log into your Control Panel (e.g. [Sandbox](https://sandbox.braintreegateway.com/login), or [Production](https://www.braintreegateway.com/login)).
2. Click on the **gear icon** in the top right corner. A drop-down menu will open.
3. Click **Processing** from the drop-down menu.
4. Scroll to the **Payment Methods** section.
5. Next to **PayPal**, click the **Options** link. This will take you to your linked PayPal Account(s) page.
3. Select **Account Settings** from the drop-down menu.
4. In the **Processing Options** tab, go to **Payment Methods** section.
5. Next to **PayPal**, click the **Link Sandbox** link. This will give you option to link your Braintree and PayPal accounts.
- If your accounts are already linked, you'd see an **Options** button instead.
6. Click the **View Domain Names** button. This will take you to the **PayPal Domain Names** page.
- Note: If you have a single PayPal account, it will be at the bottom of the page. If you have multiple PayPal accounts, it will be at the top right of the page.
7. Click the **+ Add** link on the top right of the page or scroll to the **Specify Your Domain Names** section.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.braintreepayments.api.core

import android.content.Context
import androidx.annotation.RestrictTo
import androidx.work.Data
import androidx.work.ExistingWorkPolicy
import androidx.work.ListenableWorker
Expand All @@ -13,30 +14,49 @@ import org.json.JSONObject
import java.util.*
import java.util.concurrent.TimeUnit

@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
@Suppress("SwallowedException", "TooGenericExceptionCaught")
internal class AnalyticsClient(
context: Context,
class AnalyticsClient internal constructor(
private val httpClient: BraintreeHttpClient = BraintreeHttpClient(),
private val analyticsDatabase: AnalyticsDatabase = AnalyticsDatabase.getInstance(context.applicationContext),
private val workManager: WorkManager = WorkManager.getInstance(context.applicationContext),
private val analyticsDatabase: AnalyticsDatabase = AnalyticsDatabaseProvider().analyticsDatabase,
private val workManager: WorkManager = WorkManagerProvider().workManager,
private val deviceInspector: DeviceInspector = DeviceInspector(),
private val analyticsParamRepository: AnalyticsParamRepository = AnalyticsParamRepository.instance,
private val time: Time = Time()
private val time: Time = Time(),
private val configurationLoader: ConfigurationLoader = ConfigurationLoader.instance,
private val merchantRepository: MerchantRepository = MerchantRepository.instance
) {
private val applicationContext = context.applicationContext

private val applicationContext: Context
get() = merchantRepository.applicationContext

fun sendEvent(
configuration: Configuration,
event: AnalyticsEvent,
integration: IntegrationType?,
authorization: Authorization
): UUID {
scheduleAnalyticsWriteInBackground(event, authorization)
return scheduleAnalyticsUploadInBackground(
configuration,
authorization,
integration
eventName: String,
analyticsEventParams: AnalyticsEventParams = AnalyticsEventParams()
) {
val analyticsEvent = AnalyticsEvent(
name = eventName,
timestamp = time.currentTime,
payPalContextId = analyticsEventParams.payPalContextId,
linkType = analyticsEventParams.linkType,
isVaultRequest = analyticsEventParams.isVaultRequest,
startTime = analyticsEventParams.startTime,
endTime = analyticsEventParams.endTime,
endpoint = analyticsEventParams.endpoint,
experiment = analyticsEventParams.experiment,
paymentMethodsDisplayed = analyticsEventParams.paymentMethodsDisplayed,
appSwitchUrl = analyticsEventParams.appSwitchUrl
)
configurationLoader.loadConfiguration { result ->
if (result is ConfigurationLoaderResult.Success) {
scheduleAnalyticsWriteInBackground(analyticsEvent, merchantRepository.authorization)
scheduleAnalyticsUploadInBackground(
configuration = result.configuration,
authorization = merchantRepository.authorization,
integration = merchantRepository.integrationType
)
}
}
}

private fun scheduleAnalyticsWriteInBackground(
Expand Down Expand Up @@ -221,6 +241,7 @@ internal class AnalyticsClient(
.putOpt(FPTI_KEY_MERCHANT_EXPERIMENT, event.experiment)
.putOpt(FPTI_KEY_MERCHANT_PAYMENT_METHODS_DISPLAYED,
event.paymentMethodsDisplayed.ifEmpty { null })
.putOpt(FPTI_KEY_URL, event.appSwitchUrl)
return json.toString()
}

Expand Down Expand Up @@ -252,6 +273,9 @@ internal class AnalyticsClient(
}

companion object {

val lazyInstance: Lazy<AnalyticsClient> = lazy { AnalyticsClient() }

private const val FPTI_ANALYTICS_URL = "https://api-m.paypal.com/v1/tracking/batch/events"

private const val FPTI_KEY_PAYPAL_CONTEXT_ID = "paypal_context_id"
Expand All @@ -270,6 +294,7 @@ internal class AnalyticsClient(
private const val FPTI_KEY_ENDPOINT = "endpoint"
private const val FPTI_KEY_MERCHANT_EXPERIMENT = "experiment"
private const val FPTI_KEY_MERCHANT_PAYMENT_METHODS_DISPLAYED = "payment_methods_displayed"
private const val FPTI_KEY_URL = "url"

private const val FPTI_BATCH_KEY_VENMO_INSTALLED = "venmo_installed"
private const val FPTI_BATCH_KEY_PAYPAL_INSTALLED = "paypal_installed"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ internal data class AnalyticsEvent(
val endTime: Long? = null,
val endpoint: String? = null,
val experiment: String? = null,
val paymentMethodsDisplayed: List<String> = emptyList()
val paymentMethodsDisplayed: List<String> = emptyList(),
val appSwitchUrl: String? = null
)
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ data class AnalyticsEventParams @JvmOverloads constructor(
var endTime: Long? = null,
var endpoint: String? = null,
val experiment: String? = null,
val paymentMethodsDisplayed: List<String> = emptyList()
val paymentMethodsDisplayed: List<String> = emptyList(),
val appSwitchUrl: String? = null
)
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ internal class AnalyticsUploadWorker(
) : Worker(context, params) {

override fun doWork(): Result {
val analyticsClient = AnalyticsClient(applicationContext)
val analyticsClient = AnalyticsClient()
return analyticsClient.performAnalyticsUpload(inputData)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ internal class AnalyticsWriteToDbWorker(
) : Worker(context, params) {

override fun doWork(): Result {
val analyticsClient = AnalyticsClient(applicationContext)
val analyticsClient = AnalyticsClient()
return analyticsClient.performAnalyticsWrite(inputData)
}
}
Loading

0 comments on commit 8849562

Please sign in to comment.