MCPcopy Create free account
hub / github.com/Acode-Foundation/Acode / refund

Function refund

src/pages/plugin/plugin.js:344–410  ·  view source on GitHub ↗
(e)

Source from the content-addressed store, hash-verified

342 }
343
344 async function refund(e) {
345 const $button = e.target;
346 const oldText = $button.textContent;
347
348 if (helpers.shouldAllowExternalPurchase()) {
349 await customTab(`${config.BASE_URL}/plugin/${id}?callback=app`);
350
351 if (!refundHandlerSet) {
352 refundHandlerSet = true;
353 const handler = ({ module, action, value }) => {
354 if (module === "plugin" && action === "uninstall" && value === id) {
355 purchased = false;
356
357 if (installed) {
358 uninstall();
359 } else {
360 render();
361 }
362
363 refundHandlerSet = false;
364 removeIntentHandler(handler);
365 }
366 };
367
368 addIntentHandler(handler);
369 cleanups.push(() => removeIntentHandler(handler));
370 }
371 return;
372 }
373
374 try {
375 if (!product) throw new Error("Product not found");
376 $button.textContent = strings["loading..."];
377 const res = await fetch(Url.join(config.API_BASE, "plugin/refund"), {
378 method: "POST",
379 body: JSON.stringify({
380 id: plugin.id,
381 package: BuildInfo.packageName,
382 token: purchaseToken,
383 }),
384 });
385
386 if (!res.ok) {
387 throw new Error("Failed to fetch refund");
388 }
389
390 const { refer, refunded, error } = await res.json();
391 if (refer) {
392 system.openInBrowser(refer);
393 return;
394 }
395
396 if (refunded) {
397 toast(strings.success);
398 if (installed) uninstall();
399 else render();
400 return;
401 }

Callers

nothing calls this directly

Calls 8

addIntentHandlerFunction · 0.90
removeIntentHandlerFunction · 0.90
customTabFunction · 0.85
logMethod · 0.80
uninstallFunction · 0.70
renderFunction · 0.70
openInBrowserMethod · 0.65
errorMethod · 0.45

Tested by

no test coverage detected