Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
package com.paypal.android.paypalwebpayments
package com.paypal.android.corepayments

import android.content.Context
import androidx.annotation.RawRes
import com.paypal.android.corepayments.CoreConfig
import com.paypal.android.corepayments.LoadRawResourceResult
import com.paypal.android.corepayments.PayPalSDKError
import com.paypal.android.corepayments.ResourceLoader
import androidx.annotation.RestrictTo
import com.paypal.android.corepayments.graphql.GraphQLClient
import com.paypal.android.corepayments.graphql.GraphQLResult
import org.json.JSONException
import org.json.JSONObject

internal class UpdateClientConfigAPI(
/**
* @suppress
*/
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
class UpdateClientConfigAPI(
private val coreConfig: CoreConfig,
private val applicationContext: Context,
private val graphQLClient: GraphQLClient,
private val resourceLoader: ResourceLoader
) {

private object Defaults {
const val INTEGRATION_ARTIFACT = "MOBILE_SDK"
const val USER_EXPERIENCE_FLOW = "INCONTEXT"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

USER_EXPERIENCE_FLOW is this value not NATIVE? because flow is initiated by native app, even though it's completed in web
Q: HERMES what does this mean?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe HERMES is an internal name I'm not 100% sure of its origin. All of the values in Defaults come from the JIRA ticket I was assigned. Nirvan may have further background on the actual meaning of each.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we took JS SDK's INCONTEXT value as web view and meant to distinguish native experiences like Apple Pay and Venmo as NATIVE.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HERMES is name for old checkout experience, I think but here it is just default value most flows have for product_flow.
From what I understand, product_flow refers to a specific flow within your SDK and I don't think it applies to our SDK
so we were advised to just go with the default.

const val PRODUCT_FLOW = "HERMES"
}

constructor(context: Context, coreConfig: CoreConfig) : this(
coreConfig,
context.applicationContext,
GraphQLClient(coreConfig),
ResourceLoader()
)

suspend fun updateClientConfig(
orderId: String,
fundingSource: PayPalWebCheckoutFundingSource
): UpdateClientConfigResult {
suspend fun updateClientConfig(params: UpdateClientConfigParams): UpdateClientConfigResult {
@RawRes val resId = R.raw.graphql_query_update_client_config
return when (val result = resourceLoader.loadRawResource(applicationContext, resId)) {
is LoadRawResourceResult.Success ->
sendUpdateClientConfigGraphQLRequest(
query = result.value,
orderId = orderId,
fundingSource = fundingSource
)
sendUpdateClientConfigGraphQLRequest(query = result.value, params = params)

is LoadRawResourceResult.Failure -> UpdateClientConfigResult.Failure(
PayPalSDKError(0, "TODO: implement")
Expand All @@ -46,15 +46,14 @@ internal class UpdateClientConfigAPI(

private suspend fun sendUpdateClientConfigGraphQLRequest(
query: String,
orderId: String,
fundingSource: PayPalWebCheckoutFundingSource
params: UpdateClientConfigParams
): UpdateClientConfigResult {
val variables = JSONObject()
.put("orderID", orderId)
.put("fundingSource", fundingSource.value)
.put("integrationArtifact", "PAYPAL_JS_SDK")
.put("userExperienceFlow", "INCONTEXT")
.put("productFlow", "SMART_PAYMENT_BUTTONS")
.put("orderID", params.orderId)
.put("fundingSource", params.fundingSource)
.put("integrationArtifact", Defaults.INTEGRATION_ARTIFACT)
.put("userExperienceFlow", Defaults.USER_EXPERIENCE_FLOW)
.put("productFlow", Defaults.PRODUCT_FLOW)
.put("buttonSessionId", JSONObject.NULL)

val graphQLRequest = JSONObject()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.paypal.android.corepayments

import androidx.annotation.RestrictTo

/**
* @suppress
*/
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
data class UpdateClientConfigParams(
val orderId: String,
val fundingSource: String
)
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package com.paypal.android.paypalwebpayments
package com.paypal.android.corepayments

import com.paypal.android.corepayments.PayPalSDKError
import androidx.annotation.RestrictTo

/**
* @suppress
*/
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
sealed class UpdateClientConfigResult {

data class Success(val clientConfig: String) : UpdateClientConfigResult()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import android.content.Context
import android.content.Intent
import androidx.activity.ComponentActivity
import com.paypal.android.corepayments.CoreConfig
import com.paypal.android.corepayments.UpdateClientConfigAPI
import com.paypal.android.corepayments.UpdateClientConfigParams
import com.paypal.android.corepayments.analytics.AnalyticsService
import com.paypal.android.paypalwebpayments.analytics.CheckoutEvent
import com.paypal.android.paypalwebpayments.analytics.PayPalWebAnalytics
Expand Down Expand Up @@ -55,11 +57,7 @@ class PayPalWebCheckoutClient internal constructor(
): PayPalPresentAuthChallengeResult {
checkoutOrderId = request.orderId
analytics.notify(CheckoutEvent.STARTED, checkoutOrderId)

if (request.fundingSource == PayPalWebCheckoutFundingSource.CARD) {
// TODO: consider returning an error immediately
}

updateCCO(request)
val result = payPalWebLauncher.launchPayPalWebCheckout(activity, request)
when (result) {
is PayPalPresentAuthChallengeResult.Success -> analytics.notify(
Expand All @@ -73,53 +71,6 @@ class PayPalWebCheckoutClient internal constructor(
return result
}

/**
* Confirm PayPal payment source for an order.
*
* @param request [PayPalWebCheckoutRequest] for requesting an order approval
*/
fun start(
activity: ComponentActivity,
request: PayPalWebCheckoutRequest,
callback: PayPalWebStartCallback
) {
CoroutineScope(dispatcher).launch {
checkoutOrderId = request.orderId
analytics.notify(CheckoutEvent.STARTED, checkoutOrderId)

if (request.fundingSource == PayPalWebCheckoutFundingSource.CARD) {
val updateConfigResult = request.run {
updateClientConfigAPI.updateClientConfig(
orderId = orderId,
fundingSource = fundingSource
)
}
if (updateConfigResult is UpdateClientConfigResult.Failure) {
// notify failure
callback.onPayPalWebStartResult(
PayPalPresentAuthChallengeResult.Failure(updateConfigResult.error)
)
return@launch
}
}

val result = payPalWebLauncher.launchPayPalWebCheckout(activity, request)
when (result) {
is PayPalPresentAuthChallengeResult.Success -> analytics.notify(
CheckoutEvent.AUTH_CHALLENGE_PRESENTATION_SUCCEEDED,
checkoutOrderId
)

is PayPalPresentAuthChallengeResult.Failure ->
analytics.notify(
CheckoutEvent.AUTH_CHALLENGE_PRESENTATION_FAILED,
checkoutOrderId
)
}
callback.onPayPalWebStartResult(result)
}
}

/**
* Vault PayPal as a payment method.
*
Expand Down Expand Up @@ -205,4 +156,18 @@ class PayPalWebCheckoutClient internal constructor(
}
return result
}

private fun updateCCO(request: PayPalWebCheckoutRequest) {
CoroutineScope(dispatcher).launch {
val fundingSource = when (request.fundingSource) {
PayPalWebCheckoutFundingSource.PAYPAL -> "payPal"
else -> request.fundingSource.value
}
val params =
UpdateClientConfigParams(orderId = request.orderId, fundingSource = fundingSource)
// ignore result; in the rare occasion this call fails, we will still allow
// the transaction to proceed
updateClientConfigAPI.updateClientConfig(params = params)
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.paypal.android.paypalwebpayments
import android.content.Intent
import androidx.fragment.app.FragmentActivity
import com.paypal.android.corepayments.PayPalSDKError
import com.paypal.android.corepayments.UpdateClientConfigAPI
import com.paypal.android.paypalwebpayments.analytics.PayPalWebAnalytics
import io.mockk.every
import io.mockk.mockk
Expand Down