Skip to content

Commit f9ff401

Browse files
authored
Add issued_to field support to Orders APIs (#68)
* Add issued_to field support to Orders APIs * Update to camelCase naming
1 parent be9db2e commit f9ff401

13 files changed

+3068
-10
lines changed

Diff for: CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [1.23.0] - 2022-06-03
9+
10+
### Added
11+
12+
- Adds support for the `issuedTo` parameter on `orders`, to add support for creating and placing orders on behalf of another party.
13+
814
## [1.22.0] - 2022-05-16
915

1016
### Added

Diff for: README.md

+11
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ const totalPrice = 500; // Pass in the total price in smallest currency unit (ie
7777
const currency = 'USD';
7878
patch.orders.createOrder({ total_price: totalPrice, currency: currency });
7979

80+
// Create order with the issuedTo field (optional)
81+
const amount = 1_000_000; // Pass in the amount in unit specified
82+
const unit = 'g';
83+
const issuedTo = { email: '[email protected]', name: 'Olivia Jones' };
84+
patch.orders.createOrder({ amount: amount, unit: unit, issuedTo: issuedTo });
85+
8086
// Retrieve an order
8187
orderId = 'ord_test_1234'; // Pass in the order's id
8288
patch.orders.retrieveOrder(orderId);
@@ -85,6 +91,11 @@ patch.orders.retrieveOrder(orderId);
8591
const orderId = 'ord_test_1234'; // Pass in the order's id
8692
patch.orders.placeOrder(orderId);
8793

94+
// Place an order with the issuedTo field (optional)
95+
const orderId = 'ord_test_1234'; // Pass in the order's id
96+
const issuedTo = { email: '[email protected]', name: 'Olivia Jones' };
97+
patch.orders.placeOrder(orderId, { issuedTo: issuedTo });
98+
8899
// Cancel an order
89100
const orderId = 'ord_test_1234'; // Pass in the order's id
90101
patch.orders.cancelOrder(orderId);

Diff for: package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@patch-technology/patch",
3-
"version": "1.22.0",
3+
"version": "1.23.0",
44
"description": "Node.js wrapper for the Patch API",
55
"license": "MIT",
66
"repository": {

Diff for: src/ApiClient.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class ApiClient {
1616
};
1717

1818
this.defaultHeaders = {
19-
'User-Agent': 'patch-node/1.22.0'
19+
'User-Agent': 'patch-node/1.23.0'
2020
};
2121

2222
/**

Diff for: src/api/OrdersApi.js

+12-5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import CreateOrderRequest from '../model/CreateOrderRequest';
1010
import ErrorResponse from '../model/ErrorResponse';
1111
import OrderListResponse from '../model/OrderListResponse';
1212
import OrderResponse from '../model/OrderResponse';
13+
import PlaceOrderRequest from '../model/PlaceOrderRequest';
1314

1415
export default class OrdersApi {
1516
constructor(apiClient) {
@@ -100,8 +101,14 @@ export default class OrdersApi {
100101
return this.createOrderWithHttpInfo(createOrderRequest);
101102
}
102103

103-
placeOrderWithHttpInfo(id) {
104-
let postBody = null;
104+
placeOrderWithHttpInfo(id, opts) {
105+
opts = opts || {};
106+
107+
const _placeOrderRequest = PlaceOrderRequest.constructFromObject(
108+
opts,
109+
new CreateOrderRequest()
110+
);
111+
let postBody = _placeOrderRequest;
105112

106113
// verify the required parameter 'id' is set
107114
if (id === undefined || id === null) {
@@ -118,7 +125,7 @@ export default class OrdersApi {
118125
let formParams = {};
119126

120127
let authNames = ['bearer_auth'];
121-
let contentTypes = [];
128+
let contentTypes = ['application/json'];
122129
let accepts = ['application/json'];
123130
let returnType = OrderResponse;
124131

@@ -137,8 +144,8 @@ export default class OrdersApi {
137144
);
138145
}
139146

140-
placeOrder(id) {
141-
return this.placeOrderWithHttpInfo(id);
147+
placeOrder(id, opts) {
148+
return this.placeOrderWithHttpInfo(id, opts);
142149
}
143150

144151
retrieveOrderWithHttpInfo(id) {

Diff for: src/model/CreateOrderRequest.js

+9
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77

88
import ApiClient from '../ApiClient';
9+
import V1OrdersIssuedTo from './V1OrdersIssuedTo';
910

1011
class CreateOrderRequest {
1112
constructor() {
@@ -69,6 +70,12 @@ class CreateOrderRequest {
6970
if (data.hasOwnProperty('unit')) {
7071
obj['unit'] = ApiClient.convertToType(data['unit'], 'String');
7172
}
73+
74+
if (data.hasOwnProperty('issuedTo')) {
75+
obj['issued_to'] = V1OrdersIssuedTo.constructFromObject(
76+
data['issuedTo']
77+
);
78+
}
7279
}
7380
return obj;
7481
}
@@ -94,4 +101,6 @@ CreateOrderRequest.prototype['amount'] = undefined;
94101

95102
CreateOrderRequest.prototype['unit'] = undefined;
96103

104+
CreateOrderRequest.prototype['issued_to'] = undefined;
105+
97106
export default CreateOrderRequest;

Diff for: src/model/IssuedTo.js

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* Patch API V1
3+
* The core API used to integrate with Patch's service
4+
*
5+
* Contact: [email protected]
6+
*/
7+
8+
import ApiClient from '../ApiClient';
9+
10+
class IssuedTo {
11+
constructor() {
12+
IssuedTo.initialize(this);
13+
}
14+
15+
static initialize(obj) {}
16+
17+
static constructFromObject(data, obj) {
18+
if (data) {
19+
obj = obj || new IssuedTo();
20+
21+
if (data.hasOwnProperty('name')) {
22+
obj['name'] = ApiClient.convertToType(data['name'], 'String');
23+
}
24+
25+
if (data.hasOwnProperty('email')) {
26+
obj['email'] = ApiClient.convertToType(data['email'], 'String');
27+
}
28+
}
29+
return obj;
30+
}
31+
}
32+
33+
IssuedTo.prototype['name'] = undefined;
34+
35+
IssuedTo.prototype['email'] = undefined;
36+
37+
export default IssuedTo;

Diff for: src/model/Order.js

+7
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import ApiClient from '../ApiClient';
99
import Allocation from './Allocation';
10+
import IssuedTo from './IssuedTo';
1011
import OrderInventory from './OrderInventory';
1112

1213
class Order {
@@ -164,6 +165,10 @@ class Order {
164165
OrderInventory
165166
]);
166167
}
168+
169+
if (data.hasOwnProperty('issued_to')) {
170+
obj['issued_to'] = IssuedTo.constructFromObject(data['issued_to']);
171+
}
167172
}
168173
return obj;
169174
}
@@ -203,4 +208,6 @@ Order.prototype['metadata'] = undefined;
203208

