Skip to content

Commit ed99d38

Browse files
authored
Merge pull request #11 from samudary/orders-api
Orders API
2 parents 54c6638 + 35ba455 commit ed99d38

8 files changed

Lines changed: 403 additions & 115 deletions

File tree

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,14 @@ The following methods are currently available on the client instance. You can fi
7777
| List all forms | `client.listForms(callback)` |
7878
| Fetch a form | `client.fetchForm(formId, callback)` |
7979

80-
### Purchases
80+
**Note:** The beta purchases endpoint has been deprecated and its methods have been removed from the package except `createPurchase`, which now sends requests to the Order creation endpoint [here](https://developer.drip.com/#orders).
81+
82+
### Orders
8183
| Action | Method |
8284
|--------------------------------------|------------------------------------------------------------------------------|
83-
| List all purchases | `client.listPurchases(idOrEmail, options = {}, callback)` |
84-
| Create a purchase | `client.createPurchase(idOrEmail, payload, callback)` |
85-
| Fetch a purchase | `client.fetchPurchase(idOrEmail, purchaseId, callback)` |
85+
| Record an order for a subscriber | `client.createUpdateOrder(payload, callback)` |
86+
| Record a batch of orders | `client.createUpdateBatchOrders(payload, callback)` |
87+
| Record a refund for an order | `client.createUpdateRefund(payload, callback)` |
8688

8789
### Subscribers
8890
| Action | Method |

lib/index.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const Conversions = require('./conversions.js');
55
const Events = require('./events');
66
const Fields = require('./custom_fields');
77
const Forms = require('./forms');
8+
const Orders = require('./orders');
89
const Purchases = require('./purchases');
910
const Subscribers = require('./subscribers');
1011
const Subscriptions = require('./subscriptions');
@@ -138,8 +139,11 @@ Client.prototype.fetchForm = Forms.fetchForm;
138139

139140
// Purchases methods
140141
Client.prototype.createPurchase = Purchases.createPurchase;
141-
Client.prototype.listPurchases = Purchases.listPurchases;
142-
Client.prototype.fetchPurchase = Purchases.fetchPurchase;
142+
143+
// Order methods
144+
Client.prototype.createUpdateOrder = Orders.createUpdateOrder;
145+
Client.prototype.createUpdateBatchOrders = Orders.createUpdateBatchOrders;
146+
Client.prototype.createUpdateRefund = Orders.createUpdateRefund;
143147

144148
// Subscriber methods
145149
Client.prototype.listSubscribers = Subscribers.listSubscribers;

lib/orders.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
module.exports = {
2+
/**
3+
* Record an order for a subscriber
4+
* Docs: http://developer.drip.com/#create-or-update-an-order
5+
*
6+
* @param {object} payload - An object with order details
7+
* @param {callback} callback - An optional callback
8+
* @returns {promise}
9+
*/
10+
createUpdateOrder(payload, callback) {
11+
return this.post(`${this.accountId}/orders`, { payload }, callback);
12+
},
13+
/**
14+
* Record a batch of orders
15+
* Docs: http://developer.drip.com/#create-or-update-a-batch-of-orders
16+
*
17+
* @param {object} payload - An object of an array of multiple orders
18+
* @param {callback} callback - An optional callback
19+
* @returns {promise}
20+
*/
21+
createUpdateBatchOrders(payload, callback) {
22+
return this.post(`${this.accountId}/orders/batches`, { payload }, callback);
23+
},
24+
/**
25+
* Record a refund for an order
26+
* Docs: http://developer.drip.com/#create-or-update-a-refund
27+
*
28+
* @param {object} payload - Required. An object with refund details
29+
* @param {callback} callback - An optional callback
30+
* @returns {promise}
31+
*/
32+
createUpdateRefund(payload, callback) {
33+
return this.post(`${this.accountId}/refunds`, { payload }, callback);
34+
}
35+
};

lib/purchases.js

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,18 @@
1-
const helpers = require('./helpers');
2-
31
module.exports = {
42
/**
53
* Record purchases for a subscriber
64
*
5+
* @deprecated Deprecated since version 2.0.0. Will be deleted in version 3.0.0.
6+
* The beta Purchase endpoint has been deprecated and this method now sends requests
7+
* to the Order creation endpoint. Please use `createUpdateOrder` instead
8+
*
79
* @param {string} idOrEmail - The subscriber's email or id
810
* @param {object} payload - An object with purchase details
911
* @param {callback} callback - An optional callback
1012
* @returns {promise}
1113
*/
1214
createPurchase(idOrEmail, payload, callback) {
13-
const encodedIdOrEmail = helpers.escapeString(idOrEmail);
14-
return this.post(`${this.accountId}/subscribers/${encodedIdOrEmail}/purchases`, { payload }, callback);
15-
},
16-
/**
17-
* List purchases for a subscriber
18-
*
19-
* @param {string} idOrEmail - The subscriber's email or id
20-
* @param {object} options - An object with `page` properties
21-
* @param {callback} callback - An optional callback
22-
* @returns {promise}
23-
*/
24-
listPurchases(idOrEmail, options = {}, callback) {
25-
const encodedIdOrEmail = helpers.escapeString(idOrEmail);
26-
return this.get(`${this.accountId}/subscribers/${encodedIdOrEmail}/purchases`, { qs: options }, callback);
27-
},
28-
/**
29-
* Fetch a purchase record
30-
*
31-
* @param {string} idOrEmail - The subscriber's email or id
32-
* @param {number} purchaseId - Required. A purchase id
33-
* @param {callback} callback - An optional callback
34-
* @returns {promise}
35-
*/
36-
fetchPurchase(idOrEmail, purchaseId, callback) {
37-
const encodedIdOrEmail = helpers.escapeString(idOrEmail);
38-
return this.get(`${this.accountId}/subscribers/${encodedIdOrEmail}/purchases/${purchaseId}`, {}, callback);
15+
const options = Object.assign(payload, { email: idOrEmail });
16+
return this.post(`${this.accountId}/orders`, { options }, callback);
3917
}
4018
};

lib/version.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
module.exports = '0.2.1';
1+
module.exports = '2.0.0';

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)