Skip to content

Commit

Permalink
Add contact information toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
richherrera committed Nov 26, 2024
1 parent 251073e commit a364c93
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
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 @@ -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

0 comments on commit a364c93

Please sign in to comment.