Created
February 16, 2023 18:16
-
-
Save shanwixcode/d87ae5f38475a24d9d99d9a2c7bea4a2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const accountSid = ''; | |
const authToken = ''; | |
const client = require('twilio')(accountSid, authToken); | |
import wixData from 'wix-data'; | |
import {award_points} from 'backend/member.js'; | |
let options = { | |
"suppressAuth": true | |
}; | |
export function verify(num) { | |
return client.verify.v2.services('VAX') //Verification Service created under Verify in the Develop column of your Twilio Dashboard. Sample URL console.twilio.com/us1/develop/verify/services | |
.verifications | |
.create({to: num, channel: 'sms'}) | |
.then( (verification) => { | |
return verification; | |
}) | |
.catch( (err) => { | |
return err; | |
}); | |
} | |
export function verify_code(num, code, memid) { | |
return client.verify.v2.services('VAX') //Verification Service created under Verify in the Develop column of your Twilio Dashboard. Sample URL console.twilio.com/us1/develop/verify/services | |
.verificationChecks | |
.create({to: num, code: code}) | |
.then( (verification) => { | |
return get_user(verification, memid); | |
}) | |
.catch( (err) => { | |
return err; | |
}); | |
} | |
const get_user = (veri, id) => { | |
return wixData.query('users').eq('memberId', id).find(options).then( (res) => { | |
let Item = res.items[0]; | |
let opt = { | |
amount: 50, | |
description: 'Phone Number Verification', | |
appId: '553c79f3-5625-4f38-b14b-ef7c0d1e87df', //Refer documentation | |
idempotencyKey: String(Math.floor(Math.random() * 99999999)) | |
} | |
return award_points(Item.loyaltyId, opt) | |
.then( (resa) => { | |
return veri; | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment