in payment-3p/src/updateAmount/index.ts [29:60]
export async function updateAmount(client : DocumentClient, paymentToken: string, amount: number) : Promise<boolean | null> {
try {
// Retrieve the paymentToken from DynamoDB
const response = await client.get({
TableName: TABLE_NAME,
Key: { paymentToken }
}).promise();
// If the paymentToken doesn't exist, we cannot update it.
// Therefore, the operation fails.
if (!response.Item)
return false;
// We can only update if the amount is less or equal to the current
// amount for that paymentToken.
if (response.Item.amount < amount)
return false;
// Update the amount.
await client.put({
TableName: TABLE_NAME,
Item: {
paymentToken: paymentToken,
amount: amount
}
}).promise();
return true;
} catch (dbError) {
console.log({"message": "Error updating the paymentToken in the database", "errormsg": dbError});
return null;
}
}