Get User Instruments options from SDK
Initialise the PhonePeUserAccount
let phonePeUserAccount = PhonePeUserAccount(
appSchema: "YOUR_APP_SCHEMA",
delegate: self)
Parameter Name | Type | Description |
---|---|---|
appSchema | String | Your App schema created under the URL Schema of info.plist file. This helps to redirect back to the merchant app after the user has completed the payment. |
delegate | PhonePeUserAccountProvider | Set the delegate to your class where you want the callbacks for all the handling |
Interface looks like below
public protocol PhonePeUserAccountProvider: AnyObject {
func onInstrumentsReady(instruments: [PhonePePayment.Instrument]?, failure: PhonePePayment.SavedInstrumentFailure?)
func showLinkButton()
func hideLinkButton(_ state: PhonePePayment.OptionState)
func onConsentGiven()
func onConsentNotGiven()
}
Example and callback details
You need to conforms to this protocol in your class and define all the methods for callbacks.
func showLinkButton()
: You get this callback when phonepe doesn’t have user consent to share phonepe options. 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).
extension SavedInstrumentViewModel: PhonePeUserAccountProvider {
func showLinkButton() {
consoleLog(“Show Link Button”)
}
}
func hideLinkButton()
: When you get this callback, you can hide your UI for linking phonepe account. You additionaly get the reason in the param failure. You can optionally log it on your side for any issue debugging.
func hideLinkButton(_ failure:
PhonePePayment.OptionState) {
consoleLog(failure)
}
func onConsentGiven()
: You can optionally override this. This callback is given when user accepts the consent.
func onConsentGiven() {
consoleLog("Consent Given", type: .success)
}
func onConsentNotGiven()
: This callback is given when user rejects the consent.
func onConsentNotGiven() {
consoleLog("Consent Not Given", type: .error)
}
Call getUserInstruments(token: String)
method of PhonePeUserAccount instance.
phonePeUserAccount.getUserInstruments(token: "YOUR_TOKEN")
Parameter Name | Type | Description |
---|---|---|
token | String | Pass the SDK Token for User Accounts fetched from Merchant Server in Fetch Saved Instruments Token API call. You will get the callback in the protocol methods. |
For linking the PhonePe app for payment options, Call the link method of the PhonePeUserAccount
phonePeUserAccount.link()
After getting the consent, We will call the Instrument api and get the options to you.
func onInstrumentsReady(instruments:[PhonePePayment.Instrument]?, failure:PhonePePayment.SavedInstrumentFailure?) {
consoleLog(instruments)
consoleLog(failure)
}
Merchants should render the received saved Instruments on the checkout page. Once user selects one of the instrument then move to the Initiate Payment step.
public struct Instrument: Codable {
public let type: String?
public let title: String?
public let subTitle: String?
public let logoUrl: String?
public let id: String?
public let priority: Int?
public let available: Bool?
public let subType: String?
public let bankCode: String?
public let networkLogoUrl: String?
public let metaInfo: [[String: AnyValue]]?
}
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 |
available | 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 |