Resolve dependency * @param {object} manifest * @returns {Promise } has error
(manifest)
| 440 | * @returns {Promise<boolean>} has error |
| 441 | */ |
| 442 | async function resolveDep(manifest) { |
| 443 | let purchaseToken; |
| 444 | let product; |
| 445 | let isPaid = false; |
| 446 | |
| 447 | isPaid = manifest.price > 0; |
| 448 | [product] = await helpers.promisify(iap.getProducts, [manifest.sku]); |
| 449 | if (product) { |
| 450 | const purchase = await getPurchase(product.productId); |
| 451 | purchaseToken = purchase?.purchaseToken; |
| 452 | } |
| 453 | |
| 454 | if (isPaid && !purchaseToken) { |
| 455 | if (!product) throw new Error("Product not found"); |
| 456 | const apiStatus = await helpers.checkAPIStatus(); |
| 457 | |
| 458 | if (!apiStatus) { |
| 459 | alert(strings.error, strings.api_error); |
| 460 | return true; |
| 461 | } |
| 462 | |
| 463 | iap.setPurchaseUpdatedListener(...purchaseListener(onpurchase, onerror)); |
| 464 | loaderDialog.setMessage(strings["loading..."]); |
| 465 | await helpers.promisify(iap.purchase, product.productId); |
| 466 | |
| 467 | async function onpurchase(e) { |
| 468 | const purchase = await getPurchase(product.productId); |
| 469 | await fetch(Url.join(config.API_BASE, "plugin/order"), { |
| 470 | method: "POST", |
| 471 | body: JSON.stringify({ |
| 472 | id: manifest.id, |
| 473 | token: purchase?.purchaseToken, |
| 474 | package: BuildInfo.packageName, |
| 475 | }), |
| 476 | }); |
| 477 | purchaseToken = purchase?.purchaseToken; |
| 478 | } |
| 479 | |
| 480 | async function onerror(error) { |
| 481 | throw error; |
| 482 | } |
| 483 | } |
| 484 | |
| 485 | loaderDialog.setMessage( |
| 486 | `${strings.installing.replace("...", "")} ${manifest.name}...`, |
| 487 | ); |
| 488 | await installPlugin(manifest.id, undefined, purchaseToken, true); |
| 489 | |
| 490 | async function getPurchase(sku) { |
| 491 | const purchases = await helpers.promisify(iap.getPurchases); |
| 492 | const purchase = purchases.find((p) => p.productIds.includes(sku)); |
| 493 | return purchase; |
| 494 | } |
| 495 | } |
| 496 | |
| 497 | /** |
| 498 | * |
no test coverage detected