PhonePe provides a key-value storage. Both the keys and values can only be of type string.

getItem

(preferenceName:
Description: This method is used to get a stored value from native key-value storage

Request Parameters

Parameter NameTypeDescription
preferenceNamestringName of the key-value storage file. A merchant can have multiple key-value storage files for their app
keystringName of the key to fetch the value for
defaultValueundefined/stringDefault value in case the key doesn't exist

Usage:

sdk.getItem('app', 'key', undefined)
  .then((data) => {})
  .catch((err) => {})
Promise resolve:
'valueForKey'

Promise reject:
{
  'error_code': 'KEY_NOT_FOUND'
}

Response Parameter

Promise<string>
Promise resolve with the value of the corresponding key or the defaultValue if the key doesn't exist.
Otherwise, Promise reject is called with an appropriate error_code.
Promise failure reasons can be as follows:

CodeDescription
KEY_NOT_FOUNDNo value found for this key and no default value was provided

setItem

(preferenceName:
Description: This method is used to store a value (string) for the corresponding key (string) into native key-value storage.

Request Parameters

Parameter NameTypeDescription
preferenceNamestringName of the key-value storage file. A merchant can have multiple key-value storage files for their app
keystringName of the key to set the value for
valuestringValue that you would like to set for the key

Response Parameter

void
Usage:

sdk.setItem('app', 'key', 'value')

removeItem

(preferenceName:
Description: This method is used remove a key-value pair from native key-value storage

Request Parameters

Parameter NameTypeDescription
preferenceNamestringName of the key-value storage file. A merchant can have multiple key-value storage files for their app
keystringName of the key whose value needs to be removed

Usage:

sdk.removeItem('app', 'key')