204209
Order.prototype['inventory'] = undefined;
205210

211+
Order.prototype['issued_to'] = undefined;
212+
206213
export default Order;

Diff for: src/model/PlaceOrderRequest.js

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* Patch API V1
3+
* The core API used to integrate with Patch's service
4+
*
5+
* Contact: [email protected]
6+
*/
7+
8+
import ApiClient from '../ApiClient';
9+
import V1OrdersIssuedTo from './V1OrdersIssuedTo';
10+
11+
class PlaceOrderRequest {
12+
constructor() {
13+
PlaceOrderRequest.initialize(this);
14+
}
15+
16+
static initialize(obj) {}
17+
18+
static constructFromObject(data, obj) {
19+
if (data) {
20+
obj = obj || new PlaceOrderRequest();
21+
22+
if (data.hasOwnProperty('issuedTo')) {
23+
obj['issued_to'] = V1OrdersIssuedTo.constructFromObject(
24+
data['issuedTo']
25+
);
26+
}
27+
}
28+
return obj;
29+
}
30+
}
31+
32+
PlaceOrderRequest.prototype['issued_to'] = undefined;
33+
34+
export default PlaceOrderRequest;

Diff for: src/model/V1OrdersIssuedTo.js

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* Patch API V1
3+
* The core API used to integrate with Patch's service
4+
*
5+
* Contact: [email protected]
6+
*/
7+
8+
import ApiClient from '../ApiClient';
9+
10+
class V1OrdersIssuedTo {
11+
constructor() {
12+
V1OrdersIssuedTo.initialize(this);
13+
}
14+
15+
static initialize(obj) {}
16+
17+
static constructFromObject(data, obj) {
18+
if (data) {
19+
obj = obj || new V1OrdersIssuedTo();
20+
21+
if (data.hasOwnProperty('email')) {
22+
obj['email'] = ApiClient.convertToType(data['email'], 'String');
23+
}
24+
25+
if (data.hasOwnProperty('name')) {
26+
obj['name'] = ApiClient.convertToType(data['name'], 'String');
27+
}
28+
}
29+
return obj;
30+
}
31+
}
32+
33+
V1OrdersIssuedTo.prototype['email'] = undefined;
34+
35+
V1OrdersIssuedTo.prototype['name'] = undefined;
36+
37+
export default V1OrdersIssuedTo;

