Skip to content

Commit

Permalink
Merge pull request #1015 from braintree/paypal-messaging-feature
Browse files Browse the repository at this point in the history
[DO NOT REVIEW] Merge `paypal-messaing-feature` into `main`
  • Loading branch information
jaxdesmarais authored May 30, 2024
2 parents 6520ac2 + a485b10 commit 8444746
Show file tree
Hide file tree
Showing 32 changed files with 974 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,18 @@ jobs:
uses: ./.github/actions/unit_test_module
with:
module: PayPal
unit_test_paypal_messaging:
name: PayPal Messaging Unit Tests
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v2
- name: Setup Java 8
uses: ./.github/actions/setup
- name: Run Unit Tests
uses: ./.github/actions/unit_test_module
with:
module: PayPalMessaging
unit_test_samsung_pay:
name: SamsungPay Unit Tests
runs-on: ubuntu-latest
Expand Down Expand Up @@ -222,6 +234,7 @@ jobs:
unit_test_google_pay,
unit_test_local_payment,
unit_test_paypal,
unit_test_paypal_messaging,
unit_test_samsung_pay,
unit_test_three_d_secure,
unit_test_union_pay,
Expand Down
13 changes: 13 additions & 0 deletions .github/workflows/release_snapshot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,18 @@ jobs:
uses: ./.github/actions/unit_test_module
with:
module: PayPal
unit_test_paypal_messaging:
name: PayPal Messaging Unit Tests
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v2
- name: Setup Java 8
uses: ./.github/actions/setup
- name: Run Unit Tests
uses: ./.github/actions/unit_test_module
with:
module: PayPalMessaging
unit_test_samsung_pay:
name: SamsungPay Unit Tests
runs-on: ubuntu-latest
Expand Down Expand Up @@ -222,6 +234,7 @@ jobs:
unit_test_google_pay,
unit_test_local_payment,
unit_test_paypal,
unit_test_paypal_messaging,
unit_test_samsung_pay,
unit_test_three_d_secure,
unit_test_union_pay,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.braintreepayments.api

/**
* The annotated method or class is in beta. It's public API may change or be removed in future releases.
*/
@RequiresOptIn
annotation class ExperimentalBetaApi
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
# Braintree Android SDK Release Notes

## unreleased

* PayPalMessaging (BETA)
* Add `PayPalMessagingRequest`, `PayPalMessagingColor`, `PayPalMessagingLogoType`, `PayPalMessagingOfferType`, `PayPalMessagingPageType`, `PayPalMessagingTextAlignment`, and `PayPalMessagingListener`
* Add `PayPalMessagingView(BraintreeClient, Context)` to display PayPal messages to promote offers such as Pay Later and PayPal Credit to customers.
* To get started call `PayPalMessagingView#start()` with an optional `PayPalMessagingRequest`

## 4.45.1 (2024-05-28)

* PayPal
* Update `PayPalInternalClient` to use pairing ID as client metadata ID by default.
* Send `is_vault` in `event_params` analytics
Expand Down
3 changes: 3 additions & 0 deletions Demo/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
id 'com.android.application'
id 'androidx.navigation.safeargs'
id 'kotlin-android'
}

