forked from coinbase/coinbase-commerce-node
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcheckout.js
74 lines (63 loc) · 1.86 KB
/
checkout.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
63
64
65
66
67
68
69
70
71
72
73
74
'use strict';
var coinbase = require('coinbase-commerce-node');
var Client = coinbase.Client;
var Checkout = coinbase.resources.Checkout;
Client.init('YOUR_API_KEY');
// Try to create checkout via Checkout resource create method
Checkout.create({
'description': 'Mastering the Transition to the Information Age',
'local_price': {
'amount': '1.00',
'currency': 'USD'
},
'name': 'test item 15 edited',
'pricing_type': 'fixed_price',
'requested_info': ['email']
}, function (error, response) {
console.log('Created checkout via create method');
console.log(response);
console.log(error);
if (response && response.id) {
// Try to update created checkout
Checkout.updateById(response.id, {'name': 'new name'}, function (error, response) {
console.log('Updated checkout with id ' + response.id);
console.log(error);
console.log(response);
});
}
});
// Try to create checkout via Checkout object save method
var checkoutObj = new Checkout();
checkoutObj.name = 'test name';
checkoutObj.description = 'test description';
checkoutObj.pricing_type = 'fixed_price';
checkoutObj.requested_info = ['email'];
checkoutObj.local_price = {
'amount': '100.00',
'currency': 'USD'
};
checkoutObj.save(function (error, response) {
console.log('Created checkout via save method');
console.log(error);
console.log(response);
if (response && response.id) {
var id = response.id;
// Try to delete created checkout
Checkout.deleteById(response.id, function (error, response) {
console.log('Deleted checkout with id ' + id);
console.log(error);
console.log(response);
});
}
});
// Get list of checkouts
Checkout.list({order: 'asc', limit: 2}, function (error, list, pagination) {
console.log(list);
console.log(pagination);
console.log(error);
});
// Get all checkouts
Checkout.all({order: 'asc'}, function (error, list) {
console.log(list);
console.log(error);
});