@moroccangateway/morpaysdk
v0.0.3
Published
Official Node.js SDK for MorPay
Downloads
2
Maintainers
Readme
MorPay Node.js SDK
The official Node.js library for the MorPay API.
Installation
npm install @moroccangateway/morpaysdk
# or
yarn add @moroccangateway/morpaysdk
# or
pnpm add @moroccangateway/morpaysdkUsage
Initialization
import { MorPay } from '@moroccangateway/morpaysdk';
const morpay = new MorPay('pk_test_...');Create a Payment
const payment = await morpay.payments.create({
amount: 100.00,
currency: 'MAD',
provider: 'cmi',
redirect_url: 'https://your-app.com/callback',
customer: {
email: '[email protected]',
name: 'John Doe'
}
});
console.log(payment.action.url); // Redirect user hereList Transactions
const transactions = await morpay.payments.list({
limit: 10,
status: 'succeeded'
});Manage Customers
const customer = await morpay.customers.create({
email: '[email protected]',
name: 'New Customer'
});Webhook Verification
import { Webhooks } from '@moroccangateway/morpaysdk';
const wh = new Webhooks();
const payload = request.body;
const headers = request.headers;
const secret = 'whsec_...';
try {
const event = wh.verify(payload, headers, secret);
console.log(event.type);
} catch (err) {
console.error('Webhook verification failed');
}Configuration
You can configure the SDK with options:
const morpay = new MorPay('pk_test_...', {
timeout: 10000, // 10 seconds
retries: 3, // Auto-retry network errors
debug: true // Enable debug logging
});TypeScript Support
The SDK is written in TypeScript and includes full type definitions.
import { PaymentResponse, CreatePaymentRequest } from '@moroccangateway/morpaysdk';