· 4 years ago · Aug 24, 2021, 07:08 AM
1function doPost() {}
2
3function doGet() {}
4
5function onOpen() {}
6
7function connect() {}
8
9function embed() {}
10
11function picker() {}
12
13function help() {}
14
15function activate() {}(() => {
16 "use strict";
17 var e = {};
18 e.g = function() {
19 if ("object" == typeof globalThis) return globalThis;
20 try {
21 return this || new Function("return this")()
22 } catch (e) {
23 if ("object" == typeof window) return window
24 }
25 }();
26 const t = "Items",
27 r = "Sale",
28 s = "Invoice",
29 n = "activate",
30 a = e => {
31 for (let t = 0; t < 5; t += 1) try {
32 return e()
33 } catch (e) {
34 if (4 === t) throw e;
35 Utilities.sleep(2 ** t * 1e3 + Math.round(1e3 * Math.random()))
36 }
37 return null
38 },
39 o = new class {
40 constructor() {
41 this.userCache = null
42 }
43 getUserCache() {
44 if (null === this.userCache) try {
45 this.userCache = a((() => CacheService.getDocumentCache()))
46 } catch (e) {
47 this.userCache = !1
48 }
49 return this.userCache
50 }
51 getUserCacheValue(e, t = !1) {
52 if (!this.getUserCache()) return null;
53 try {
54 const r = this.getUserCache().get(e);
55 if (r) return t ? JSON.parse(r) : r
56 } catch (e) {}
57 return null
58 }
59 setUserCacheValue(e, t, r = !1, s = 21600) {
60 if (this.getUserCache()) try {
61 if (!t || r && !Object.keys(t).length) return void this.deleteUserCacheValue(e);
62 this.getUserCache().put(e, r ? JSON.stringify(t) : t, s)
63 } catch (e) {}
64 }
65 deleteUserCacheValue(e) {
66 this.getUserCache() && this.getUserCache().remove(e)
67 }
68 },
69 i = new class {
70 constructor() {
71 this.userProps = null
72 }
73 getUserProps() {
74 if (null === this.userProps) try {
75 this.userProps = a((() => PropertiesService.getDocumentProperties()))
76 } catch (e) {
77 this.userProps = !1
78 }
79 return this.userProps
80 }
81 getUserProperty(e, t = !1) {
82 if (!this.getUserProps()) return null;
83 const r = o.getUserCacheValue(`user${e}`) || this.getUserProps().getProperty(e);
84 return t ? JSON.parse(r || "{}") : r
85 }
86 getUserProperties() {
87 return this.getUserProps() ? this.getUserProps().getProperties() : {}
88 }
89 setUserProperty(e, t, r = !1) {
90 if (this.getUserProps()) {
91 const s = r ? JSON.stringify(t) : t;
92 o.setUserCacheValue(`user${e}`, s), this.getUserProps().setProperty(e, s)
93 }
94 }
95 deleteUserProperty(e) {
96 this.getUserProps() && (o.deleteUserCacheValue(`user${e}`), this.getUserProps().deleteProperty(e))
97 }
98 deleteUserProperties() {
99 this.getUserProps() && this.getUserProps().deleteAllProperties()
100 }
101 },
102 c = "SSID";
103 let l = null;
104 const u = () => {
105 if (null === l) {
106 const e = i.getUserProperty(c);
107 l = a((() => e ? SpreadsheetApp.openById(e) : SpreadsheetApp.getActiveSpreadsheet())), e || i.setUserProperty(c, l.getId())
108 }
109 return l
110 },
111 p = e => u().getSheetByName(e),
112 h = e => {
113 u().toast(e)
114 },
115 d = e => {
116 Browser.msgBox(e)
117 },
118 g = (e, t = 2) => p(e).getDataRange().getDisplayValues().splice(t),
119 m = {
120 MODES: {
121 LIVE: "live",
122 SANDBOX: "sandbox"
123 },
124 CLIENTID: "client-id",
125 CLIENTSECRET: "client-secret",
126 CURRENCY: "currency",
127 DFUNDING: "disable-funding",
128 DCARD: "disable-card",
129 MERCHANT: ["brand_name", "landing_page", "shipping_preference", "payee_preferred", "description", "soft_descriptor", "success_message"],
130 SOURCE: "digitalgoods.dev",
131 CAPTURE_EVENT: "PAYMENT.CAPTURE.COMPLETED",
132 BRAND_NAME: "brand_name",
133 WEBHOOK: "webhook",
134 CC: "cc",
135 BCC: "bcc",
136 DEBUG: "debug",
137 INVOICE_ID: "invoiceId"
138 },
139 f = "",
140 y = "WEBHOOK_URL",
141 E = "ORDERS",
142 S = "EXPIRED",
143 D = (e, t = m.MODES.SANDBOX) => `${e}-${t}`,
144 C = "template",
145 U = Date.now(),
146 O = "Digital Goods",
147 P = "https://digitalgoods.dev",
148 v = (e, t = f) => e || t;
149 let A = null;
150 const N = () => {
151 if (null === A) {
152 const e = g("Configuration");
153 A = {}, e.forEach((e => {
154 const [, t, r] = e;
155 t && (A[t] = v(r).trim())
156 }))
157 }
158 return A
159 },
160 w = () => {
161 const {
162 currency: e = "USD"
163 } = N();
164 return e
165 },
166 _ = e => `https://api-m.${e===m.MODES.SANDBOX?`${m.MODES.SANDBOX}.`:f}paypal.com`,
167 $ = e => v(N()[e]),
168 b = e => $(`${e}-${m.CLIENTID}`),
169 I = e => $(`${e}-${m.CLIENTSECRET}`),
170 R = e => ((e, t = 2) => p(e).getDataRange().getValues().splice(t))(t).map((t => {
171 const [, r, s, n, a, o, i] = t;
172 return e && r !== e ? null : r && o ? {
173 sku: r,
174 name: s,
175 description: i,
176 price: n,
177 tax: a,
178 amount: o
179 } : null
180 })).filter((e => null !== e)),
181 k = e => {
182 const t = [];
183 return t.push([m.CLIENTID, b(e)]), t.push([m.CURRENCY, w()]), t.push((() => {
184 const e = $(m.DFUNDING);
185 return [m.DFUNDING, "none" === e ? f : e]
186 })()), t.push((() => {
187 const e = $(m.DCARD);
188 return [m.DCARD, "none" === e ? f : e]
189 })()), t.map((([e = f, t = f]) => e && t ? `${e}=${t}` : f)).filter((e => e)).join("&")
190 },
191 T = (...e) => {
192 console.error(...e)
193 },
194 M = e => {
195 try {
196 if ("object" == typeof e) return e.message ? e.message : JSON.stringify(e, null, 2)
197 } catch (e) {
198 T(e)
199 }
200 return e.toString()
201 };
202 let V = null;
203 const B = e => {
204 try {
205 null === V && (V = p("Logs")), V ? V.appendRow(["", new Date, M(e)]) : T(e)
206 } catch (e) {
207 T(e)
208 }
209 },
210 L = (e = f) => {
211 try {
212 return String(e).replace(/[\s{}<>_-]/g, f).toLowerCase()
213 } catch (t) {
214 return e
215 }
216 },
217 H = (e = f, t = {}) => {
218 try {
219 const r = e.match(/\{\{(?:[^}}]+)\}\}/g) || e.match(/<<(?:[^>>]+)>>/g);
220 if (null !== r) {
221 let s = e;
222 return r.forEach((e => {
223 s = s.replace(e, t[L(e)] || f)
224 })), s
225 }
226 } catch (e) {
227 B(e)
228 }
229 return e
230 },
231 x = e => e.evaluate().getContent().replace(/\s*[\r\n]+\s*/g, f).replace(/\s+/g, " "),
232 F = (e = f) => {
233 const t = "object" == typeof e ? JSON.stringify(e) : e;
234 return ContentService.createTextOutput().setContent(t)
235 },
236 j = e => HtmlService.createTemplateFromFile(e),
237 G = "/v1/oauth2/token",
238 W = "/v1/notifications/webhooks",
239 X = "/v2/checkout/orders",
240 J = e => ({
241 method: "POST",
242 headers: {
243 Authorization: ` Basic ${Utilities.base64Encode(`${b(e)}:${I(e)}`)}`,
244 Accept: "application/json",
245 "Content-Type": "application/json"
246 },
247 contentType: "application/x-www-form-urlencoded",
248 muteHttpExceptions: !1,
249 payload: {
250 grant_type: "client_credentials"
251 }
252 }),
253 Y = (e, t = !1) => {
254 try {
255 const r = D("ACCESS_TOKEN", e);
256 if (!t) {
257 const {
258 access_token: e,
259 expires_in: t
260 } = o.getUserCacheValue(r, !0) || {};
261 if (e && t && t > U) return e
262 }
263 const {
264 access_token: s,
265 expires_in: n
266 } = ((e, t) => {
267 const r = `${_(e)}${G}`,
268 s = t ? UrlFetchApp.fetch(r, J(e)) : a((() => UrlFetchApp.fetch(r, J(e))));
269 return JSON.parse(s)
270 })(e, t);
271 if (s && n) return o.setUserCacheValue(r, {
272 access_token: s,
273 expires_in: 1e3 * n + U
274 }, !0), s
275 } catch (e) {
276 B(e)
277 }
278 return null
279 },
280 z = e => {
281 B(e)
282 };
283 let K = null;
284 const q = e => {
285 null === K && (K = /y/i.test($(m.DEBUG))), K && B(e)
286 },
287 Q = (e, t, r = {}) => {
288 const s = Y(t);
289 if (!s) throw Error("Cannot connect to PayPal API");
290 const n = Object.assign({
291 headers: {
292 Authorization: `Bearer ${s}`,
293 "Content-Type": "application/json"
294 },
295 muteHttpExceptions: !1
296 }, r),
297 o = `${_(t)}${e}`,
298 i = a((() => UrlFetchApp.fetch(o, n))),
299 c = JSON.parse(i);
300 return q(c), c
301 },
302 Z = (e, t) => (o.setUserCacheValue(e, t), !0),
303 ee = e => {
304 const t = (() => {
305 try {
306 const e = $(m.WEBHOOK),
307 t = o.getUserCacheValue(y);
308 if (t && e && t === e) return e;
309 if (/https:\/\/script\./.test(e) && a((() => UrlFetchApp.fetch(e, {
310 muteHttpExceptions: !0
311 }).getContentText())) === m.SOURCE) return o.setUserCacheValue(y, e), e
312 } catch (e) {
313 B(e)
314 }
315 return f
316 })();
317 if (!t) return !1;
318 const r = D("WEBHOOK_ID", e);
319 if (o.getUserCacheValue(r) === t) return !0;
320 const {
321 webhooks: s = []
322 } = Q(W, e);
323 for (let e = 0; e < s.length; e += 1) {
324 if (s[e].url === t) return Z(r, t);
325 z(`Error: Invalid webhook: ${s[e].url}`)
326 }
327 const {
328 id: n = f
329 } = Q(W, e, {
330 method: "POST",
331 payload: JSON.stringify({
332 url: t,
333 event_types: [{
334 name: m.CAPTURE_EVENT
335 }]
336 })
337 });
338 return n && (Z(r, t), z(`Webhook (${e}) set to ${t}`)), !!n
339 },
340 te = "until",
341 re = "modules",
342 se = e => {
343 i.setUserProperty(te, String(e))
344 },
345 ne = (e, t) => {
346 se(t), i.setUserProperty(re, e)
347 },
348 ae = () => (() => {
349 const e = i.getUserProperty(te);
350 if (e) return Number(e);
351 const t = new Date;
352 t.setHours(t.getHours() + 168);
353 const r = t.getTime();
354 return se(r), r
355 })() > U,
356 oe = () => ae(),
357 ie = () => {
358 const e = HtmlService.createHtmlOutputFromFile("premium");
359 return e.setTitle("Upgrade License"), e
360 },
361 ce = () => {
362 try {
363 const e = ie().setWidth(600).setHeight(700);
364 SpreadsheetApp.getUi().showModalDialog(e, "Sell Digital Goods via PayPal"), h("Your trial has expired!")
365 } catch (e) {
366 B(e)
367 }
368 },
369 le = (e = !0) => oe() ? null === Y(m.MODES.SANDBOX, !0) ? (d("Please specify valid sandbox-client-id and secret key in the configuration sheet!"), !1) : null === Y(m.MODES.LIVE, !0) ? (d("Please specify valid live-client-id and secret key in the configuration sheet!"), !1) : ee(m.MODES.SANDBOX) && ee(m.MODES.LIVE) ? !e || (h("PayPal Connection is OK!"), !1) : (d("Please specify a valid Webhook URL in the configuration sheet"), !1) : (ce(), !1),
370 ue = (e, t) => {
371 try {
372 const r = j("preview"),
373 {
374 html: s,
375 product: {
376 name: n,
377 sku: a
378 }
379 } = ((e, t) => {
380 const [r = null] = R(e);
381 if (!r) throw Error("The selected item cannot be found.");
382 const s = j(C);
383 s.src = k(t), s[m.CURRENCY] = w(), m.MERCHANT.forEach((e => {
384 s[e] = $(e)
385 }));
386 const {
387 sku: n,
388 name: a,
389 description: o,
390 price: i,
391 tax: c,
392 amount: l
393 } = r;
394 return s.divId = `paypal-button-${U}-${t}`, s.item_name = a, s.item_description = o, s.sku = n, s.item_total = i, s.tax_total = c, s.amount = l, {
395 product: r,
396 html: x(s)
397 }
398 })(e, t);
399 r.html = s, r.name = n, r.sku = a, r.mode = t;
400 const o = r.evaluate().setWidth(350).setHeight(250);
401 SpreadsheetApp.getUi().showModalDialog(o, "Smart Buttons")
402 } catch (e) {
403 d(e.toString())
404 }
405 },
406 pe = (e = "") => e.toLowerCase().trim(),
407 he = () => {
408 try {
409 return a((() => pe(Session.getEffectiveUser().getEmail())))
410 } catch (e) {
411 T(e)
412 }
413 return ""
414 };
415 let de = null;
416 const ge = () => de || (de = he() || (() => {
417 try {
418 const e = a((() => pe(Session.getActiveUser().getEmail())));
419 return e && T({
420 activeUser: e
421 }), e
422 } catch (e) {
423 T(e)
424 }
425 return ""
426 })(), de || `unknownemail@${Date.now()}.com`),
427 me = e => {
428 const t = (e => {
429 const t = (e => {
430 try {
431 return String(e).toLowerCase().replace(/[^\w]/g, f)
432 } catch (t) {
433 return e
434 }
435 })("Digital Goods" + e);
436 return Utilities.computeDigest(Utilities.DigestAlgorithm.MD5, t).reduce(((e, t) => {
437 const r = (t < 0 ? t + 256 : t).toString(16);
438 return e + (1 === r.length ? "0" : "") + r
439 }), "")
440 })(ge()),
441 {
442 length: r
443 } = t,
444 s = e.substr(1, r);
445 return s === t && ne(e.substr(0, 1), e.substr(r + 1)), s === t ? e : f
446 },
447 fe = "<br>",
448 ye = (e = f, t = f) => [e, t].join(" ").trim(),
449 Ee = ({
450 email_address: e = f
451 }) => e,
452 Se = ({
453 phone_number: e = {}
454 }) => {
455 const {
456 national_number: t = f
457 } = e;
458 return t
459 },
460 De = ({
461 name: e = {}
462 }) => {
463 const {
464 given_name: t,
465 surname: r
466 } = e;
467 return ye(t, r)
468 },
469 Ce = e => {
470 const {
471 address: {
472 address_line_1: t,
473 address_line_2: r,
474 admin_area_1: s = f,
475 admin_area_2: n = f,
476 postal_code: a = f,
477 country_code: o = f
478 } = {}
479 } = e;
480 return {
481 address: ye(t, r),
482 city: n,
483 state: s,
484 zip: a,
485 country: o
486 }
487 },
488 Ue = ({
489 orderId: e,
490 payer: t = {},
491 txn: s
492 }) => Object.assign({
493 orderId: e,
494 invoiceId: f
495 }, (e => ({
496 name: De(e),
497 email: Ee(e),
498 phone: Se(e)
499 }))(t), ((e, {
500 shipping: t = {}
501 }) => {
502 const r = Ce(e),
503 s = Ce(t);
504 return Object.keys(r).forEach((e => {
505 s[e] && (r[e] = s[e])
506 })), r
507 })(t, s), (e => {
508 const {
509 amount: t = {},
510 items: r = [{}]
511 } = e, {
512 name: s = f,
513 quantity: n = 1,
514 description: a = f,
515 sku: o = f
516 } = r[0];
517 return Object.assign({
518 item_name: s,
519 sku: o,
520 quantity: Number(n),
521 description: a
522 }, (e => {
523 const {
524 currency_code: t,
525 value: r = 0,
526 breakdown: {
527 item_total: {
528 value: s = 0
529 },
530 tax_total: {
531 value: n = 0
532 }
533 } = {}
534 } = e;
535 return {
536 currency: t,
537 total: r,
538 price: s,
539 tax: n
540 }
541 })(t))
542 })(s), N(), (() => {
543 const e = {};
544 try {
545 if (oe()) {
546 const t = p("Codes"),
547 s = t.getLastColumn(),
548 n = e => t.getRange(e, 1, 1, s).getDisplayValues()[0],
549 a = n(2),
550 o = n(p(r).getLastRow() + 1);
551 a.forEach(((t, r) => {
552 t && (e[t] = o[r])
553 }))
554 }
555 } catch (e) {
556 B(e)
557 }
558 return e
559 })()),
560 Oe = (e = f) => {
561 try {
562 const [, t] = e.match(/[=/(]?([-\w]{25,})/) || [];
563 if (t) {
564 const e = DriveApp.getFileById(t);
565 if (e.getSize() < 20971520) return e.getBlob();
566 z(`The file ${e.getName()} is large for sending as an attachment. Please include a link in the email`)
567 }
568 } catch (e) {
569 B(e)
570 }
571 return null
572 },
573 Pe = (e, n) => {
574 const o = ((e, t) => {
575 const {
576 payer: r,
577 purchase_units: s = [{}]
578 } = Q(`${X}/${e}`, t);
579 return {
580 payer: r,
581 orderId: e,
582 txn: s[0]
583 }
584 })(e, n),
585 i = Ue(o),
586 c = ((e = {}) => {
587 const t = {};
588 return Object.keys(e).forEach((r => {
589 t[L(r)] = e[r]
590 })), t
591 })(i);
592 c.invoiceid = (e => {
593 const t = $(m.INVOICE_ID),
594 s = /row/i.test(t) ? p(r).getLastRow() - 1 : f;
595 return H(t, Object.assign({
596 row: s
597 }, e))
598 })(c), (e => {
599 const t = p(r);
600 a((() => {
601 t.appendRow([f, e.invoiceid, new Date, e.name, e.email, e.country, e.itemname, e.sku, e.price, e.tax, e.total, e.address, e.city, e.state, e.zip, e.phone, e.orderid])
602 }))
603 })(c);
604 const {
605 amount: l = f,
606 files: u = [],
607 links: h = ""
608 } = (e => {
609 const r = g(t);
610 for (let t = 0; t < r.length; t += 1) {
611 const [, s, , , , n, , a] = r[t];
612 if (s && n && s === e) return {
613 amount: n,
614 files: a.split(/[;,\s\n]/).map((e => Oe(e))).filter((e => null !== e)),
615 links: a
616 }
617 }
618 return z(`Error: Product ${e} not found`), {}
619 })(i.sku);
620 if (l)
621 if (l === c.total) {
622 c.filelink = h;
623 ((e, t = []) => {
624 const [r, ...s] = p("Email").getDataRange().getDisplayValues(), n = H(r.join(f), e), o = H(s.map((e => e.join(f))).join(fe).trim().replace(/\n/g, fe) + (oe() ? f : `<br><p>Sent via <a href="${P}">${O}</a></p>`), e), i = o.replace(/<[^>]+>/g, " "), c = e.email, l = $(m.CC), u = $(m.BCC);
625 c || z(`Error: Payer's email not found (Order: ${e.orderid})`);
626 const h = c || l || u;
627 h && (a((() => {
628 MailApp.sendEmail(c, n, i, {
629 htmlBody: o,
630 attachments: t.filter((e => e)),
631 cc: l,
632 bcc: u,
633 name: $(m.BRAND_NAME)
634 })
635 })), z(`Delivered: Order ${e.orderid} (Email sent to ${h})`))
636 })(c, [(e => {
637 try {
638 if (oe()) {
639 const t = p(s);
640 if (t) {
641 const r = SpreadsheetApp.create((new Date).toString());
642 return t.copyTo(r).setName(s), r.getSheets().forEach((t => {
643 t.getName() !== s ? r.deleteSheet(t) : (((e, t) => {
644 e.getDataRange().getDisplayValues().forEach(((r, s) => {
645 r.forEach(((r, n) => {
646 if (r && /{/.test(r)) {
647 const a = H(r, t);
648 a !== r && e.getRange(s + 1, n + 1).setValue(a)
649 }
650 }))
651 }))
652 })(t, e), SpreadsheetApp.flush())
653 })), (e => {
654 const t = DriveApp.getFileById(e),
655 r = t.getAs("application/pdf").setName(s);
656 return t.setTrashed(!0), r
657 })(r.getId())
658 }
659 }
660 } catch (e) {
661 B(e)
662 }
663 return null
664 })(c), ...u])
665 } else z(`Error: Amount mismatch. Received ${c.total}, Expected ${l}`)
666 },
667 ve = (e = f) => e === m.MODES.SANDBOX ? m.MODES.SANDBOX : m.MODES.LIVE,
668 Ae = ({
669 id: e = f,
670 links: t = []
671 }) => {
672 const [
673 [r = f, s = f] = []
674 ] = t.filter((({
675 rel: e = f
676 }) => /^up$/i.test(e))).map((({
677 href: e = f
678 }) => {
679 const [, t, r = f] = e.replace(X, f).match(/([a-z]+)\.paypal\.com\/([a-z0-9]+)$/i) || [];
680 return [ve(t), r]
681 }));
682 if (r && s) return r !== m.MODES.LIVE || oe() ? {
683 mode: r,
684 orderId: s
685 } : ((e => {
686 const t = `PayPal Order ${e} not delivered`;
687 throw o.getUserCacheValue(S) || (MailApp.sendEmail(Session.getActiveUser().getEmail(), t, [`Your ${O} trial has expired.`, `Please buy a license from ${P}/buy to continue.`, "For assistance, email the developer at amit@labnol.org", "Thanks!"].join("\n\n")), o.setUserCacheValue(S, e)), Error(t)
688 })(s), {
689 error: s
690 });
691 throw Error(`Cannot capture ${e} ${JSON.stringify(t)}`)
692 },
693 Ne = () => v(i.getUserProperty(E)).split(","),
694 we = e => {
695 const t = (e => o.getUserCacheValue(e) === e)(e) || (e => -1 !== Ne().indexOf(e))(e);
696 return t || (e => {
697 o.setUserCacheValue(e, e), (e => {
698 const t = Ne();
699 t.push(e), i.setUserProperty(E, t.slice(-500).join(","))
700 })(e)
701 })(e), t
702 };
703 e.g.doPost = e => {
704 try {
705 const {
706 event_type: t,
707 summary: r,
708 resource: s = {}
709 } = (({
710 postData: e = {}
711 } = {}) => {
712 try {
713 const {
714 contents: t = "{}"
715 } = e, r = JSON.parse(t);
716 return q(r), r
717 } catch (e) {
718 B(e)
719 }
720 return {}
721 })(e);
722 if (t === m.CAPTURE_EVENT) {
723 const {
724 orderId: e,
725 mode: t,
726 error: n
727 } = Ae(s);
728 n || we(e) || (z(`Received: Order ${e} (${r})`), Pe(e, t))
729 } else z(`PayPal event: ${t}`)
730 } catch (e) {
731 B(e)
732 }
733 return HtmlService.createHtmlOutput(f)
734 }, e.g.doGet = (e = {}) => {
735 try {
736 const {
737 action: t = f,
738 a: r = f,
739 b: s = f,
740 parameter: a,
741 email: o
742 } = e;
743 if (o) {
744 const e = ((e = "") => {
745 try {
746 const t = he();
747 if (e && t && e !== t) return `Please <a target="_blank" href="https://accounts.google.com/logout">log out</a> of your Google Account ${t} to use Mail Merge with ${e}`
748 } catch (e) {
749 T(e)
750 }
751 return ""
752 })(o);
753 if (e) return e
754 }
755 switch (t) {
756 case n:
757 return me(r);
758 case "append":
759 return (e => {
760 const t = SpreadsheetApp.getActiveRange().getRow();
761 return SpreadsheetApp.getActiveSheet().getRange(t, 8).setValue(e), h(`Files added to row #${t}`), ""
762 })(r);
763 case "preview":
764 return ue(r, s);
765 case "deliver":
766 return Pe(r, s);
767 default:
768 return ((e = {}) => ((e = {}) => {
769 const t = v(e.paypal);
770 if (t) {
771 const e = new Date;
772 return e.setFullYear(e.getFullYear() + 1), ne(t.toLowerString().substr(0, 1), e.getTime()), !0
773 }
774 return !1
775 })(e) ? F(e) : oe() ? F(m.SOURCE) : ie())(a)
776 }
777 } catch (e) {
778 return F(e.toString())
779 }
780 }, e.g.onOpen = () => {
781 SpreadsheetApp.getUi().createMenu(`➪ ${O}`).addItem("Test PayPal Configuration", "connect").addItem("Attach Google Drive Files", "picker").addItem("Embed Smart PayPal Buttons", "embed").addSeparator().addItem("Activate License", n).addSeparator().addItem("Help and Support", "help").addToUi()
782 }, e.g.connect = le, e.g.embed = () => {
783 try {
784 if (le(!1)) {
785 const e = j("embed"),
786 t = (() => {
787 const e = R();
788 if (0 === e.length) throw Error("Please add one or more products in the sheet");
789 const t = {
790 [m.MODES.LIVE]: k(m.MODES.LIVE),
791 [m.MODES.SANDBOX]: k(m.MODES.SANDBOX)
792 },
793 r = j(C);
794 return r[m.CURRENCY] = w(), m.MERCHANT.forEach((e => {
795 r[e] = $(e)
796 })), e.map((e => {
797 const {
798 sku: s,
799 name: n,
800 description: a,
801 price: o,
802 tax: i,
803 amount: c
804 } = e;
805 r.item_name = n, r.item_description = a, r.sku = s, r.item_total = o, r.tax_total = i, r.amount = c, r.src = t[m.MODES.SANDBOX], r.divId = ((e = f) => {
806 const t = e.toLowerCase().replace(/[\s\W]/g, f),
807 r = Utilities.formatDate(new Date, "IST", "ddMMyyHHmmss");
808 return `${m.SOURCE.replace(".dev",f)}-${r}-${t}`
809 })(s);
810 const l = x(r);
811 return r.src = t[m.MODES.LIVE], {
812 product: e,
813 sandbox: l,
814 live: x(r)
815 }
816 }))
817 })();
818 e.items = t, e.active = 1 === t.length ? "active" : f;
819 const r = e.evaluate().setWidth(600).setHeight(400);
820 SpreadsheetApp.getUi().showModalDialog(r, "PayPal Buttons")
821 }
822 } catch (e) {
823 d(e.toString())
824 }
825 }, e.g.picker = () => {
826 if (oe())
827 if (SpreadsheetApp.getActiveSheet().getName() !== t) h("Please switch to the Items sheet!");
828 else if (SpreadsheetApp.getActiveRange().getRow() < 3) h("Please select a cell under the File Link column and try again.");
829 else {
830 h("Loading..");
831 const e = j("picker");
832 e.token = ScriptApp.getOAuthToken(), e.email = ge();
833 const t = e.evaluate().setWidth(620).setHeight(425);
834 SpreadsheetApp.getUi().showModalDialog(t, "Select File(s) from your Google Drive")
835 } else ce()
836 }, e.g.help = () => {
837 const e = HtmlService.createHtmlOutputFromFile("help").setWidth(575).setHeight(475);
838 SpreadsheetApp.getUi().showModelessDialog(e, "Digital Goods Help")
839 }, e.g.activate = () => {
840 if ("t" !== (i.getUserProperty(re) || "t") && ae()) return void h("You are a premium user!");
841 h("Loading..");
842 const e = j("activate");
843 e.email = ge();
844 const t = e.evaluate().setWidth(600).setHeight(300);
845 SpreadsheetApp.getUi().showModalDialog(t, "Activate Digital Goods")
846 }
847})();