Last active
January 31, 2023 17:19
-
-
Save AlaaZarifa/c2c25d1b7a8ac4c2f69a7b6bf60ce1ea to your computer and use it in GitHub Desktop.
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
class PaymentActivity : AppCompatActivity(), PaymentSheetResultCallback { | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_payment) | |
val config = PaymentConfig( | |
amount = 100, | |
currency = "SAR", | |
description = "Sample Android SDK Payment", | |
apiKey = "pk_test_xZUWm2GkQugcXZeLn3oMpNWpTdvLfZUNQ4m6ZYy9" | |
) | |
val paymentSheet = PaymentSheet(this, this, config) | |
paymentSheet.present() | |
} | |
// this method does not get triggered. When I click on the pay button, | |
// it opens the SDK web-view,then I enter 12345 then click on Submit and the activtiy gets dismissed. | |
// After that, I expected this method to be triggered but it does not! | |
override fun onResult(result: PaymentResult) { | |
Toast.makeText(this, "Test", Toast.LENGTH_SHORT).show() | |
when (result) { | |
is PaymentResult.Completed -> { | |
result.payment.log() | |
} | |
is PaymentResult.Failed -> { | |
result.error.message?.log() | |
result.error.printStackTrace() | |
} | |
PaymentResult.Canceled -> { | |
"PaymentResult.Canceled".log() | |
} | |
} | |
} | |
} | |
fun Any.log() = Log.e(">> ", " $this") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment