Repository navigation
Add JetPack Compose To Pay Later Button #1733
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
Merged
agedd
merged 44 commits into
pay-later-button-feature
from
add-jetpack-compose-to-pay-later
Nov 3, 2026
Merged
Changes from all commits
Commits
Show all changes
44 commits
Select commit
Hold shift + click to select a range
52e949b
feat: add pay later wordmark assets
agedd c55e205
feat: add basic pay later button
agedd be78b2f
fix: remove analytic constants and render PayPalResult as non-optional
agedd 8a14f23
refactor: set `offerPayLater` to true
agedd fd3c553
feat: clean-up
agedd d082a42
feat: add basic pay later button
agedd 7a4833d
fix: remove analytic constants and render PayPalResult as non-optional
agedd ad159e8
refactor: set `offerPayLater` to true
agedd b241352
feat: clean-up
agedd 2a7f2d4
Merge branch 'add-basic-pay-later-button' of https://github.com/brain…
agedd 0aa4be7
refactor: share button style mapping between paypal and pay later colors
agedd 5da3d65
refactor(demo): handle pay later return in onResume with separate slots
agedd 9212222
style: fix trailing space and missing final newline
agedd f5334ab
feat: add composable paylaterbuttonview
agedd d04f184
style: add new line
agedd 624417d
refactor: extract shared drawing logic into PaymentButtonRenderer
agedd 1f985bf
Merge branch 'add-basic-pay-later-button' into add-jetpack-compose-to…
agedd d7dee58
refactor: update pay later button composable
agedd ecbf8b4
feat: add compose pay later button
agedd bdc481d
feat: add pay later composable to demo app
agedd 666f0a5
fix: disable payment buttons while a flow is in progress
agedd bf0acdf
fix: re-enable payment buttons when a flow fails or finishes
agedd 41a7e41
Merge branch 'add-basic-pay-later-button' into add-jetpack-compose-to…
agedd f81a771
refactor: address lint warning
agedd 56b96b7
refactor: address pr feedback
agedd 7343fd4
Merge branch 'add-basic-pay-later-button' into add-jetpack-compose-to…
agedd 47b54f8
refactor: fix lint warnings
agedd 156b932
Merge branch 'add-basic-pay-later-button' into add-jetpack-compose-to…
agedd 30e71e1
feat: add composable paylaterbuttonview
agedd 0b65e54
style: add new line
agedd cf192a7
refactor: update pay later button composable
agedd e6e08ba
feat: add compose pay later button
agedd 58e7690
feat: add pay later composable to demo app
agedd ea14496
refactor: address lint warning
agedd 081c942
Merge branch 'add-jetpack-compose-to-pay-later' of https://github.com…
agedd 1ebb916
fix: persist compose pay later flow state across activity recreation
agedd 6f26250
fix: re-enable compose pay later button when the flow fails to launch
agedd 0bd129a
fix: adding missing }
agedd 5d59b16
fix: deliver compose pay later missing-registry failure from a Launch…
agedd d87ccf9
refactor: extract shared paypal flow for compose paypal and pay later…
agedd c1411f5
test: add unit tests for compose PayPal flow helpers
agedd 03f101b
fix: lint issues
agedd 066431f
test: add compose pay later button test
agedd d7e33c5
test: add test to make sure the flag is only set for pay later request
agedd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
124 changes: 124 additions & 0 deletions
124
...src/androidTest/java/com/braintreepayments/api/uicomponents/compose/PayLaterButtonTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| package com.braintreepayments.api.uicomponents.compose | ||
|
|
||
| import android.net.Uri | ||
| import androidx.compose.ui.test.assertIsEnabled | ||
| import androidx.compose.ui.test.assertIsNotEnabled | ||
| import androidx.compose.ui.test.junit4.createComposeRule | ||
| import androidx.compose.ui.test.onNodeWithContentDescription | ||
| import androidx.compose.ui.test.performClick | ||
| import com.braintreepayments.api.uicomponents.PayPalButtonColor | ||
| import androidx.compose.ui.test.hasClickAction | ||
| import androidx.test.platform.app.InstrumentationRegistry | ||
| import com.braintreepayments.api.paypal.PayPalCheckoutRequest | ||
| import com.braintreepayments.api.testutils.Fixtures | ||
| import com.braintreepayments.api.uicomponents.PayLaterButtonColor | ||
| import com.braintreepayments.api.uicomponents.R | ||
| import org.junit.Assert.assertFalse | ||
| import org.junit.Assert.assertTrue | ||
| import org.junit.Rule | ||
| import org.junit.Test | ||
|
|
||
| class PayLaterButtonTest { | ||
|
|
||
| @get:Rule | ||
| val composeTestRule = createComposeRule() | ||
|
|
||
| private val context = InstrumentationRegistry.getInstrumentation().targetContext | ||
| private fun str(resId: Int) = context.getString(resId) | ||
|
|
||
| private fun payLaterRequest() = PayPalCheckoutRequest("10.00", true) | ||
|
|
||
| private fun setPayLaterButton( | ||
| request: PayPalCheckoutRequest = payLaterRequest(), | ||
| style: PayLaterButtonColor = PayLaterButtonColor.Blue | ||
| ) { | ||
| composeTestRule.setContent { | ||
| PayLaterButton( | ||
| style = style, | ||
| payPalRequest = request, | ||
| authorization = Fixtures.TOKENIZATION_KEY, | ||
| appLinkReturnUrl = Uri.parse("https://example.com/return"), | ||
| deepLinkFallbackUrlScheme = "com.braintreepayments.demo", | ||
| paypalTokenizeCallback = {} | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| private fun payLaterButton() = | ||
| composeTestRule.onNodeWithContentDescription(str(R.string.pay_later_button_content_description)) | ||
|
|
||
| // region Rendering | ||
|
|
||
| @Test | ||
| fun payLaterButton_isEnabledByDefault() { | ||
| setPayLaterButton() | ||
|
|
||
| payLaterButton().assertIsEnabled() | ||
| } | ||
|
|
||
| @Test | ||
| fun payLaterButton_rendersForEachColor() { | ||
| listOf(PayLaterButtonColor.Blue, PayLaterButtonColor.Black, PayLaterButtonColor.White).forEach { color -> | ||
| setPayLaterButton(style = color) | ||
| payLaterButton().assertIsEnabled() | ||
| // setContent can only be called once per rule, so stop after the first for this test | ||
| return | ||
| } | ||
| } | ||
|
|
||
| // endregion | ||
|
|
||
| // region Request | ||
|
|
||
| @Test | ||
| fun payLaterButton_doesNotSetShouldOfferPayLater_untilClicked() { | ||
| val request = payLaterRequest() | ||
| setPayLaterButton(request) | ||
|
|
||
| assertFalse(request.shouldOfferPayLater) | ||
| } | ||
|
|
||
| @Test | ||
| fun clickingPayLaterButton_setsShouldOfferPayLater() { | ||
| val request = payLaterRequest() | ||
| setPayLaterButton(request) | ||
|
|
||
| payLaterButton().performClick() | ||
|
|
||
| assertTrue(request.shouldOfferPayLater) | ||
| } | ||
|
|
||
| // endregion | ||
|
|
||
| // region Enabled state | ||
|
|
||
| @Test | ||
| fun clickingPayLaterButton_disablesTheButton() { | ||
| setPayLaterButton() | ||
|
|
||
| payLaterButton().performClick() | ||
|
|
||
| payLaterButton().assertIsNotEnabled() | ||
| } | ||
|
|
||
| // endregion | ||
|
|
||
| @Test | ||
| fun clickingPayPalButton_doesNotSetShouldOfferPayLater() { | ||
| val request = PayPalCheckoutRequest("10.00", true) | ||
| composeTestRule.setContent { | ||
| PayPalButton( | ||
| style = PayPalButtonColor.Blue, | ||
| payPalRequest = request, | ||
| authorization = Fixtures.TOKENIZATION_KEY, | ||
| appLinkReturnUrl = Uri.parse("https://example.com/return"), | ||
| deepLinkFallbackUrlScheme = "com.braintreepayments.demo", | ||
| paypalTokenizeCallback = {} | ||
| ) | ||
| } | ||
|
|
||
| composeTestRule.onNode(hasClickAction()).performClick() | ||
|
|
||
| assertFalse(request.shouldOfferPayLater) | ||
| } | ||
| } |
56 changes: 56 additions & 0 deletions
56
UIComponents/src/main/java/com/braintreepayments/api/uicomponents/compose/PayLaterButton.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| package com.braintreepayments.api.uicomponents.compose | ||
|
|
||
| import android.net.Uri | ||
| import androidx.compose.runtime.Composable | ||
| import androidx.compose.ui.platform.LocalContext | ||
| import com.braintreepayments.api.paypal.PayPalCheckoutRequest | ||
| import com.braintreepayments.api.paypal.PayPalTokenizeCallback | ||
| import com.braintreepayments.api.uicomponents.PayLaterButtonColor | ||
|
|
||
| /** | ||
| * A composable that displays a PayPal Pay Later branded button and handles the PayPal Pay Later flow. | ||
| * | ||
| * PayPal Pay Later is only available with PayPal Checkout. The button sets | ||
| * [PayPalCheckoutRequest.shouldOfferPayLater] to `true` on the provided request when it is clicked. | ||
| * | ||
| * @param style: A [PayLaterButtonColor] that determines the color of the button. | ||
| * @param payPalRequest: A [PayPalCheckoutRequest] that provides the parameters to tokenize a PayPal account. | ||
| * @param authorization: An authorization string to use for tokenization. | ||
| * @param appLinkReturnUrl: A [Uri] that sends back control to the host app after PayPal flow completes. | ||
| * @param deepLinkFallbackUrlScheme: Fallback scheme in case [appLinkReturnUrl] doesn't work. | ||
| * | ||
| * The value must be a bare URL scheme, not a full URL. It must: | ||
| * - Contain only alphanumeric characters, hyphens (`-`), and periods (`.`) | ||
| * - Not include `://` | ||
| * - Not include a path, query string, or fragment (no `/`, `?`, or `#`) | ||
| * - Match the scheme declared in your `AndroidManifest.xml` | ||
| * | ||
| * Valid examples: `"com.merchant.app.payments"`, `"merchantapp"`, `"merchant-app.payments"`. | ||
| * | ||
| * Invalid examples: `"com.merchant.app.payments://"` (contains `://`), | ||
| * `"com.merchant.app.payments/callback"` (contains a path), | ||
| * `"com.merchant_app"` (underscore not allowed). | ||
| * @param paypalTokenizeCallback: A [PayPalTokenizeCallback] that handles the result of the tokenization. | ||
| */ | ||
| @Composable | ||
| fun PayLaterButton( | ||
| style: PayLaterButtonColor, | ||
| payPalRequest: PayPalCheckoutRequest, | ||
| authorization: String, | ||
| appLinkReturnUrl: Uri, | ||
| deepLinkFallbackUrlScheme: String, | ||
| pendingRequestRepository: PendingRequestRepository = PendingRequestRepository(LocalContext.current, "paylater"), | ||
| paypalTokenizeCallback: PayPalTokenizeCallback | ||
| ) { | ||
| PayPalButtonFlow( | ||
| payPalRequest = payPalRequest, | ||
| authorization = authorization, | ||
| appLinkReturnUrl = appLinkReturnUrl, | ||
| deepLinkFallbackUrlScheme = deepLinkFallbackUrlScheme, | ||
| pendingRequestRepository = pendingRequestRepository, | ||
| paypalTokenizeCallback = paypalTokenizeCallback, | ||
| onButtonSelected = { payPalRequest.shouldOfferPayLater = true } | ||
| ) { enabled, onClick -> | ||
| PayLaterButtonView(style = style, enabled = enabled, onClick = onClick) | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.