@reevit/node 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,72 @@
1
+ type PaymentMethod = 'card' | 'mobile_money' | 'bank_transfer';
2
+ interface PaymentError {
3
+ code: string;
4
+ message: string;
5
+ details?: any;
6
+ }
7
+ interface ReevitCheckoutConfig {
8
+ amount: number;
9
+ currency: string;
10
+ metadata?: Record<string, unknown>;
11
+ }
12
+ interface PaymentIntentResponse {
13
+ id: string;
14
+ connection_id: string;
15
+ provider: string;
16
+ status: string;
17
+ client_secret: string;
18
+ amount: number;
19
+ currency: string;
20
+ fee_amount: number;
21
+ fee_currency: string;
22
+ net_amount: number;
23
+ }
24
+ interface PaymentDetailResponse {
25
+ id: string;
26
+ connection_id: string;
27
+ provider: string;
28
+ method: string;
29
+ status: string;
30
+ amount: number;
31
+ currency: string;
32
+ fee_amount: number;
33
+ fee_currency: string;
34
+ net_amount: number;
35
+ customer_id?: string;
36
+ client_secret: string;
37
+ provider_ref_id?: string;
38
+ metadata?: Record<string, unknown>;
39
+ created_at: string;
40
+ updated_at: string;
41
+ }
42
+ interface ReevitAPIClientConfig {
43
+ publicKey: string;
44
+ baseUrl?: string;
45
+ timeout?: number;
46
+ }
47
+ export declare class ReevitAPIClient {
48
+ private publicKey;
49
+ private baseUrl;
50
+ private timeout;
51
+ constructor(config: ReevitAPIClientConfig);
52
+ private request;
53
+ createPaymentIntent(config: ReevitCheckoutConfig, method: PaymentMethod, country?: string): Promise<{
54
+ data?: PaymentIntentResponse;
55
+ error?: PaymentError;
56
+ }>;
57
+ getPaymentIntent(paymentId: string): Promise<{
58
+ data?: PaymentDetailResponse;
59
+ error?: PaymentError;
60
+ }>;
61
+ confirmPayment(paymentId: string): Promise<{
62
+ data?: PaymentDetailResponse;
63
+ error?: PaymentError;
64
+ }>;
65
+ cancelPaymentIntent(paymentId: string): Promise<{
66
+ data?: PaymentDetailResponse;
67
+ error?: PaymentError;
68
+ }>;
69
+ private mapPaymentMethod;
70
+ }
71
+ export declare function createReevitClient(config: ReevitAPIClientConfig): ReevitAPIClient;
72
+ export {};
package/dist/client.js ADDED
@@ -0,0 +1,117 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.ReevitAPIClient = void 0;
7
+ exports.createReevitClient = createReevitClient;
8
+ const axios_1 = __importDefault(require("axios"));
9
+ // Constants
10
+ const API_BASE_URL_PRODUCTION = 'https://api.reevit.io';
11
+ const API_BASE_URL_SANDBOX = 'https://sandbox-api.reevit.io';
12
+ const DEFAULT_TIMEOUT = 30000;
13
+ function isSandboxKey(publicKey) {
14
+ return publicKey.startsWith('pk_test_') || publicKey.startsWith('pk_sandbox_');
15
+ }
16
+ function createPaymentError(response, errorData) {
17
+ return {
18
+ code: errorData.code || 'api_error',
19
+ message: errorData.message || 'An unexpected error occurred',
20
+ details: {
21
+ httpStatus: response.status,
22
+ ...errorData.details,
23
+ },
24
+ };
25
+ }
26
+ class ReevitAPIClient {
27
+ constructor(config) {
28
+ this.publicKey = config.publicKey;
29
+ this.baseUrl = config.baseUrl || (isSandboxKey(config.publicKey) ? API_BASE_URL_SANDBOX : API_BASE_URL_PRODUCTION);
30
+ this.timeout = config.timeout || DEFAULT_TIMEOUT;
31
+ }
32
+ async request(method, path, body) {
33
+ try {
34
+ const response = await (0, axios_1.default)({
35
+ method,
36
+ url: `${this.baseUrl}${path}`,
37
+ data: body,
38
+ headers: {
39
+ 'Content-Type': 'application/json',
40
+ 'Authorization': `Bearer ${this.publicKey}`,
41
+ 'X-Reevit-Client': '@reevit/node',
42
+ 'X-Reevit-Client-Version': '0.3.0',
43
+ },
44
+ timeout: this.timeout,
45
+ });
46
+ return { data: response.data };
47
+ }
48
+ catch (error) {
49
+ if (error.response) {
50
+ return {
51
+ error: createPaymentError(error.response, error.response.data),
52
+ };
53
+ }
54
+ else if (error.code === 'ECONNABORTED') {
55
+ return {
56
+ error: {
57
+ code: 'request_timeout',
58
+ message: 'The request timed out. Please try again.',
59
+ },
60
+ };
61
+ }
62
+ else if (error.message.includes('Network Error') || error.code === 'ENOTFOUND') {
63
+ return {
64
+ error: {
65
+ code: 'network_error',
66
+ message: 'Unable to connect to Reevit. Please check your internet connection.',
67
+ },
68
+ };
69
+ }
70
+ else {
71
+ return {
72
+ error: {
73
+ code: 'unknown_error',
74
+ message: 'An unexpected error occurred. Please try again.',
75
+ },
76
+ };
77
+ }
78
+ }
79
+ }
80
+ async createPaymentIntent(config, method, country = 'GH') {
81
+ var _a;
82
+ const request = {
83
+ amount: config.amount,
84
+ currency: config.currency,
85
+ method: this.mapPaymentMethod(method),
86
+ country,
87
+ customer_id: (_a = config.metadata) === null || _a === void 0 ? void 0 : _a.customerId,
88
+ metadata: config.metadata,
89
+ };
90
+ return this.request('POST', '/v1/payments/intents', request);
91
+ }
92
+ async getPaymentIntent(paymentId) {
93
+ return this.request('GET', `/v1/payments/${paymentId}`);
94
+ }
95
+ async confirmPayment(paymentId) {
96
+ return this.request('POST', `/v1/payments/${paymentId}/confirm`);
97
+ }
98
+ async cancelPaymentIntent(paymentId) {
99
+ return this.request('POST', `/v1/payments/${paymentId}/cancel`);
100
+ }
101
+ mapPaymentMethod(method) {
102
+ switch (method) {
103
+ case 'card':
104
+ return 'card';
105
+ case 'mobile_money':
106
+ return 'mobile_money';
107
+ case 'bank_transfer':
108
+ return 'bank_transfer';
109
+ default:
110
+ return method;
111
+ }
112
+ }
113
+ }
114
+ exports.ReevitAPIClient = ReevitAPIClient;
115
+ function createReevitClient(config) {
116
+ return new ReevitAPIClient(config);
117
+ }
@@ -0,0 +1,13 @@
1
+ import { PaymentsService } from './services/payments';
2
+ import { ConnectionsService } from './services/connections';
3
+ import { SubscriptionsService } from './services/subscriptions';
4
+ import { FraudService } from './services/fraud';
5
+ export declare class Reevit {
6
+ private client;
7
+ payments: PaymentsService;
8
+ connections: ConnectionsService;
9
+ subscriptions: SubscriptionsService;
10
+ fraud: FraudService;
11
+ constructor(apiKey: string, orgId: string, baseUrl?: string);
12
+ }
13
+ export * from './types';
package/dist/index.js ADDED
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ var __importDefault = (this && this.__importDefault) || function (mod) {
17
+ return (mod && mod.__esModule) ? mod : { "default": mod };
18
+ };
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.Reevit = void 0;
21
+ const axios_1 = __importDefault(require("axios"));
22
+ const payments_1 = require("./services/payments");
23
+ const connections_1 = require("./services/connections");
24
+ const subscriptions_1 = require("./services/subscriptions");
25
+ const fraud_1 = require("./services/fraud");
26
+ // Default API base URLs (secure HTTPS)
27
+ const API_BASE_URL_PRODUCTION = 'https://api.reevit.io';
28
+ const API_BASE_URL_SANDBOX = 'https://sandbox-api.reevit.io';
29
+ /**
30
+ * Determines if an API key is for sandbox mode
31
+ */
32
+ function isSandboxKey(apiKey) {
33
+ return apiKey.startsWith('sk_test_') || apiKey.startsWith('sk_sandbox_');
34
+ }
35
+ class Reevit {
36
+ constructor(apiKey, orgId, baseUrl) {
37
+ // Use provided baseUrl, or auto-detect based on API key prefix
38
+ const resolvedBaseUrl = baseUrl || (isSandboxKey(apiKey) ? API_BASE_URL_SANDBOX : API_BASE_URL_PRODUCTION);
39
+ this.client = axios_1.default.create({
40
+ baseURL: resolvedBaseUrl,
41
+ timeout: 10000,
42
+ headers: {
43
+ 'Content-Type': 'application/json',
44
+ 'User-Agent': 'reevit-node/0.1.0',
45
+ 'X-Reevit-Key': apiKey,
46
+ 'X-Org-Id': orgId,
47
+ },
48
+ });
49
+ this.payments = new payments_1.PaymentsService(this.client);
50
+ this.connections = new connections_1.ConnectionsService(this.client);
51
+ this.subscriptions = new subscriptions_1.SubscriptionsService(this.client);
52
+ this.fraud = new fraud_1.FraudService(this.client);
53
+ }
54
+ }
55
+ exports.Reevit = Reevit;
56
+ __exportStar(require("./types"), exports);
@@ -0,0 +1,9 @@
1
+ import { AxiosInstance } from 'axios';
2
+ import { Connection, ConnectionRequest } from '../types';
3
+ export declare class ConnectionsService {
4
+ private client;
5
+ constructor(client: AxiosInstance);
6
+ create(data: ConnectionRequest): Promise<Connection>;
7
+ list(): Promise<Connection[]>;
8
+ test(data: ConnectionRequest): Promise<boolean>;
9
+ }
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ConnectionsService = void 0;
4
+ class ConnectionsService {
5
+ constructor(client) {
6
+ this.client = client;
7
+ }
8
+ async create(data) {
9
+ const response = await this.client.post('/v1/connections', data);
10
+ return response.data;
11
+ }
12
+ async list() {
13
+ const response = await this.client.get('/v1/connections');
14
+ return response.data;
15
+ }
16
+ async test(data) {
17
+ const response = await this.client.post('/v1/connections/test', data);
18
+ return response.data.success;
19
+ }
20
+ }
21
+ exports.ConnectionsService = ConnectionsService;
@@ -0,0 +1,8 @@
1
+ import { AxiosInstance } from 'axios';
2
+ import { FraudPolicy } from '../types';
3
+ export declare class FraudService {
4
+ private client;
5
+ constructor(client: AxiosInstance);
6
+ get(): Promise<FraudPolicy>;
7
+ update(policy: FraudPolicy): Promise<FraudPolicy>;
8
+ }
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FraudService = void 0;
4
+ class FraudService {
5
+ constructor(client) {
6
+ this.client = client;
7
+ }
8
+ async get() {
9
+ const response = await this.client.get('/v1/policies/fraud');
10
+ return response.data;
11
+ }
12
+ async update(policy) {
13
+ const response = await this.client.post('/v1/policies/fraud', policy);
14
+ return response.data;
15
+ }
16
+ }
17
+ exports.FraudService = FraudService;
@@ -0,0 +1,10 @@
1
+ import { AxiosInstance } from 'axios';
2
+ import { Payment, PaymentIntentRequest, PaymentSummary, Refund } from '../types';
3
+ export declare class PaymentsService {
4
+ private client;
5
+ constructor(client: AxiosInstance);
6
+ createIntent(data: PaymentIntentRequest): Promise<Payment>;
7
+ list(limit?: number, offset?: number): Promise<PaymentSummary[]>;
8
+ get(id: string): Promise<Payment>;
9
+ refund(id: string, amount?: number, reason?: string): Promise<Refund>;
10
+ }
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PaymentsService = void 0;
4
+ class PaymentsService {
5
+ constructor(client) {
6
+ this.client = client;
7
+ }
8
+ async createIntent(data) {
9
+ const response = await this.client.post('/v1/payments/intents', data);
10
+ return response.data;
11
+ }
12
+ async list(limit = 50, offset = 0) {
13
+ const response = await this.client.get('/v1/payments', {
14
+ params: { limit, offset }
15
+ });
16
+ return response.data;
17
+ }
18
+ async get(id) {
19
+ const response = await this.client.get(`/v1/payments/${id}`);
20
+ return response.data;
21
+ }
22
+ async refund(id, amount, reason) {
23
+ const response = await this.client.post(`/v1/payments/${id}/refund`, {
24
+ amount,
25
+ reason
26
+ });
27
+ return response.data;
28
+ }
29
+ }
30
+ exports.PaymentsService = PaymentsService;
@@ -0,0 +1,8 @@
1
+ import { AxiosInstance } from 'axios';
2
+ import { Subscription, SubscriptionRequest } from '../types';
3
+ export declare class SubscriptionsService {
4
+ private client;
5
+ constructor(client: AxiosInstance);
6
+ create(data: SubscriptionRequest): Promise<Subscription>;
7
+ list(): Promise<Subscription[]>;
8
+ }
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SubscriptionsService = void 0;
4
+ class SubscriptionsService {
5
+ constructor(client) {
6
+ this.client = client;
7
+ }
8
+ async create(data) {
9
+ const response = await this.client.post('/v1/subscriptions', data);
10
+ return response.data;
11
+ }
12
+ async list() {
13
+ const response = await this.client.get('/v1/subscriptions');
14
+ return response.data;
15
+ }
16
+ }
17
+ exports.SubscriptionsService = SubscriptionsService;
@@ -0,0 +1,118 @@
1
+ export interface PaymentIntentRequest {
2
+ amount: number;
3
+ currency: string;
4
+ method: string;
5
+ country: string;
6
+ customer_id?: string;
7
+ policy?: FraudPolicyInput;
8
+ metadata?: Record<string, any>;
9
+ }
10
+ export interface FraudPolicyInput {
11
+ prefer?: string[];
12
+ max_amount?: number;
13
+ blocked_bins?: string[];
14
+ allowed_bins?: string[];
15
+ velocity_max_per_minute?: number;
16
+ }
17
+ export interface Payment {
18
+ id: string;
19
+ connection_id: string;
20
+ provider: string;
21
+ provider_ref_id: string;
22
+ method: string;
23
+ status: string;
24
+ amount: number;
25
+ currency: string;
26
+ fee_amount: number;
27
+ fee_currency: string;
28
+ net_amount: number;
29
+ customer_id: string;
30
+ metadata: Record<string, any>;
31
+ route: PaymentRouteAttempt[];
32
+ created_at: string;
33
+ updated_at: string;
34
+ }
35
+ export interface PaymentSummary {
36
+ id: string;
37
+ connection_id: string;
38
+ provider: string;
39
+ method: string;
40
+ status: string;
41
+ amount: number;
42
+ currency: string;
43
+ fee_amount: number;
44
+ fee_currency: string;
45
+ net_amount: number;
46
+ customer_id: string;
47
+ metadata: Record<string, any>;
48
+ created_at: string;
49
+ }
50
+ export interface PaymentRouteAttempt {
51
+ connection_id: string;
52
+ provider: string;
53
+ status: string;
54
+ error: string;
55
+ labels: string[];
56
+ routing_hints?: RoutingHints;
57
+ }
58
+ export interface RoutingHints {
59
+ country_preference: string[];
60
+ method_bias: Record<string, string>;
61
+ fallback_only: boolean;
62
+ }
63
+ export interface Refund {
64
+ id: string;
65
+ payment_id: string;
66
+ amount: number;
67
+ status: string;
68
+ reason: string;
69
+ created_at: string;
70
+ }
71
+ export interface ConnectionRequest {
72
+ provider: string;
73
+ mode: string;
74
+ credentials: Record<string, any>;
75
+ capabilities?: Record<string, any>;
76
+ routing_hints?: RoutingHints;
77
+ labels?: string[];
78
+ }
79
+ export interface Connection {
80
+ id: string;
81
+ provider: string;
82
+ mode: string;
83
+ status: string;
84
+ capabilities: Record<string, any>;
85
+ routing_hints: RoutingHints;
86
+ labels: string[];
87
+ }
88
+ export interface SubscriptionRequest {
89
+ customer_id: string;
90
+ plan_id: string;
91
+ amount: number;
92
+ currency: string;
93
+ method: string;
94
+ interval: 'monthly' | 'yearly';
95
+ metadata?: Record<string, any>;
96
+ }
97
+ export interface Subscription {
98
+ id: string;
99
+ org_id: string;
100
+ customer_id: string;
101
+ plan_id: string;
102
+ amount: number;
103
+ currency: string;
104
+ method: string;
105
+ interval: string;
106
+ status: string;
107
+ next_renewal_at: string;
108
+ metadata: Record<string, any>;
109
+ created_at: string;
110
+ updated_at: string;
111
+ }
112
+ export interface FraudPolicy {
113
+ prefer: string[];
114
+ max_amount: number;
115
+ blocked_bins: string[];
116
+ allowed_bins: string[];
117
+ velocity_max_per_minute: number;
118
+ }
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "@reevit/node",
3
+ "version": "0.3.0",
4
+ "description": "Reevit Node.js SDK",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "scripts": {
8
+ "build": "tsc",
9
+ "prepublishOnly": "npm run build"
10
+ },
11
+ "keywords": [
12
+ "reevit",
13
+ "payments",
14
+ "africa",
15
+ "orchestration"
16
+ ],
17
+ "author": "Reevit",
18
+ "license": "MIT",
19
+ "devDependencies": {
20
+ "typescript": "^5.0.0",
21
+ "@types/node": "^18.0.0"
22
+ },
23
+ "dependencies": {
24
+ "axios": "^1.4.0"
25
+ }
26
+ }