The capability will give the users to use the on-device camera for scanning QR codes or taking/uploading images.
scanQRCode(showGallery, validator)
Description: This method opens up a user interface that allows the user to scan QR codes and upon validation returns the scanned data back to the user.
Request Parameters
Parameter Name | Type | Description |
---|---|---|
showGallery | boolean | Whether there is a gallery option in the QR code interface (So that users can select QR codes from gallery). |
validator | string(Regex) | Optional validator regular expression that the scanned data should match in order to be considered valid. Use this to filter out invalid formats for your data (ex: HTTP url’s etc). |
Usage:
Examplesdk.scanQRCode(true) .then((data) => { console.log('Value received = ' + data) }) .catch((err) => {})
Response Parameter
Promise<string>
A promise with the desired value or error if there is some issue. Promise failure reasons can be as follows:
Code | Description |
---|---|
USER_BACK_PRESSED | User pressed the back button to cancel the operation |
INTERNAL_ERROR | PhonePe’s internal error |
INVALID_REGEX | Regex sent is invalid |
ResponsePromise resolve: Resolution { “uri”: “25134125737621837823213” } Promise reject: { 'error_code': 'USER_BACK_PRESSED' }
startCamera
Description: This method starts the camera to allow the user to take an image for use within the app. On completion, returns a URI with a path to the captured image.
Promise – The promise resolution returns a JS object with the URI of the taken image. The contents of the URI can be read through the readFile method stated here.
Usage:
JavaScriptPhonePe.PhonePe.build(PhonePe.Constants.Species.web).then((sdk) => { sdk.startCamera().then((res) => { console.log("URI" + res) alert(res) }).catch((err) => { console.log("error " + err) alert(err) }) })
Response Parameter
Promise<any>
A promise resolution with the grant token. Promise rejection if the grant token fetching failed.
responsePromise resolve: { "uri": "content://main/folder/image.jpeg" "name": “image.jpeg” //string "size":100 //double } Promise reject: { "error_code": "NETWORK_ERROR" }
Code | Description |
---|---|
PERMISSION_DENIED | The user denied access to the camera. |
INTERNAL_ERROR | PhonePe’s internal error |