monegasy-js
v1.0.6
Published
SDK JavaScript officiel pour intégrer les paiements Monegasy
Maintainers
Readme
Monegasy Payment SDK
SDK JavaScript officiel pour intégrer les paiements Monegasy à votre application web.
📦 Installation
npm install monegasy-jsOu avec Yarn:
yarn add monegasy-jsOu via CDN:
<!-- CDN Monegasy (recommandé) -->
<script src="https://cdn.monegasy.com/v1/monegasy-sdk.umd.min.js"></script>
<!-- Ou via jsDelivr -->
<script src="https://cdn.jsdelivr.net/npm/monegasy-js@latest/dist/monegasy-sdk.umd.min.js"></script>
<!-- Ou via unpkg -->
<script src="https://unpkg.com/monegasy-js@latest/dist/monegasy-sdk.umd.min.js"></script>🚀 Démarrage Rapide
1. Initialiser le SDK
import MonegasySDK from "monegasy-js";
const monegasy = new MonegasySDK({
apiKey: "YOUR_API_KEY",
sandbox: false, // true pour le mode test
});2. Créer un bouton de paiement
await monegasy.renderPaymentButton(
{
amount: 50000,
description: "iPhone 15 Pro",
buttonText: "Payer avec Monegasy",
onSuccess: (payment) => {
console.log("Paiement réussi!", payment);
},
},
"#payment-button"
);📚 Documentation
Configuration
interface MonegasyConfig {
apiKey: string; // Clé API (requis)
baseURL?: string; // URL de l'API (optionnel)
webURL?: string; // URL de la page de paiement (optionnel)
sandbox?: boolean; // Mode test (optionnel)
}Méthodes
createPaymentLink()
Crée un lien de paiement unique.
const payment = await monegasy.createPaymentLink({
amount: 50000, // Montant en Ariary (requis)
description: "Description", // Description (requis)
productName: "Produit", // Nom du produit (optionnel)
productImage: "https://...", // URL image (optionnel)
metadata: { key: "value" }, // Données custom (optionnel)
successUrl: "https://...", // URL succès (optionnel)
cancelUrl: "https://...", // URL annulation (optionnel)
webhookUrl: "https://...", // URL webhook (optionnel)
expiresInHours: 24, // Expiration en heures (défaut: 24)
});
console.log(payment.paymentUrl); // URL de paiement web
console.log(payment.mobileDeepLink); // Deep link mobilegetPaymentLink()
Récupère les détails d'un paiement.
const payment = await monegasy.getPaymentLink("pl_abc123");
console.log(payment.status); // "pending" | "paid" | "expired" | "cancelled"openPaymentPopup()
Ouvre le paiement dans une popup.
const popup = monegasy.openPaymentPopup("pl_abc123", {
width: 500,
height: 700,
});redirectToPayment()
Redirige vers la page de paiement.
monegasy.redirectToPayment("pl_abc123");renderPaymentButton()
Crée et affiche un bouton de paiement.
await monegasy.renderPaymentButton(
{
amount: 50000,
description: "Achat produit",
buttonText: "Payer maintenant",
buttonStyle: {
background: "linear-gradient(to right, #2563eb, #9333ea)",
borderRadius: "12px",
},
onSuccess: (payment) => {
console.log("✅ Paiement réussi!", payment);
},
onError: (error) => {
console.error("❌ Erreur:", error);
},
onCancel: () => {
console.log("ℹ️ Paiement annulé");
},
},
"#payment-container"
);🌐 Utilisation avec Frameworks
React
import { useEffect } from "react";
import MonegasySDK from "monegasy-js";
function PaymentButton({ amount, productName }) {
useEffect(() => {
const monegasy = new MonegasySDK({
apiKey: process.env.REACT_APP_MONEGASY_API_KEY,
sandbox: false,
});
monegasy.renderPaymentButton(
{
amount,
description: `Achat ${productName}`,
productName,
onSuccess: (payment) => {
window.location.href = `/success?id=${payment.linkId}`;
},
},
"#monegasy-button"
);
}, [amount, productName]);
return <div id="monegasy-button"></div>;
}Vue.js
<template>
<div ref="paymentButton"></div>
</template>
<script>
import { onMounted, ref } from "vue";
import MonegasySDK from "monegasy-js";
export default {
props: ["amount", "productName"],
setup(props) {
const paymentButton = ref(null);
onMounted(() => {
const monegasy = new MonegasySDK({
apiKey: import.meta.env.VITE_MONEGASY_API_KEY,
sandbox: false,
});
monegasy.renderPaymentButton(
{
amount: props.amount,
description: `Achat ${props.productName}`,
productName: props.productName,
},
paymentButton.value
);
});
return { paymentButton };
},
};
</script>Next.js
"use client";
import { useEffect } from "react";
import MonegasySDK from "monegasy-js";
export default function PaymentButton({ amount, productName }) {
useEffect(() => {
const monegasy = new MonegasySDK({
apiKey: process.env.NEXT_PUBLIC_MONEGASY_API_KEY!,
sandbox: false,
});
monegasy.renderPaymentButton(
{
amount,
description: `Achat ${productName}`,
onSuccess: (payment) => {
window.location.href = `/success?id=${payment.linkId}`;
},
},
"#monegasy-button"
);
}, [amount, productName]);
return <div id="monegasy-button"></div>;
}🔒 Sécurité
- Ne jamais exposer votre clé API publiquement
- Utilisez des variables d'environnement
- Validez toujours les montants côté serveur
📖 Documentation Complète
Pour plus d'informations, consultez :
🐛 Support
- Email: [email protected]
- GitHub: Issues
- Discord: Communauté Monegasy
📝 Licence
MIT © Monegasy
Fait avec ❤️ à Madagascar 🇲🇬
