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

Create BecsDebitMandateAcceptanceTextView #2295

Merged
merged 1 commit into from
Mar 18, 2020
Merged
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
2 changes: 1 addition & 1 deletion example/res/layout/becs_debit_activity.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content" />

<TextView
<com.stripe.android.view.BecsDebitMandateAcceptanceTextView
android:id="@+id/mandate_acceptance"
android:layout_width="match_parent"
android:layout_height="wrap_content"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import com.stripe.android.ApiResultCallback
import com.stripe.android.PaymentConfiguration
import com.stripe.android.Stripe
import com.stripe.android.model.PaymentMethod
import com.stripe.android.view.BecsDebitMandateAcceptanceFactory
import com.stripe.example.databinding.BecsDebitActivityBinding

class BecsDebitPaymentMethodActivity : AppCompatActivity() {
Expand All @@ -19,15 +18,12 @@ class BecsDebitPaymentMethodActivity : AppCompatActivity() {
private val keyboardController: KeyboardController by lazy {
KeyboardController(this)
}
private val mandateAcceptanceFactory: BecsDebitMandateAcceptanceFactory by lazy {
BecsDebitMandateAcceptanceFactory(this)
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(viewBinding.root)

viewBinding.mandateAcceptance.text = mandateAcceptanceFactory.create("Rocketship Inc.")
viewBinding.mandateAcceptance.merchantName = "Rocketship Inc."

viewBinding.submit.setOnClickListener {
viewBinding.element.params?.let { params ->
Expand Down
5 changes: 3 additions & 2 deletions stripe/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,9 @@
<!-- BECS Debit Widget - mandate acceptance -->
<string name="becs_mandate_acceptance" tools:ignore="MissingTranslation">
By providing your bank account details and confirming this payment, you agree to this
Direct Debit Request and the Direct Debit Request service agreement, and authorise
Stripe Payments Australia Pty Ltd ACN 160 180 343 Direct Debit User ID number 507156
Direct Debit Request and the
&lt;a href="https://stripe.com/au-becs-dd-service-agreement/legal"&gt;Direct Debit Request service agreement&lt;/a&gt;,
and authorise Stripe Payments Australia Pty Ltd ACN 160 180 343 Direct Debit User ID number 507156
(“Stripe”) to debit your account through the Bulk Electronic Clearing System (BECS) on
behalf of %1$s (the "Merchant") for any amounts separately communicated to you
by the Merchant. You certify that you are either an account holder or an authorised
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.stripe.android.view

import android.content.Context
import android.os.Build
import android.text.Html
import com.stripe.android.R

/**
* A class to create BECS Debit Mandate Agreement text for the [BecsDebitWidget].
*/
class BecsDebitMandateAcceptanceTextFactory(
private val context: Context
) {
fun create(merchantName: String): CharSequence {
val mandateAcceptanceText = context.getString(
R.string.becs_mandate_acceptance,
merchantName
)
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
Html.fromHtml(mandateAcceptanceText, Html.FROM_HTML_MODE_LEGACY)
} else {
Html.fromHtml(mandateAcceptanceText)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.stripe.android.view

import android.content.Context
import android.text.method.LinkMovementMethod
import android.util.AttributeSet
import androidx.appcompat.widget.AppCompatTextView
import kotlin.properties.Delegates

class BecsDebitMandateAcceptanceTextView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = android.R.attr.textViewStyle
) : AppCompatTextView(context, attrs, defStyleAttr) {

private val factory = BecsDebitMandateAcceptanceTextFactory(context)

init {
movementMethod = LinkMovementMethod.getInstance()
}

var merchantName: String by Delegates.observable(
""
) { _, _, merchantName ->
text = merchantName.takeIf { it.isNotBlank() }?.let { factory.create(it) } ?: ""
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import com.stripe.android.model.PaymentMethodCreateParams
/**
* A form for accepting a customer's BECS account information.
*
* See [BecsDebitMandateAcceptanceFactory] for creating the mandate acceptance copy.
* See [BecsDebitMandateAcceptanceTextFactory] for creating the mandate acceptance copy.
*/
class BecsDebitWidget @JvmOverloads constructor(
context: Context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import org.robolectric.RobolectricTestRunner

@RunWith(RobolectricTestRunner::class)
class BecsDebitMandateAcceptanceFactoryTest {
private val factory = BecsDebitMandateAcceptanceFactory(
private val factory = BecsDebitMandateAcceptanceTextFactory(
ApplicationProvider.getApplicationContext()
)

@Test
fun testCreate() {
Locale.setDefault(Locale.US)
assertThat(factory.create("Rocketship Inc."))
assertThat(factory.create("Rocketship Inc.").toString())
.isEqualTo("By providing your bank account details and confirming this payment, you agree to this Direct Debit Request and the Direct Debit Request service agreement, and authorise Stripe Payments Australia Pty Ltd ACN 160 180 343 Direct Debit User ID number 507156 (“Stripe”) to debit your account through the Bulk Electronic Clearing System (BECS) on behalf of Rocketship Inc. (the Merchant) for any amounts separately communicated to you by the Merchant. You certify that you are either an account holder or an authorised signatory on the account listed above.")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.stripe.android.view

import androidx.test.core.app.ApplicationProvider
import com.google.common.truth.Truth.assertThat
import kotlin.test.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner

@RunWith(RobolectricTestRunner::class)
class BecsDebitMandateAcceptanceTextViewTest {

private val textView = BecsDebitMandateAcceptanceTextView(
ApplicationProvider.getApplicationContext()
)

@Test
fun merchantName_whenUpdated_shouldUpdatedText() {
assertThat(textView.text.toString())
.isEqualTo("")

textView.merchantName = "Rocketship Inc."

assertThat(textView.text.toString())
.isEqualTo("By providing your bank account details and confirming this payment, you agree to this Direct Debit Request and the Direct Debit Request service agreement, and authorise Stripe Payments Australia Pty Ltd ACN 160 180 343 Direct Debit User ID number 507156 (“Stripe”) to debit your account through the Bulk Electronic Clearing System (BECS) on behalf of Rocketship Inc. (the Merchant) for any amounts separately communicated to you by the Merchant. You certify that you are either an account holder or an authorised signatory on the account listed above.")
}
}