merchi_sdk_js 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/address.js +109 -0
- package/dist/assignment.js +175 -0
- package/dist/automatic_payment_relationship.js +72 -0
- package/dist/backup.js +32 -0
- package/dist/bank.js +25 -0
- package/dist/cart.js +133 -0
- package/dist/cart_item.js +71 -0
- package/dist/cart_shipment_group.js +23 -0
- package/dist/cart_shipment_quote.js +26 -0
- package/dist/category.js +68 -0
- package/dist/company.js +248 -0
- package/dist/company_invitation.js +70 -0
- package/dist/component.js +107 -0
- package/dist/component_tag.js +60 -0
- package/dist/component_version.js +21 -0
- package/dist/country_tax.js +93 -0
- package/dist/dictionary.js +130 -0
- package/dist/discount.js +22 -0
- package/dist/discount_group.js +18 -0
- package/dist/domain.js +245 -0
- package/dist/domain_invitation.js +17 -0
- package/dist/domain_tag.js +87 -0
- package/dist/domain_types.js +22 -0
- package/dist/draft.js +97 -0
- package/dist/draft_comment.js +45 -0
- package/dist/draft_template.js +39 -0
- package/dist/email_address.js +34 -0
- package/dist/email_counter.js +47 -0
- package/dist/enrolled_domain.js +88 -0
- package/dist/exchange_rate.js +66 -0
- package/dist/field_types.js +19 -0
- package/dist/helpers.js +86 -0
- package/dist/internal_tag.js +98 -0
- package/dist/inventory.js +100 -0
- package/dist/inventory_unit_variation.js +19 -0
- package/dist/invoice.js +225 -0
- package/dist/invoice_types.js +11 -0
- package/dist/item.js +25 -0
- package/dist/job.js +536 -0
- package/dist/job_comment.js +45 -0
- package/dist/job_status.js +47 -0
- package/dist/matching_inventory.js +21 -0
- package/dist/md5.js +149 -0
- package/dist/menu.js +37 -0
- package/dist/menu_item.js +24 -0
- package/dist/merchi.js +1004 -0
- package/dist/merchi_file.js +165 -0
- package/dist/model.js +753 -0
- package/dist/notification.js +151 -0
- package/dist/notification_types.js +199 -0
- package/dist/output.cjs.js +31317 -0
- package/dist/output.esm.js +31312 -0
- package/dist/page.js +41 -0
- package/dist/payment.js +32 -0
- package/dist/payment_device.js +21 -0
- package/dist/payment_types.js +20 -0
- package/dist/phone_number.js +37 -0
- package/dist/product.js +288 -0
- package/dist/product_types.js +32 -0
- package/dist/production_comment.js +44 -0
- package/dist/quote.js +91 -0
- package/dist/quote_item.js +59 -0
- package/dist/roles.js +29 -0
- package/dist/seo_domain_page.js +42 -0
- package/dist/session.js +103 -0
- package/dist/set.js +29 -0
- package/dist/shipment.js +181 -0
- package/dist/shipment_item.js +17 -0
- package/dist/shipment_item_fulfillment.js +17 -0
- package/dist/shipment_method.js +81 -0
- package/dist/shipment_method_variation.js +38 -0
- package/dist/subscription_plan.js +75 -0
- package/dist/supply_domain.js +65 -0
- package/dist/system_role.js +12 -0
- package/dist/theme.js +180 -0
- package/dist/theme_css_setting.js +61 -0
- package/dist/theme_status.js +11 -0
- package/dist/user.js +409 -0
- package/dist/user_company.js +19 -0
- package/dist/user_types.js +23 -0
- package/dist/uuid.js +12 -0
- package/dist/variation.js +233 -0
- package/dist/variation_field.js +233 -0
- package/dist/variation_fields_option.js +41 -0
- package/dist/variation_option.js +62 -0
- package/dist/variations_group.js +43 -0
- package/dist/white_label_accessibilities.js +11 -0
- package/package.json +30 -0
- package/src/address.js +107 -0
- package/src/assignment.js +165 -0
- package/src/automatic_payment_relationship.js +65 -0
- package/src/backup.js +29 -0
- package/src/bank.js +21 -0
- package/src/cart.js +131 -0
- package/src/cart_item.js +71 -0
- package/src/cart_shipment_group.js +20 -0
- package/src/cart_shipment_quote.js +23 -0
- package/src/category.js +62 -0
- package/src/company.js +267 -0
- package/src/company_invitation.js +63 -0
- package/src/component.js +100 -0
- package/src/component_tag.js +53 -0
- package/src/component_version.js +17 -0
- package/src/country_tax.js +89 -0
- package/src/dictionary.js +135 -0
- package/src/discount.js +19 -0
- package/src/discount_group.js +15 -0
- package/src/domain.js +254 -0
- package/src/domain_invitation.js +13 -0
- package/src/domain_tag.js +79 -0
- package/src/domain_types.js +18 -0
- package/src/draft.js +92 -0
- package/src/draft_comment.js +41 -0
- package/src/draft_template.js +35 -0
- package/src/email_address.js +27 -0
- package/src/email_counter.js +42 -0
- package/src/enrolled_domain.js +79 -0
- package/src/exchange_rate.js +61 -0
- package/src/field_types.js +15 -0
- package/src/helpers.js +81 -0
- package/src/internal_tag.js +90 -0
- package/src/inventory.js +99 -0
- package/src/inventory_unit_variation.js +18 -0
- package/src/invoice.js +224 -0
- package/src/invoice_types.js +7 -0
- package/src/item.js +22 -0
- package/src/job.js +616 -0
- package/src/job_comment.js +41 -0
- package/src/job_status.js +51 -0
- package/src/matching_inventory.js +17 -0
- package/src/md5.js +162 -0
- package/src/menu.js +32 -0
- package/src/menu_item.js +22 -0
- package/src/merchi.js +1074 -0
- package/src/merchi_file.js +163 -0
- package/src/model.js +820 -0
- package/src/notification.js +153 -0
- package/src/notification_types.js +246 -0
- package/src/page.js +38 -0
- package/src/payment.js +32 -0
- package/src/payment_device.js +17 -0
- package/src/payment_types.js +18 -0
- package/src/phone_number.js +30 -0
- package/src/product.js +309 -0
- package/src/product_types.js +28 -0
- package/src/production_comment.js +40 -0
- package/src/quote.js +89 -0
- package/src/quote_item.js +51 -0
- package/src/roles.js +27 -0
- package/src/seo_domain_page.js +35 -0
- package/src/session.js +102 -0
- package/src/set.js +28 -0
- package/src/shipment.js +191 -0
- package/src/shipment_item.js +13 -0
- package/src/shipment_item_fulfillment.js +13 -0
- package/src/shipment_method.js +73 -0
- package/src/shipment_method_variation.js +34 -0
- package/src/subscription_plan.js +68 -0
- package/src/supply_domain.js +60 -0
- package/src/system_role.js +8 -0
- package/src/theme.js +188 -0
- package/src/theme_css_setting.js +54 -0
- package/src/theme_status.js +6 -0
- package/src/user.js +442 -0
- package/src/user_company.js +15 -0
- package/src/user_types.js +19 -0
- package/src/uuid.js +3 -0
- package/src/variation.js +257 -0
- package/src/variation_field.js +261 -0
- package/src/variation_fields_option.js +41 -0
- package/src/variation_option.js +59 -0
- package/src/variations_group.js +43 -0
- package/src/white_label_accessibilities.js +6 -0
package/src/invoice.js
ADDED
@@ -0,0 +1,224 @@
|
|
1
|
+
import moment from 'moment-timezone';
|
2
|
+
import { generateUUID } from './uuid.js';
|
3
|
+
import { addPropertyTo, create, serialise, enumerateFiles, getOne, getList,
|
4
|
+
fromJson, deleteOne, fromJsonList, patchOne, Request } from './model.js';
|
5
|
+
import { isUndefinedOrNull } from './helpers.js';
|
6
|
+
import { Address } from './address.js';
|
7
|
+
import { EmailAddress } from './email_address.js';
|
8
|
+
import { Domain } from './domain.js';
|
9
|
+
import { DomainTag } from './domain_tag.js';
|
10
|
+
import { Item } from './item.js';
|
11
|
+
import { Company } from './company.js';
|
12
|
+
import { PhoneNumber } from './phone_number.js';
|
13
|
+
import { User } from './user.js';
|
14
|
+
import { Shipment } from './shipment.js';
|
15
|
+
import { MerchiFile } from './merchi_file.js';
|
16
|
+
import { Quote } from './quote.js';
|
17
|
+
import { Payment } from './payment.js';
|
18
|
+
import { Job } from './job.js';
|
19
|
+
import { InternalTag } from './internal_tag.js';
|
20
|
+
|
21
|
+
export function Invoice() {
|
22
|
+
this.resource = '/invoices';
|
23
|
+
this.json = 'invoice';
|
24
|
+
this.temporaryId = generateUUID();
|
25
|
+
|
26
|
+
addPropertyTo(this, 'id');
|
27
|
+
addPropertyTo(this, 'note');
|
28
|
+
addPropertyTo(this, 'creationDate');
|
29
|
+
addPropertyTo(this, 'paymentDeadline');
|
30
|
+
addPropertyTo(this, 'sendSms');
|
31
|
+
addPropertyTo(this, 'sendEmail');
|
32
|
+
addPropertyTo(this, 'unpaid');
|
33
|
+
addPropertyTo(this, 'totalCost');
|
34
|
+
addPropertyTo(this, 'subtotalCost');
|
35
|
+
addPropertyTo(this, 'taxAmount');
|
36
|
+
addPropertyTo(this, 'invoiceToken');
|
37
|
+
addPropertyTo(this, 'canAutoPay');
|
38
|
+
addPropertyTo(this, 'responsibleManager', User);
|
39
|
+
addPropertyTo(this, 'creator', User);
|
40
|
+
addPropertyTo(this, 'client', User);
|
41
|
+
addPropertyTo(this, 'clientEmail', EmailAddress);
|
42
|
+
addPropertyTo(this, 'clientPhone', PhoneNumber);
|
43
|
+
addPropertyTo(this, 'clientCompany', Company);
|
44
|
+
addPropertyTo(this, 'clientCompanyEmail', EmailAddress);
|
45
|
+
addPropertyTo(this, 'clientCompanyPhone', PhoneNumber);
|
46
|
+
addPropertyTo(this, 'jobs', Job);
|
47
|
+
addPropertyTo(this, 'quotes', Quote);
|
48
|
+
addPropertyTo(this, 'items', Item);
|
49
|
+
addPropertyTo(this, 'shipping', Address);
|
50
|
+
addPropertyTo(this, 'domain', Domain);
|
51
|
+
addPropertyTo(this, 'pdf', MerchiFile);
|
52
|
+
addPropertyTo(this, 'receipt', MerchiFile);
|
53
|
+
addPropertyTo(this, 'payments', Payment);
|
54
|
+
addPropertyTo(this, 'currency');
|
55
|
+
addPropertyTo(this, 'acceptSquare');
|
56
|
+
addPropertyTo(this, 'acceptStripe');
|
57
|
+
addPropertyTo(this, 'acceptPaypal');
|
58
|
+
addPropertyTo(this, 'acceptUtrust');
|
59
|
+
addPropertyTo(this, 'acceptBankTransfer');
|
60
|
+
addPropertyTo(this, 'acceptPhonePayment');
|
61
|
+
addPropertyTo(this, 'tags', DomainTag);
|
62
|
+
addPropertyTo(this, 'reminderMessage');
|
63
|
+
addPropertyTo(this, 'reminded');
|
64
|
+
addPropertyTo(this, 'isRemindable');
|
65
|
+
addPropertyTo(this, 'forceReminders');
|
66
|
+
addPropertyTo(this, 'owedMoney');
|
67
|
+
addPropertyTo(this, 'paidMoney');
|
68
|
+
addPropertyTo(this, 'isCompletelyPaid');
|
69
|
+
addPropertyTo(this, 'shipments', Shipment);
|
70
|
+
addPropertyTo(this, 'shopifyOrderId');
|
71
|
+
addPropertyTo(this, 'internalTags', InternalTag);
|
72
|
+
|
73
|
+
this.create = function (success, error, embed, asDomain) {
|
74
|
+
var data = serialise(this),
|
75
|
+
self = this,
|
76
|
+
domain = self.domain() ? self.domain().id() : null,
|
77
|
+
domainId = isUndefinedOrNull(asDomain) ? domain : asDomain;
|
78
|
+
function handleResponse(result) {
|
79
|
+
success(fromJson(self, result[self.json]));
|
80
|
+
}
|
81
|
+
create({resource: this.resource,
|
82
|
+
parameters: data[0],
|
83
|
+
as_domain: domainId,
|
84
|
+
files: enumerateFiles(data[1]),
|
85
|
+
success: handleResponse,
|
86
|
+
error: error,
|
87
|
+
embed: embed});
|
88
|
+
};
|
89
|
+
|
90
|
+
this.patch = function (success, error, embed, asDomain) {
|
91
|
+
var self = this,
|
92
|
+
data = serialise(this, undefined, undefined, undefined,
|
93
|
+
{excludeOld: true})[0],
|
94
|
+
domain = self.domain() ? self.domain().id() : null,
|
95
|
+
domainId = isUndefinedOrNull(asDomain) ? domain : asDomain;
|
96
|
+
function handleResponse(result) {
|
97
|
+
success(fromJson(self, result[self.json],
|
98
|
+
{makesDirty: false}));
|
99
|
+
}
|
100
|
+
patchOne({resource: this.resource,
|
101
|
+
id: this.id(),
|
102
|
+
success: handleResponse,
|
103
|
+
error: error,
|
104
|
+
as_domain: domainId,
|
105
|
+
data: data,
|
106
|
+
embed: embed});
|
107
|
+
};
|
108
|
+
|
109
|
+
this.publicCreate = function (success, error) {
|
110
|
+
var data = serialise(this),
|
111
|
+
self = this,
|
112
|
+
request = new Request();
|
113
|
+
request.data().merge(data[0]);
|
114
|
+
request.resource('/public-invoice-create/');
|
115
|
+
request.method('POST');
|
116
|
+
function handleResponse(status, data) {
|
117
|
+
if (status === 201) {
|
118
|
+
success(fromJson(self, data[self.json]));
|
119
|
+
} else {
|
120
|
+
error(status, data);
|
121
|
+
}
|
122
|
+
}
|
123
|
+
function handleError(status, data) {
|
124
|
+
error(status, data);
|
125
|
+
}
|
126
|
+
request.responseHandler(handleResponse).errorHandler(handleError);
|
127
|
+
request.send();
|
128
|
+
};
|
129
|
+
|
130
|
+
this.get = function (success, error, embed) {
|
131
|
+
var self = this;
|
132
|
+
function handleResponse(result) {
|
133
|
+
success(fromJson(self, result[self.json],
|
134
|
+
{makesDirty: false}));
|
135
|
+
}
|
136
|
+
getOne({resource: this.resource,
|
137
|
+
id: this.id(),
|
138
|
+
success: handleResponse,
|
139
|
+
error: error,
|
140
|
+
embed: embed});
|
141
|
+
};
|
142
|
+
|
143
|
+
this.destroy = function (success, error) {
|
144
|
+
deleteOne(this.resource + "/" + this.id(), success, error);
|
145
|
+
};
|
146
|
+
|
147
|
+
this.company = function () {
|
148
|
+
return this.domain() ? this.domain().company() : null;
|
149
|
+
};
|
150
|
+
|
151
|
+
this.paymentPhoneNumbers = function () {
|
152
|
+
return this.company() ?
|
153
|
+
this.company().paymentPhoneNumbers() : null;
|
154
|
+
}
|
155
|
+
|
156
|
+
this.paymentBanks = function () {
|
157
|
+
return this.company() ? this.company().banks() : null;
|
158
|
+
}
|
159
|
+
|
160
|
+
this.stripePublishableKey = function () {
|
161
|
+
return this.company() ?
|
162
|
+
this.company().stripePublishableKey() : null;
|
163
|
+
}
|
164
|
+
|
165
|
+
this.calculate = function (success, error, embed) {
|
166
|
+
var self = this,
|
167
|
+
request = new Request(),
|
168
|
+
data = serialise(this)[0];
|
169
|
+
request.resource('/invoice-cost-estimate/');
|
170
|
+
request.method('POST');
|
171
|
+
request.query().add("as_domain", self.domain().id());
|
172
|
+
request.query().add('skip_rights', true);
|
173
|
+
request.data().merge(data);
|
174
|
+
function handleResponse(status, data) {
|
175
|
+
if (status === 201) {
|
176
|
+
success(fromJson(self, data));
|
177
|
+
} else {
|
178
|
+
error(data);
|
179
|
+
}
|
180
|
+
}
|
181
|
+
function handleError() {
|
182
|
+
error({message: 'could not connect to server',
|
183
|
+
errorCode: 0});
|
184
|
+
}
|
185
|
+
request.responseHandler(handleResponse).errorHandler(handleError);
|
186
|
+
request.send();
|
187
|
+
}
|
188
|
+
|
189
|
+
this.amountPaid = function () {
|
190
|
+
var payments = this.payments() ? this.payments() : [],
|
191
|
+
total = 0,
|
192
|
+
i;
|
193
|
+
for (i = 0; i < payments.length; i++) {
|
194
|
+
var amount = payments[i].amount();
|
195
|
+
total += amount ? amount : 0;
|
196
|
+
}
|
197
|
+
return total;
|
198
|
+
}
|
199
|
+
|
200
|
+
this.amountOwed = function () {
|
201
|
+
var total = this.totalCost();
|
202
|
+
return total - this.amountPaid();
|
203
|
+
}
|
204
|
+
|
205
|
+
this.isOverdue = function () {
|
206
|
+
var unpaid = this.unpaid(),
|
207
|
+
now = moment().unix();
|
208
|
+
return unpaid && (now > this.paymentDeadline());
|
209
|
+
}
|
210
|
+
}
|
211
|
+
|
212
|
+
export function Invoices() {
|
213
|
+
this.resource = '/invoices';
|
214
|
+
this.json = 'invoices';
|
215
|
+
this.single = Invoice;
|
216
|
+
|
217
|
+
this.get = function (success, error, parameters) {
|
218
|
+
var self = this;
|
219
|
+
function handleResponse(result) {
|
220
|
+
success(fromJsonList(self, result, {makesDirty: false}));
|
221
|
+
}
|
222
|
+
getList(this.resource, handleResponse, error, parameters);
|
223
|
+
};
|
224
|
+
}
|
package/src/item.js
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
import { generateUUID } from './uuid.js';
|
2
|
+
import { addPropertyTo } from './model.js';
|
3
|
+
import { CountryTax } from './country_tax.js';
|
4
|
+
|
5
|
+
export function Item() {
|
6
|
+
this.resource = '/items';
|
7
|
+
this.json = 'items';
|
8
|
+
this.temporaryId = generateUUID();
|
9
|
+
|
10
|
+
addPropertyTo(this, 'id');
|
11
|
+
addPropertyTo(this, 'quantity');
|
12
|
+
addPropertyTo(this, 'taxType', CountryTax);
|
13
|
+
addPropertyTo(this, 'taxAmount');
|
14
|
+
addPropertyTo(this, 'cost');
|
15
|
+
addPropertyTo(this, 'description');
|
16
|
+
|
17
|
+
this.totalCost = function () {
|
18
|
+
var quantity = this.quantity() ? this.quantity() : 0,
|
19
|
+
cost = this.cost() ? this.cost() : 0;
|
20
|
+
return quantity * cost;
|
21
|
+
}
|
22
|
+
}
|