@kiva/kv-shop 2.1.2 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/dist/_virtual/_commonjs-dynamic-modules.js +6 -0
  2. package/dist/_virtual/_commonjsHelpers.js +8 -0
  3. package/dist/_virtual/_plugin-vue_export-helper.js +9 -0
  4. package/dist/_virtual/dropin.js +11 -0
  5. package/dist/_virtual/dropin2.js +4 -0
  6. package/dist/basket.js +35 -12
  7. package/dist/basketCredits.js +78 -14
  8. package/dist/basketItems.js +27 -8
  9. package/dist/basketTotals.js +38 -10
  10. package/dist/basketVerification.js +6 -6
  11. package/dist/checkoutStatus.js +52 -8
  12. package/dist/components/KvPaymentSelect.css +1 -0
  13. package/dist/components/KvPaymentSelect.js +23 -0
  14. package/dist/components/KvPaymentSelect2.js +110 -0
  15. package/dist/index.d.ts +321 -20
  16. package/dist/index.js +49 -96
  17. package/dist/managedAccount.js +62 -8
  18. package/dist/oneTimeCheckout.js +156 -12
  19. package/dist/receipt.js +143 -12
  20. package/dist/shopError.js +41 -6
  21. package/dist/shopQueries.js +82 -11
  22. package/dist/subscriptionCheckout.js +88 -7
  23. package/dist/useBraintreeDropIn.js +145 -9
  24. package/dist/util/cookie.js +11 -0
  25. package/dist/util/poll.js +17 -0
  26. package/dist/util/redirect.js +8 -0
  27. package/dist/util/visitorId.js +7 -0
  28. package/dist/validatePreCheckout.js +44 -11
  29. package/dist/vendor/braintree-web-drop-in/dist/browser/dropin.js +12223 -0
  30. package/package.json +28 -26
  31. package/dist/basket.cjs +0 -141
  32. package/dist/basket.d.ts +0 -8
  33. package/dist/basketCredits.cjs +0 -250
  34. package/dist/basketCredits.d.ts +0 -32
  35. package/dist/basketItems.cjs +0 -205
  36. package/dist/basketItems.d.ts +0 -26
  37. package/dist/basketTotals.cjs +0 -228
  38. package/dist/basketTotals.d.ts +0 -37
  39. package/dist/basketVerification.cjs +0 -41
  40. package/dist/basketVerification.d.ts +0 -10
  41. package/dist/checkoutStatus.cjs +0 -111
  42. package/dist/checkoutStatus.d.ts +0 -20
  43. package/dist/chunk-4ODZGLWK.js +0 -64
  44. package/dist/chunk-ASZJVUQ7.js +0 -72
  45. package/dist/chunk-FBF4WMN6.js +0 -49
  46. package/dist/chunk-FC4QW6QA.js +0 -106
  47. package/dist/chunk-FCAOCO7O.js +0 -17
  48. package/dist/chunk-GVVI7X2R.js +0 -196
  49. package/dist/chunk-IIN37LC7.js +0 -45
  50. package/dist/chunk-IOZ5ERDX.js +0 -121
  51. package/dist/chunk-KCUOMCSN.js +0 -58
  52. package/dist/chunk-LZ4UMRCV.js +0 -16
  53. package/dist/chunk-RQNRQ2E5.js +0 -155
  54. package/dist/chunk-SRGYGDAX.js +0 -80
  55. package/dist/chunk-TPJPGUO7.js +0 -12
  56. package/dist/chunk-UJXHTR43.js +0 -86
  57. package/dist/chunk-VZ3VDRRP.js +0 -167
  58. package/dist/chunk-Z7JRY3QE.js +0 -34
  59. package/dist/components/KvPaymentSelect.vue +0 -380
  60. package/dist/index.cjs +0 -1227
  61. package/dist/managedAccount.cjs +0 -231
  62. package/dist/managedAccount.d.ts +0 -59
  63. package/dist/oneTimeCheckout.cjs +0 -636
  64. package/dist/oneTimeCheckout.d.ts +0 -21
  65. package/dist/receipt.cjs +0 -191
  66. package/dist/receipt.d.ts +0 -16
  67. package/dist/shopError.cjs +0 -88
  68. package/dist/shopError.d.ts +0 -14
  69. package/dist/shopQueries.cjs +0 -248
  70. package/dist/shopQueries.d.ts +0 -8
  71. package/dist/subscriptionCheckout.cjs +0 -187
  72. package/dist/subscriptionCheckout.d.ts +0 -13
  73. package/dist/useBraintreeDropIn.cjs +0 -258
  74. package/dist/useBraintreeDropIn.d.ts +0 -25
  75. package/dist/validatePreCheckout.cjs +0 -218
  76. package/dist/validatePreCheckout.d.ts +0 -28
