@kiva/kv-shop 3.1.1 → 3.2.0
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.
- package/dist/index.d.ts +4 -4
- package/dist/oneTimeCheckout.js +73 -71
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -114,7 +114,7 @@ export declare function executeNewSubscriptionCheckout({ amount, apollo, dayOfMo
|
|
|
114
114
|
|
|
115
115
|
export declare function executeOneTimeCheckout({ apollo, braintree, emailAddress, emailOptIn, valetInviter, deactivateRedirect, }: OneTimeCheckoutOptions): Promise<CheckoutStatusQueryResult>;
|
|
116
116
|
|
|
117
|
-
export declare function executeOneTimeCheckoutForGivingFund({ amount, apollo, braintree, emailAddress, emailOptIn, fundTarget, userId, }: OneTimeCheckoutForGivingFundOptions): Promise<CheckoutStatusQueryResult>;
|
|
117
|
+
export declare function executeOneTimeCheckoutForGivingFund({ amount, apollo, braintree, emailAddress, emailOptIn, fundTarget, userId, useKivaCredit, }: OneTimeCheckoutForGivingFundOptions): Promise<CheckoutStatusQueryResult>;
|
|
118
118
|
|
|
119
119
|
export declare function getBasketID(): string;
|
|
120
120
|
|
|
@@ -144,14 +144,14 @@ export declare function isBasketVerified(state: VerificationState): boolean;
|
|
|
144
144
|
export { KvPaymentSelect }
|
|
145
145
|
|
|
146
146
|
export declare interface OneTimeCheckoutForGivingFundOptions {
|
|
147
|
+
amount: string;
|
|
147
148
|
apollo: ApolloClient<any>;
|
|
148
149
|
braintree?: DropInWrapper;
|
|
149
150
|
emailAddress?: string;
|
|
150
151
|
emailOptIn?: boolean;
|
|
151
|
-
userId?: string;
|
|
152
152
|
fundTarget: string;
|
|
153
|
-
|
|
154
|
-
|
|
153
|
+
userId?: string;
|
|
154
|
+
useKivaCredit?: boolean;
|
|
155
155
|
}
|
|
156
156
|
|
|
157
157
|
export declare interface OneTimeCheckoutOptions {
|
package/dist/oneTimeCheckout.js
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
import { gql as $ } from "@apollo/client/core";
|
|
2
|
-
import { trackTransaction as
|
|
3
|
-
import
|
|
4
|
-
import { pollForFinishedCheckout as
|
|
2
|
+
import { trackTransaction as x } from "@kiva/kv-analytics";
|
|
3
|
+
import T from "numeral";
|
|
4
|
+
import { pollForFinishedCheckout as q } from "./checkoutStatus.js";
|
|
5
5
|
import { ShopError as v, parseShopError as S } from "./shopError.js";
|
|
6
|
-
import { callShopQuery as
|
|
7
|
-
import { validatePreCheckout as
|
|
8
|
-
import { wait as
|
|
9
|
-
import { getVisitorID as
|
|
10
|
-
import { redirectTo as
|
|
11
|
-
import { getCheckoutTrackingData as
|
|
12
|
-
import { addGivingFund as
|
|
13
|
-
import { setTipDonation as
|
|
14
|
-
|
|
6
|
+
import { callShopQuery as B, callShopMutation as D } from "./shopQueries.js";
|
|
7
|
+
import { validatePreCheckout as N } from "./validatePreCheckout.js";
|
|
8
|
+
import { wait as E } from "./util/poll.js";
|
|
9
|
+
import { getVisitorID as P } from "./util/visitorId.js";
|
|
10
|
+
import { redirectTo as _ } from "./util/redirect.js";
|
|
11
|
+
import { getCheckoutTrackingData as G } from "./receipt.js";
|
|
12
|
+
import { addGivingFund as O } from "./givingFunds.js";
|
|
13
|
+
import { setTipDonation as K } from "./basketItems.js";
|
|
14
|
+
import { removeKivaCredit as Q } from "./basketCredits.js";
|
|
15
|
+
async function R(e) {
|
|
15
16
|
var r, o, i;
|
|
16
|
-
const t = await
|
|
17
|
+
const t = await B(e, {
|
|
17
18
|
query: $`
|
|
18
19
|
query creditAmountNeeded($basketId: String) {
|
|
19
20
|
shop (basketId: $basketId) {
|
|
@@ -31,7 +32,7 @@ async function P(e) {
|
|
|
31
32
|
}, 0);
|
|
32
33
|
return (i = (o = (r = t == null ? void 0 : t.shop) == null ? void 0 : r.basket) == null ? void 0 : o.totals) == null ? void 0 : i.creditAmountNeeded;
|
|
33
34
|
}
|
|
34
|
-
const
|
|
35
|
+
const U = $`
|
|
35
36
|
mutation creditCheckout(
|
|
36
37
|
$basketId: String,
|
|
37
38
|
$visitorId: String
|
|
@@ -41,7 +42,7 @@ const Q = $`
|
|
|
41
42
|
transactionId: checkoutAsync (visitorId: $visitorId)
|
|
42
43
|
}
|
|
43
44
|
}
|
|
44
|
-
`,
|
|
45
|
+
`, V = $`
|
|
45
46
|
mutation depositCheckout(
|
|
46
47
|
$basketId: String,
|
|
47
48
|
$amount: Money!,
|
|
@@ -62,15 +63,15 @@ const Q = $`
|
|
|
62
63
|
}
|
|
63
64
|
}
|
|
64
65
|
`;
|
|
65
|
-
function
|
|
66
|
-
return
|
|
67
|
-
mutation:
|
|
66
|
+
function A(e) {
|
|
67
|
+
return D(e, {
|
|
68
|
+
mutation: U,
|
|
68
69
|
variables: {
|
|
69
|
-
visitorId:
|
|
70
|
+
visitorId: P()
|
|
70
71
|
}
|
|
71
72
|
}, 0);
|
|
72
73
|
}
|
|
73
|
-
async function
|
|
74
|
+
async function F({
|
|
74
75
|
apollo: e,
|
|
75
76
|
braintree: t,
|
|
76
77
|
amount: r
|
|
@@ -82,18 +83,18 @@ async function l({
|
|
|
82
83
|
{ code: "shop.dropinNoPaymentMethod" },
|
|
83
84
|
"No payment method returned from braintree dropin"
|
|
84
85
|
);
|
|
85
|
-
const { nonce: i, deviceData:
|
|
86
|
+
const { nonce: i, deviceData: u, type: a } = o;
|
|
86
87
|
return {
|
|
87
88
|
paymentType: a,
|
|
88
|
-
mutation:
|
|
89
|
-
mutation:
|
|
89
|
+
mutation: D(e, {
|
|
90
|
+
mutation: V,
|
|
90
91
|
variables: {
|
|
91
92
|
nonce: i,
|
|
92
93
|
amount: r,
|
|
93
94
|
savePaymentMethod: !1,
|
|
94
95
|
// save payment methods handled by braintree drop in UI
|
|
95
|
-
deviceData:
|
|
96
|
-
visitorId:
|
|
96
|
+
deviceData: u,
|
|
97
|
+
visitorId: P()
|
|
97
98
|
}
|
|
98
99
|
}, 0)
|
|
99
100
|
};
|
|
@@ -101,110 +102,111 @@ async function l({
|
|
|
101
102
|
throw S(o);
|
|
102
103
|
}
|
|
103
104
|
}
|
|
104
|
-
async function
|
|
105
|
+
async function l(e, t, r) {
|
|
105
106
|
try {
|
|
106
|
-
const o = await
|
|
107
|
+
const o = await G(
|
|
107
108
|
e,
|
|
108
109
|
t,
|
|
109
110
|
r
|
|
110
111
|
);
|
|
111
|
-
|
|
112
|
+
x(o), await E(800);
|
|
112
113
|
} catch (o) {
|
|
113
114
|
console.error("Error tracking transaction", o);
|
|
114
115
|
}
|
|
115
116
|
}
|
|
116
|
-
async function
|
|
117
|
+
async function nt({
|
|
117
118
|
apollo: e,
|
|
118
119
|
braintree: t,
|
|
119
120
|
emailAddress: r,
|
|
120
121
|
emailOptIn: o,
|
|
121
122
|
valetInviter: i,
|
|
122
|
-
deactivateRedirect:
|
|
123
|
+
deactivateRedirect: u
|
|
123
124
|
}) {
|
|
124
|
-
var d,
|
|
125
|
-
await
|
|
125
|
+
var I, d, g, h, p;
|
|
126
|
+
await N({
|
|
126
127
|
apollo: e,
|
|
127
128
|
emailAddress: r,
|
|
128
129
|
emailOptIn: o,
|
|
129
130
|
valetInviter: i
|
|
130
131
|
});
|
|
131
|
-
const a = await
|
|
132
|
-
if (
|
|
132
|
+
const a = await R(e), f = T(a).value() > 0;
|
|
133
|
+
if (f && !t)
|
|
133
134
|
throw new v({ code: "shop.dropinRequired" }, "Braintree dropin required for credit deposit checkout");
|
|
134
|
-
let
|
|
135
|
-
if (
|
|
136
|
-
const
|
|
135
|
+
let s, y = "";
|
|
136
|
+
if (f) {
|
|
137
|
+
const k = await F({
|
|
137
138
|
apollo: e,
|
|
138
139
|
braintree: t,
|
|
139
140
|
amount: a
|
|
140
141
|
});
|
|
141
|
-
|
|
142
|
+
y = k.paymentType, s = await k.mutation;
|
|
142
143
|
} else
|
|
143
|
-
|
|
144
|
-
const
|
|
144
|
+
s = await A(e);
|
|
145
|
+
const w = (I = s == null ? void 0 : s.shop) == null ? void 0 : I.transactionId, c = await q({
|
|
145
146
|
apollo: e,
|
|
146
|
-
transactionSagaId:
|
|
147
|
+
transactionSagaId: w,
|
|
147
148
|
timeout: 3e5
|
|
148
149
|
// five minutes
|
|
149
150
|
});
|
|
150
|
-
if ((
|
|
151
|
-
throw S(
|
|
152
|
-
const
|
|
153
|
-
if (await
|
|
154
|
-
return
|
|
155
|
-
let
|
|
156
|
-
i != null && i.inviterId && (
|
|
151
|
+
if ((d = c.errors) != null && d.length)
|
|
152
|
+
throw S(c.errors[0]);
|
|
153
|
+
const n = (p = (h = (g = c.data) == null ? void 0 : g.checkoutStatus) == null ? void 0 : h.receipt) == null ? void 0 : p.checkoutId;
|
|
154
|
+
if (await l(e, n, y), u)
|
|
155
|
+
return c;
|
|
156
|
+
let m = `/checkout/post-purchase?kiva_transaction_id=${n}`;
|
|
157
|
+
i != null && i.inviterId && (m += `&valet_inviter=${i.inviterId}`), await _(m);
|
|
157
158
|
}
|
|
158
|
-
async function
|
|
159
|
+
async function at({
|
|
159
160
|
amount: e,
|
|
160
161
|
apollo: t,
|
|
161
162
|
braintree: r,
|
|
162
163
|
emailAddress: o,
|
|
163
164
|
emailOptIn: i,
|
|
164
|
-
fundTarget:
|
|
165
|
-
userId: a
|
|
165
|
+
fundTarget: u,
|
|
166
|
+
userId: a,
|
|
167
|
+
useKivaCredit: f = !0
|
|
166
168
|
}) {
|
|
167
|
-
var h, p, k,
|
|
168
|
-
await
|
|
169
|
+
var h, p, k, C, b;
|
|
170
|
+
await N({
|
|
169
171
|
apollo: t,
|
|
170
172
|
emailAddress: o,
|
|
171
173
|
emailOptIn: i
|
|
172
174
|
});
|
|
173
|
-
const
|
|
175
|
+
const y = `campaignId: ${(await O({
|
|
174
176
|
apollo: t,
|
|
175
|
-
fundTarget:
|
|
177
|
+
fundTarget: u,
|
|
176
178
|
userId: a ? `${a}` : void 0
|
|
177
179
|
})).id}`;
|
|
178
|
-
await
|
|
180
|
+
await K({
|
|
179
181
|
amount: e,
|
|
180
|
-
metadata:
|
|
182
|
+
metadata: y,
|
|
181
183
|
apollo: t
|
|
182
|
-
});
|
|
183
|
-
const
|
|
184
|
-
if (
|
|
184
|
+
}), f || await Q(t);
|
|
185
|
+
const w = await R(t), c = T(w).value() > 0;
|
|
186
|
+
if (c && !r)
|
|
185
187
|
throw new v({ code: "shop.dropinRequired" }, "Braintree dropin required for credit deposit checkout");
|
|
186
188
|
let n, m = "";
|
|
187
|
-
if (
|
|
188
|
-
const
|
|
189
|
+
if (c) {
|
|
190
|
+
const M = await F({
|
|
189
191
|
apollo: t,
|
|
190
192
|
braintree: r,
|
|
191
|
-
amount:
|
|
193
|
+
amount: w
|
|
192
194
|
});
|
|
193
|
-
m =
|
|
195
|
+
m = M.paymentType, n = await M.mutation;
|
|
194
196
|
} else
|
|
195
|
-
n = await
|
|
196
|
-
const
|
|
197
|
+
n = await A(t);
|
|
198
|
+
const I = (h = n == null ? void 0 : n.shop) == null ? void 0 : h.transactionId, d = await q({
|
|
197
199
|
apollo: t,
|
|
198
|
-
transactionSagaId:
|
|
200
|
+
transactionSagaId: I,
|
|
199
201
|
timeout: 3e5
|
|
200
202
|
// five minutes
|
|
201
203
|
});
|
|
202
204
|
if ((p = d.errors) != null && p.length)
|
|
203
205
|
throw S(d.errors[0]);
|
|
204
|
-
const
|
|
205
|
-
return await
|
|
206
|
+
const g = (b = (C = (k = d.data) == null ? void 0 : k.checkoutStatus) == null ? void 0 : C.receipt) == null ? void 0 : b.checkoutId;
|
|
207
|
+
return await l(t, g, m), d;
|
|
206
208
|
}
|
|
207
209
|
export {
|
|
208
|
-
|
|
209
|
-
|
|
210
|
+
nt as executeOneTimeCheckout,
|
|
211
|
+
at as executeOneTimeCheckoutForGivingFund
|
|
210
212
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kiva/kv-shop",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.2.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@apollo/client": "^3.13.1",
|
|
28
28
|
"@kiva/kv-analytics": "^1.3.0",
|
|
29
|
-
"@kiva/kv-components": "^6.
|
|
29
|
+
"@kiva/kv-components": "^6.40.0",
|
|
30
30
|
"@kiva/vite-plugin-vue-lib-css": "^2.0.0",
|
|
31
31
|
"@types/braintree-web-drop-in": "^1.39.3",
|
|
32
32
|
"@types/jest": "^29.5.14",
|
|
@@ -55,5 +55,5 @@
|
|
|
55
55
|
"numeral": "2.x",
|
|
56
56
|
"vue": "3.x"
|
|
57
57
|
},
|
|
58
|
-
"gitHead": "
|
|
58
|
+
"gitHead": "07d41069c31f0c897a5bb17149e8ae31e338cb21"
|
|
59
59
|
}
|