问题
In my iOS application, I need to accept payments from the user. I am using UPI for the same. I have followed the following document provided by UPI
http://www.npci.org.in/documents/UPI-Linking-Specs-ver-1.1_draft.pdf
I have created a deeplink as stated in the document. UIApplication.shared.open
is used to open the deeplink url so that it opens any installed PSP(Payment Service Provider) application in my phone(like PhonePe, BHIM etc)
func payButtonClicked() {
guard let urlString = "upi://pay?pa=samplevpa@ybl&pn=Sample Name&am=1&cu=INR".addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
else {
return
}
guard let url = URL(string: urlString) else {
return
}
if !UIApplication.shared.canOpenURL(url) {
print("url cannot be opened")
return
}
UIApplication.shared.open(url, options: [:], completionHandler: { (success) in
print(success)
})
}
I have registered my application with custom URL schemes and have added the scheme upi for ApplicationQueriesScheme in plist file
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLSchemes</key>
<array>
<string>SampleApp</string>
</array>
<key>CFBundleURLName</key>
<string>com.company.SampleApp</string>
</dict>
</array>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>upi</string>
</array>
It is opening the PSP application and I'm able to make the transaction. The problem is I'm not able to get the response back from the PSP application. There is no callback method to UIApplication.shared.open
method. I need to get the status of the transaction back from the PSP application and show the status to the user. Any help appreciated
回答1:
Have not tried it but it was mentioned in the document about a url parameter on clicking of which we should show the transaction details to the user.
This should be a URL when clicked provides customer with further transaction details like complete bill details, bill copy, order copy, ticket details, etc. This can also be used to deliver digital goods such as mp3 files etc. after payment.
We could send a url with a url scheme that redirects to the app or an universal link that our app can handle.
Again I have not tried this so I do not know if this works as I think it should or whether it would exactly solve your issue.
https://www.npci.org.in/sites/all/themes/npcl/images/PDF/UPI_Linking_Specs_ver_1.5.1.pdf
回答2:
You can use the url parameter to pass your website url with the get method with order id or payment id as parameter. Once the payment is successful, it is mandate the UPI provider to hit the URL. The purpose of the URL should be keep updating the transaction status and trigger then end user an email or SMS with the transaction status.
来源:https://stackoverflow.com/questions/46178769/how-to-get-response-after-integrating-upi-using-hyperlink