|
45 | 45 | <button id="toggle-receipts">Toggle receipts</button> |
46 | 46 | <button id="clear-updates">Clear updates</button> |
47 | 47 | <button id="toggle-plans">Toggle plans</button> |
48 | | - <button id="toggle-editable-perms">Toggle Editable Permissions</button> |
| 48 | + <button id="toggle-prefilled-email">Toggle pre-filled email</button> |
| 49 | + <button id="toggle-edit-payment-method">Toggle edit payment method</button> |
| 50 | + |
| 51 | + <br> |
| 52 | + <input type="checkbox" id="force-successful-requests" name="force-successful-requests"> |
| 53 | + <label for="force-successful-requests">Force successful requests</label> |
49 | 54 |
|
50 | 55 | <p id="interaction-status-area" style="min-height: 50px;margin: 10px;"></p> |
51 | 56 | </div> |
|
59 | 64 | max-width: 800px; |
60 | 65 | } |
61 | 66 | </style> |
62 | | - <ia-monthly-giving-circle canEdit></ia-monthly-giving-circle> |
| 67 | + <ia-monthly-giving-circle |
| 68 | + canEditPaymentMethod |
| 69 | + braintreeAuthToken="sandbox_x634jsj7_7zybks4ybp63pbmd" |
| 70 | + ></ia-monthly-giving-circle> |
63 | 71 | </div> |
64 | 72 |
|
65 | 73 | <script type="module" src="../dist/src/monthly-giving-circle.js"></script> |
66 | 74 | <script type="module"> |
| 75 | + import { PaymentClients, HostingEnvironment } from '@internetarchive/donation-form'; |
| 76 | + import { LazyLoaderService } from 'https://esm.archive.org/@internetarchive/lazy-loader-service'; |
67 | 77 | import { MonthlyPlan, Receipt } from '../dist/index.js'; |
68 | 78 |
|
69 | 79 | let updateNotices = []; |
|
256 | 266 | }), |
257 | 267 | ]; |
258 | 268 |
|
| 269 | + const paymentConfig = { |
| 270 | + referrer: '', |
| 271 | + origin: '', |
| 272 | + braintreeAuthToken: 'sandbox_x634jsj7_7zybks4ybp63pbmd', |
| 273 | + venmoProfileId: '1953896702662410263', |
| 274 | + googlePayMerchantId: '', |
| 275 | + environment: 'dev', |
| 276 | + paymentClients: new PaymentClients( |
| 277 | + new LazyLoaderService(), |
| 278 | + HostingEnvironment.Development, |
| 279 | + ), |
| 280 | + endpointManager: { |
| 281 | + // eslint-disable-next-line arrow-body-style, @typescript-eslint/no-unused-vars |
| 282 | + submitData: async (_request) => { |
| 283 | + // eslint-disable-next-line no-debugger |
| 284 | + debugger; |
| 285 | + }, |
| 286 | + // eslint-disable-next-line @typescript-eslint/no-unused-vars |
| 287 | + donationSuccessful: (_response) => { |
| 288 | + // eslint-disable-next-line no-debugger |
| 289 | + debugger; |
| 290 | + }, |
| 291 | + }, |
| 292 | + }; |
| 293 | + |
259 | 294 |
|
260 | 295 | let showReceipts = true; |
261 | 296 |
|
262 | 297 | const uxMessageInfoArea = document.getElementById('interaction-status-area'); |
263 | 298 | const coinFlip = () => Math.floor(Math.random() + 0.5); |
264 | 299 |
|
| 300 | + const flipCoin = () => { |
| 301 | + const forceSuccess = document.getElementById('force-successful-requests').checked; |
| 302 | + if (forceSuccess) { |
| 303 | + return 1; |
| 304 | + } |
| 305 | + return coinFlip(); |
| 306 | + } |
| 307 | + |
265 | 308 | const mgcComponent = document.querySelector('ia-monthly-giving-circle'); |
266 | 309 |
|
267 | 310 | // load start data |
| 311 | + mgcComponent.paymentConfig = paymentConfig; |
268 | 312 | mgcComponent.receipts = receiptsData; |
269 | 313 | mgcComponent.plans = plansArray; |
270 | 314 |
|
271 | 315 | // event handlers |
272 | 316 | mgcComponent.addEventListener('EmailReceiptRequest', (e) => { |
273 | 317 |
|
274 | 318 | const { donation } = e.detail; |
275 | | - const heads = coinFlip() === 1; |
| 319 | + const heads = flipCoin() === 1; |
276 | 320 | const successOrFail = heads ? 'success' : 'fail'; |
277 | 321 | const returnTiming = heads ? 1500 : 5000; |
278 | 322 |
|
|
314 | 358 | const { plan, amountOptions } = e.detail; |
315 | 359 |
|
316 | 360 | // either error or succeed |
317 | | - const heads = coinFlip() === 1; |
| 361 | + const heads = flipCoin() === 1; |
318 | 362 | const successOrFail = heads ? 'success' : 'fail'; |
319 | 363 | const returnTiming = heads ? 1500 : 5000; |
320 | 364 |
|
|
348 | 392 | const { newDate, plan } = e.detail; |
349 | 393 |
|
350 | 394 |
|
351 | | - const heads = coinFlip() === 1; |
| 395 | + const heads = flipCoin() === 1; |
352 | 396 | const successOrFail = heads ? 'success' : 'fail'; |
353 | 397 | const returnTiming = heads ? 1500 : 5000; |
354 | 398 |
|
|
378 | 422 | }, returnTiming); |
379 | 423 | }); |
380 | 424 |
|
| 425 | + mgcComponent.addEventListener('UpdatePaymentMethod', (e) => { |
| 426 | + const { plan, newPaymentMethodRequest } = e.detail; |
| 427 | + |
| 428 | + |
| 429 | + const heads = flipCoin() === 1; |
| 430 | + const successOrFail = heads ? 'success' : 'fail'; |
| 431 | + const returnTiming = heads ? 1500 : 4000; |
| 432 | + |
| 433 | + uxMessageInfoArea.innerText = `Updating payment method for plan: ${plan ? plan.id : 'no plan'} -- Update will return ${successOrFail} in ${returnTiming} ms`; |
| 434 | + const message = successOrFail === 'success' ? 'Payment method updated' : 'Payment method failed to update'; |
| 435 | + |
| 436 | + if (heads && plan) { |
| 437 | + console.log('demo - setting new payment method', newPaymentMethodRequest); |
| 438 | + plan.setNewPaymentMethod(newPaymentMethodRequest); |
| 439 | + } |
| 440 | + |
| 441 | + const update = { |
| 442 | + message, |
| 443 | + status: successOrFail, |
| 444 | + plan, |
| 445 | + donationId: plan ? plan.id : null, |
| 446 | + action: 'paymentMethodUpdate' |
| 447 | + }; |
| 448 | + |
| 449 | + updateNotices = [update, ...updateNotices]; |
| 450 | + |
| 451 | + setTimeout(() => { |
| 452 | + mgcComponent.updateReceived(update); |
| 453 | + console.log('Amount Update Request --- index.html ----', update); |
| 454 | + uxMessageInfoArea.innerText = ''; |
| 455 | + }, returnTiming); |
| 456 | + }); |
| 457 | + |
381 | 458 | // options hooks |
382 | 459 | document.getElementById('toggle-receipts').addEventListener('click', async () => { |
383 | 460 | if (showReceipts) { |
|
396 | 473 | await mgcComponent.updateComplete; |
397 | 474 | }); |
398 | 475 | document.getElementById('toggle-plans').addEventListener('click', async () => { |
399 | | - mgcComponent.plans = mgcComponent.plans.length ? [] : plansArray; |
| 476 | + mgcComponent.plans = mgcComponent.plans .length ? [] : plansArray; |
400 | 477 | await mgcComponent.updateComplete; |
401 | 478 | }); |
402 | 479 |
|
403 | | - document.getElementById('toggle-editable-perms').addEventListener('click', async () => { |
404 | | - mgcComponent.canEdit = !mgcComponent.canEdit; |
| 480 | + document.getElementById('toggle-prefilled-email').addEventListener('click', async () => { |
| 481 | + mgcComponent.patronEmail = mgcComponent.patronEmail ? '' : 'you@thisemail.com'; |
| 482 | + await mgcComponent.updateComplete; |
| 483 | + }); |
| 484 | + |
| 485 | + document.getElementById('toggle-edit-payment-method').addEventListener('click', async () => { |
| 486 | + mgcComponent.canEditPaymentMethod = !mgcComponent.canEditPaymentMethod; |
405 | 487 | await mgcComponent.updateComplete; |
406 | 488 | }); |
407 | 489 | </script> |
|
0 commit comments