Skip to content

Instantly share code, notes, and snippets.

@AlaaZarifa
Last active January 31, 2023 17:19
Show Gist options
  • Save AlaaZarifa/c2c25d1b7a8ac4c2f69a7b6bf60ce1ea to your computer and use it in GitHub Desktop.
Save AlaaZarifa/c2c25d1b7a8ac4c2f69a7b6bf60ce1ea to your computer and use it in GitHub Desktop.
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