/
list-sources.js
62 lines (40 loc) · 1.56 KB
/
list-sources.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
58
59
60
61
62
module.exports = {
friendlyName: 'List sources',
description: 'List all payment sources for a customer.',
moreInfoUrl: 'https://stripe.com/docs/api#list_source',
sideEffects: 'cacheable',
inputs: {
apiKey: require('../constants/apiKey.input'),
customer: {
description: 'The Stripe ID of the customer whose sources will be listed.',
example: 'cus_4kmLwU2PvQBeqq',
required: true
}
},
exits: {
success: {
outputFriendlyName: 'Stripe customer payment sources',
outputDescription: 'An array of Stripe payment sources for the specified customer.',
outputExample: {
'object': 'list',
'url': '/v1/customers/cu_14YepJ2eZvKYlo2CUJrwelj2/sources',
'has_more': false,
'data': [require('../constants/source.schema')]
}
}
},
fn: function (inputs, exits) {
// Import `stripe`, and initialize it with the given API key.
// (Or fall back to the cached API key, if available)
var stripe = require('stripe')(inputs.apiKey||require('./private/cache').apiKey);
// Use the Stripe API to list the customer's payment sources.
stripe.customers.listSources(inputs.customer, function(err, sources) {
// Send any errors through the `error` exit.
// TODO: handle more specific exits (i.e. rate limit, customer does not
// exist, etc.), possibly via a separate `negotiateError` machine.
if (err) {return exits.error(err);}
// Return the list of payment sources through the `success` exit.
return exits.success(sources);
});
}
};