Bibliothèques SDK
SDK NPM
Installez le SDK officiel MakePay JavaScript et TypeScript pour les liens de paiement, la configuration et la vérification des webhooks.
MakePay NPM SDK
Aperçu
Le MakePay npm SDK est une bibliothèque typée JavaScript et TypeScript pour les intégrations MakePay côté serveur. Il englobe l'authentification par clé API, les opérations de lien de paiement hébergées, les paramètres MakePay et la vérification signée webhook.
Emballer:
@makecrypto/makepay
Installation
npm install @makecrypto/makepay
pnpm add @makecrypto/makepay
Le SDK cible Node.js 18 ou version ultérieure et utilise l'implémentation d'exécution fetch.
Authentification
Créez une clé MakePay API à partir de la zone développeur MakeCrypto merchant et stockez la clé secrète uniquement sur votre serveur.
import { MakePayClient } from "@makecrypto/makepay";
const makepay = new MakePayClient({
keyId: process.env.MAKEPAY_KEY_ID!,
keySecret: process.env.MAKEPAY_KEY_SECRET!,
// Optional: override only when MakePay gives you a custom checkout origin.
checkoutBaseUrl: "https://makepay.io",
});
Le SDK envoie les en-têtes x-makecrypto-key-id et x-makecrypto-key-secret au partenaire MakePay, API.
Créer un lien de paiement
const response = await makepay.createPaymentLink({
title: "Order #1042",
description: "Checkout for order #1042",
amount: "129.99",
currency: "USDT",
orderId: "order_1042",
customerEmail: "buyer@example.com",
returnUrl: "https://merchant.example/orders/1042",
successUrl: "https://merchant.example/orders/1042/success",
failureUrl: "https://merchant.example/orders/1042/pay",
expirationTime: "12h",
});
console.log(response.paymentLink);
Envoyer un email de demande de paiement MakePay lors de la création :
await makepay.createPaymentLink(payload, {
sendPaymentRequestEmail: true,
});
Paiement intégré
Utilisez les URL checkout hébergées pour les redirections ou les assistants d'intégration lorsque votre interface maintient l'acheteur sur la page merchant.
import {
buildMakePayEmbeddedCheckoutUrl,
buildMakePayHostedCheckoutUrl,
mountMakePayCheckout,
openMakePayCheckout,
} from "@makecrypto/makepay";
const paymentUid = response.paymentLink.uid;
const hostedUrl = buildMakePayHostedCheckoutUrl(paymentUid);
const embedUrl = buildMakePayEmbeddedCheckoutUrl(paymentUid, {
parentOrigin: "https://merchant.example",
});
await openMakePayCheckout({
paymentUid,
onEvent(event) {
if (event.type === "makepay.payment.redirect_requested") {
window.location.assign(String(event.payload?.redirectUrl || hostedUrl));
}
},
});
mountMakePayCheckout({
container: "#makepay-checkout",
paymentUid,
});
Pour les pages CMS statiques, buildMakePayEmbedButtonHtml(paymentUid) renvoie un extrait de bouton qui charge le script modal MakePay.
Lire et mettre à jour les liens
await makepay.listPaymentLinks();
await makepay.getPaymentLink("PAYMENT_LINK_UID");
await makepay.updatePaymentLink("PAYMENT_LINK_UID", {
status: "paused",
});
await makepay.sendPaymentRequestEmail("PAYMENT_LINK_UID", "buyer@example.com");
Paramètres
await makepay.getSettings();
await makepay.updateSettings({
callbackUrl: "https://merchant.example/webhooks/makepay",
});
Vérification Webhook
Lisez le corps brut exact avant d'analyser le JSON.
import { parseMakePayWebhook } from "@makecrypto/makepay";
export async function POST(request: Request) {
const rawBody = await request.text();
const event = parseMakePayWebhook(
rawBody,
request.headers.get("x-makepay-signature"),
process.env.MAKEPAY_WEBHOOK_SECRET!,
);
if (event.event?.type === "status_changed") {
// Update your local order.
}
return new Response("ok");
}
Utilisez verifyMakePayWebhook lorsque vous n’avez besoin que d’un résultat booléen.
Gestion des erreurs
Les appels API lancent MakePayError. Il inclut le statut HTTP et le corps de la réponse décodé.
import { MakePayError } from "@makecrypto/makepay";
try {
await makepay.getPaymentLink("PAYMENT_LINK_UID");
} catch (error) {
if (error instanceof MakePayError) {
console.error(error.status, error.responseBody);
}
}
Disposition des sources
La source canonique réside dans apps/plugins/npm-sdk. Le package npm publié contient les déclarations ESM JavaScript et TypeScript compilées à partir de dist.
Notes de version
Le package est publié sous le nom @makecrypto/makepay avec accès public. La publication de la version doit utiliser un jeton d'automatisation npm dans l'organisation makecrypto ou un jeton compatible OTP lorsque 2FA est requis.