-
Notifications
You must be signed in to change notification settings - Fork 629
/
BacsDebitPaymentMethodActivity.kt
53 lines (47 loc) · 1.97 KB
/
BacsDebitPaymentMethodActivity.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package com.stripe.example.activity
import android.os.Bundle
import android.view.View
import androidx.lifecycle.Observer
import com.stripe.android.model.Address
import com.stripe.android.model.PaymentMethod
import com.stripe.android.model.PaymentMethodCreateParams
import com.stripe.example.databinding.BacsDebitActivityBinding
class BacsDebitPaymentMethodActivity : StripeIntentActivity() {
private val viewBinding: BacsDebitActivityBinding by lazy {
BacsDebitActivityBinding.inflate(layoutInflater)
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(viewBinding.root)
viewModel.inProgress.observe(this, { enableUi(!it) })
viewModel.status.observe(this, Observer(viewBinding.status::setText))
viewBinding.submit.setOnClickListener {
createAndConfirmPaymentIntent(
"gb",
PaymentMethodCreateParams.create(
bacsDebit = PaymentMethodCreateParams.BacsDebit(
accountNumber = "00012345",
sortCode = "108800"
),
billingDetails = PaymentMethod.BillingDetails(
name = "Jenny Rosen",
phone = "1-800-555-1234",
email = "jrosen@example.com",
address = Address.Builder()
.setCity("San Francisco")
.setCountry("US")
.setLine1("123 Market St")
.setLine2("#345")
.setPostalCode("94107")
.setState("CA")
.build()
)
)
)
}
}
private fun enableUi(enabled: Boolean) {
viewBinding.submit.isEnabled = enabled
viewBinding.progressBar.visibility = if (enabled) View.INVISIBLE else View.VISIBLE
}
}