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

Add contact information toggle #1225

Open
wants to merge 1 commit into
base: add-contact-info-request
Choose a base branch
from
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
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 @@ -115,7 +119,8 @@ private void launchPayPal(
boolean isBillingAgreement,
String buyerEmailAddress,
String buyerPhoneCountryCode,
String buyerPhoneNationalNumber
String buyerPhoneNationalNumber,
Boolean isContactInformationEnabled
) {
FragmentActivity activity = getActivity();
activity.setProgressBarIndeterminateVisibility(true);
Expand All @@ -127,10 +132,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 @@ -140,7 +145,8 @@ private void launchPayPal(
String amount,
String buyerEmailAddress,
String buyerPhoneCountryCode,
String buyerPhoneNationalNumber
String buyerPhoneNationalNumber,
Boolean isContactInformationEnabled
) {
PayPalRequest payPalRequest;
if (isBillingAgreement) {
Expand All @@ -156,7 +162,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 @@ -111,7 +112,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 @@ -158,6 +160,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