Created
November 2, 2018 20:40
-
-
Save osrl/026b68def95e2b6decb177bc9bb8fa07 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
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
PaymentConfiguration.init("my_key") | |
CustomerSession.initCustomerSession(MyEphemeralKeyProvider()) | |
... | |
} |
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 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 | |
} | |
} | |
} | |
} |
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
//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