Diff for: test/integration/orders.test.js

+33-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ describe('Orders Integration', function () {
1717
expect(retrieveOrdersResponse.data.length).to.be.above(0);
1818
});
1919

20-
it('supports create orders with a total price', async function () {
20+
it('supports creating an order with a project_id', async function () {
2121
const { data } = await patch.orders.createOrder({
2222
total_price_cents_usd: 100,
2323
project_id: biomass_test_project_id
@@ -26,6 +26,18 @@ describe('Orders Integration', function () {
2626
expect(data.price_cents_usd + data.patch_fee_cents_usd).to.eq(100);
2727
});
2828

29+
it('supports creating an order with issuedTo', async function () {
30+
const issuedTo = { email: '[email protected]', name: 'Bob Dylan' };
31+
const { data } = await patch.orders.createOrder({
32+
total_price_cents_usd: 100,
33+
issuedTo: issuedTo
34+
});
35+
36+
expect(data.price_cents_usd + data.patch_fee_cents_usd).to.eq(100);
37+
expect(data.issued_to.email).to.equal(issuedTo.email);
38+
expect(data.issued_to.name).to.equal(issuedTo.name);
39+
});
40+
2941
it('supports placing orders in a `draft` state', async function () {
3042
const estimateResponse = await patch.orders.createOrder({
3143
mass_g: 100,
@@ -41,6 +53,26 @@ describe('Orders Integration', function () {
4153
expect(placeOrderResponse.data.mass_g).to.equal(100);
4254
});
4355

56+
it('supports placing orders in a `draft` state with issuedTo', async function () {
57+
const estimateResponse = await patch.estimates.createMassEstimate({
58+
mass_g: 100,
59+
create_order: true
60+
});
61+
const orderId = estimateResponse.data.order.id;
62+
expect(estimateResponse.data.order.state).to.equal('draft');
63+
64+
const issuedTo = { email: '[email protected]', name: 'Bob Dylan' };
65+
66+
const placeOrderResponse = await patch.orders.placeOrder(orderId, {
67+
issuedTo: issuedTo
68+
});
69+
expect(placeOrderResponse.data.created_at).to.be.an.instanceOf(Date);
70+
expect(placeOrderResponse.data.production).to.equal(false);
71+
expect(placeOrderResponse.data.mass_g).to.equal(100);
72+
expect(placeOrderResponse.data.issued_to.email).to.equal(issuedTo.email);
73+
expect(placeOrderResponse.data.issued_to.name).to.equal(issuedTo.name);
74+
});
75+
4476
it('supports placing orders in a `draft` state using an estimate', async function () {
4577
const estimateResponse = await patch.estimates.createMassEstimate({
4678
mass_g: 100,

0 commit comments

Comments
 (0)