Backend SDK Documentation
Welcome to the Mileston Payments JavaScript/Typescript Backend SDKโyour ultimate tool to manage payment links, invoices, and recurring payments like a boss! ๐ Whether youโre building a simple checkout system or a full-blown payment management solution, weโve got your back with a developer-friendly, secure, and lightweight SDK.
๐ Featuresโ
- Create and Manage Payment Links: Let your customers pay with ease!
- Generate and Update Invoices: From client billing to reminders, stay on top of your payments.
- Handle Recurring Payments: Automate those monthly, weekly, or even daily payments like a pro.
- Secure and Reliable: Sleep soundly knowing your payments are safe.
- Developer-Friendly: Simple, intuitive, and just works out of the box.
๐ ๏ธ Installationโ
First things first, install the SDK using npm
:
npm install mileston-payments
๐ Getting Startedโ
Import the SDK and initialize it with your API Key and Business ID.
import { PaymentLink, Invoice, RecurringPayment } from 'mileston-payments';
const apiKey = 'your-api-key'; // Get this from your dashboard
const businessId = 'your-business-id'; // Unique ID for your business
const paymentLink = new PaymentLink(apiKey, businessId);
const invoice = new Invoice(apiKey, businessId);
const recurringPayment = new RecurringPayment(apiKey, businessId);
๐ฅ Usage Examplesโ
๐งพ 1. Creating a Payment Linkโ
Need a quick way to collect payments? Payment links to the rescue!
const createPaymentPayload = {
amount: '100.00',
description: 'Purchase of premium subscription',
customerEmail: 'customer@example.com',
};
const paymentLinkResponse = await paymentLink.create(createPaymentPayload);
console.log('Payment Link:', paymentLinkResponse.paymentLink);
// Output: https://checkout.mileston.co/payment-link/ahddjdjdjd8848bc123
Imagine sending that link via email or embedding it in your website. So smooth, right? ๐
๐ 2. Generating an Invoiceโ
Because looking professional matters!
const createInvoicePayload = {
amount: '200.00',
itemName: 'Service Fee',
customerEmail: 'client@example.com',
dueDate: new Date(),
};
const businessName = 'Acme Corporation'; // Your business name
const invoiceResponse = await invoice.create(businessName, createInvoicePayload);
console.log('Invoice Link:', invoiceResponse.invoiceLink);
// Output: https://checkout.mileston.co/invoice/ahddjdjdjd8848bc123
Invoices have never been this elegant! Your users automatically get emails immediately you create the invoice. Who knew you could look cool while chasing payments? ๐
๐ 3. Handling Recurring Paymentsโ
Set it and forget it! Automate subscription payments effortlessly.
const createRecurringPaymentPayload = {
amount: '50.00',
subscriberFullName: 'John Doe',
subscriberEmail: 'john.doe@example.com',
recurringDate: new Date('2025-01-01'),
recurringInterval: 30, // Days between payments
};
const recurringPaymentResponse = await recurringPayment.create(
businessName,
createRecurringPaymentPayload
);
console.log('Recurring Payment Created:', recurringPaymentResponse);
// Output: https://checkout.mileston.co/recurring-payment/ahddjdjdjd8848bc123
Your users automatically receive an email to pay up and a follow up email when their subscription is due! John wonโt miss a single payment, and neither will you! ๐ธ
๐ ๏ธ 4. Updating a Payment Linkโ
Did the customer change their mind? No problemโupdate the payment link on the fly.
const updatePayload = {
amount: '120.00',
description: 'Updated subscription fee',
};
const updatedPaymentLink = await paymentLink.update('paymentLinkId', updatePayload);
console.log('Updated Payment Link:', updatedPaymentLink);
// Output: { id: 'pl123', amount: '120.00', description: 'Updated subscription fee' }
Youโre in full controlโno more โOops!โ moments.
๐ฅ Bonus: Fetching & Deleting Dataโ
- Get Payment Link:
const paymentData = await paymentLink.get('paymentLinkId');
console.log(paymentData);
- Delete Payment Link:
await paymentLink.delete('paymentLinkId');
console.log('Payment link deleted.');
- Similar methods exist for invoices and recurring payments. Go wild! ๐
๐ API Referenceโ
PaymentLink
Classโ
create(payload: CreatePaymentLinkPayload): Promise<CreatePaymentLinkResponse>
Create a new payment link.update(id: string, payload: UpdatePaymentLinkPayload): Promise<UpdatePaymentLinkResponse>
Update an existing payment link.get(id: string): Promise<UpdatePaymentLinkResponse>
Retrieve details of a specific payment link.delete(id: string): Promise<DeletePaymentLinkResponse>
Delete a payment link.
Invoice
Classโ
- Similar methods for creating, updating, fetching, and deleting invoices.
RecurringPayment
Classโ
create(payload: CreateRecurringPaymentPayload): Promise<CreateRecurringPaymentResponse>
Set up a recurring payment.update(id: string, payload: UpdateRecurringPaymentPayload): Promise<UpdateRecurringPaymentResponse>
Update recurring payment details.getAll(): Promise<GetAllRecurringPaymentResponse>
Retrieve all active recurring payments.
๐ก๏ธ Pro Tipsโ
- Secure your API key! Donโt hardcode it in your codebaseโuse environment variables.
- Error Handling: Wrap all calls in try-catch blocks for a smoother experience.
๐ค Contributingโ
Got ideas to make this SDK better? Fork the repo, submit pull requests, and letโs make this tool even more awesome together.
๐ Start Now!โ
Say goodbye to payment chaos and hello to streamlined success. Install the SDK, write some code, and watch the magic happen. โจ
npm install mileston-payments
What are you waiting for? Go build something amazing! ๐