Get User Instruments


let phonePeUserAccount = PhonePeUserAccount(
                     appSchema: "YOUR_APP_SCHEMA",
                     delegate: self)
Parameter NameTypeDescription
appSchemaStringYour 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.
delegatePhonePeUserAccountProviderSet 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()
}

To properly integrate with PhonePe, your class must conform to our protocol. This means you need to define and implement all of the required callback methods. Doing so ensures your application can listen for and correctly handle all messages sent by the PhonePe SDK.

  • 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 NameTypeDescription
tokenStringPass 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)
    }
  • You 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 NameTypeDescription
typeStringType of payment instrument
titleStringDisplay name of the Instrument
subTitleStringThis is optional parameter
logoUrlStringFetch bank logo from this parameter
idStringUnique Id for the instrument
availableBooleanMerchant should hide/grey out the instrument if this is false
priorityIntLower the priority, better it is to show at the top
networkLogoUrlStringFetch Card logo from this parameter
bankCodeStringBank Code
metaInfoAnyExtra parameter for future usage
subTypeStringType of card – Debit or Credit

In the next section, you will learn how to create an order by calling the Create Order API. You will understand what information needs to be passed in the request and how the response provides an order token. This token will then be used in the subsequent steps of the payment flow.

Is this article helpful?