Skip to content

Commit

Permalink
New cancel delayed conversion request
Browse files Browse the repository at this point in the history
Also few minor fixes
  • Loading branch information
mrz1836 committed Jan 10, 2020
1 parent 9c5451e commit ecef024
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
8 changes: 7 additions & 1 deletion examples/examples.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,15 @@ let apiKey = process.env.TONICPOW_API_KEY || ''
//
// Example: Convert a goal (by user)
//
let conversion = await TonicPow.createConversionByUserID(1, 1, 'my custom attributes')
let conversion = await TonicPow.createConversionByUserID(1, 1, 'my custom attributes', 10)
console.log('conversion successful', conversion)

//
// Example: Cancel a Delayed Conversion
//
conversion = await TonicPow.cancelConversion(conversion.id, 'not needed anymore')
console.log('conversion status', conversion.status)

} catch(e){
console.error(e)
}
Expand Down
24 changes: 23 additions & 1 deletion lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,7 @@ async function getCampaign (t, campaignId, userSessionToken = '') {
}

// getCampaignBalance will update the models's balance from the chain
// This will return an error if the campaign is not found (404)
//
// For more information: https://docs.tonicpow.com/#b6c60c63-8ac5-4c74-a4a2-cf3e858e5a8d
async function getCampaignBalance (t, campaignId) {
Expand All @@ -570,6 +571,7 @@ async function updateCampaign (t, campaign, userSessionToken = '') {
}

// listCampaigns will return a list of active campaigns
// This will return an error if the campaign is not found (404)
//
// For more information: https://docs.tonicpow.com/#c1b17be6-cb10-48b3-a519-4686961ff41c
async function listCampaigns (t, customSessionToken = '') {
Expand Down Expand Up @@ -643,6 +645,15 @@ async function createConversionByUserID (t, goalId, userId, additionalData = '',
return tonicAxios.post(t.config.apiUrl + version + '/conversions', data, getOptions())
}

// cancelConversion will cancel an existing conversion (if delay was set and > 1 minute remaining)
//
// For more information: https://docs.tonicpow.com/#e650b083-bbb4-4ff7-9879-c14b1ab3f753
async function cancelConversion (t, conversionId, reason) {
let data = { id: conversionId, reason: reason }
return tonicAxios.put(t.config.apiUrl + version + '/conversions/cancel', data, getOptions())
}


//
// TonicPow API - Link Requests
// =====================================================================================================================
Expand Down Expand Up @@ -1062,7 +1073,7 @@ module.exports = {
return new Promise(async (resolve, reject) => {
try {
initCheck(this.loaded)
let response = await createConversionByUserID(this, goalId, userId, additionalData, delayInMinutes = 0)
let response = await createConversionByUserID(this, goalId, userId, additionalData, delayInMinutes)
resolve(response.data)
} catch (e) {
reject(checkError(e))
Expand All @@ -1080,6 +1091,17 @@ module.exports = {
}
})
},
cancelConversion: async function (conversionId, reason) {
return new Promise(async (resolve, reject) => {
try {
initCheck(this.loaded)
let response = await cancelConversion(this, conversionId, reason)
resolve(response.data)
} catch (e) {
reject(checkError(e))
}
})
},
createLink: async function (link, userSessionToken = '') {
return new Promise(async (resolve, reject) => {
try {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tonicpow-js",
"version": "0.1.33",
"version": "0.1.34",
"description": "TonicPow API Library in JS - https://docs.tonicpow.com",
"main": "lib/api.js",
"repository": {
Expand Down

0 comments on commit ecef024

Please sign in to comment.