Skip to content

Commit

Permalink
Merge pull request #9 from JoseLuisGJ/enabling-figma-payment
Browse files Browse the repository at this point in the history
Enabling figma payment
  • Loading branch information
JoseLuisGJ authored Jan 12, 2024
2 parents bf88d42 + c1f6249 commit 2715500
Show file tree
Hide file tree
Showing 6 changed files with 121,359 additions and 40 deletions.
290 changes: 289 additions & 1 deletion dist/code.js

Large diffs are not rendered by default.

60,543 changes: 60,516 additions & 27 deletions dist/ui.html

Large diffs are not rendered by default.

60,509 changes: 60,499 additions & 10 deletions dist/ui.js

Large diffs are not rendered by default.

14 changes: 13 additions & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,17 @@
"ui": "dist/ui.html",
"editorType": [
"figma","figjam"
]
],
"permissions": ["payments"],
"networkAccess": {
"allowedDomains": [
"https://api.mapbox.com",
"https://events.mapbox.com/",
"https://bam.eu01.nr-data.net",
"https://js-agent.newrelic.com",
"https://api-js.mixpanel.com",
"https://fonts.googleapis.com",
"https://fonts.gstatic.com"
]
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"viewport-mercator-project": "^7.0.1"
},
"devDependencies": {
"@figma/plugin-typings": "^1.33.0",
"@figma/plugin-typings": "^1.80.0",
"@types/react": "^16.9.35",
"@types/react-dom": "^16.9.8",
"bootstrap": "^4.5.2",
Expand Down
41 changes: 41 additions & 0 deletions src/plugin/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,3 +186,44 @@ figma.ui.onmessage = msg => {
});
}
};
///////////////////
// Figma payment //
///////////////////

// Force payment status to be unpaid for development
type _PaymentStatus = {
type: "UNPAID" | "PAID";
};
const paymentStatus: _PaymentStatus = { type: "UNPAID" };
figma.payments.setPaymentStatusInDevelopment(paymentStatus);
//
async function runPaymentDetect() {
if (figma.payments.status.type === "UNPAID") {
const usageCount = (await figma.clientStorage.getAsync("usage-count")) || 0;
const maxUsages = 15;
if (usageCount >= maxUsages) {
await figma.payments.initiateCheckoutAsync({
interstitial: "TRIAL_ENDED"
});
if (figma.payments.status.type === "UNPAID") {
figma.notify(
"You have run out of free usages of this plugin. Buy me a ☕️ to continue using it.",
{
timeout: 6000
}
);
figma.closePlugin();
return;
} else {
figma.notify("🎉 Thanks for purchasing it.");
}
} else {
await figma.clientStorage.setAsync("usage-count", usageCount + 1);
figma.notify("ℹ️ " + usageCount + "/" + maxUsages + " free trials.", {
timeout: 6000
});
}
}
}

runPaymentDetect();

0 comments on commit 2715500

Please sign in to comment.