Skip to content

Commit

Permalink
Merge pull request #1250 from braintree/contact-information-feature
Browse files Browse the repository at this point in the history
[DO NOT REVIEW] Merge Contact Information Feature Branch
  • Loading branch information
jaxdesmarais authored Jan 23, 2025
2 parents 3816fe1 + 5155b50 commit 8bf4a69
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 9 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# Braintree Android SDK Release Notes

## unreleased

* PayPal
* Add `PayPalContactInformation` request object
* Add `PayPalCheckoutRequest.contactInformation` optional property
* Fix bug where `intent=order` was not being set as expected

## 5.4.0 (2025-01-21)
Expand Down
21 changes: 14 additions & 7 deletions Demo/src/main/java/com/braintreepayments/demo/PayPalFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.Switch;
import android.widget.Toast;

import androidx.annotation.NonNull;
Expand Down Expand Up @@ -49,13 +50,15 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
TextInputEditText buyerPhoneNationalNumberEditText = view.findViewById(R.id.buyer_phone_national_number_edit_text);
Button billingAgreementButton = view.findViewById(R.id.paypal_billing_agreement_button);
Button singlePaymentButton = view.findViewById(R.id.paypal_single_payment_button);
Switch contactInformationSwitch = view.findViewById(R.id.contact_info_switch);

singlePaymentButton.setOnClickListener(v -> {
launchPayPal(
false,
buyerEmailEditText.getText().toString(),
buyerPhoneCountryCodeEditText.getText().toString(),
buyerPhoneNationalNumberEditText.getText().toString()
buyerPhoneNationalNumberEditText.getText().toString(),
contactInformationSwitch.isChecked()
);
});
billingAgreementButton.setOnClickListener(v -> {
Expand All @@ -70,7 +73,8 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
true,
buyerEmailEditText.getText().toString(),
buyerPhoneCountryCodeEditText.getText().toString(),
buyerPhoneNationalNumberEditText.getText().toString()
buyerPhoneNationalNumberEditText.getText().toString(),
false
);
});

Expand Down Expand Up @@ -116,7 +120,8 @@ private void launchPayPal(
boolean isBillingAgreement,
String buyerEmailAddress,
String buyerPhoneCountryCode,
String buyerPhoneNationalNumber
String buyerPhoneNationalNumber,
Boolean isContactInformationEnabled
) {
FragmentActivity activity = getActivity();
activity.setProgressBarIndeterminateVisibility(true);
Expand All @@ -128,10 +133,10 @@ private void launchPayPal(
if (dataCollectorResult instanceof DataCollectorResult.Success) {
deviceData = ((DataCollectorResult.Success) dataCollectorResult).getDeviceData();
}
launchPayPal(activity, isBillingAgreement, amount, buyerEmailAddress, buyerPhoneCountryCode, buyerPhoneNationalNumber);
launchPayPal(activity, isBillingAgreement, amount, buyerEmailAddress, buyerPhoneCountryCode, buyerPhoneNationalNumber, isContactInformationEnabled);
});
} else {
launchPayPal(activity, isBillingAgreement, amount, buyerEmailAddress, buyerPhoneCountryCode, buyerPhoneNationalNumber);
launchPayPal(activity, isBillingAgreement, amount, buyerEmailAddress, buyerPhoneCountryCode, buyerPhoneNationalNumber, isContactInformationEnabled);
}
}

