-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Paypal Web Vault Without Purchase (#220)
* Bump AGP and Kotlin library versions, and add PaymentMethod enum to OrderRequest. * Refactor CreateOrderUseCase to use an internal JSON builder method. * Add extra parameter to CreateSetupTokenUseCase to take a PaymentMethod enum. * Update CreateSetupToken to create a paypal setup token. * Add PayPalWebVaultView and supporting classes to project. * Add PayPal Web Vault screen. * Integrate PayPal Web Vault view into Demo app. * Add deep link url to PayPalWebClient. * Add vault method. * Print setup token approval result. * Rename Demo app PaymentToken class to CardPaymentToken. * Differentiate between CardPaymentToken and PayPalPaymentToken. * Fix detekt lint errors. * Add error reporting to PayPalWebCheckoutClient. * Update view model in response to paypal web vaulting notifications. * Add proper user canceled notification for vault paypal. * Add error handling for PayPal vault without purchase. * Add PayPalWebCheckoutVaultExperienceContext type. * Add PayPal experience context support to CreatePayPalSetupTokenUseCase. * Add parsing constants for PayPalWebCheckoutClient deep link. * Update README.md with new changes and use constant in BrowserSwitchHelper instead of magic string. * Fix broken unit tests. * Create CardSetupToken and PayPalSetupToken types. * Change MainActivity superclass to Component activity. * Remove PaymentMethod enum. * Revert PayPalWebViewModel. * Update cancel URL format in unit test. * Update CHANGELOG after rebase. * Add serializable type to CreateSetupTokenRequest. * Refactor parsing logic for CreatePayPalSetupTokenUseCase. * Update CreateCardSetupToken to use kotlinx.serialization. * Update CreatePayPalPaymentTokenUseCase to use serializable. * Update CreateCardPaymentTokenUseCase to use kotlin serialization. * Change AnalyticsService coroutine invocation method. * Remove internal order ID property from PayPalWebCheckoutClient." * Rename PayPalDeepLinkUrlResult to PayPalWebCheckoutDeepLink. * Add PayPalWebStatus to project. * Add PayPalWebVaultRequest to project. * Delete BrowserSwitchHelper. * Add unit test for PayPalWebLauncher. * Migrate BrowserSwitchHelper unit tests into PayPalWebLauncher file. * Refactor unit tests for PayPalWebLauncher and PayPalWebCheckoutClient. * Refactor nested block depth lint error. * Fix detekt errors. * Update demo app to call new vault method. * Revert to AppCompatActivty until our app supports ComponentActivity. * Fix double parsing error. * Remove kotlinx.serialization from project. * Remove mention of Kotlinx Retrofit. * Reanme PayPalWebCheckoutVaultListener to PayPalWebVaultListener. * Add test for browser switch failure propagation. * Add additonal test cases for browser switch failure. * Clean up lint errors. * Add tests for vault and checkout error propagation in PayPalWebCheckoutClient. * Add metadata to browser switch call for vaulting and checkout. * Refactor unit tests. * Fix lint errors. * Clean up compilation error. * Fix loader bug. * Update PayPalWebCheckoutVault prefix to PayPalWebVault when naming. * Rename PayPal web vault view model method from updateSetupToken to vaultSetupToken. * Add documentation where needed.
- Loading branch information
1 parent
f204a22
commit 7d4c613
Showing
48 changed files
with
1,377 additions
and
640 deletions.
There are no files selected for viewing
This file contains 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 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 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
2 changes: 1 addition & 1 deletion
2
.../paypal/android/api/model/PaymentToken.kt → ...pal/android/api/model/CardPaymentToken.kt
This file contains 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
7 changes: 7 additions & 0 deletions
7
Demo/src/main/java/com/paypal/android/api/model/CardSetupToken.kt
This file contains 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,7 @@ | ||
package com.paypal.android.api.model | ||
|
||
data class CardSetupToken( | ||
val id: String, | ||
val customerId: String, | ||
val status: String, | ||
) |
3 changes: 1 addition & 2 deletions
3
...om/paypal/android/api/model/SetupToken.kt → ...l/android/api/model/PayPalPaymentToken.kt
This file contains 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 |
---|---|---|
@@ -1,7 +1,6 @@ | ||
package com.paypal.android.api.model | ||
|
||
data class SetupToken( | ||
data class PayPalPaymentToken( | ||
val id: String, | ||
val customerId: String, | ||
val status: String | ||
) |
8 changes: 8 additions & 0 deletions
8
Demo/src/main/java/com/paypal/android/api/model/PayPalSetupToken.kt
This file contains 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,8 @@ | ||
package com.paypal.android.api.model | ||
|
||
data class PayPalSetupToken( | ||
val id: String, | ||
val customerId: String, | ||
val status: String, | ||
val approveVaultHref: String? = null | ||
) |
This file contains 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 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 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 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 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 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
22 changes: 22 additions & 0 deletions
22
Demo/src/main/java/com/paypal/android/ui/paypalwebvault/PayPalWebVaultCanceledView.kt
This file contains 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,22 @@ | ||
package com.paypal.android.ui.paypalwebvault | ||
|
||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.material3.OutlinedCard | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.unit.dp | ||
import com.paypal.android.R | ||
|
||
@Composable | ||
fun PayPalWebCheckoutCanceledView() { | ||
OutlinedCard(modifier = Modifier.fillMaxWidth()) { | ||
Column(modifier = Modifier.padding(8.dp)) { | ||
Text(stringResource(id = R.string.pay_pal_vault_canceled)) | ||
Text(stringResource(id = R.string.user_canceled)) | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
Demo/src/main/java/com/paypal/android/ui/paypalwebvault/PayPalWebVaultUiState.kt
This file contains 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,18 @@ | ||
package com.paypal.android.ui.paypalwebvault | ||
|
||
import com.paypal.android.api.model.PayPalPaymentToken | ||
import com.paypal.android.api.model.PayPalSetupToken | ||
import com.paypal.android.corepayments.PayPalSDKError | ||
import com.paypal.android.paypalwebpayments.PayPalWebVaultResult | ||
|
||
data class PayPalWebVaultUiState( | ||
val isCreateSetupTokenLoading: Boolean = false, | ||
val vaultCustomerId: String = "", | ||
val setupToken: PayPalSetupToken? = null, | ||
val isVaultPayPalLoading: Boolean = false, | ||
val payPalWebVaultResult: PayPalWebVaultResult? = null, | ||
val payPalWebVaultError: PayPalSDKError? = null, | ||
val isCreatePaymentTokenLoading: Boolean = false, | ||
val paymentToken: PayPalPaymentToken? = null, | ||
val isVaultingCanceled: Boolean = false, | ||
) |
134 changes: 134 additions & 0 deletions
134
Demo/src/main/java/com/paypal/android/ui/paypalwebvault/PayPalWebVaultView.kt
This file contains 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,134 @@ | ||
package com.paypal.android.ui.paypalwebvault | ||
|
||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.Spacer | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.layout.size | ||
import androidx.compose.foundation.rememberScrollState | ||
import androidx.compose.foundation.verticalScroll | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.OutlinedCard | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.LaunchedEffect | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.platform.LocalContext | ||
import androidx.compose.ui.unit.dp | ||
import androidx.hilt.navigation.compose.hiltViewModel | ||
import androidx.lifecycle.compose.collectAsStateWithLifecycle | ||
import com.paypal.android.paypalwebpayments.PayPalWebVaultResult | ||
import com.paypal.android.ui.WireframeButton | ||
import com.paypal.android.ui.approveorder.getActivity | ||
import com.paypal.android.ui.paypalweb.PayPalWebCheckoutCanceledView | ||
import com.paypal.android.ui.vaultcard.CreatePaymentTokenForm | ||
import com.paypal.android.ui.vaultcard.CreateSetupTokenForm | ||
import com.paypal.android.uishared.components.PayPalPaymentTokenView | ||
import com.paypal.android.uishared.components.PayPalSDKErrorView | ||
import com.paypal.android.uishared.components.PayPalSetupTokenView | ||
import com.paypal.android.uishared.components.PropertyView | ||
|
||
@Composable | ||
fun PayPalWebVaultView(viewModel: PayPalWebVaultViewModel = hiltViewModel()) { | ||
val context = LocalContext.current | ||
val uiState by viewModel.uiState.collectAsStateWithLifecycle() | ||
|
||
val scrollState = rememberScrollState() | ||
LaunchedEffect(uiState) { | ||
// continuously scroll to bottom of the list when event state is updated | ||
scrollState.animateScrollTo(scrollState.maxValue) | ||
} | ||
Column( | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.padding(8.dp) | ||
.verticalScroll(scrollState) | ||
) { | ||
CreateSetupTokenForm( | ||
isLoading = uiState.isCreateSetupTokenLoading, | ||
customerId = uiState.vaultCustomerId, | ||
onCustomerIdValueChange = { value -> viewModel.vaultCustomerId = value }, | ||
onSubmit = { | ||
viewModel.createSetupToken() | ||
} | ||
) | ||
uiState.setupToken?.let { setupToken -> | ||
Spacer(modifier = Modifier.size(8.dp)) | ||
PayPalSetupTokenView(setupToken = setupToken) | ||
Spacer(modifier = Modifier.size(8.dp)) | ||
VaultPayPal( | ||
isLoading = uiState.isVaultPayPalLoading, | ||
onSubmit = { | ||
context.getActivity()?.let { activity -> | ||
viewModel.vaultSetupToken(activity) | ||
} | ||
} | ||
) | ||
} | ||
uiState.payPalWebVaultResult?.let { vaultResult -> | ||
Spacer(modifier = Modifier.size(8.dp)) | ||
PayPalWebVaultResultView(vaultResult) | ||
Spacer(modifier = Modifier.size(8.dp)) | ||
CreatePaymentTokenForm( | ||
isLoading = uiState.isCreatePaymentTokenLoading, | ||
onSubmit = { viewModel.createPaymentToken() } | ||
) | ||
} | ||
uiState.payPalWebVaultError?.let { error -> | ||
Spacer(modifier = Modifier.size(24.dp)) | ||
PayPalSDKErrorView(error = error) | ||
} | ||
if (uiState.isVaultingCanceled) { | ||
Spacer(modifier = Modifier.size(24.dp)) | ||
PayPalWebCheckoutCanceledView() | ||
} | ||
uiState.paymentToken?.let { paymentToken -> | ||
Spacer(modifier = Modifier.size(8.dp)) | ||
PayPalPaymentTokenView(paymentToken = paymentToken) | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
fun VaultPayPal( | ||
isLoading: Boolean, | ||
onSubmit: () -> Unit | ||
) { | ||
OutlinedCard( | ||
modifier = Modifier.fillMaxWidth() | ||
) { | ||
Column( | ||
modifier = Modifier.padding(8.dp) | ||
) { | ||
Text( | ||
text = "Vault PayPal", | ||
style = MaterialTheme.typography.headlineSmall | ||
) | ||
Spacer(modifier = Modifier.size(8.dp)) | ||
WireframeButton( | ||
text = "Vault PayPal", | ||
isLoading = isLoading, | ||
onClick = { onSubmit() }, | ||
modifier = Modifier.fillMaxWidth() | ||
) | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
fun PayPalWebVaultResultView(result: PayPalWebVaultResult) { | ||
OutlinedCard( | ||
modifier = Modifier.fillMaxWidth() | ||
) { | ||
Column( | ||
modifier = Modifier.padding(8.dp) | ||
) { | ||
Text( | ||
text = "PayPal Web Vault Result", | ||
style = MaterialTheme.typography.titleLarge | ||
) | ||
PropertyView(name = "Approval Session ID", value = result.approvalSessionId) | ||
} | ||
} | ||
} |
Oops, something went wrong.