@@ -3,6 +3,7 @@ import android.widget.Toast
3
3
import androidx.activity.ComponentActivity
4
4
import com.stripe.android.PaymentConfiguration
5
5
import com.stripe.android.Stripe
6
+ import com.stripe.android.payments.paymentlauncher.PaymentLauncher
6
7
import com.stripe.android.paymentsheet.PaymentSheet
7
8
import com.stripe.android.paymentsheet.PaymentSheetResult
8
9
import model.InitialiseParams
@@ -16,6 +17,14 @@ class InitializeStripe {
16
17
lateinit var paymentSheet: PaymentSheet
17
18
var clientSecret = " "
18
19
20
+ private var paymentResultCallback: PaymentResult ? = null
21
+
22
+
23
+ interface PaymentResult {
24
+ fun onSuccess (status : Map <String , Any ?>)
25
+ fun onFailure (throwable : Throwable )
26
+ }
27
+
19
28
20
29
// Initialize Stripe only once
21
30
fun initializeStripe (initialObject : InitialiseParams ) {
@@ -31,6 +40,7 @@ class InitializeStripe {
31
40
}
32
41
}
33
42
43
+
34
44
fun initialisePaymentSheet (initialiseParams : InitialiseParams ) {
35
45
if ((initialiseParams.androidContext != null ) && (initialiseParams.androidActivity != null )) {
36
46
PaymentConfiguration .init (
@@ -40,30 +50,34 @@ class InitializeStripe {
40
50
41
51
paymentSheet =
42
52
PaymentSheet (initialiseParams.androidActivity as ComponentActivity ) { paymentSheet ->
43
- val result = onPaymentSheetResult(paymentSheet)
44
- Toast .makeText(
45
- initialiseParams.androidContext as Context ,
46
- result,
47
- Toast .LENGTH_LONG
48
- ).show()
53
+ onPaymentSheetResult(paymentSheet)
49
54
}
50
55
}
51
56
}
52
- private fun onPaymentSheetResult (paymentSheetResult : PaymentSheetResult ): String {
57
+ private fun onPaymentSheetResult (paymentSheetResult : PaymentSheetResult ) {
53
58
when (paymentSheetResult) {
54
59
is PaymentSheetResult .Canceled -> {
55
- return " cancelled"
60
+ paymentResultCallback?.onFailure(Throwable (message = " Cancelled" ))
61
+ paymentResultCallback = null
56
62
}
57
63
58
64
is PaymentSheetResult .Failed -> {
59
- return " Error: ${paymentSheetResult.error} "
65
+ paymentResultCallback?.onFailure(Throwable (message = " Failed" ))
66
+ paymentResultCallback = null
60
67
}
61
68
62
69
is PaymentSheetResult .Completed -> {
63
- return " Completed"
70
+ // TODO: Handle paymentSheetResult
71
+ paymentResultCallback?.onSuccess(emptyMap())
72
+ paymentResultCallback = null
64
73
}
65
74
}
66
75
}
76
+
77
+ fun setPaymentResultCallback (callback : InitializeStripe .PaymentResult ) {
78
+ paymentResultCallback = callback
79
+ }
80
+
67
81
}
68
82
69
83
object SingletonStripeInitialization {
0 commit comments