-
Notifications
You must be signed in to change notification settings - Fork 237
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
Shopper insights rp1 feature include session #1235
Changes from 7 commits
7dedb0a
dedaf01
b1f1767
ebb92f1
7b06a23
a51d13b
737f16f
c4437cd
c6b72d5
e548542
c9f419a
179e35b
152b11e
073938b
fe9def0
41a47b0
c5c0c21
41c4f17
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,26 +18,32 @@ | |
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
public class PayPalRequestFactory { | ||
|
||
public static PayPalVaultRequest createPayPalVaultRequest( | ||
Context context, | ||
String buyerEmailAddress, | ||
String buyerPhoneCountryCode, | ||
String buyerPhoneNationalNumber | ||
String buyerPhoneNationalNumber, | ||
String shopperInsightsSessionId | ||
) { | ||
|
||
PayPalVaultRequest request = new PayPalVaultRequest(true); | ||
|
||
if (!buyerEmailAddress.isEmpty()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need to change all these other params? It seems like it should be unaffected by this PR There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My understanding is that the original code is potentially a run time crash if the value is null. In the case of the demo app and how its setup, setting the toggles to null didn't have an impact on this flow because the values would always be true. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah ok in that case do we need to check that it's not null and it's not empty? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, great catch! |
||
if (buyerEmailAddress != null) { | ||
request.setUserAuthenticationEmail(buyerEmailAddress); | ||
} | ||
|
||
if (!buyerPhoneCountryCode.isEmpty() && !buyerPhoneNationalNumber.isEmpty()) { | ||
if (buyerPhoneCountryCode != null && buyerPhoneNationalNumber != null) { | ||
request.setUserPhoneNumber(new PayPalPhoneNumber(buyerPhoneCountryCode, buyerPhoneNationalNumber)); | ||
} | ||
|
||
if (shopperInsightsSessionId != null) { | ||
request.setShopperSessionId(shopperInsightsSessionId); | ||
} | ||
|
||
if (Settings.isPayPalAppSwithEnabled(context)) { | ||
request.setEnablePayPalAppSwitch(true); | ||
} | ||
|
@@ -111,18 +117,23 @@ public static PayPalCheckoutRequest createPayPalCheckoutRequest( | |
String amount, | ||
String buyerEmailAddress, | ||
String buyerPhoneCountryCode, | ||
String buyerPhoneNationalNumber | ||
String buyerPhoneNationalNumber, | ||
String shopperInsightsSessionId | ||
) { | ||
PayPalCheckoutRequest request = new PayPalCheckoutRequest(amount, true); | ||
|
||
if (!buyerEmailAddress.isEmpty()) { | ||
if (buyerEmailAddress != null) { | ||
request.setUserAuthenticationEmail(buyerEmailAddress); | ||
} | ||
|
||
if (!buyerPhoneCountryCode.isEmpty() && !buyerPhoneNationalNumber.isEmpty()) { | ||
if (buyerPhoneCountryCode != null && buyerPhoneNationalNumber != null) { | ||
request.setUserPhoneNumber(new PayPalPhoneNumber(buyerPhoneCountryCode, buyerPhoneNationalNumber)); | ||
} | ||
|
||
if (shopperInsightsSessionId != null) { | ||
request.setShopperSessionId(shopperInsightsSessionId); | ||
} | ||
|
||
request.setDisplayName(Settings.getPayPalDisplayName(context)); | ||
|
||
String landingPageType = Settings.getPayPalLandingPageType(context); | ||
|
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -49,6 +49,7 @@ class ShopperInsightsFragment : BaseFragment() { | |||
private lateinit var nationalNumberInput: TextInputLayout | ||||
private lateinit var emailNullSwitch: SwitchMaterial | ||||
private lateinit var phoneNullSwitch: SwitchMaterial | ||||
private lateinit var shopperInsightsSessionIdNullSwitch: SwitchMaterial | ||||
|
||||
private lateinit var shopperInsightsClient: ShopperInsightsClient | ||||
private lateinit var payPalClient: PayPalClient | ||||
|
@@ -60,12 +61,14 @@ class ShopperInsightsFragment : BaseFragment() { | |||
private lateinit var venmoStartedPendingRequest: VenmoPendingRequest.Started | ||||
private lateinit var paypalStartedPendingRequest: PayPalPendingRequest.Started | ||||
|
||||
private var sessionId: String = "test-shopper-session-id" | ||||
|
||||
override fun onCreateView( | ||||
inflater: LayoutInflater, | ||||
container: ViewGroup?, | ||||
savedInstanceState: Bundle? | ||||
): View? { | ||||
shopperInsightsClient = ShopperInsightsClient(requireContext(), authStringArg, "test-shopper-session-id") | ||||
shopperInsightsClient = ShopperInsightsClient(requireContext(), authStringArg, sessionId) | ||||
|
||||
venmoClient = VenmoClient(requireContext(), super.getAuthStringArg(), null) | ||||
payPalClient = PayPalClient( | ||||
|
@@ -229,7 +232,9 @@ class ShopperInsightsFragment : BaseFragment() { | |||
activity, | ||||
emailInput.editText?.text.toString(), | ||||
countryCodeInput.editText?.text.toString(), | ||||
nationalNumberInput.editText?.text.toString() | ||||
nationalNumberInput.editText?.text.toString(), | ||||
sessionId | ||||
|
||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
) | ||||
) { authRequest -> | ||||
when (authRequest) { | ||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -126,6 +126,10 @@ class PayPalCheckoutRequest @JvmOverloads constructor( | |
|
||
userPhoneNumber?.let { parameters.put(PHONE_NUMBER_KEY, it.toJson()) } | ||
|
||
shopperSessionId?.let { | ||
if (it.isNotEmpty()) parameters.put(SHOPPER_SESSION_ID, it) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should be able to use the same simplified putOpt logic from the |
||
|
||
if (currencyCode == null) { | ||
currencyCode = configuration?.payPalCurrencyIsoCode | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,6 +72,8 @@ import org.json.JSONException | |
* where the user has a PayPal Account with the same email. | ||
* @property userPhoneNumber User phone number used to initiate a quicker authentication flow in | ||
* cases where the user has a PayPal Account with the phone number. | ||
* @property shopperSessionId value should be the shopper session ID returned from your server SDK | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this doc string was included in the ticket but I'm wondering if it's clear enough for when we are outside of the shopper insights module. Should we include something like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll make the changes in iOS as well. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep we can for sure give this the beta/experimental API tag |
||
* request. | ||
* @property lineItems The line items for this transaction. It can include up to 249 line items. | ||
*/ | ||
abstract class PayPalRequest internal constructor( | ||
|
@@ -87,6 +89,7 @@ abstract class PayPalRequest internal constructor( | |
open var riskCorrelationId: String? = null, | ||
open var userAuthenticationEmail: String? = null, | ||
open var userPhoneNumber: PayPalPhoneNumber? = null, | ||
open var shopperSessionId: String? = null, | ||
open var lineItems: List<PayPalLineItem> = emptyList() | ||
) : Parcelable { | ||
|
||
|
@@ -132,5 +135,6 @@ abstract class PayPalRequest internal constructor( | |
internal const val PLAN_TYPE_KEY: String = "plan_type" | ||
internal const val PLAN_METADATA_KEY: String = "plan_metadata" | ||
internal const val PHONE_NUMBER_KEY: String = "phone_number" | ||
internal const val SHOPPER_SESSION_ID: String = "shopper_session_id" | ||
} | ||
} |
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.
nit: it looks like there are some extra spaces for the 2 null properties here