-
Notifications
You must be signed in to change notification settings - Fork 663
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create BecsDebitMandateAcceptanceTextView (#2295)
A `TextView` that shows the BECS mandate acceptance copy and links to the service agreement.
- Loading branch information
1 parent
0a3a76d
commit 25baf47
Showing
9 changed files
with
85 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 0 additions & 15 deletions
15
stripe/src/main/java/com/stripe/android/view/BecsDebitMandateAcceptanceFactory.kt
This file was deleted.
Oops, something went wrong.
25 changes: 25 additions & 0 deletions
25
stripe/src/main/java/com/stripe/android/view/BecsDebitMandateAcceptanceTextFactory.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
stripe/src/main/java/com/stripe/android/view/BecsDebitMandateAcceptanceTextView.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) } ?: "" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
stripe/src/test/java/com/stripe/android/view/BecsDebitMandateAcceptanceTextViewTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.") | ||
} | ||
} |