Skip to content

Commit 49e127e

Browse files
authored
order price creation (#16)
1 parent 0a19f31 commit 49e127e

File tree

5 files changed

+63
-22
lines changed

5 files changed

+63
-22
lines changed

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [1.2.4] - 2020-10-14
11+
12+
### Added
13+
14+
- `total_price_cents_usd` field to `orders`
15+
- allows users to create an order by total price
16+
17+
### Changed
18+
19+
- order creation requires either `mass_g` or `total_price_cents_usd`, but not both
20+
1021
## [1.2.3] - 2020-09-28
1122

1223
### Added

README.md

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,32 +45,43 @@ var patch = require('@patch-technology/patch').default('key_test_1234');
4545

4646
### Orders
4747

48-
In Patch, orders represent a purchase of carbon offsets or negative emissions by mass. Place orders directly if you know the amount of carbon dioxide you would like to sequester. If you do not know how much to purchase, use an estimate.
48+
In Patch, orders represent a purchase of carbon offsets or negative emissions by mass.
49+
Place orders directly if you know the amount of carbon dioxide you would like to sequester.
50+
If you do not know how much to purchase, use an estimate.
51+
You can also create an order with a maximum desired price, and we'll allocate enough mass to
52+
fulfill the order for you.
4953

5054
[API Reference](https://docs.usepatch.com/#/?id=orders)
5155

5256
#### Examples
5357

5458
```javascript
55-
// Create an order
56-
const mass = 1000000 // Pass in the mass in grams (i.e. 1 metric tonne)
57-
patch.orders.createOrder({ mass_g: mass })
59+
// Create an order - you can create an order
60+
// providing either mass_g or total_price_cents_usd, but not both
5861

59-
# Retrieve an order
60-
orderId = 'ord_test_1234' // Pass in the order's id
61-
patch.orders.retrieveOrder(orderId)
62+
// Create order with mass
63+
const mass = 1000000; // Pass in the mass in grams (i.e. 1 metric tonne)
64+
patch.orders.createOrder({ mass_g: mass });
65+
66+
// Create an order with a maximum total price
67+
const totalPriceCentsUSD = 500; // Pass in the total price in cents (i.e. 5 dollars)
68+
patch.orders.createOrder({ total_price_cents_usd: totalPriceCentsUSD });
69+
70+
// Retrieve an order
71+
orderId = 'ord_test_1234'; // Pass in the order's id
72+
patch.orders.retrieveOrder(orderId);
6273

6374
// Place an order
64-
const orderId = 'ord_test_1234' // Pass in the order's id
65-
patch.orders.placeOrder(orderId)
75+
const orderId = 'ord_test_1234'; // Pass in the order's id
76+
patch.orders.placeOrder(orderId);
6677

6778
// Cancel an order
68-
const orderId = 'ord_test_1234' // Pass in the order's id
69-
patch.orders.cancelOrder(orderId)
79+
const orderId = 'ord_test_1234'; // Pass in the order's id
80+
patch.orders.cancelOrder(orderId);
7081

7182
// Retrieve a list of orders
72-
const page = 1 // Pass in which page of orders you'd like
73-
patch.orders.retrieveOrders({ page })
83+
const page = 1; // Pass in which page of orders you'd like
84+
patch.orders.retrieveOrders({ page });
7485
```
7586

7687
### Estimates
@@ -176,7 +187,7 @@ This will create a `node_modules` directory in your test repository which will s
176187
```
177188
$ node
178189
> const Patch = require('@patch-technology/patch')
179-
> Patch.default('<PATCH_API_KEY>').projects.retrieveProjects().then((response) => console.log(response))
190+
> Patch.default(process.env.SANDBOX_API_KEY).projects.retrieveProjects().then((response) => console.log(response))
180191
```
181192

182193
### Run the specs

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@patch-technology/patch",
3-
"version": "1.2.3",
3+
"version": "1.2.4",
44
"description": "Javascript wrapper for the Patch API",
55
"license": "MIT",
66
"repository": {

src/model/CreateOrderRequest.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,11 @@
88
import ApiClient from '../ApiClient';
99

1010
class CreateOrderRequest {
11-
constructor(massG) {
12-
CreateOrderRequest.initialize(this, massG);
11+
constructor() {
12+
CreateOrderRequest.initialize(this);
1313
}
1414

15-
static initialize(obj, massG) {
16-
obj['mass_g'] = massG;
17-
}
15+
static initialize(obj) {}
1816

1917
static constructFromObject(data, obj) {
2018
if (data) {
@@ -24,6 +22,13 @@ class CreateOrderRequest {
2422
obj['mass_g'] = ApiClient.convertToType(data['mass_g'], 'Number');
2523
}
2624

25+
if (data.hasOwnProperty('total_price_cents_usd')) {
26+
obj['total_price_cents_usd'] = ApiClient.convertToType(
27+
data['total_price_cents_usd'],
28+
'Number'
29+
);
30+
}
31+
2732
if (data.hasOwnProperty('project_id')) {
2833
obj['project_id'] = ApiClient.convertToType(
2934
data['project_id'],
@@ -41,6 +46,8 @@ class CreateOrderRequest {
4146

4247
CreateOrderRequest.prototype['mass_g'] = undefined;
4348

49+
CreateOrderRequest.prototype['total_price_cents_usd'] = undefined;
50+
4451
CreateOrderRequest.prototype['project_id'] = undefined;
4552

4653
CreateOrderRequest.prototype['metadata'] = undefined;

test/integration/orders.test.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,33 @@
11
import { expect } from 'chai';
22
import Patch from '../../dist/index';
33
const patch = Patch(process.env.SANDBOX_API_KEY);
4+
const biomass_test_project_id = 'pro_test_c3a9feba769fc7a8806377266ca9ff6a';
45

56
describe('Orders Integration', function () {
67
it('supports create, place, cancel, retrieve and list', async function () {
78
const createOrderResponse = await patch.orders.createOrder({ mass_g: 100 });
89
const orderId = createOrderResponse.data.id;
910

10-
const retreiveOrderResponse = await patch.orders.retrieveOrder(orderId);
11-
expect(retreiveOrderResponse.data.id).to.equal(orderId);
11+
const retrieveOrderResponse = await patch.orders.retrieveOrder(orderId);
12+
expect(retrieveOrderResponse.data.id).to.equal(orderId);
1213

1314
const retrieveOrdersResponse = await patch.orders.retrieveOrders({
1415
page: 1
1516
});
1617
expect(retrieveOrdersResponse.data.length).to.be.above(0);
1718
});
1819

20+
it('supports create orders with a total price', async function () {
21+
const createOrderResponse = await patch.orders.createOrder({
22+
total_price_cents_usd: 500,
23+
project_id: biomass_test_project_id
24+
});
25+
26+
expect(createOrderResponse.data.price_cents_usd).to.equal('500.0');
27+
expect(createOrderResponse.data.patch_fee_cents_usd).to.equal('0.0');
28+
expect(createOrderResponse.data.mass_g).to.equal(5000000);
29+
});
30+
1931
it('supports placing orders in a `draft` state', async function () {
2032
const estimateResponse = await patch.estimates.createMassEstimate({
2133
mass_g: 100

0 commit comments

Comments
 (0)