Skip to content

Commit

Permalink
feat: added tax_inclusive parameter to Order objects and Subscripti…
Browse files Browse the repository at this point in the history
…on invoice objects (#58)

* feat(orders): add setup_fee, setup_fee_usd, tax_inclusive and setup_fee_formatted

* feat(subscriptionInvoices): add tax_inclusive

* docs: changeset added
  • Loading branch information
keyding authored Feb 16, 2024
1 parent 1a58f7a commit 5bc530a
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 40 deletions.
5 changes: 5 additions & 0 deletions .changeset/real-steaks-drop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@lemonsqueezy/lemonsqueezy.js": minor
---

Added `tax_inclusive` parameter to Order objects and Subscription invoice objects
16 changes: 16 additions & 0 deletions src/orders/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ type Attributes = {
* A positive integer in cents representing the subtotal of the order in the order currency.
*/
subtotal: number;
/**
* A positive integer in cents representing the setup fee of the order in the order currency.
*/
setup_fee: number;
/**
* A positive integer in cents representing the total discount value applied to the order in the order currency.
*/
Expand All @@ -116,6 +120,10 @@ type Attributes = {
* A positive integer in cents representing the subtotal of the order in USD.
*/
subtotal_usd: number;
/**
* A positive integer in cents representing the setup fee of the order in USD.
*/
setup_fee_usd: number;
/**
* A positive integer in cents representing the total discount value applied to the order in USD.
*/
Expand All @@ -136,6 +144,10 @@ type Attributes = {
* If tax is applied to the order, this will be the rate of tax as a decimal percentage.
*/
tax_rate: string;
/**
* A boolean indicating if the order was created with tax inclusive or exclusive pricing.
*/
tax_inclusive: boolean;
/**
* The status of the order. One of
*
Expand All @@ -161,6 +173,10 @@ type Attributes = {
* A human-readable string representing the subtotal of the order in the order currency (e.g. `$9.99`).
*/
subtotal_formatted: string;
/**
* A human-readable string representing the setup fee of the order in the order currency (e.g. $9.99).
*/
setup_fee_formatted: string;
/**
* A human-readable string representing the total discount value applied to the order in the order currency (e.g. `$9.99`).
*/
Expand Down
4 changes: 4 additions & 0 deletions src/subscriptionInvoices/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ type Attributes = {
* A positive integer in cents representing the tax applied to the invoice in the invoice currency.
*/
tax: number;
/**
* A boolean indicating if the order was created with tax inclusive or exclusive pricing.
*/
tax_inclusive: boolean;
/**
* A positive integer in cents representing the total cost of the invoice in the invoice currency.
*/
Expand Down
128 changes: 88 additions & 40 deletions test/orders/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ describe("Retrieve an order", () => {
expect(attributes).toBeDefined();
expect(relationships).toBeDefined();

// attributes
const {
store_id,
customer_id,
Expand All @@ -249,63 +250,79 @@ describe("Retrieve an order", () => {
user_email,
currency,
currency_rate,
subtotal,
discount_total,
tax,
subtotal_usd,
tax_usd,
total_usd,
tax_name,
tax_rate,
tax_inclusive,
status,
status_formatted,
refunded,
refunded_at,
subtotal,
discount_total,
tax,
setup_fee,
total,
subtotal_usd,
discount_total_usd,
tax_usd,
setup_fee_usd,
total_usd,
subtotal_formatted,
discount_total_formatted,
tax_formatted,
setup_fee_formatted,
total_formatted,
first_order_item,
urls,
created_at,
updated_at,
test_mode,
} = attributes;
expect(store_id).toEqual(Number(storeId));
expect(urls.receipt).toBeDefined();
for (const item of [
const items = [
store_id,
customer_id,
identifier,
order_number,
user_name,
user_email,
currency,
currency_rate,
subtotal,
discount_total,
tax,
subtotal_usd,
tax_usd,
total_usd,
tax_name,
tax_rate,
tax_inclusive,
status,
status_formatted,
refunded,
refunded_at,
subtotal,
discount_total,
tax,
setup_fee,
total,
subtotal_usd,
discount_total_usd,
tax_usd,
setup_fee_usd,
total_usd,
subtotal_formatted,
discount_total_formatted,
tax_formatted,
setup_fee_formatted,
total_formatted,
first_order_item,
urls,
created_at,
updated_at,
test_mode,
]) {
];
expect(store_id).toEqual(Number(storeId));
expect(urls.receipt).toBeDefined();
expect(Object.keys(attributes).length).toEqual(items.length);
for (const item of items) {
expect(item).toBeDefined();
}

// first_order_item
const {
id: firstOrderItemId,
order_id,
Expand All @@ -320,7 +337,7 @@ describe("Retrieve an order", () => {
updated_at: updatedAt,
test_mode: testMode,
} = first_order_item;
for (const item of [
const firstOrderItems = [
firstOrderItemId,
order_id,
product_id,
Expand All @@ -333,10 +350,15 @@ describe("Retrieve an order", () => {
createdAt,
updatedAt,
testMode,
]) {
];
expect(Object.keys(first_order_item).length).toEqual(
firstOrderItems.length
);
for (const item of firstOrderItems) {
expect(item).toBeDefined();
}

// relationships
const {
store,
customer,
Expand All @@ -345,14 +367,16 @@ describe("Retrieve an order", () => {
"license-keys": licenseKeys,
"discount-redemptions": discountRedemptions,
} = relationships;
for (const item of [
const relationshipItems = [
store,
customer,
orderItems,
subscriptions,
licenseKeys,
discountRedemptions,
]) {
];
expect(Object.keys(relationships).length).toEqual(relationshipItems.length);
for (const item of relationshipItems) {
expect(item.links).toBeDefined();
}
});
Expand All @@ -379,6 +403,7 @@ describe("Retrieve an order", () => {
expect(attributes).toBeDefined();
expect(relationships).toBeDefined();

// attributes
const {
store_id,
customer_id,
Expand All @@ -388,63 +413,79 @@ describe("Retrieve an order", () => {
user_email,
currency,
currency_rate,
subtotal,
discount_total,
tax,
subtotal_usd,
tax_usd,
total_usd,
tax_name,
tax_rate,
tax_inclusive,
status,
status_formatted,
refunded,
refunded_at,
subtotal,
discount_total,
tax,
setup_fee,
total,
subtotal_usd,
discount_total_usd,
tax_usd,
setup_fee_usd,
total_usd,
subtotal_formatted,
discount_total_formatted,
tax_formatted,
setup_fee_formatted,
total_formatted,
first_order_item,
urls,
created_at,
updated_at,
test_mode,
} = attributes;
expect(store_id).toEqual(Number(storeId));
expect(urls.receipt).toBeDefined();
for (const item of [
const items = [
store_id,
customer_id,
identifier,
order_number,
user_name,
user_email,
currency,
currency_rate,
subtotal,
discount_total,
tax,
subtotal_usd,
tax_usd,
total_usd,
tax_name,
tax_rate,
tax_inclusive,
status,
status_formatted,
refunded,
refunded_at,
subtotal,
discount_total,
tax,
setup_fee,
total,
subtotal_usd,
discount_total_usd,
tax_usd,
setup_fee_usd,
total_usd,
subtotal_formatted,
discount_total_formatted,
tax_formatted,
setup_fee_formatted,
total_formatted,
first_order_item,
urls,
created_at,
updated_at,
test_mode,
]) {
];
expect(store_id).toEqual(Number(storeId));
expect(urls.receipt).toBeDefined();
expect(Object.keys(attributes).length).toEqual(items.length);
for (const item of items) {
expect(item).toBeDefined();
}

// first_order_item
const {
id: firstOrderItemId,
order_id,
Expand All @@ -459,7 +500,7 @@ describe("Retrieve an order", () => {
updated_at: updatedAt,
test_mode: testMode,
} = first_order_item;
for (const item of [
const firstOrderItems = [
firstOrderItemId,
order_id,
product_id,
Expand All @@ -472,10 +513,15 @@ describe("Retrieve an order", () => {
createdAt,
updatedAt,
testMode,
]) {
];
expect(Object.keys(first_order_item).length).toEqual(
firstOrderItems.length
);
for (const item of firstOrderItems) {
expect(item).toBeDefined();
}

// relationships
const {
store,
customer,
Expand All @@ -484,14 +530,16 @@ describe("Retrieve an order", () => {
"license-keys": licenseKeys,
"discount-redemptions": discountRedemptions,
} = relationships;
for (const item of [
const relationshipItems = [
store,
customer,
orderItems,
subscriptions,
licenseKeys,
discountRedemptions,
]) {
];
expect(Object.keys(relationships).length).toEqual(relationshipItems.length);
for (const item of relationshipItems) {
expect(item.links).toBeDefined();
}
});
Expand Down
4 changes: 4 additions & 0 deletions test/subscriptionInvoices/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ describe("Retrieve a subscription invoice", () => {
subtotal,
discount_total,
tax,
tax_inclusive,
total,
subtotal_usd,
discount_total_usd,
Expand Down Expand Up @@ -256,6 +257,7 @@ describe("Retrieve a subscription invoice", () => {
subtotal,
discount_total,
tax,
tax_inclusive,
total,
subtotal_usd,
discount_total_usd,
Expand Down Expand Up @@ -329,6 +331,7 @@ describe("Retrieve a subscription invoice", () => {
subtotal,
discount_total,
tax,
tax_inclusive,
total,
subtotal_usd,
discount_total_usd,
Expand Down Expand Up @@ -361,6 +364,7 @@ describe("Retrieve a subscription invoice", () => {
subtotal,
discount_total,
tax,
tax_inclusive,
total,
subtotal_usd,
discount_total_usd,
Expand Down

0 comments on commit 5bc530a

Please sign in to comment.