Expand All @@ -141,7 +146,8 @@ private void launchPayPal(
String amount,
String buyerEmailAddress,
String buyerPhoneCountryCode,
String buyerPhoneNationalNumber
String buyerPhoneNationalNumber,
Boolean isContactInformationEnabled
) {
PayPalRequest payPalRequest;
if (isBillingAgreement) {
Expand All @@ -157,7 +163,8 @@ private void launchPayPal(
amount,
buyerEmailAddress,
buyerPhoneCountryCode,
buyerPhoneNationalNumber
buyerPhoneNationalNumber,
isContactInformationEnabled
);
}
payPalClient.createPaymentAuthRequest(requireContext(), payPalRequest,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.braintreepayments.api.paypal.PayPalBillingInterval;
import com.braintreepayments.api.paypal.PayPalBillingPricing;
import com.braintreepayments.api.paypal.PayPalCheckoutRequest;
import com.braintreepayments.api.paypal.PayPalContactInformation;
import com.braintreepayments.api.paypal.PayPalLandingPageType;
import com.braintreepayments.api.paypal.PayPalPaymentIntent;
import com.braintreepayments.api.paypal.PayPalPaymentUserAction;
Expand Down Expand Up @@ -112,7 +113,8 @@ public static PayPalCheckoutRequest createPayPalCheckoutRequest(
String amount,
String buyerEmailAddress,
String buyerPhoneCountryCode,
String buyerPhoneNationalNumber
String buyerPhoneNationalNumber,
Boolean isContactInformationEnabled
) {
PayPalCheckoutRequest request = new PayPalCheckoutRequest(amount, true);

Expand Down Expand Up @@ -159,6 +161,10 @@ public static PayPalCheckoutRequest createPayPalCheckoutRequest(
request.setShippingAddressOverride(shippingAddress);
}

if (isContactInformationEnabled) {
request.setContactInformation(new PayPalContactInformation("[email protected]", new PayPalPhoneNumber("1", "1234567890")));
}

return request;
}
}
6 changes: 6 additions & 0 deletions Demo/src/main/res/layout/fragment_paypal.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@

</com.google.android.material.textfield.TextInputLayout>

<Switch
android:id="@+id/contact_info_switch"
android:layout_width="match_parent"
android:layout_height="@dimen/margin_40"
android:text="Add Contact Information" />

<Button
android:id="@+id/paypal_single_payment_button"
android:layout_width="match_parent"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,12 @@ import org.json.JSONObject
*
* @property shouldOfferPayLater Offers PayPal Pay Later if the customer qualifies. Defaults to
* false.
*
* @property shippingCallbackUrl Server side shipping callback URL to be notified when a customer
* updates their shipping address or options. A callback request will be sent to the merchant server
* at this URL.
*
* @property contactInformation Contact information of the recipient for the order
*/
@Parcelize
class PayPalCheckoutRequest @JvmOverloads constructor(
Expand All @@ -69,6 +72,7 @@ class PayPalCheckoutRequest @JvmOverloads constructor(
var shouldRequestBillingAgreement: Boolean = false,
var shouldOfferPayLater: Boolean = false,
var shippingCallbackUrl: Uri? = null,
var contactInformation: PayPalContactInformation? = null,
override var localeCode: String? = null,
override var billingAgreementDescription: String? = null,
override var isShippingAddressRequired: Boolean = false,
Expand Down Expand Up @@ -135,6 +139,11 @@ class PayPalCheckoutRequest @JvmOverloads constructor(

userPhoneNumber?.let { parameters.put(PHONE_NUMBER_KEY, it.toJson()) }

contactInformation?.let { info ->
info.recipientEmail?.let { parameters.put(RECIPIENT_EMAIL_KEY, it) }
info.recipentPhoneNumber?.let { parameters.put(RECIPIENT_PHONE_NUMBER_KEY, it.toJson()) }
}

if (currencyCode == null) {
currencyCode = configuration?.payPalCurrencyIsoCode
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.braintreepayments.api.paypal

import android.os.Parcelable
import kotlinx.parcelize.Parcelize

/**
* Representation of a recipient Contact Information for the order.
*
* @property recipientEmail Email address of the recipient.
* @property recipentPhoneNumber Phone number of the recipient.
*/
@Parcelize
data class PayPalContactInformation(
val recipientEmail: String? = null,
val recipentPhoneNumber: PayPalPhoneNumber? = null
) : Parcelable
Original file line number Diff line number Diff line change
Expand Up @@ -133,5 +133,7 @@ abstract class PayPalRequest internal constructor(
internal const val PLAN_METADATA_KEY: String = "plan_metadata"
internal const val PHONE_NUMBER_KEY: String = "phone_number"
internal const val SHIPPING_CALLBACK_URL_KEY: String = "shipping_callback_url"
internal const val RECIPIENT_EMAIL_KEY: String = "recipient_email"
internal const val RECIPIENT_PHONE_NUMBER_KEY: String = "international_phone"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -225,5 +225,37 @@ public void createRequestBody_sets_userPhoneNumber_when_not_null() throws JSONEx

assertTrue(requestBody.contains("\"phone_number\":{\"country_code\":\"1\",\"national_number\":\"1231231234\"}"));
}
}

@Test
public void createRequestBody_sets_contactInformation_when_not_null() throws JSONException {
PayPalCheckoutRequest request = new PayPalCheckoutRequest("1.00", true);

request.setContactInformation(new PayPalContactInformation("[email protected]", new PayPalPhoneNumber("1", "1234567890")));
String requestBody = request.createRequestBody(
mock(Configuration.class),
mock(Authorization.class),
"success_url",
"cancel_url",
null
);

assertTrue(requestBody.contains("\"recipient_email\":\"[email protected]\""));
assertTrue(requestBody.contains("\"international_phone\":{\"country_code\":\"1\",\"national_number\":\"1234567890\"}"));
}

@Test
public void createRequestBody_does_not_set_contactInformation_when_contactInformation_is_null() throws JSONException {
PayPalCheckoutRequest request = new PayPalCheckoutRequest("1.00", true);

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

assertFalse(requestBody.contains("\"recipient_email\":\"[email protected]\""));
assertFalse(requestBody.contains("\"international_phone\":{\"country_code\":\"1\",\"national_number\":\"1234567890\"}"));
}
}

0 comments on commit 8bf4a69

Please sign in to comment.