Skip to content
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

[DO NOT REVIEW] Merge Contact Information Feature Branch #1250

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Braintree Android SDK Release Notes

## unreleased
* PayPal
* Add `PayPalContactInformation` request object
* Add `PayPalCheckoutRequest.contactInformation` optional property

## 5.3.0 (2024-12-11)

* PayPal
Expand Down
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 @@ -64,6 +64,7 @@ class PayPalCheckoutRequest @JvmOverloads constructor(
var currencyCode: String? = null,
var shouldRequestBillingAgreement: Boolean = false,
var shouldOfferPayLater: Boolean = false,
var contactInformation: PayPalContactInformation? = null,
Copy link
Contributor

Choose a reason for hiding this comment

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

I know this is the final PR not requiring review but realized we are missing the doc string for this property - iOS has Optional: Contact information of the recipient for the order

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch, looks like we don't use the Optional part on Android based on the docstrings here, added the missing one here: 028271a

override var localeCode: String? = null,
override var billingAgreementDescription: String? = null,
override var isShippingAddressRequired: Boolean = false,
Expand Down Expand Up @@ -126,6 +127,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 @@ -132,5 +132,7 @@ 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 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 @@ -171,4 +171,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\"}"));
}
}
Loading