Skip to content

Commit

Permalink
Add optional param, payerEmail, to PayPalVaultRequest (#944)
Browse files Browse the repository at this point in the history
* Add optional param, payerEmail, to PayPalVaultRequest (#918)

* Update JSONObject put() to putOpt()

Co-authored-by: sshropshire <58225613+sshropshire@users.noreply.github.com>

* Add nullable annotations

Co-authored-by: sshropshire <58225613+sshropshire@users.noreply.github.com>

* Add nullable import

---------

Co-authored-by: Tim Chow <tichow@paypal.com>
Co-authored-by: sshropshire <58225613+sshropshire@users.noreply.github.com>
  • Loading branch information
3 people authored Mar 19, 2024
1 parent a008068 commit 57a8850
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

## 4.42.0 (2024-03-12)

* PayPal
* Add optional property `PayPalVaultRequest.setUserAuthenticationEmail()`
* BraintreeCore
* Send `paypal_context_id` in `analytics_event` to PayPal's analytics service (FPTI) when available
* Venmo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public abstract class PayPalRequest implements Parcelable {
static final String REQUEST_BILLING_AGREEMENT_KEY = "request_billing_agreement";
static final String BILLING_AGREEMENT_DETAILS_KEY = "billing_agreement_details";
static final String DESCRIPTION_KEY = "description";
static final String PAYER_EMAIL_KEY = "payer_email";
static final String AUTHORIZATION_FINGERPRINT_KEY = "authorization_fingerprint";
static final String TOKENIZATION_KEY = "client_key";
static final String RETURN_URL_KEY = "return_url";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import android.os.Parcelable;
import android.text.TextUtils;

import androidx.annotation.Nullable;

import org.json.JSONException;
import org.json.JSONObject;

Expand All @@ -14,6 +16,8 @@ public class PayPalVaultRequest extends PayPalRequest implements Parcelable {

private boolean shouldOfferCredit;

private String userAuthenticationEmail;

public PayPalVaultRequest() {
}

Expand All @@ -30,6 +34,21 @@ public boolean getShouldOfferCredit() {
return shouldOfferCredit;
}

/**
* Optional: User email to initiate a quicker authentication flow in cases where the user has a
* PayPal Account with the same email.
*
* @param userAuthenticationEmail - email address of the payer
*/
public void setUserAuthenticationEmail(@Nullable String userAuthenticationEmail) {
this.userAuthenticationEmail = userAuthenticationEmail;
}

@Nullable
public String getUserAuthenticationEmail() {
return this.userAuthenticationEmail;
}

String createRequestBody(Configuration configuration, Authorization authorization, String successUrl, String cancelUrl) throws JSONException {
JSONObject parameters = new JSONObject()
.put(RETURN_URL_KEY, successUrl)
Expand All @@ -47,6 +66,8 @@ String createRequestBody(Configuration configuration, Authorization authorizatio
parameters.put(DESCRIPTION_KEY, billingAgreementDescription);
}

parameters.putOpt(PAYER_EMAIL_KEY, userAuthenticationEmail);

JSONObject experienceProfile = new JSONObject();
experienceProfile.put(NO_SHIPPING_KEY, !isShippingAddressRequired());
experienceProfile.put(LANDING_PAGE_TYPE_KEY, getLandingPageType());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package com.braintreepayments.api;

import android.content.pm.Signature;
import android.os.Parcel;

import org.json.JSONException;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.robolectric.RobolectricTestRunner;

import java.util.ArrayList;
Expand All @@ -12,6 +15,7 @@
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertNull;
import static junit.framework.Assert.assertTrue;
import static org.mockito.Mockito.mock;

@RunWith(RobolectricTestRunner.class)
public class PayPalVaultRequestUnitTest {
Expand Down Expand Up @@ -80,17 +84,33 @@ public void parcelsCorrectly() {

assertEquals("en-US", result.getLocaleCode());
assertEquals("Billing Agreement Description",
result.getBillingAgreementDescription());
result.getBillingAgreementDescription());
assertTrue(result.getShouldOfferCredit());
assertTrue(result.isShippingAddressRequired());
assertTrue(result.isShippingAddressEditable());
assertEquals("Postal Address", result.getShippingAddressOverride()
.getRecipientName());
.getRecipientName());
assertEquals(PayPalRequest.LANDING_PAGE_TYPE_LOGIN, result.getLandingPageType());
assertEquals("Display Name", result.getDisplayName());
assertEquals("123-correlation", result.getRiskCorrelationId());
assertEquals("merchant_account_id", result.getMerchantAccountId());
assertEquals(1, result.getLineItems().size());
assertEquals("An Item", result.getLineItems().get(0).getName());
}

@Test
public void createRequestBody_sets_userAuthenticationEmail_when_not_null() throws JSONException {
String payerEmail = "payer_email@example.com";
PayPalVaultRequest request = new PayPalVaultRequest();

request.setUserAuthenticationEmail(payerEmail);
String requestBody = request.createRequestBody(
mock(Configuration.class),
mock(Authorization.class),
"success_url",
"cancel_url"
);

assertTrue(requestBody.contains("\"payer_email\":" + "\"" + payerEmail + "\""));
}
}

0 comments on commit 57a8850

Please sign in to comment.