@@ -1,636 +0,0 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
- // If the importer is in node compatibility mode or this is not an ESM
21
- // file that has been converted to a CommonJS file using a Babel-
22
- // compatible transform (i.e. "__esModule" has not been set), then set
23
- // "default" to the CommonJS "module.exports" for node compatibility.
24
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
- mod
26
- ));
27
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
-
29
- // src/oneTimeCheckout.ts
30
- var oneTimeCheckout_exports = {};
31
- __export(oneTimeCheckout_exports, {
32
- executeOneTimeCheckout: () => executeOneTimeCheckout
33
- });
34
- module.exports = __toCommonJS(oneTimeCheckout_exports);
35
- var import_core5 = require("@apollo/client/core/core.cjs");
36
- var import_kv_analytics = require("@kiva/kv-analytics");
37
- var import_numeral = __toESM(require("numeral"), 1);
38
-
39
- // src/checkoutStatus.ts
40
- var import_core = require("@apollo/client/core/core.cjs");
41
-
42
- // src/util/poll.ts
43
- function wait(ms) {
44
- return new Promise((resolve) => setTimeout(resolve, ms));
45
- }
46
- async function poll(fn, fnCondition, interval, timeout) {
47
- const endTime = Date.now() + timeout;
48
- let result = await fn();
49
- while (!fnCondition(result)) {
50
- if (Date.now() > endTime) {
51
- throw new Error("Polling timed out");
52
- }
53
- await wait(interval);
54
- result = await fn();
55
- }
56
- return result;
57
- }
58
-
59
- // src/util/cookie.ts
60
- var getCookieValue = (name) => {
61
- if (typeof document !== void 0) {
62
- return decodeURIComponent(document.cookie.match(`(^|;)\\s*${name}\\s*=\\s*([^;]+)`)?.pop() || "");
63
- }
64
- };
65
- var setCookieValue = (name, value, options = "") => {
66
- if (typeof document !== void 0) {
67
- document.cookie = `${name}=${encodeURIComponent(value)};${options}`;
68
- }
69
- };
70
-
71
- // src/util/visitorId.ts
72
- function getVisitorID() {
73
- return getCookieValue("uiv");
74
- }
75
-
76
- // src/checkoutStatus.ts
77
- async function getCheckoutStatus({ apollo, transactionSagaId }) {
78
- return apollo.query({
79
- query: import_core.gql`
80
- query checkoutStatus($transactionId: String!, $visitorId: String) {
81
- checkoutStatus(transactionId: $transactionId, visitorId: $visitorId) {
82
- basketId
83
- errorCode
84
- errorMessage
85
- receipt {
86
- checkoutId
87
- }
88
- requestedAt
89
- status
90
- transactionId
91
- updatedAt
92
- }
93
- }
94
- `,
95
- variables: {
96
- transactionId: transactionSagaId,
97
- visitorId: getVisitorID()
98
- },
99
- fetchPolicy: "network-only"
100
- });
101
- }
102
- async function pollForFinishedCheckout({
103
- apollo,
104
- transactionSagaId,
105
- interval = 1e3,
106
- timeout = 6e4
107
- }) {
108
- return poll(
109
- // function to poll
110
- () => getCheckoutStatus({
111
- apollo,
112
- transactionSagaId
113
- }),
114
- // function to check for completed status
115
- (result) => {
116
- const { status, errorCode, errorMessage } = result?.data?.checkoutStatus;
117
- if (status === "COMPLETED" || errorCode || errorMessage) {
118
- return true;
119
- }
120
- return false;
121
- },
122
- interval,
123
- timeout
124
- );
125
- }
126
-
127
- // src/shopError.ts
128
- var ShopError = class extends Error {
129
- constructor({ code, original }, ...params) {
130
- super(...params);
131
- if (Error.captureStackTrace) {
132
- Error.captureStackTrace(this, ShopError);
133
- }
134
- this.name = "ShopError";
135
- this.code = code;
136
- this.original = original;
137
- }
138
- aggregateErrors(errors) {
139
- this.errors = errors;
140
- }
141
- };
142
- function parseShopError(error) {
143
- if (error instanceof ShopError) {
144
- return error;
145
- }
146
- const errorCode = error?.code ?? error?.extensions?.code ?? error?.name ?? "";
147
- const errorMessage = typeof error === "string" ? error : error?.message ?? "";
148
- if (errorCode === "invalidMethodParameter" && errorMessage.includes("paymentMethod.create")) {
149
- return new ShopError({
150
- code: "paymentMethod.create.invalidMethodParameter",
151
- original: error
152
- }, "There was a problem validating your payment information. Please double-check the details and try again.");
153
- }
154
- if (errorMessage.includes("Invalid request: ")) {
155
- const finalError = errorMessage.split("Invalid request: ")[1].split("., ").map((e) => e.matchAll(/[A-Z_]+: (.*)/g))[0];
156
- const finalCode = finalError[1];
157
- const finalMessage = finalError[2];
158
- return new ShopError({
159
- code: `paymentMethod.${finalCode}`,
160
- original: error
161
- }, finalMessage);
162
- }
163
- if (errorCode === "insufficientFunds" || errorMessage.includes("There is not enough credit")) {
164
- return new ShopError({
165
- code: "shop.insufficientFunds",
166
- original: error
167
- }, "There is not enough money to complete the checkout. Please double-check the details and try again.");
168
- }
169
- if (errorCode === "shop.invalidBasketId" || errorCode === "shop.basketRequired" || errorCode === "shop.alreadyCheckedOut") {
170
- return new ShopError({
171
- code: errorCode,
172
- original: error
173
- }, "There was a problem with your basket. Please, refresh the page and try again.");
174
- }
175
- if (errorCode === "donationAmountTooLarge") {
176
- return new ShopError({
177
- code: errorCode,
178
- original: error
179
- }, errorMessage);
180
- }
181
- return new ShopError({
182
- code: "shop.unknown",
183
- original: error
184
- }, "An unknown error occurred.");
185
- }
186
-
187
- // src/basket.ts
188
- var import_core2 = require("@apollo/client/core/core.cjs");
189
- function getBasketID() {
190
- return getCookieValue("kvbskt");
191
- }
192
- function setBasketID(basketId) {
193
- setCookieValue("kvbskt", basketId, "path=/;secure;");
194
- }
195
- async function createBasketHelper(apollo) {
196
- try {
197
- return apollo.mutate({
198
- mutation: import_core2.gql`mutation createNewBasketForUser { shop { id createBasket } }`
199
- }).then(({ data }) => {
200
- const newBasketId = data.shop?.createBasket ?? null;
201
- if (newBasketId) {
202
- setBasketID(newBasketId);
203
- }
204
- });
205
- } catch (error) {
206
- throw parseShopError(error);
207
- }
208
- }
209
- var activeBasketCreationQuery = null;
210
- async function createBasket(apollo) {
211
- if (activeBasketCreationQuery) {
212
- return activeBasketCreationQuery;
213
- }
214
- activeBasketCreationQuery = createBasketHelper(apollo);
215
- return activeBasketCreationQuery;
216
- }
217
- function hasBasketExpired(error) {
218
- const errorCode = error?.code ?? error?.extensions?.code ?? error?.name ?? "";
219
- return ["shop.invalidBasketId", "shop.basketRequired", "shop.alreadyCheckedOut"].includes(errorCode);
220
- }
221
-
222
- // src/shopQueries.ts
223
- var watchQueries = /* @__PURE__ */ new Set();
224
- async function callShopMutation(apollo, options, maxretries = 2) {
225
- try {
226
- const result = await apollo.mutate({
227
- ...options,
228
- variables: {
229
- ...options.variables,
230
- basketId: getBasketID()
231
- },
232
- refetchQueries: options.awaitRefetchQueries ? Array.from(watchQueries) : []
233
- });
234
- if (result?.errors?.length) {
235
- const basketErrors = result?.errors.filter((err) => hasBasketExpired(err));
236
- if (basketErrors.length) {
237
- if (maxretries > 0) {
238
- await createBasket(apollo);
239
- return callShopMutation(apollo, options, maxretries - 1);
240
- }
241
- throw basketErrors[0];
242
- }
243
- if (result?.errors?.length) {
244
- throw result.errors[0];
245
- }
246
- }
247
- return result?.data;
248
- } catch (e) {
249
- throw parseShopError(e);
250
- }
251
- }
252
- async function callShopQuery(apollo, options, maxretries = 2) {
253
- try {
254
- const result = await apollo.query({
255
- ...options,
256
- variables: {
257
- ...options.variables,
258
- basketId: getBasketID()
259
- }
260
- });
261
- if (result?.errors?.length) {
262
- const basketErrors = result?.errors.filter((err) => hasBasketExpired(err));
263
- if (basketErrors.length) {
264
- if (maxretries > 0) {
265
- await createBasket(apollo);
266
- return callShopQuery(apollo, options, maxretries - 1);
267
- }
268
- throw basketErrors[0];
269
- }
270
- if (result?.errors?.length) {
271
- throw result.errors[0];
272
- }
273
- }
274
- return result?.data;
275
- } catch (e) {
276
- throw parseShopError(e);
277
- }
278
- }
279
-
280
- // src/validatePreCheckout.ts
281
- var import_core3 = require("@apollo/client/core/core.cjs");
282
- var validatePreCheckoutMutation = import_core3.gql`
283
- mutation validatePreCheckout(
284
- $basketId: String,
285
- $email: String,
286
- $visitorId: String,
287
- $emailOptIn: Boolean,
288
- $inviter: InviterInput
289
- ) {
290
- shop (basketId: $basketId) {
291
- id
292
- validatePreCheckout (email: $email, visitorId: $visitorId, emailOptIn: $emailOptIn, inviter: $inviter) {
293
- error
294
- success
295
- value
296
- }
297
- }
298
- }`;
299
- async function validatePreCheckout({
300
- apollo,
301
- emailAddress,
302
- emailOptIn,
303
- valetInviter
304
- }) {
305
- const data = await callShopMutation(apollo, {
306
- mutation: validatePreCheckoutMutation,
307
- variables: {
308
- visitorId: getVisitorID(),
309
- email: emailAddress,
310
- emailOptIn,
311
- inviter: valetInviter
312
- }
313
- }, 0);
314
- const results = data?.shop?.validatePreCheckout;
315
- const errors = results.filter(({ success }) => !success).map((result) => parseShopError(result));
316
- if (errors.length) {
317
- const aggregate = new ShopError({ code: "shop.failedCheckoutValidation" });
318
- aggregate.aggregateErrors(errors);
319
- throw aggregate;
320
- }
321
- }
322
-
323
- // src/util/redirect.ts
324
- function redirectTo(href) {
325
- return new Promise(() => {
326
- window.location.href = href;
327
- });
328
- }
329
-
330
- // src/receipt.ts
331
- var import_core4 = require("@apollo/client/core/core.cjs");
332
- async function getFTDStatus(apollo) {
333
- const result = await apollo.query({
334
- query: import_core4.gql`
335
- query ftdStatus {
336
- my {
337
- id
338
- userAccount {
339
- id
340
- isFirstTimeDepositor
341
- }
342
- }
343
- }
344
- `
345
- });
346
- return result.data?.my?.userAccount?.isFirstTimeDepositor ?? false;
347
- }
348
- async function getReceiptItems(apollo, checkoutId) {
349
- return new Promise((resolve, reject) => {
350
- const limit = 100;
351
- let offset = 0;
352
- const observer = apollo.watchQuery({
353
- query: import_core4.gql`
354
- query receiptItems($checkoutId: Int, $visitorId: String, $limit: Int, $offset: Int) {
355
- shop {
356
- id
357
- receipt(checkoutId: $checkoutId, visitorId: $visitorId) {
358
- id
359
- items(limit: $limit, offset: $offset) {
360
- totalCount
361
- values {
362
- id
363
- price
364
- __typename
365
-
366
- ... on Donation {
367
- id
368
- isTip
369
- isUserEdited
370
- }
371
- }
372
- }
373
- }
374
- }
375
- }
376
- `,
377
- variables: {
378
- checkoutId,
379
- visitorId: getVisitorID(),
380
- limit,
381
- offset
382
- }
383
- });
384
- let items = [];
385
- const handleResult = async (result) => {
386
- const total = result.data?.shop?.receipt?.items?.totalCount;
387
- items = items.concat(result.data?.shop?.receipt?.items?.values);
388
- if (total > offset + limit) {
389
- offset += limit;
390
- const nextResult = await observer.fetchMore({
391
- variables: {
392
- offset
393
- }
394
- });
395
- try {
396
- handleResult(nextResult);
397
- } catch (e) {
398
- reject(e);
399
- }
400
- } else {
401
- resolve(items);
402
- }
403
- };
404
- observer.subscribe({
405
- next: handleResult,
406
- error: (error) => {
407
- reject(error);
408
- }
409
- });
410
- });
411
- }
412
- async function getReceiptTotals(apollo, checkoutId) {
413
- const result = await apollo.query({
414
- query: import_core4.gql`
415
- query receiptTotals($checkoutId: Int, $visitorId: String) {
416
- shop {
417
- id
418
- receipt(checkoutId: $checkoutId, visitorId: $visitorId) {
419
- id
420
- totals {
421
- loanReservationTotal
422
- donationTotal
423
- kivaCardTotal
424
- itemTotal
425
- kivaCreditAppliedTotal
426
- depositTotals {
427
- depositTotal
428
- }
429
- }
430
- }
431
- }
432
- }
433
- `,
434
- variables: {
435
- checkoutId,
436
- visitorId: getVisitorID()
437
- }
438
- });
439
- return result.data?.shop?.receipt?.totals;
440
- }
441
- async function getCheckoutTrackingData(apollo, checkoutId, paymentType) {
442
- const checkoutIdInt = parseInt(checkoutId, 10);
443
- const [isFTD, items, totals] = await Promise.all([
444
- getFTDStatus(apollo),
445
- getReceiptItems(apollo, checkoutIdInt),
446
- getReceiptTotals(apollo, checkoutIdInt)
447
- ]);
448
- const loans = items.filter((item) => item.__typename === "LoanReservation");
449
- const donations = items.filter((item) => item.__typename === "Donation");
450
- const kivaCards = items.filter((item) => item.__typename === "KivaCard");
451
- return {
452
- transactionId: checkoutId,
453
- itemTotal: totals.itemTotal,
454
- // Loan reservations
455
- loans,
456
- loanCount: loans.length,
457
- loanTotal: totals.loanReservationTotal,
458
- // Donations
459
- donations: donations.map(({ id, price, __typename }) => ({ id, price, __typename })),
460
- donationTotal: totals.donationTotal,
461
- isTip: donations.every((donation) => donation.isTip),
462
- isUserEdited: donations.some((donation) => donation.isUserEdited),
463
- // Kiva Cards
464
- kivaCards,
465
- kivaCardCount: kivaCards.length,
466
- kivaCardTotal: totals.kivaCardTotal,
467
- // Credit & deposit
468
- kivaCreditAppliedTotal: totals.kivaCreditAppliedTotal,
469
- depositTotal: totals.depositTotals?.depositTotal ?? "0.00",
470
- paymentType,
471
- isFTD
472
- };
473
- }
474
-
475
- // src/oneTimeCheckout.ts
476
- async function creditAmountNeeded(apollo) {
477
- const data = await callShopQuery(apollo, {
478
- query: import_core5.gql`
479
- query creditAmountNeeded($basketId: String) {
480
- shop (basketId: $basketId) {
481
- id
482
- basket {
483
- id
484
- totals {
485
- creditAmountNeeded
486
- }
487
- }
488
- }
489
- }
490
- `,
491
- fetchPolicy: "network-only"
492
- }, 0);
493
- return data?.shop?.basket?.totals?.creditAmountNeeded;
494
- }
495
- var creditCheckoutMutation = import_core5.gql`
496
- mutation creditCheckout(
497
- $basketId: String,
498
- $visitorId: String
499
- ) {
500
- shop (basketId: $basketId) {
501
- id
502
- transactionId: checkoutAsync (visitorId: $visitorId)
503
- }
504
- }
505
- `;
506
- var depositCheckoutMutation = import_core5.gql`
507
- mutation depositCheckout(
508
- $basketId: String,
509
- $amount: Money!,
510
- $nonce: String!,
511
- $savePaymentMethod: Boolean,
512
- $deviceData: String,
513
- $visitorId: String
514
- ) {
515
- shop (basketId: $basketId) {
516
- id
517
- transactionId: doNoncePaymentDepositAndCheckoutAsync(
518
- amount: $amount,
519
- nonce: $nonce,
520
- savePaymentMethod: $savePaymentMethod,
521
- deviceData: $deviceData,
522
- visitorId: $visitorId
523
- )
524
- }
525
- }
526
- `;
527
- function creditCheckout(apollo) {
528
- return callShopMutation(apollo, {
529
- mutation: creditCheckoutMutation,
530
- variables: {
531
- visitorId: getVisitorID()
532
- }
533
- }, 0);
534
- }
535
- async function depositCheckout({
536
- apollo,
537
- braintree,
538
- amount
539
- }) {
540
- try {
541
- const paymentMethod = await braintree.requestPaymentMethod();
542
- if (!paymentMethod) {
543
- throw new ShopError(
544
- { code: "shop.dropinNoPaymentMethod" },
545
- "No payment method returned from braintree dropin"
546
- );
547
- }
548
- const { nonce, deviceData, type } = paymentMethod;
549
- return {
550
- paymentType: type,
551
- mutation: callShopMutation(apollo, {
552
- mutation: depositCheckoutMutation,
553
- variables: {
554
- nonce,
555
- amount,
556
- savePaymentMethod: false,
557
- // save payment methods handled by braintree drop in UI
558
- deviceData,
559
- visitorId: getVisitorID()
560
- }
561
- }, 0)
562
- };
563
- } catch (e) {
564
- throw parseShopError(e);
565
- }
566
- }
567
- async function trackSuccess(apollo, checkoutId, paymentType) {
568
- try {
569
- const transactionData = await getCheckoutTrackingData(
570
- apollo,
571
- checkoutId,
572
- paymentType
573
- );
574
- (0, import_kv_analytics.trackTransaction)(transactionData);
575
- await wait(800);
576
- } catch (e) {
577
- console.error("Error tracking transaction", e);
578
- }
579
- }
580
- async function executeOneTimeCheckout({
581
- apollo,
582
- braintree,
583
- emailAddress,
584
- emailOptIn,
585
- valetInviter,
586
- deactivateRedirect
587
- }) {
588
- await validatePreCheckout({
589
- apollo,
590
- emailAddress,
591
- emailOptIn,
592
- valetInviter
593
- });
594
- const creditNeeded = await creditAmountNeeded(apollo);
595
- const creditRequired = (0, import_numeral.default)(creditNeeded).value() > 0;
596
- if (creditRequired && !braintree) {
597
- throw new ShopError({ code: "shop.dropinRequired" }, "Braintree dropin required for credit deposit checkout");
598
- }
599
- let data;
600
- let paymentType = "";
601
- if (creditRequired) {
602
- const checkoutResult = await depositCheckout({
603
- apollo,
604
- braintree,
605
- amount: creditNeeded
606
- });
607
- paymentType = checkoutResult.paymentType;
608
- data = await checkoutResult.mutation;
609
- } else {
610
- data = await creditCheckout(apollo);
611
- }
612
- const transactionId = data?.shop?.transactionId;
613
- const result = await pollForFinishedCheckout({
614
- apollo,
615
- transactionSagaId: transactionId,
616
- timeout: 3e5
617
- // five minutes
618
- });
619
- if (result.errors?.length) {
620
- throw parseShopError(result.errors[0]);
621
- }
622
- const checkoutId = result.data?.checkoutStatus?.receipt?.checkoutId;
623
- await trackSuccess(apollo, checkoutId, paymentType);
624
- if (deactivateRedirect) {
625
- return result;
626
- }
627
- let redirectUrl = `/checkout/post-purchase?kiva_transaction_id=${checkoutId}`;
628
- if (valetInviter?.inviterId) {
629
- redirectUrl += `&valet_inviter=${valetInviter.inviterId}`;
630
- }
631
- await redirectTo(redirectUrl);
632
- }
633
- // Annotate the CommonJS export names for ESM import in node:
634
- 0 && (module.exports = {
635
- executeOneTimeCheckout
636
- });
@@ -1,21 +0,0 @@
1
- import { CheckoutStatusQueryResult } from './checkoutStatus.js';
2
- import { ApolloClient } from '@apollo/client/core/core.cjs';
3
- import { DropInWrapper } from './useBraintreeDropIn.js';
4
- import 'vue-demi';
5
- import 'braintree-web-drop-in';
6
-
7
- type ValetInviter = {
8
- inviterId: string;
9
- invitationUrl: string;
10
- };
11
- interface OneTimeCheckoutOptions {
12
- apollo: ApolloClient<any>;
13
- braintree?: DropInWrapper;
14
- emailAddress?: string;
15
- emailOptIn?: boolean;
16
- valetInviter?: ValetInviter;
17
- deactivateRedirect?: boolean;
18
- }
19
- declare function executeOneTimeCheckout({ apollo, braintree, emailAddress, emailOptIn, valetInviter, deactivateRedirect, }: OneTimeCheckoutOptions): Promise<CheckoutStatusQueryResult>;
20
-
21
- export { OneTimeCheckoutOptions, ValetInviter, executeOneTimeCheckout };