-
Notifications
You must be signed in to change notification settings - Fork 66
Feature/app switch #391
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
Open
kgangineni
wants to merge
14
commits into
develop
Choose a base branch
from
feature/app_switch
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Feature/app switch #391
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
39de947
Adds functionality for creating Low Scoped Access Token
kgangineni d2591e0
Integration with App Switch Eligibility for checkout and vault operat…
kgangineni 4a86bd0
UI and create order changes required for app switch in Demo app
kgangineni 44cd350
Check for Paypal Mobile app before app switch (#334)
kgangineni 5a784df
Merge branch 'develop' into feature/app_switch
kgangineni ea10c2d
* Fix PatchCCOWithAppSwitchEligibility graphQL call
kgangineni 597d571
* Fixed merge conflicts
kgangineni dd36a2b
* Minor improvements
kgangineni 32f9294
* parallel updateCCo and PatchCCOWithAppSwitchEligibility
kgangineni 0b6fcd8
* parallel updateCCo and PatchCCOWithAppSwitchEligibility
kgangineni f05feec
Merge branch 'develop' into feature/app_switch
kgangineni 69bbb37
dump public API
kgangineni 1a9d63a
fix CHANGELOG.md
kgangineni 8332960
* cleanup unwanted changes
kgangineni 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
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
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
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
128 changes: 128 additions & 0 deletions
128
...nts/src/main/java/com/paypal/android/corepayments/api/PatchCCOWithAppSwitchEligibility.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,128 @@ | ||
| package com.paypal.android.corepayments.api | ||
|
|
||
| import android.content.Context | ||
| import androidx.annotation.RestrictTo | ||
| import com.paypal.android.corepayments.APIClientError | ||
| import com.paypal.android.corepayments.CoreConfig | ||
| import com.paypal.android.corepayments.LoadRawResourceResult | ||
| import com.paypal.android.corepayments.R | ||
| import com.paypal.android.corepayments.ResourceLoader | ||
| import com.paypal.android.corepayments.UpdateClientConfigAPI | ||
| import com.paypal.android.corepayments.graphql.GraphQLClient | ||
| import com.paypal.android.corepayments.graphql.GraphQLRequest | ||
| import com.paypal.android.corepayments.graphql.GraphQLResult | ||
| import com.paypal.android.corepayments.model.APIResult | ||
| import com.paypal.android.corepayments.model.AppSwitchEligibility | ||
| import com.paypal.android.corepayments.model.ExperimentationContext | ||
| import com.paypal.android.corepayments.model.PatchCcoWithAppSwitchEligibilityResponse | ||
| import com.paypal.android.corepayments.model.PatchCcoWithAppSwitchEligibilityVariables | ||
| import com.paypal.android.corepayments.model.TokenType | ||
| import kotlinx.serialization.InternalSerializationApi | ||
|
|
||
| @OptIn(InternalSerializationApi::class) | ||
| @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) | ||
| class PatchCCOWithAppSwitchEligibility internal constructor( | ||
| private val graphQLClient: GraphQLClient, | ||
| private val resourceLoader: ResourceLoader, | ||
| ) { | ||
|
|
||
| constructor(coreConfig: CoreConfig) : this( | ||
| graphQLClient = GraphQLClient(coreConfig), | ||
| resourceLoader = ResourceLoader() | ||
| ) | ||
|
|
||
| suspend operator fun invoke( | ||
| context: Context, | ||
| orderId: String, | ||
| tokenType: TokenType, | ||
| merchantOptInForAppSwitch: Boolean, | ||
| paypalNativeAppInstalled: Boolean | ||
| ): APIResult<AppSwitchEligibility> { | ||
|
|
||
| val graphQLRequest = createGraphQLRequest( | ||
| context = context, | ||
| tokenType = tokenType, | ||
| orderId = orderId, | ||
| merchantOptInForAppSwitch = merchantOptInForAppSwitch, | ||
| paypalNativeAppInstalled = paypalNativeAppInstalled | ||
| ) ?: return APIResult.Failure( | ||
| APIClientError.dataParsingError(correlationId = null) | ||
| ) | ||
|
|
||
| val graphQLResult = graphQLClient.send< | ||
| PatchCcoWithAppSwitchEligibilityResponse, | ||
| PatchCcoWithAppSwitchEligibilityVariables>(graphQLRequest) | ||
| return when (graphQLResult) { | ||
| is GraphQLResult.Success -> { | ||
| graphQLResult.response.data?.let { responseData -> | ||
| parseResponse(responseData)?.let { appSwitchEligibility -> | ||
| APIResult.Success(data = appSwitchEligibility) | ||
| } ?: APIResult.Failure( | ||
| APIClientError.dataParsingError(graphQLResult.correlationId) | ||
| ) | ||
| } ?: APIResult.Failure( | ||
| APIClientError.noResponseData(graphQLResult.correlationId) | ||
| ) | ||
| } | ||
|
|
||
| is GraphQLResult.Failure -> APIResult.Failure(graphQLResult.error) | ||
| } | ||
| } | ||
|
|
||
| private suspend fun createGraphQLRequest( | ||
| context: Context, | ||
| tokenType: TokenType, | ||
| orderId: String, | ||
| merchantOptInForAppSwitch: Boolean, | ||
| paypalNativeAppInstalled: Boolean | ||
| ): GraphQLRequest<PatchCcoWithAppSwitchEligibilityVariables>? { | ||
| val resourceResult = resourceLoader.loadRawResource( | ||
| context, | ||
| R.raw.graphql_query_patch_cco_app_switch_eligibility | ||
| ) | ||
|
|
||
| val query = when (resourceResult) { | ||
| is LoadRawResourceResult.Success -> resourceResult.value | ||
| is LoadRawResourceResult.Failure -> return null | ||
| } | ||
|
|
||
| val variables = PatchCcoWithAppSwitchEligibilityVariables( | ||
| tokenType = tokenType.name, | ||
| contextId = orderId, | ||
| token = orderId, | ||
| merchantOptInForAppSwitch = merchantOptInForAppSwitch, | ||
| experimentationContext = ExperimentationContext( | ||
| integrationChannel = INTEGRATION_CHANNEL, | ||
| ), | ||
| integrationArtifact = UpdateClientConfigAPI.Defaults.INTEGRATION_ARTIFACT, | ||
| userExperienceFlow = UpdateClientConfigAPI.Defaults.USER_EXPERIENCE_FLOW, | ||
| osType = OS_TYPE, | ||
| paypalNativeAppInstalled = paypalNativeAppInstalled | ||
| ) | ||
|
|
||
| return GraphQLRequest( | ||
| query = query, | ||
| variables = variables, | ||
| operationName = "PatchCcoWithAppSwitchEligibility" | ||
| ) | ||
| } | ||
|
|
||
| private fun parseResponse(response: PatchCcoWithAppSwitchEligibilityResponse): AppSwitchEligibility? { | ||
| val appSwitchEligibilityData = response.external | ||
| ?.patchCcoWithAppSwitchEligibility | ||
| ?.appSwitchEligibility | ||
|
|
||
| return appSwitchEligibilityData?.let { | ||
| AppSwitchEligibility( | ||
| appSwitchEligible = it.appSwitchEligible, | ||
| launchUrl = it.redirectURL, | ||
| ineligibleReason = it.ineligibleReason | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| companion object { | ||
| const val INTEGRATION_CHANNEL = "PPCP_NATIVE_SDK" | ||
| const val OS_TYPE = "ANDROID" | ||
| } | ||
| } |
20 changes: 20 additions & 0 deletions
20
CorePayments/src/main/java/com/paypal/android/corepayments/common/DeviceInspector.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,20 @@ | ||
| package com.paypal.android.corepayments.common | ||
|
|
||
| import android.content.Context | ||
| import androidx.annotation.RestrictTo | ||
|
|
||
| @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) | ||
| class DeviceInspector(private val context: Context) { | ||
|
|
||
| val isPayPalInstalled: Boolean | ||
| get() = isAppInstalled(PAYPAL_APP_PACKAGE) | ||
|
|
||
| private fun isAppInstalled(packageName: String): Boolean = runCatching { | ||
| context.packageManager.getApplicationInfo(packageName, 0) | ||
| true | ||
| }.getOrDefault(false) | ||
|
|
||
| companion object { | ||
| const val PAYPAL_APP_PACKAGE = "com.paypal.android.p2pmobile" | ||
| } | ||
| } |
7 changes: 7 additions & 0 deletions
7
CorePayments/src/main/java/com/paypal/android/corepayments/common/Headers.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,7 @@ | ||
| package com.paypal.android.corepayments.common | ||
|
|
||
| internal object Headers { | ||
| const val PAYPAL_DEBUG_ID = "paypal-debug-id" | ||
| const val AUTHORIZATION = "Authorization" | ||
| const val CONTENT_TYPE = "Content-Type" | ||
| } |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this CHANGELOG entry a duplicate? I see a similar one listed in version
2.3.0for "Add PayPalWebCheckoutClient.start(activity, request, callback) method with asynchronous callback support."