Skip to content

Commit 90722fd

Browse files
committed
Render Pay with Card button on PayPal view.
1 parent 3f75d1e commit 90722fd

File tree

3 files changed

+18
-22
lines changed

3 files changed

+18
-22
lines changed

Demo/src/main/java/com/paypal/android/ui/paypalweb/PayPalWebView.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import androidx.compose.ui.tooling.preview.Preview
1919
import androidx.hilt.navigation.compose.hiltViewModel
2020
import androidx.lifecycle.compose.collectAsStateWithLifecycle
2121
import com.paypal.android.uishared.components.ActionButtonColumn
22+
import com.paypal.android.uishared.components.ActionPaymentButtonColumn
2223
import com.paypal.android.uishared.components.CreateOrderForm
2324
import com.paypal.android.uishared.components.ErrorView
2425
import com.paypal.android.uishared.components.OrderView
@@ -106,9 +107,8 @@ private fun Step2_StartPayPalWebCheckout(uiState: PayPalWebUiState, viewModel: P
106107
fundingSource = uiState.fundingSource,
107108
onFundingSourceChange = { value -> viewModel.fundingSource = value },
108109
)
109-
ActionButtonColumn(
110-
defaultTitle = "START CHECKOUT",
111-
successTitle = "CHECKOUT COMPLETE",
110+
ActionPaymentButtonColumn(
111+
fundingSource = uiState.fundingSource,
112112
state = uiState.payPalWebCheckoutState,
113113
onClick = { context.getActivityOrNull()?.let { viewModel.startWebCheckout(it) } },
114114
modifier = Modifier

Demo/src/main/java/com/paypal/android/uishared/components/ActionPaymentButtonColumn.kt

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ import com.paypal.android.paymentbuttons.PayPalButton
1919
import com.paypal.android.paymentbuttons.PayPalButtonColor
2020
import com.paypal.android.paymentbuttons.PayPalButtonLabel
2121
import com.paypal.android.paymentbuttons.PaymentButtonSize
22-
import com.paypal.android.uishared.enums.DemoPaymentButtonType
22+
import com.paypal.android.paypalwebpayments.PayPalWebCheckoutFundingSource
2323
import com.paypal.android.uishared.state.ActionState
2424
import com.paypal.android.uishared.state.CompletedActionState
2525
import com.paypal.android.utils.UIConstants
2626

2727
@Composable
2828
fun <S, E> ActionPaymentButtonColumn(
29-
type: DemoPaymentButtonType,
29+
fundingSource: PayPalWebCheckoutFundingSource,
3030
state: ActionState<S, E>,
3131
onClick: () -> Unit,
3232
modifier: Modifier = Modifier,
@@ -36,7 +36,7 @@ fun <S, E> ActionPaymentButtonColumn(
3636
modifier = modifier
3737
) {
3838
DemoPaymentButton(
39-
type = type,
39+
fundingSource = fundingSource,
4040
onClick = {
4141
if (state is ActionState.Idle) {
4242
onClick()
@@ -59,29 +59,31 @@ fun <S, E> ActionPaymentButtonColumn(
5959

6060
@Composable
6161
fun DemoPaymentButton(
62-
type: DemoPaymentButtonType,
62+
fundingSource: PayPalWebCheckoutFundingSource,
6363
onClick: () -> Unit,
6464
modifier: Modifier = Modifier
6565
) {
66-
when (type) {
67-
DemoPaymentButtonType.PAYPAL -> AndroidView(
66+
when (fundingSource) {
67+
68+
PayPalWebCheckoutFundingSource.CARD -> AndroidView(
6869
factory = { context ->
69-
PayPalButton(context).apply { setOnClickListener { onClick() } }
70+
CardButton(context).apply { setOnClickListener { onClick() } }
7071
},
7172
update = { button ->
72-
button.color = PayPalButtonColor.BLUE
73-
button.label = PayPalButtonLabel.PAY
73+
button.label = CardButtonLabel.PAY
7474
button.size = PaymentButtonSize.LARGE
7575
},
7676
modifier = modifier
7777
)
7878

79-
DemoPaymentButtonType.CARD -> AndroidView(
79+
else -> AndroidView(
8080
factory = { context ->
81-
CardButton(context).apply { setOnClickListener { onClick() } }
81+
PayPalButton(context).apply { setOnClickListener { onClick() } }
8282
},
8383
update = { button ->
84-
button.label = CardButtonLabel.PAY
84+
button.color = PayPalButtonColor.BLUE
85+
button.label = PayPalButtonLabel.PAY
86+
button.size = PaymentButtonSize.LARGE
8587
},
8688
modifier = modifier
8789
)
@@ -95,7 +97,7 @@ fun StatefulActionPaymentButtonPreview() {
9597
Surface(modifier = Modifier.fillMaxSize()) {
9698
Column {
9799
ActionPaymentButtonColumn(
98-
type = DemoPaymentButtonType.CARD,
100+
fundingSource = PayPalWebCheckoutFundingSource.CARD,
99101
state = ActionState.Idle,
100102
onClick = {},
101103
modifier = Modifier

Demo/src/main/java/com/paypal/android/uishared/enums/DemoPaymentButtonType.kt

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)