Skip to content

Commit acc3b5e

Browse files
committed
* make startAsync, vaultAsync functions internal
* use appUrl and fallback app url scheme in demo app
1 parent 7946747 commit acc3b5e

File tree

5 files changed

+34
-35
lines changed

5 files changed

+34
-35
lines changed

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

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,11 @@ class PayPalCheckoutViewModel @Inject constructor(
108108
if (orderId == null) {
109109
payPalWebCheckoutState = ActionState.Failure(Exception("Create an order to continue."))
110110
} else {
111-
viewModelScope.launch {
112-
startCheckoutWithOrderId(activity, orderId)
113-
}
111+
startCheckoutWithOrderId(activity, orderId)
114112
}
115113
}
116114

117-
private suspend fun startCheckoutWithOrderId(activity: ComponentActivity, orderId: String) {
115+
private fun startCheckoutWithOrderId(activity: ComponentActivity, orderId: String) {
118116
payPalWebCheckoutState = ActionState.Loading
119117

120118
val checkoutRequest = PayPalWebCheckoutRequest(
@@ -124,13 +122,16 @@ class PayPalCheckoutViewModel @Inject constructor(
124122
APP_URL,
125123
APP_FALLBACK_URL_SCHEME
126124
)
127-
when (val startResult = paypalClient.startAsync(activity, checkoutRequest)) {
128-
is PayPalPresentAuthChallengeResult.Success -> {
129-
// do nothing; wait for user to authenticate PayPal checkout in Chrome Custom Tab
130-
}
131125

132-
is PayPalPresentAuthChallengeResult.Failure ->
133-
payPalWebCheckoutState = ActionState.Failure(startResult.error)
126+
paypalClient.start(activity, checkoutRequest) { startResult ->
127+
when (startResult) {
128+
is PayPalPresentAuthChallengeResult.Success -> {
129+
// do nothing; wait for user to authenticate PayPal checkout in Chrome Custom Tab
130+
}
131+
132+
is PayPalPresentAuthChallengeResult.Failure ->
133+
payPalWebCheckoutState = ActionState.Failure(startResult.error)
134+
}
134135
}
135136
}
136137

Demo/src/main/java/com/paypal/android/ui/paypalwebvault/PayPalVaultViewModel.kt

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import android.content.Intent
55
import androidx.activity.ComponentActivity
66
import androidx.lifecycle.ViewModel
77
import androidx.lifecycle.viewModelScope
8+
import com.paypal.android.DemoConstants.APP_FALLBACK_URL_SCHEME
89
import com.paypal.android.DemoConstants.APP_URL
910
import com.paypal.android.api.model.PayPalSetupToken
1011
import com.paypal.android.api.services.SDKSampleServerAPI
@@ -30,11 +31,6 @@ class PayPalVaultViewModel @Inject constructor(
3031
val createPayPalSetupTokenUseCase: CreatePayPalSetupTokenUseCase,
3132
val createPayPalPaymentTokenUseCase: CreatePayPalPaymentTokenUseCase,
3233
) : ViewModel() {
33-
34-
companion object {
35-
const val URL_SCHEME = "com.paypal.android.demo"
36-
}
37-
3834
private val coreConfig = CoreConfig(SDKSampleServerAPI.clientId)
3935
private val paypalClient = PayPalWebCheckoutClient(applicationContext, coreConfig)
4036

@@ -85,7 +81,8 @@ class PayPalVaultViewModel @Inject constructor(
8581
val request = PayPalWebVaultRequest(
8682
setupTokenId,
8783
appSwitchWhenEligible,
88-
APP_URL
84+
APP_URL,
85+
APP_FALLBACK_URL_SCHEME
8986
)
9087
vaultSetupTokenWithRequest(activity, request)
9188
}
@@ -98,8 +95,8 @@ class PayPalVaultViewModel @Inject constructor(
9895
) {
9996
vaultPayPalState = ActionState.Loading
10097

101-
viewModelScope.launch {
102-
when (val result = paypalClient.vaultAsync(activity, request)) {
98+
paypalClient.vault(activity, request) { result ->
99+
when (result) {
103100
is PayPalPresentAuthChallengeResult.Success -> {
104101
// do nothing; wait for user to authenticate PayPal vault in Chrome Custom Tab
105102
}

PayPalWebPayments/api/PayPalWebPayments.api

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,8 @@ public final class com/paypal/android/paypalwebpayments/PayPalWebCheckoutClient
4545
public final fun restore (Ljava/lang/String;)V
4646
public final fun start (Landroid/app/Activity;Lcom/paypal/android/paypalwebpayments/PayPalWebCheckoutRequest;)Lcom/paypal/android/paypalwebpayments/PayPalPresentAuthChallengeResult;
4747
public final fun start (Landroid/app/Activity;Lcom/paypal/android/paypalwebpayments/PayPalWebCheckoutRequest;Lcom/paypal/android/paypalwebpayments/PayPalWebStartCallback;)V
48-
public final fun startAsync (Landroid/app/Activity;Lcom/paypal/android/paypalwebpayments/PayPalWebCheckoutRequest;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
4948
public final fun vault (Landroid/app/Activity;Lcom/paypal/android/paypalwebpayments/PayPalWebVaultRequest;)Lcom/paypal/android/paypalwebpayments/PayPalPresentAuthChallengeResult;
5049
public final fun vault (Landroidx/activity/ComponentActivity;Lcom/paypal/android/paypalwebpayments/PayPalWebVaultRequest;Lcom/paypal/android/paypalwebpayments/PayPalWebVaultCallback;)V
51-
public final fun vaultAsync (Landroid/app/Activity;Lcom/paypal/android/paypalwebpayments/PayPalWebVaultRequest;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
5250
}
5351

5452
public abstract class com/paypal/android/paypalwebpayments/PayPalWebCheckoutFinishStartResult {

PayPalWebPayments/src/main/java/com/paypal/android/paypalwebpayments/PayPalWebCheckoutClient.kt

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import android.content.Context
55
import android.content.Intent
66
import android.net.Uri
77
import androidx.activity.ComponentActivity
8+
import androidx.annotation.VisibleForTesting
89
import androidx.core.net.toUri
910
import com.paypal.android.corepayments.CoreConfig
1011
import com.paypal.android.corepayments.Environment
@@ -108,8 +109,8 @@ class PayPalWebCheckoutClient internal constructor(
108109
* @param request [PayPalWebCheckoutRequest] for requesting an order approval
109110
*/
110111
@Deprecated(
111-
message = "Use startAsync(activity, request) or start(activity, request, callback) instead.",
112-
replaceWith = ReplaceWith("startAsync(activity, request)")
112+
message = "Use start(activity, request, callback) for callback-based flows, includes app switching feature",
113+
replaceWith = ReplaceWith("start(activity, request, callback)")
113114
)
114115
fun start(
115116
activity: Activity,
@@ -159,7 +160,8 @@ class PayPalWebCheckoutClient internal constructor(
159160
*
160161
* @param request [PayPalWebCheckoutRequest] for requesting an order approval
161162
*/
162-
suspend fun startAsync(
163+
@VisibleForTesting
164+
internal suspend fun startAsync(
163165
activity: Activity,
164166
request: PayPalWebCheckoutRequest
165167
): PayPalPresentAuthChallengeResult {
@@ -250,8 +252,8 @@ class PayPalWebCheckoutClient internal constructor(
250252
* @param request [PayPalWebVaultRequest] for vaulting PayPal as a payment method
251253
*/
252254
@Deprecated(
253-
message = "Use vaultAsync(activity, request) or vault(activity, request, callback) instead.",
254-
replaceWith = ReplaceWith("vaultAsync(activity, request)")
255+
message = "Use vault(activity, request, callback) for callback-based flows, includes app switching feature",
256+
replaceWith = ReplaceWith("vault(activity, request, callback)")
255257
)
256258
fun vault(
257259
activity: Activity,
@@ -298,7 +300,8 @@ class PayPalWebCheckoutClient internal constructor(
298300
*
299301
* @param request [PayPalWebVaultRequest] for vaulting PayPal as a payment method
300302
*/
301-
suspend fun vaultAsync(
303+
@VisibleForTesting
304+
internal suspend fun vaultAsync(
302305
activity: Activity,
303306
request: PayPalWebVaultRequest
304307
): PayPalPresentAuthChallengeResult {
@@ -359,20 +362,20 @@ class PayPalWebCheckoutClient internal constructor(
359362
request: PayPalWebVaultRequest,
360363
callback: PayPalWebVaultCallback
361364
) {
362-
CoroutineScope(Dispatchers.Main).launch {
365+
applicationScope.launch(Dispatchers.Main) {
363366
callback.onPayPalWebVaultResult(vaultAsync(activity, request))
364367
}
365368
}
366369

367370
/**
368371
* After a merchant app has re-entered the foreground following an auth challenge
369-
* (@see [PayPalWebCheckoutClient.startAsync]), call this method to see if a user has
372+
* (@see [PayPalWebCheckoutClient.start]), call this method to see if a user has
370373
* successfully authorized a PayPal account as a payment source.
371374
*
372375
* @param [intent] An Android intent that holds the deep link put the merchant app
373376
* back into the foreground after an auth challenge.
374377
* @param [authState] A continuation state received from [PayPalPresentAuthChallengeResult.Success]
375-
* when calling [PayPalWebCheckoutClient.startAsync]. This is needed to properly verify that an
378+
* when calling [PayPalWebCheckoutClient.start]. This is needed to properly verify that an
376379
* authorization completed successfully.
377380
*/
378381
@Deprecated(
@@ -400,7 +403,7 @@ class PayPalWebCheckoutClient internal constructor(
400403

401404
/**
402405
* After a merchant app has re-entered the foreground following an auth challenge
403-
* (@see [PayPalWebCheckoutClient.startAsync]), call this method to see if a user has
406+
* (@see [PayPalWebCheckoutClient.start]), call this method to see if a user has
404407
* successfully authorized a PayPal account as a payment source.
405408
*
406409
* @param [intent] An Android intent that holds the deep link put the merchant app
@@ -434,13 +437,13 @@ class PayPalWebCheckoutClient internal constructor(
434437

435438
/**
436439
* After a merchant app has re-entered the foreground following an auth challenge
437-
* (@see [PayPalWebCheckoutClient.vaultAsync]), call this method to see if a user has
440+
* (@see [PayPalWebCheckoutClient.vault]), call this method to see if a user has
438441
* successfully authorized a PayPal account for vaulting.
439442
*
440443
* @param [intent] An Android intent that holds the deep link put the merchant app
441444
* back into the foreground after an auth challenge.
442445
* @param [authState] A continuation state received from [PayPalPresentAuthChallengeResult.Success]
443-
* when calling [PayPalWebCheckoutClient.vaultAsync]. This is needed to properly verify that an
446+
* when calling [PayPalWebCheckoutClient.vault]. This is needed to properly verify that an
444447
* authorization completed successfully.
445448
*/
446449
@Deprecated(
@@ -528,7 +531,7 @@ class PayPalWebCheckoutClient internal constructor(
528531
}
529532
/**
530533
* After a merchant app has re-entered the foreground following an auth challenge
531-
* (@see [PayPalWebCheckoutClient.vaultAsync]), call this method to see if a user has
534+
* (@see [PayPalWebCheckoutClient.vault]), call this method to see if a user has
532535
* successfully authorized a PayPal account for vaulting.
533536
*
534537
* @param [intent] An Android intent that holds the deep link put the merchant app

PayPalWebPayments/src/main/java/com/paypal/android/paypalwebpayments/PayPalWebVaultRequest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.paypal.android.paypalwebpayments
22

33
/**
4-
* Request to vault a PayPal payment method using [PayPalWebCheckoutClient.vaultAsync].
4+
* Request to vault a PayPal payment method using [PayPalWebCheckoutClient.vault].
55
*
66
* @property [setupTokenId] ID for the setup token associated with the vault approval
77
* @property [approveVaultHref] URL for the approval web page
@@ -20,7 +20,7 @@ constructor(
2020
) {
2121

2222
/**
23-
* Request to vault a PayPal payment method using [PayPalWebCheckoutClient.vaultAsync].
23+
* Request to vault a PayPal payment method using [PayPalWebCheckoutClient.vault].
2424
*
2525
* @property [setupTokenId] ID for the setup token associated with the vault approval
2626
*/

0 commit comments

Comments
 (0)