Get Payment Options

anchor image
Copied !

Initialise the PhonePe Payment Option

let paymentOptionManager = PhonePeOptionManager(merchantId: "YOUR_MERCHANT_ID", flowId: UUID().uuidString, appSchema: "YOUR_APP_SCHEMA", delegate: self)

You need to pass the following params:

1. merchantId: Your Merchant ID that is provided by the integration team
2. flowId: Pass the unique string (UUID().uuidString) for every init for analytics purposes.
3. appSchema: Your App schema that you created under the URL Schema
4. Set the delegate to your class where you want the callbacks for all the handling

The delegate is of PaymentOptionProvider type.

Interface looks like below

public protocol PaymentOptionProvider: AnyObject { func onOptionsReady(options: [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: PaymentOptionProvider { func onOptionsReady(options [PhonePePayment.Instrument]?, failure: PhonePePayment.SavedInstrumentFailure?) { consoleLog(options) consoleLog(failure) } 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(): You can optionally override this. This callback is given when user rejects the consent.

func onConsentNotGiven() { consoleLog("Consent Not Given", type: .error) }
Call 
getPaymentOptions(token: String)
method of PhonePeOptionManager instance.
paymentOptionManager.getPaymentOptions(token: "YOUR_TOKEN")
token: pass the token that is provided by the backend in the /init call.
You will get the callback in the protocol methods.
For linking the PhonePe app for payment options, Call the linkPhonePe method of the PhonePeOptionManager
paymentOptionManager.linkPhonePe()

After getting the consent, We will call the payment optons api and get the options to you. Once user selects one of the payment option and click on pay, Hit the Create Order API from your backend and get the token and merchant order id.