Skip to content

Instantly share code, notes, and snippets.

@osrl
Created November 2, 2018 20:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save osrl/026b68def95e2b6decb177bc9bb8fa07 to your computer and use it in GitHub Desktop.
Save osrl/026b68def95e2b6decb177bc9bb8fa07 to your computer and use it in GitHub Desktop.
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
PaymentConfiguration.init("my_key")
CustomerSession.initCustomerSession(MyEphemeralKeyProvider())
...
}
class MyEphemeralKeyProvider(val context: Context): EphemeralKeyProvider {
override fun createEphemeralKey(apiVersion: String,
keyUpdateListener: EphemeralKeyUpdateListener) {
//my api call
PaymentApi.create().getEphemeralKey()
.enqueue {
when(this) {
is Result.Success -> {
keyUpdateListener.onKeyUpdate(data.string())
}
is Result.Error -> //error
}
}
}
}
//none of the CustomerRetrievalListener methods called if getting ephemeral key failed. so my progress never hides itself
//I want to learn if there is a way to check ephemeral key is available. if not i will not start retreiving customer
//or should I run CustomerSession.initCustomerSession(MyEphemeralKeyProvider()) before every CustomerSession methods
showProgress()
CustomerSession.getInstance().retrieveCurrentCustomer(object : CustomerSession.CustomerRetrievalListener {
override fun onCustomerRetrieved(customer: Customer) {
recyclerView.adapter = PaymentAdapter(customer.sources)
hideProgress()
}
override fun onError(errorCode: Int, errorMessage: String?) {
hideProgress()
toast("Error retrieving payment methods")
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment