Get payment options from SDK
Initialise the PhonePe Payment Option
let paymentOptionManager =
PhonePeOptionManager(merchantId: "YOUR_MERCHANT_ID",
flowId: UUID().uuidString,
appSchema: "YOUR_APP_SCHEMA",
delegate: self)
Parameter Name | Type | Description |
---|---|---|
merchantId | String | The Merchant ID provided by PhonePe |
flowId | String | Pass the unique string (UUID().uuidString) for every init for analytics purposes. |
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 | Object | 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 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")
Parameter Name | Type | Description |
---|---|---|
token | String | Pass the token that is provided by the backend in the 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 linkPhonePe method of the PhonePeOptionManager
paymentOptionManager.linkPhonePe()
After getting the consent, We will call the payment options api and get the options to you.
func onOptionsReady(options
[PhonePePayment.Instrument]?, failure:
PhonePePayment.SavedInstrumentFailure?) {
consoleLog(options)
consoleLog(failure)
}
Once user selects one of the payment option then move to the Initiate Payment step.