-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
examples.js
57 lines (46 loc) · 1.45 KB
/
examples.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Load the api package
import TonicPow from '../dist/api';
// Set the API key from our local environment
let apiKey = process.env.TONICPOW_API_KEY || ''
;(async () => {
try {
//
// Example: All Options (these are all optional, use as needed) (example for Firebase Cloud Functions)
//
const allOptions = {
environment: TonicPow.config.environments.Local,
}
//
// Example: Load TonicPow API
//
const tpow = new TonicPow(apiKey, allOptions)
const response = await tpow.auth();
console.log(response)
//
// Example: Get an advertiser profile
//
const advertiser = await tpow.getAdvertiserProfile(123)
console.log('advertiser found: '+advertiser.name)
//
// Example: Update an advertiser profile
//
advertiser.name = 'Acme Advertising'
advertiser = await tpow.updateAdvertiserProfile(advertiser)
console.log('updated name: '+advertiser.name)
//
// Example: Get a current rate
//
const rate = await tpow.getCurrentRate('usd',1.00)
console.log('price in satoshis', rate.price_in_satoshis)
//
// Example: Trigger a conversion
// Get the visitor session ( passed from frontend via tonicpow.getSessionId() )
const tncpwSession = "session-id-goes-here";
const result = await tpow.createConversionByGoalName(
"high_score", tncpwSession
);
console.log("Conversion result", result);
} catch(e){
console.error(e)
}
})();