forked from voucherifyio/voucherify-js-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server-customer.ts
49 lines (43 loc) · 1.16 KB
/
server-customer.ts
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
// require('source-map-support').install()
import { VoucherifyServerSide } from '@voucherify/sdk'
const voucherify = VoucherifyServerSide({
applicationId: '5452e923-810c-4880-83fb-65202fab8e28',
secretKey: '6a0f56de-b5a8-4893-bedd-79711134108b',
})
const payload = {
name: 'John Doe',
email: '[email protected]',
description: 'Premium user, ACME Inc.',
metadata: {
lang: 'en',
},
}
console.log('==== CREATE ====')
voucherify.customers
.create(payload)
.then(customer => {
console.log('New Customer: ', customer)
console.log('==== READ ====')
return voucherify.customers.get(customer.id).then(result => {
console.log('Result: ', result)
return customer
})
})
.then(customer => {
console.log('==== UPDATE ====')
customer.metadata.type = 'premium'
return voucherify.customers.update(customer).then(result => {
console.log('Result: ', result)
return customer
})
})
.then(customer => {
console.log('==== DELETE ====')
return voucherify.customers.delete(customer.id).then(() => {
console.log('Checking...')
return voucherify.customers.get(customer.id).catch(err => {
console.log('Result:', err)
})
})
})
.catch(console.error)