-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtest-helper-routes.js
More file actions
97 lines (96 loc) · 2.94 KB
/
Copy pathtest-helper-routes.js
File metadata and controls
97 lines (96 loc) · 2.94 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
const stripeCache = require('./src/stripe-cache.js')
module.exports = {
createFakePayout: {
api: {
get: async (req) => {
if (process.env.NODE_ENV !== 'testing') {
throw new Error('invalid-route')
}
const chargeInfo = {
amount: 1000,
currency: 'usd',
source: 'tok_bypassPending',
description: 'Payout charge',
metadata: {
appid: global.appid,
testNumber: global.testNumber
}
}
await stripeCache.execute('charges', 'create', chargeInfo, req.stripeKey)
const payoutInfo = {
amount: 100,
currency: 'usd',
metadata: {
appid: global.appid,
testNumber: global.testNumber
}
}
return stripeCache.execute('payouts', 'create', payoutInfo, req.stripeKey)
}
}
},
fakeAmountOwed: {
api: {
get: async (req) => {
if (process.env.NODE_ENV !== 'testing') {
throw new Error('invalid-route')
}
if (!req.query || !req.query.customerid) {
throw new Error('invalid-customerid')
}
const customer = await stripeCache.execute('customers', 'retrieve', req.query.customerid, req.stripeKey)
await stripeCache.execute('invoiceItems', 'create', {
customer: req.query.customerid,
amount: 2500,
currency: 'usd',
description: 'One-time setup fee'
}, req.stripeKey)
let invoice
if (req.query.due_date && req.query.due_date !== '0') {
invoice = await stripeCache.execute('invoices', 'create', {
customer: req.query.customerid,
auto_advance: true,
collection_method: 'send_invoice',
due_date: req.query.due_date,
metadata: customer.metadata
}, req.stripeKey)
} else {
invoice = await stripeCache.execute('invoices', 'create', {
customer: req.query.customerid,
auto_advance: true,
metadata: customer.metadata
}, req.stripeKey)
}
return stripeCache.execute('invoices', 'finalizeInvoice', invoice.id, { auto_advance: false }, req.stripeKey)
}
}
},
toggleRefunds: {
api: {
get: async (req) => {
if (process.env.NODE_ENV !== 'testing') {
throw new Error('invalid-route')
}
if (req.query && req.query.enable) {
global.subscriptionRefundPeriod = 7 * 24 * 60 * 60
} else {
global.subscriptionRefundPeriod = false
}
}
}
},
toggleOverdueInvoiceThreshold: {
api: {
get: async (req) => {
if (process.env.NODE_ENV !== 'testing') {
throw new Error('invalid-route')
}
if (req.query && req.query.enable) {
global.overdueInvoiceThreshold = 7 * 24 * 60 * 60
} else {
global.overdueInvoiceThreshold = false
}
}
}
}
}