android {
Expand Down Expand Up @@ -75,6 +76,7 @@ android {

dependencies {
implementation 'androidx.preference:preference:1.1.1'
implementation deps.kotlinStdLib

implementation('com.squareup.retrofit:retrofit:1.9.0') {
exclude module: 'com.google.gson'
Expand All @@ -86,6 +88,7 @@ dependencies {
implementation project(':GooglePay')
implementation project(':LocalPayment')
implementation project(':PayPal')
implementation project(':PayPalMessaging')
implementation project(':PayPalNativeCheckout')
implementation project(':SamsungPay')
implementation project(':SEPADirectDebit')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
Button samsungButton = view.findViewById(R.id.samsung_pay);
Button sepaDirectDebitButton = view.findViewById(R.id.sepa_debit);
Button payPalNativeCheckoutButton = view.findViewById(R.id.paypal_native_checkout);
Button payPalMessagingButton = view.findViewById(R.id.paypal_messaging);

cardsButton.setOnClickListener(this::launchCards);
payPalButton.setOnClickListener(this::launchPayPal);
Expand All @@ -47,6 +48,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
samsungButton.setOnClickListener(this::launchSamsungPay);
payPalNativeCheckoutButton.setOnClickListener(this::launchPayPalNativeCheckout);
sepaDirectDebitButton.setOnClickListener(this::launchSEPADirectDebit);
payPalMessagingButton.setOnClickListener(this::launchPayPalMessaging);

return view;
}
Expand Down Expand Up @@ -126,4 +128,10 @@ public void launchSEPADirectDebit(View v) {
NavDirections action = MainFragmentDirections.actionMainFragmentToSepaDirectDebitFragment();
Navigation.findNavController(v).navigate(action);
}

public void launchPayPalMessaging(View v) {
NavDirections action =
MainFragmentDirections.actionMainFragmentToPayPalMessagingFragment();
Navigation.findNavController(v).navigate(action);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package com.braintreepayments.demo

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
import com.braintreepayments.api.ExperimentalBetaApi
import com.braintreepayments.api.PayPalMessagingColor
import com.braintreepayments.api.PayPalMessagingListener
import com.braintreepayments.api.PayPalMessagingLogoType
import com.braintreepayments.api.PayPalMessagingOfferType
import com.braintreepayments.api.PayPalMessagingRequest
import com.braintreepayments.api.PayPalMessagingTextAlignment
import com.braintreepayments.api.PayPalMessagingView

@OptIn(ExperimentalBetaApi::class)
class PayPalMessagingFragment : BaseFragment(), PayPalMessagingListener {
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
return inflater.inflate(R.layout.fragment_paypal_messaging, container, false)
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

val payPalMessagingRequest = PayPalMessagingRequest(
amount = 2.0,
pageType = null,
offerType = PayPalMessagingOfferType.PAY_LATER_LONG_TERM,
buyerCountry = "US",
logoType = PayPalMessagingLogoType.PRIMARY,
textAlignment = PayPalMessagingTextAlignment.CENTER,
color = PayPalMessagingColor.BLACK
)

val payPalMessagingView = PayPalMessagingView(braintreeClient, requireActivity())
payPalMessagingView.setListener(this)
payPalMessagingView.start(payPalMessagingRequest)
payPalMessagingView.layoutParams = ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT
)

val messagingView: LinearLayout = view.findViewById(R.id.content)
messagingView.addView(payPalMessagingView)
}

override fun onPayPalMessagingClick() {
println("User clicked on the PayPalMessagingView")
}

override fun onPayPalMessagingApply() {
println("User is attempting to apply for PayPal Credit")
}

override fun onPayPalMessagingLoading() {
println("Loading PayPalMessagingView")
}

override fun onPayPalMessagingSuccess() {
println("PayPalMessagingView displayed to user")
}

override fun onPayPalMessagingFailure(error: Exception) {
println("PayPalMessagingView returned the error:" + error.message)
}
}
8 changes: 8 additions & 0 deletions Demo/src/main/res/layout/fragment_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@
android:text="@string/cards"
android:textSize="12sp" />

<Button
android:id="@+id/paypal_messaging"
style="?android:attr/buttonStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/paypal_messaging_button"
android:textSize="12sp" />
</TableRow>

<TableRow
Expand Down
10 changes: 10 additions & 0 deletions Demo/src/main/res/layout/fragment_paypal_messaging.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="80dp"
android:orientation="vertical"
android:layout_gravity="center_vertical"
android:padding="10dp"
tools:context=".PayPalMessagingFragment" />
8 changes: 8 additions & 0 deletions Demo/src/main/res/navigation/nav_graph.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
<action
android:id="@+id/action_mainFragment_to_payPalNativeCheckoutFragment"
app:destination="@id/payPalNativeCheckoutFragment" />
<action
android:id="@+id/action_mainFragment_to_payPalMessagingFragment"
app:destination="@id/payPalMessagingFragment" />
</fragment>
<fragment
android:id="@+id/cardFragment"
Expand Down Expand Up @@ -179,5 +182,10 @@
app:popUpTo="@id/mainFragment"
app:popUpToInclusive="false" />
</fragment>
<fragment
android:id="@+id/payPalMessagingFragment"
android:name="com.braintreepayments.demo.PayPalMessagingFragment"
tools:layout="fragment_paypal_messaging">
</fragment>

</navigation>
1 change: 1 addition & 0 deletions Demo/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<string name="local_payment_button">Local Payment</string>
<string name="sepa_direct_debit_button">SEPA Direct Debit</string>
<string name="cards">Credit or Debit Cards</string>
<string name="paypal_messaging_button">PayPal Messaging</string>
<string name="paypal_native_checkout">PayPal Native Checkout</string>
<string name="samsung_pay">Samsung Pay</string>
<string name="create_transaction">Create a Transaction</string>
Expand Down
67 changes: 67 additions & 0 deletions PayPalMessaging/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
plugins {
id 'com.android.library'
id 'org.jetbrains.kotlin.android'
}

android {
compileSdkVersion rootProject.compileSdkVersion

defaultConfig {
// required to be out of sync with other modules due to messaging SDK min version
minSdkVersion rootProject.minSdkVersionPayPalMessaging
targetSdkVersion rootProject.targetSdkVersion

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

buildConfigField "String", "VERSION_NAME", "\"${rootProject.versionName}\""
}

testOptions {
unitTests {
includeAndroidResources = true
returnDefaultValues true
all {
jvmArgs '-noverify'
}
}
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility versions.javaSourceCompatibility
targetCompatibility versions.javaTargetCompatibility
}
}

dependencies {
api project(':BraintreeCore')

implementation deps.coreKtx
implementation deps.kotlinStdLib
implementation deps.appCompat
implementation('com.paypal.messages:paypal-messages:1.0.1')

testImplementation deps.robolectric
testImplementation deps.jsonAssert
testImplementation deps.junitTest
testImplementation deps.mockk
testImplementation deps.mockitoCore
testImplementation project(':TestUtils')
}

// region signing and publishing

project.ext.name = "paypal-messaging"
project.ext.pom_name = "paypal-messaging"
project.ext.group_id = "com.braintreepayments.api"
project.ext.version = rootProject.version
project.ext.pom_desc = "PayPal Messaging dependencies for Braintree Android."

apply from: rootProject.file("gradle/gradle-publish.gradle")

// endregion
4 changes: 4 additions & 0 deletions PayPalMessaging/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.braintreepayments.api.paypalmessaging">
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.braintreepayments.api

internal object PayPalMessagingAnalytics {
const val STARTED = "paypal-messaging:create-view:started"
const val FAILED = "paypal-messaging:create-view:failed"
const val SUCCEEDED = "paypal-messaging:create-view:succeeded"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.braintreepayments.api

import com.paypal.messages.config.message.style.PayPalMessageColor

/**
* Text and logo color option for a PayPal Message
* Note: **This module is in beta. It's public API may change or be removed in future releases.**
*/
@ExperimentalBetaApi
enum class PayPalMessagingColor {
/**
* Black text with a color logo
*/
BLACK,

/**
* White text with a color logo
*/
WHITE,

/**
* Black text with a black logo
*/
MONOCHROME,

/**
* Black text with a desaturated logo
*/
GRAYSCALE;

internal val internalValue: PayPalMessageColor
get() = when (this) {
BLACK -> PayPalMessageColor.BLACK
WHITE -> PayPalMessageColor.WHITE
MONOCHROME -> PayPalMessageColor.MONOCHROME
GRAYSCALE -> PayPalMessageColor.GRAYSCALE
}
}
Loading

0 comments on commit 8444746

Please sign in to comment.