Camera / QR code Scanner

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.

<html-block html=”

Request Parameters

“>

Parameter NameTypeDescription
showGallerybooleanWhether there is a gallery option in the QR code interface (So that users can select QR codes from gallery).
validatorstring(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:

sdk.scanQRCode(true)
  .then((data) => {
	console.log('Value received = ' + data)
})
  .catch((err) => {})

<html-block html=”

Response Parameter

“>

Promise<string>
A promise with the desired value or error if there is some issue. Promise failure reasons can be as follows:

CodeDescription
USER_BACK_PRESSEDUser pressed the back button to cancel the operation
INTERNAL_ERRORPhonePe’s internal error
INVALID_REGEXRegex sent is invalid
Promise 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:

PhonePe.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)
	})
})

<html-block html=”

Response Parameter

“>

Promise<any>
A promise resolution with the grant token. Promise rejection if the grant token fetching failed.

Promise resolve:
{
"uri": "content://main/folder/image.jpeg"
"name": “image.jpeg” //string
"size":100        //double

}


Promise reject:
{
  "error_code": "NETWORK_ERROR"
}
CodeDescription
PERMISSION_DENIEDThe user denied access to the camera.
INTERNAL_ERRORPhonePe’s internal error