Get User Instruments from SDK
Copied !
In onCreate of your Activity or Fragment add the below code
import com.phonepe.intent.sdk.api.ppeInstruments.PhonePeUserAccount
PhonePeUserAccount.setLifecycleCoroutineScope(this.lifecycleScope)
PhonePeUserAccount.setPhonePeUserAccountProvider(this)
PhonePeUserAccount.setActivityResultCaller(this)
In onDestroy of your Activity or Fragment add the below code
override fun onDestroy() {
super.onDestroy()
PhonePeUserAccount.unsetLifecycleCoroutineScope()
PhonePeUserAccount.unsetPhonePeUserAccountProvider()
PhonePeUserAccount.unsetActivityResultCaller()
}
Parameter Name | Type | Description |
---|---|---|
| LifecycleCoroutineScope | The lifecycleCoroutineScope of your activity or fragment or viewModel. |
phonePeUserAccountProvider | PhonePeUserAccountProvider | Pass the instance of the class where you want to get the callback. It can be your activity or fragment or viewModel that extend the PhonePeUserAccountProvider. |
| ActivityResultCaller | Pass the instance of your class that extends ActivityResultCaller. It can be AppCompatActivity or Fragment etc. |
call getUserInstruments
method of PhonePeUserAccount
. You will get the result in the phonePeUserAccountProvider that you provided in PhonePeUserAccount.setPhonePeUserAccountProvider()
PhonePeUserAccount.getUserInstruments(token = "")
Parameter Name | Type | Description |
---|---|---|
token | String | This is the SDK Token for User Accounts fetched from Merchant Server in Fetch Saved Instruments Token API. |
Note: The Class that will handle the callbacks should extend the PhonePeUserAccountProvider.
Callback Details
fun showLinkButton()
You get this callback when PhonePe doesn’t have user consent to share the Saved Instruments. Once you get this callback, show your UI with which user can interact with to trigger the consent (preferably a button which says link PhonePe). Once user clicks on the above button, call below method to trigger consent.
PhonePeUserAccount.linkPhonePe()
fun hideLinkButton(reason: LinkButtonHideReason)
When you get this callback, you can hide your UI for linking phonepe account. You additionaly get the reason in the param reason. You can optionally log it on your side for any issue debugging.fun onConsentGiven()
You can optionally override this. This callback is given when user accepts the consent.fun onConsentNotGiven()
This callback is given when user rejects the consent.fun onInstrumentsReady()
fun onInstrumentsReady(resultCode: InstrumentsResultCode, instruments: List<Instrument>? = null, additionalInfo: String? = null)
You get the callback as a terminal state of this flow. Saved Instruments are returned when all the conditions are met.
If resultCode == InstrumentsResultCode.SUCCESS, then you can render the instruments on your UI.
For any error, you get appropriate code in resultCode parameter.
class Instrument(
val type: String,
val title: String,
val subTitle: String?,
val logoUrl: String,
val isAvailable: Boolean,
val priority: Int,
val networkLogoUrl: String?,
val bankCode: String?,
val id: String?,
val metaInfo: Any?,
val subType: String?
)
Parameter Name | Type | Description |
---|---|---|
type | String | Type of payment instrument |
title | String | Display name of the Instrument |
subTitle | String | This is optional parameter |
logoUrl | String | Fetch bank logo from this parameter |
id | String | Unique Id for the instrument |
isAvailable | Boolean | Merchant should hide/grey out the instrument if this is false |
priority | Int | Lower the priority, better it is to show at the top |
networkLogoUrl | String | Fetch Card logo from this parameter |
bankCode | String | Bank Code |
metaInfo | Any | Extra parameter for future usage |
subType | String | Type of card – Debit or Credit |