@paymove-io/sdk 0.1.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.
- package/README.md +157 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +130 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.ts +130 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/package.json +48 -0
package/README.md
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
# @paymove-io/sdk
|
|
2
|
+
|
|
3
|
+
Official Paymove SDK for payment integration.
|
|
4
|
+
|
|
5
|
+
## Requirements
|
|
6
|
+
|
|
7
|
+
- Node.js >= 18.0.0
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @paymove-io/sdk
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import { PaymoveClient, PaymoveApiError } from '@paymove-io/sdk';
|
|
19
|
+
|
|
20
|
+
// Initialize the client
|
|
21
|
+
const client = new PaymoveClient({
|
|
22
|
+
apiKey: 'your-api-key',
|
|
23
|
+
merchantId: 'your-merchant-id',
|
|
24
|
+
environment: 'sandbox', // or 'production'
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
// Create a payment
|
|
28
|
+
try {
|
|
29
|
+
const response = await client.createPayment({
|
|
30
|
+
amount: 1000, // amount in smallest currency unit (e.g., cents)
|
|
31
|
+
currency: 'PLN',
|
|
32
|
+
orderId: 'order-123',
|
|
33
|
+
returnUrl: 'https://your-shop.com/success',
|
|
34
|
+
// optional: description
|
|
35
|
+
description: 'Payment for order #123',
|
|
36
|
+
// optional: any additional custom fields
|
|
37
|
+
customField: 'custom-value',
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
// Redirect user to payment page
|
|
41
|
+
console.log(response.redirectUrl);
|
|
42
|
+
} catch (error) {
|
|
43
|
+
if (error instanceof PaymoveApiError) {
|
|
44
|
+
console.error('API Error:', error.statusCode, error.message);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## API Reference
|
|
50
|
+
|
|
51
|
+
### PaymoveClient
|
|
52
|
+
|
|
53
|
+
#### Constructor
|
|
54
|
+
|
|
55
|
+
```typescript
|
|
56
|
+
new PaymoveClient(config: PaymoveConfig)
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
| Parameter | Type | Description |
|
|
60
|
+
|-----------|------|-------------|
|
|
61
|
+
| `config.apiKey` | `string` | Your Paymove API key |
|
|
62
|
+
| `config.merchantId` | `string` | Your merchant ID |
|
|
63
|
+
| `config.environment` | `'sandbox' \| 'production'` | API environment |
|
|
64
|
+
|
|
65
|
+
#### Methods
|
|
66
|
+
|
|
67
|
+
##### createPayment(params)
|
|
68
|
+
|
|
69
|
+
Creates a new payment and returns the response with redirect URL.
|
|
70
|
+
|
|
71
|
+
```typescript
|
|
72
|
+
client.createPayment(params: CreatePaymentParams): Promise<PaymentResponse>
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
| Parameter | Type | Required | Description |
|
|
76
|
+
|-----------|------|----------|-------------|
|
|
77
|
+
| `amount` | `number` | Yes | Payment amount in smallest currency unit |
|
|
78
|
+
| `currency` | `string` | Yes | Currency code (e.g., 'PLN', 'EUR') |
|
|
79
|
+
| `orderId` | `string` | Yes | Your unique order identifier |
|
|
80
|
+
| `returnUrl` | `string` | Yes | URL to redirect after payment |
|
|
81
|
+
| `description` | `string` | No | Payment description |
|
|
82
|
+
| `[key]` | `unknown` | No | Additional custom fields |
|
|
83
|
+
|
|
84
|
+
**Returns:** `Promise<PaymentResponse>` - Response containing `redirectUrl` and other API fields.
|
|
85
|
+
|
|
86
|
+
## Error Handling
|
|
87
|
+
|
|
88
|
+
The SDK provides custom error classes for different error scenarios:
|
|
89
|
+
|
|
90
|
+
### PaymoveValidationError
|
|
91
|
+
|
|
92
|
+
Thrown when input validation fails.
|
|
93
|
+
|
|
94
|
+
```typescript
|
|
95
|
+
import { PaymoveValidationError } from '@paymove-io/sdk';
|
|
96
|
+
|
|
97
|
+
try {
|
|
98
|
+
await client.createPayment({ /* invalid params */ });
|
|
99
|
+
} catch (error) {
|
|
100
|
+
if (error instanceof PaymoveValidationError) {
|
|
101
|
+
console.error('Validation failed for field:', error.field);
|
|
102
|
+
console.error('Message:', error.message);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### PaymoveApiError
|
|
108
|
+
|
|
109
|
+
Thrown when the API returns an error response.
|
|
110
|
+
|
|
111
|
+
```typescript
|
|
112
|
+
import { PaymoveApiError } from '@paymove-io/sdk';
|
|
113
|
+
|
|
114
|
+
try {
|
|
115
|
+
await client.createPayment({ /* params */ });
|
|
116
|
+
} catch (error) {
|
|
117
|
+
if (error instanceof PaymoveApiError) {
|
|
118
|
+
console.error('Status code:', error.statusCode);
|
|
119
|
+
console.error('Message:', error.message);
|
|
120
|
+
console.error('Response body:', error.responseBody);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### PaymoveNetworkError
|
|
126
|
+
|
|
127
|
+
Thrown when a network error occurs.
|
|
128
|
+
|
|
129
|
+
```typescript
|
|
130
|
+
import { PaymoveNetworkError } from '@paymove-io/sdk';
|
|
131
|
+
|
|
132
|
+
try {
|
|
133
|
+
await client.createPayment({ /* params */ });
|
|
134
|
+
} catch (error) {
|
|
135
|
+
if (error instanceof PaymoveNetworkError) {
|
|
136
|
+
console.error('Network error:', error.message);
|
|
137
|
+
console.error('Original error:', error.cause);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
## TypeScript Support
|
|
143
|
+
|
|
144
|
+
This package is written in TypeScript and includes type definitions.
|
|
145
|
+
|
|
146
|
+
```typescript
|
|
147
|
+
import type {
|
|
148
|
+
PaymoveConfig,
|
|
149
|
+
CreatePaymentParams,
|
|
150
|
+
PaymentResponse,
|
|
151
|
+
Environment,
|
|
152
|
+
} from '@paymove-io/sdk';
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
## License
|
|
156
|
+
|
|
157
|
+
MIT
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";const e={sandbox:`https://gateway-api.sandbox.paymove.io`,production:`https://gateway-api.paymove.io`};var t=class extends Error{constructor(e){super(e),this.name=`PaymoveError`,Object.setPrototypeOf(this,new.target.prototype)}},n=class extends t{statusCode;responseBody;constructor(e,t,n){super(e),this.name=`PaymoveApiError`,this.statusCode=t,this.responseBody=n}},r=class extends t{field;constructor(e,t){super(e),this.name=`PaymoveValidationError`,this.field=t}},i=class extends t{cause;constructor(e,t){super(e),this.name=`PaymoveNetworkError`,this.cause=t}},a=class{apiKey;merchantId;baseUrl;constructor(t){this.validateConfig(t),this.apiKey=t.apiKey,this.merchantId=t.merchantId,this.baseUrl=e[t.environment]}async createPayment(e){this.validatePaymentParams(e);let t=`${this.baseUrl}/api/pay/product/${this.merchantId}/subproduct/pricing`,{amount:a,currency:o,orderId:s,returnUrl:c,description:l,...u}=e,d={...u,price:a,externalId:s,description:l??s,details:JSON.stringify({currency:o,redirectUrl:c})};try{let e=await fetch(t,{method:`POST`,headers:{"Content-Type":`application/json`,"X-API-KEY":this.apiKey},body:JSON.stringify(d)}),r=await this.parseResponse(e);if(!e.ok){let t=this.extractErrorMessage(r);throw new n(t,e.status,r)}return r}catch(e){throw e instanceof n||e instanceof r?e:e instanceof Error?new i(`Network error while creating payment: ${e.message}`,e):new i(`Unknown network error while creating payment`,Error(String(e)))}}validateConfig(e){if(!e.apiKey||typeof e.apiKey!=`string`)throw new r(`apiKey is required and must be a string`,`apiKey`);if(!e.merchantId||typeof e.merchantId!=`string`)throw new r(`merchantId is required and must be a string`,`merchantId`);if(!e.environment||![`sandbox`,`production`].includes(e.environment))throw new r(`environment must be either "sandbox" or "production"`,`environment`)}validatePaymentParams(e){if(typeof e.amount!=`number`||e.amount<=0)throw new r(`amount is required and must be a positive number`,`amount`);if(!e.currency||typeof e.currency!=`string`)throw new r(`currency is required and must be a string`,`currency`);if(!e.orderId||typeof e.orderId!=`string`)throw new r(`orderId is required and must be a string`,`orderId`);if(!e.returnUrl||typeof e.returnUrl!=`string`)throw new r(`returnUrl is required and must be a string`,`returnUrl`);try{new URL(e.returnUrl)}catch{throw new r(`returnUrl must be a valid URL`,`returnUrl`)}}async parseResponse(e){let t=e.headers.get(`content-type`);if(t?.includes(`application/json`))try{return await e.json()}catch{throw new n(`Failed to parse JSON response from API`,e.status)}let r=await e.text();return{message:r}}extractErrorMessage(e){if(typeof e==`object`&&e){let t=e;return t.message||t.error||`Unknown API error`}return`Unknown API error`}};exports.PaymoveApiError=n,exports.PaymoveClient=a,exports.PaymoveError=t,exports.PaymoveNetworkError=i,exports.PaymoveValidationError=r;
|
|
2
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["ENDPOINTS: Record<Environment, string>","message: string","statusCode: number","responseBody?: unknown","field: string","cause: Error","config: PaymoveConfig","params: CreatePaymentParams","response: Response","responseData: unknown"],"sources":["../src/constants.ts","../src/errors.ts","../src/client.ts"],"sourcesContent":["import type { Environment } from \"./types.js\";\n\nexport const ENDPOINTS: Record<Environment, string> = {\n sandbox: \"https://gateway-api.sandbox.paymove.io\",\n production: \"https://gateway-api.paymove.io\",\n} as const;\n","/**\n * Base error class for all Paymove SDK errors\n */\nexport class PaymoveError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'PaymoveError';\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\n/**\n * Error thrown when the API returns an error response\n */\nexport class PaymoveApiError extends PaymoveError {\n /** HTTP status code from the API */\n public readonly statusCode: number;\n /** Raw response body from the API */\n public readonly responseBody: unknown;\n\n constructor(message: string, statusCode: number, responseBody?: unknown) {\n super(message);\n this.name = 'PaymoveApiError';\n this.statusCode = statusCode;\n this.responseBody = responseBody;\n }\n}\n\n/**\n * Error thrown when input validation fails\n */\nexport class PaymoveValidationError extends PaymoveError {\n /** The field that failed validation */\n public readonly field: string;\n\n constructor(message: string, field: string) {\n super(message);\n this.name = 'PaymoveValidationError';\n this.field = field;\n }\n}\n\n/**\n * Error thrown when a network error occurs\n */\nexport class PaymoveNetworkError extends PaymoveError {\n /** The original error that caused this network error */\n public readonly cause: Error;\n\n constructor(message: string, cause: Error) {\n super(message);\n this.name = 'PaymoveNetworkError';\n this.cause = cause;\n }\n}\n","import { ENDPOINTS } from \"./constants.js\";\nimport {\n PaymoveApiError,\n PaymoveNetworkError,\n PaymoveValidationError,\n} from \"./errors.js\";\nimport type {\n ApiErrorResponse,\n CreatePaymentParams,\n PaymoveConfig,\n PaymentResponse,\n} from \"./types.js\";\n\n/**\n * Paymove SDK client for payment integration\n *\n * @example\n * ```typescript\n * const client = new PaymoveClient({\n * apiKey: 'your-api-key',\n * merchantId: 'your-merchant-id',\n * environment: 'sandbox'\n * });\n *\n * const response = await client.createPayment({\n * amount: 1000,\n * currency: 'PLN',\n * orderId: 'order-123',\n * returnUrl: 'https://your-shop.com/success'\n * });\n *\n * console.log(response.redirectUrl);\n * ```\n */\nexport class PaymoveClient {\n private readonly apiKey: string;\n private readonly merchantId: string;\n private readonly baseUrl: string;\n\n constructor(config: PaymoveConfig) {\n this.validateConfig(config);\n\n this.apiKey = config.apiKey;\n this.merchantId = config.merchantId;\n this.baseUrl = ENDPOINTS[config.environment];\n }\n\n /**\n * Creates a new payment and returns the response with redirect URL\n *\n * @param params - Payment parameters\n * @returns Payment response containing redirectUrl\n * @throws {PaymoveValidationError} When required parameters are missing or invalid\n * @throws {PaymoveApiError} When the API returns an error response\n * @throws {PaymoveNetworkError} When a network error occurs\n */\n async createPayment(params: CreatePaymentParams): Promise<PaymentResponse> {\n this.validatePaymentParams(params);\n\n const url = `${this.baseUrl}/api/pay/product/${this.merchantId}/subproduct/pricing`;\n\n const { amount, currency, orderId, returnUrl, description, ...rest } =\n params;\n\n const body = {\n ...rest,\n price: amount,\n externalId: orderId,\n description: description ?? orderId,\n details: JSON.stringify({\n currency,\n redirectUrl: returnUrl,\n }),\n };\n\n try {\n const response = await fetch(url, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n \"X-API-KEY\": this.apiKey,\n },\n body: JSON.stringify(body),\n });\n\n const responseData = await this.parseResponse(response);\n\n if (!response.ok) {\n const errorMessage = this.extractErrorMessage(responseData);\n throw new PaymoveApiError(errorMessage, response.status, responseData);\n }\n\n return responseData as PaymentResponse;\n } catch (error) {\n if (\n error instanceof PaymoveApiError ||\n error instanceof PaymoveValidationError\n ) {\n throw error;\n }\n\n if (error instanceof Error) {\n throw new PaymoveNetworkError(\n `Network error while creating payment: ${error.message}`,\n error\n );\n }\n\n throw new PaymoveNetworkError(\n \"Unknown network error while creating payment\",\n new Error(String(error))\n );\n }\n }\n\n private validateConfig(config: PaymoveConfig): void {\n if (!config.apiKey || typeof config.apiKey !== \"string\") {\n throw new PaymoveValidationError(\n \"apiKey is required and must be a string\",\n \"apiKey\"\n );\n }\n\n if (!config.merchantId || typeof config.merchantId !== \"string\") {\n throw new PaymoveValidationError(\n \"merchantId is required and must be a string\",\n \"merchantId\"\n );\n }\n\n if (\n !config.environment ||\n ![\"sandbox\", \"production\"].includes(config.environment)\n ) {\n throw new PaymoveValidationError(\n 'environment must be either \"sandbox\" or \"production\"',\n \"environment\"\n );\n }\n }\n\n private validatePaymentParams(params: CreatePaymentParams): void {\n if (typeof params.amount !== \"number\" || params.amount <= 0) {\n throw new PaymoveValidationError(\n \"amount is required and must be a positive number\",\n \"amount\"\n );\n }\n\n if (!params.currency || typeof params.currency !== \"string\") {\n throw new PaymoveValidationError(\n \"currency is required and must be a string\",\n \"currency\"\n );\n }\n\n if (!params.orderId || typeof params.orderId !== \"string\") {\n throw new PaymoveValidationError(\n \"orderId is required and must be a string\",\n \"orderId\"\n );\n }\n\n if (!params.returnUrl || typeof params.returnUrl !== \"string\") {\n throw new PaymoveValidationError(\n \"returnUrl is required and must be a string\",\n \"returnUrl\"\n );\n }\n\n try {\n new URL(params.returnUrl);\n } catch {\n throw new PaymoveValidationError(\n \"returnUrl must be a valid URL\",\n \"returnUrl\"\n );\n }\n }\n\n private async parseResponse(response: Response): Promise<unknown> {\n const contentType = response.headers.get(\"content-type\");\n\n if (contentType?.includes(\"application/json\")) {\n try {\n return await response.json();\n } catch {\n throw new PaymoveApiError(\n \"Failed to parse JSON response from API\",\n response.status\n );\n }\n }\n\n const text = await response.text();\n return { message: text };\n }\n\n private extractErrorMessage(responseData: unknown): string {\n if (typeof responseData === \"object\" && responseData !== null) {\n const data = responseData as ApiErrorResponse;\n return data.message || data.error || \"Unknown API error\";\n }\n\n return \"Unknown API error\";\n }\n}\n"],"mappings":"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"}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
//#region src/types.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Environment type for Paymove API
|
|
4
|
+
*/
|
|
5
|
+
type Environment = 'sandbox' | 'production';
|
|
6
|
+
/**
|
|
7
|
+
* Configuration for PaymoveClient initialization
|
|
8
|
+
*/
|
|
9
|
+
interface PaymoveConfig {
|
|
10
|
+
/** Your Paymove API key */
|
|
11
|
+
apiKey: string;
|
|
12
|
+
/** Your merchant ID */
|
|
13
|
+
merchantId: string;
|
|
14
|
+
/** Environment to use (sandbox or production) */
|
|
15
|
+
environment: Environment;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Parameters for creating a payment
|
|
19
|
+
*/
|
|
20
|
+
interface CreatePaymentParams {
|
|
21
|
+
/** Payment amount in smallest currency unit (e.g., cents) */
|
|
22
|
+
amount: number;
|
|
23
|
+
/** Currency code (e.g., 'PLN', 'EUR', 'USD') */
|
|
24
|
+
currency: string;
|
|
25
|
+
/** Your unique order identifier */
|
|
26
|
+
orderId: string;
|
|
27
|
+
/** URL to redirect the user after payment */
|
|
28
|
+
returnUrl: string;
|
|
29
|
+
/** Optional payment description */
|
|
30
|
+
description?: string;
|
|
31
|
+
/** Additional custom fields */
|
|
32
|
+
[key: string]: unknown;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Response from payment creation
|
|
36
|
+
*/
|
|
37
|
+
interface PaymentResponse {
|
|
38
|
+
/** URL to redirect the user for payment */
|
|
39
|
+
redirectUrl: string;
|
|
40
|
+
/** Additional response fields from the API */
|
|
41
|
+
[key: string]: unknown;
|
|
42
|
+
} //#endregion
|
|
43
|
+
//#region src/client.d.ts
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* API error response structure
|
|
47
|
+
*/
|
|
48
|
+
/**
|
|
49
|
+
* Paymove SDK client for payment integration
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```typescript
|
|
53
|
+
* const client = new PaymoveClient({
|
|
54
|
+
* apiKey: 'your-api-key',
|
|
55
|
+
* merchantId: 'your-merchant-id',
|
|
56
|
+
* environment: 'sandbox'
|
|
57
|
+
* });
|
|
58
|
+
*
|
|
59
|
+
* const response = await client.createPayment({
|
|
60
|
+
* amount: 1000,
|
|
61
|
+
* currency: 'PLN',
|
|
62
|
+
* orderId: 'order-123',
|
|
63
|
+
* returnUrl: 'https://your-shop.com/success'
|
|
64
|
+
* });
|
|
65
|
+
*
|
|
66
|
+
* console.log(response.redirectUrl);
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
declare class PaymoveClient {
|
|
70
|
+
private readonly apiKey;
|
|
71
|
+
private readonly merchantId;
|
|
72
|
+
private readonly baseUrl;
|
|
73
|
+
constructor(config: PaymoveConfig);
|
|
74
|
+
/**
|
|
75
|
+
* Creates a new payment and returns the response with redirect URL
|
|
76
|
+
*
|
|
77
|
+
* @param params - Payment parameters
|
|
78
|
+
* @returns Payment response containing redirectUrl
|
|
79
|
+
* @throws {PaymoveValidationError} When required parameters are missing or invalid
|
|
80
|
+
* @throws {PaymoveApiError} When the API returns an error response
|
|
81
|
+
* @throws {PaymoveNetworkError} When a network error occurs
|
|
82
|
+
*/
|
|
83
|
+
createPayment(params: CreatePaymentParams): Promise<PaymentResponse>;
|
|
84
|
+
private validateConfig;
|
|
85
|
+
private validatePaymentParams;
|
|
86
|
+
private parseResponse;
|
|
87
|
+
private extractErrorMessage;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
//#endregion
|
|
91
|
+
//#region src/errors.d.ts
|
|
92
|
+
//# sourceMappingURL=client.d.ts.map
|
|
93
|
+
/**
|
|
94
|
+
* Base error class for all Paymove SDK errors
|
|
95
|
+
*/
|
|
96
|
+
declare class PaymoveError extends Error {
|
|
97
|
+
constructor(message: string);
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Error thrown when the API returns an error response
|
|
101
|
+
*/
|
|
102
|
+
declare class PaymoveApiError extends PaymoveError {
|
|
103
|
+
/** HTTP status code from the API */
|
|
104
|
+
readonly statusCode: number;
|
|
105
|
+
/** Raw response body from the API */
|
|
106
|
+
readonly responseBody: unknown;
|
|
107
|
+
constructor(message: string, statusCode: number, responseBody?: unknown);
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Error thrown when input validation fails
|
|
111
|
+
*/
|
|
112
|
+
declare class PaymoveValidationError extends PaymoveError {
|
|
113
|
+
/** The field that failed validation */
|
|
114
|
+
readonly field: string;
|
|
115
|
+
constructor(message: string, field: string);
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Error thrown when a network error occurs
|
|
119
|
+
*/
|
|
120
|
+
declare class PaymoveNetworkError extends PaymoveError {
|
|
121
|
+
/** The original error that caused this network error */
|
|
122
|
+
readonly cause: Error;
|
|
123
|
+
constructor(message: string, cause: Error);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
//#endregion
|
|
127
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
128
|
+
|
|
129
|
+
export { CreatePaymentParams, Environment, PaymentResponse, PaymoveApiError, PaymoveClient, PaymoveConfig, PaymoveError, PaymoveNetworkError, PaymoveValidationError };
|
|
130
|
+
//# sourceMappingURL=index.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/types.ts","../src/client.ts","../src/errors.ts"],"sourcesContent":null,"mappings":";;;;KAGY,WAAA;AAAZ;;;UAKiB,aAAA;EAAA;;;;EAYA;eANF;;;AAwBf;;UAlBiB,mBAAA;;;;;;;;;;;;;;;;;UAkBA,eAAA;;;;;;;;ACJjB;;;;;;AD/BA;;;;AAKA;;;;AAYA;;;;AAkBA;;;;;;cCJa,aAAA;;;;sBAKS;;;;;;;;;;wBAiBQ,sBAAsB,QAAQ;;;;;AAtB5D;;;;;;;;cC/Ba,YAAA,SAAqB,KAAK;EFA3B,WAAA,CAAA,OAAW,EAAA,MAAA;;;;AAKvB;cEMa,eAAA,SAAwB,YAAY;;;EFMhC;;;;AAkBjB;;;cEPa,sBAAA,SAA+B,YAAY;;;;;;;;cAc3C,mBAAA,SAA4B,YAAA;;kBAEhB;sCAEa"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
//#region src/types.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Environment type for Paymove API
|
|
4
|
+
*/
|
|
5
|
+
type Environment = 'sandbox' | 'production';
|
|
6
|
+
/**
|
|
7
|
+
* Configuration for PaymoveClient initialization
|
|
8
|
+
*/
|
|
9
|
+
interface PaymoveConfig {
|
|
10
|
+
/** Your Paymove API key */
|
|
11
|
+
apiKey: string;
|
|
12
|
+
/** Your merchant ID */
|
|
13
|
+
merchantId: string;
|
|
14
|
+
/** Environment to use (sandbox or production) */
|
|
15
|
+
environment: Environment;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Parameters for creating a payment
|
|
19
|
+
*/
|
|
20
|
+
interface CreatePaymentParams {
|
|
21
|
+
/** Payment amount in smallest currency unit (e.g., cents) */
|
|
22
|
+
amount: number;
|
|
23
|
+
/** Currency code (e.g., 'PLN', 'EUR', 'USD') */
|
|
24
|
+
currency: string;
|
|
25
|
+
/** Your unique order identifier */
|
|
26
|
+
orderId: string;
|
|
27
|
+
/** URL to redirect the user after payment */
|
|
28
|
+
returnUrl: string;
|
|
29
|
+
/** Optional payment description */
|
|
30
|
+
description?: string;
|
|
31
|
+
/** Additional custom fields */
|
|
32
|
+
[key: string]: unknown;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Response from payment creation
|
|
36
|
+
*/
|
|
37
|
+
interface PaymentResponse {
|
|
38
|
+
/** URL to redirect the user for payment */
|
|
39
|
+
redirectUrl: string;
|
|
40
|
+
/** Additional response fields from the API */
|
|
41
|
+
[key: string]: unknown;
|
|
42
|
+
} //#endregion
|
|
43
|
+
//#region src/client.d.ts
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* API error response structure
|
|
47
|
+
*/
|
|
48
|
+
/**
|
|
49
|
+
* Paymove SDK client for payment integration
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```typescript
|
|
53
|
+
* const client = new PaymoveClient({
|
|
54
|
+
* apiKey: 'your-api-key',
|
|
55
|
+
* merchantId: 'your-merchant-id',
|
|
56
|
+
* environment: 'sandbox'
|
|
57
|
+
* });
|
|
58
|
+
*
|
|
59
|
+
* const response = await client.createPayment({
|
|
60
|
+
* amount: 1000,
|
|
61
|
+
* currency: 'PLN',
|
|
62
|
+
* orderId: 'order-123',
|
|
63
|
+
* returnUrl: 'https://your-shop.com/success'
|
|
64
|
+
* });
|
|
65
|
+
*
|
|
66
|
+
* console.log(response.redirectUrl);
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
declare class PaymoveClient {
|
|
70
|
+
private readonly apiKey;
|
|
71
|
+
private readonly merchantId;
|
|
72
|
+
private readonly baseUrl;
|
|
73
|
+
constructor(config: PaymoveConfig);
|
|
74
|
+
/**
|
|
75
|
+
* Creates a new payment and returns the response with redirect URL
|
|
76
|
+
*
|
|
77
|
+
* @param params - Payment parameters
|
|
78
|
+
* @returns Payment response containing redirectUrl
|
|
79
|
+
* @throws {PaymoveValidationError} When required parameters are missing or invalid
|
|
80
|
+
* @throws {PaymoveApiError} When the API returns an error response
|
|
81
|
+
* @throws {PaymoveNetworkError} When a network error occurs
|
|
82
|
+
*/
|
|
83
|
+
createPayment(params: CreatePaymentParams): Promise<PaymentResponse>;
|
|
84
|
+
private validateConfig;
|
|
85
|
+
private validatePaymentParams;
|
|
86
|
+
private parseResponse;
|
|
87
|
+
private extractErrorMessage;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
//#endregion
|
|
91
|
+
//#region src/errors.d.ts
|
|
92
|
+
//# sourceMappingURL=client.d.ts.map
|
|
93
|
+
/**
|
|
94
|
+
* Base error class for all Paymove SDK errors
|
|
95
|
+
*/
|
|
96
|
+
declare class PaymoveError extends Error {
|
|
97
|
+
constructor(message: string);
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Error thrown when the API returns an error response
|
|
101
|
+
*/
|
|
102
|
+
declare class PaymoveApiError extends PaymoveError {
|
|
103
|
+
/** HTTP status code from the API */
|
|
104
|
+
readonly statusCode: number;
|
|
105
|
+
/** Raw response body from the API */
|
|
106
|
+
readonly responseBody: unknown;
|
|
107
|
+
constructor(message: string, statusCode: number, responseBody?: unknown);
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Error thrown when input validation fails
|
|
111
|
+
*/
|
|
112
|
+
declare class PaymoveValidationError extends PaymoveError {
|
|
113
|
+
/** The field that failed validation */
|
|
114
|
+
readonly field: string;
|
|
115
|
+
constructor(message: string, field: string);
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Error thrown when a network error occurs
|
|
119
|
+
*/
|
|
120
|
+
declare class PaymoveNetworkError extends PaymoveError {
|
|
121
|
+
/** The original error that caused this network error */
|
|
122
|
+
readonly cause: Error;
|
|
123
|
+
constructor(message: string, cause: Error);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
//#endregion
|
|
127
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
128
|
+
|
|
129
|
+
export { CreatePaymentParams, Environment, PaymentResponse, PaymoveApiError, PaymoveClient, PaymoveConfig, PaymoveError, PaymoveNetworkError, PaymoveValidationError };
|
|
130
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/types.ts","../src/client.ts","../src/errors.ts"],"sourcesContent":null,"mappings":";;;;KAGY,WAAA;AAAZ;;;UAKiB,aAAA;EAAA;;;;EAYA;eANF;;;AAwBf;;UAlBiB,mBAAA;;;;;;;;;;;;;;;;;UAkBA,eAAA;;;;;;;;ACJjB;;;;;;AD/BA;;;;AAKA;;;;AAYA;;;;AAkBA;;;;;;cCJa,aAAA;;;;sBAKS;;;;;;;;;;wBAiBQ,sBAAsB,QAAQ;;;;;AAtB5D;;;;;;;;cC/Ba,YAAA,SAAqB,KAAK;EFA3B,WAAA,CAAA,OAAW,EAAA,MAAA;;;;AAKvB;cEMa,eAAA,SAAwB,YAAY;;;EFMhC;;;;AAkBjB;;;cEPa,sBAAA,SAA+B,YAAY;;;;;;;;cAc3C,mBAAA,SAA4B,YAAA;;kBAEhB;sCAEa"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e={sandbox:`https://gateway-api.sandbox.paymove.io`,production:`https://gateway-api.paymove.io`};var t=class extends Error{constructor(e){super(e),this.name=`PaymoveError`,Object.setPrototypeOf(this,new.target.prototype)}},n=class extends t{statusCode;responseBody;constructor(e,t,n){super(e),this.name=`PaymoveApiError`,this.statusCode=t,this.responseBody=n}},r=class extends t{field;constructor(e,t){super(e),this.name=`PaymoveValidationError`,this.field=t}},i=class extends t{cause;constructor(e,t){super(e),this.name=`PaymoveNetworkError`,this.cause=t}},a=class{apiKey;merchantId;baseUrl;constructor(t){this.validateConfig(t),this.apiKey=t.apiKey,this.merchantId=t.merchantId,this.baseUrl=e[t.environment]}async createPayment(e){this.validatePaymentParams(e);let t=`${this.baseUrl}/api/pay/product/${this.merchantId}/subproduct/pricing`,{amount:a,currency:o,orderId:s,returnUrl:c,description:l,...u}=e,d={...u,price:a,externalId:s,description:l??s,details:JSON.stringify({currency:o,redirectUrl:c})};try{let e=await fetch(t,{method:`POST`,headers:{"Content-Type":`application/json`,"X-API-KEY":this.apiKey},body:JSON.stringify(d)}),r=await this.parseResponse(e);if(!e.ok){let t=this.extractErrorMessage(r);throw new n(t,e.status,r)}return r}catch(e){throw e instanceof n||e instanceof r?e:e instanceof Error?new i(`Network error while creating payment: ${e.message}`,e):new i(`Unknown network error while creating payment`,Error(String(e)))}}validateConfig(e){if(!e.apiKey||typeof e.apiKey!=`string`)throw new r(`apiKey is required and must be a string`,`apiKey`);if(!e.merchantId||typeof e.merchantId!=`string`)throw new r(`merchantId is required and must be a string`,`merchantId`);if(!e.environment||![`sandbox`,`production`].includes(e.environment))throw new r(`environment must be either "sandbox" or "production"`,`environment`)}validatePaymentParams(e){if(typeof e.amount!=`number`||e.amount<=0)throw new r(`amount is required and must be a positive number`,`amount`);if(!e.currency||typeof e.currency!=`string`)throw new r(`currency is required and must be a string`,`currency`);if(!e.orderId||typeof e.orderId!=`string`)throw new r(`orderId is required and must be a string`,`orderId`);if(!e.returnUrl||typeof e.returnUrl!=`string`)throw new r(`returnUrl is required and must be a string`,`returnUrl`);try{new URL(e.returnUrl)}catch{throw new r(`returnUrl must be a valid URL`,`returnUrl`)}}async parseResponse(e){let t=e.headers.get(`content-type`);if(t?.includes(`application/json`))try{return await e.json()}catch{throw new n(`Failed to parse JSON response from API`,e.status)}let r=await e.text();return{message:r}}extractErrorMessage(e){if(typeof e==`object`&&e){let t=e;return t.message||t.error||`Unknown API error`}return`Unknown API error`}};export{n as PaymoveApiError,a as PaymoveClient,t as PaymoveError,i as PaymoveNetworkError,r as PaymoveValidationError};
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["ENDPOINTS: Record<Environment, string>","message: string","statusCode: number","responseBody?: unknown","field: string","cause: Error","config: PaymoveConfig","params: CreatePaymentParams","response: Response","responseData: unknown"],"sources":["../src/constants.ts","../src/errors.ts","../src/client.ts"],"sourcesContent":["import type { Environment } from \"./types.js\";\n\nexport const ENDPOINTS: Record<Environment, string> = {\n sandbox: \"https://gateway-api.sandbox.paymove.io\",\n production: \"https://gateway-api.paymove.io\",\n} as const;\n","/**\n * Base error class for all Paymove SDK errors\n */\nexport class PaymoveError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'PaymoveError';\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\n/**\n * Error thrown when the API returns an error response\n */\nexport class PaymoveApiError extends PaymoveError {\n /** HTTP status code from the API */\n public readonly statusCode: number;\n /** Raw response body from the API */\n public readonly responseBody: unknown;\n\n constructor(message: string, statusCode: number, responseBody?: unknown) {\n super(message);\n this.name = 'PaymoveApiError';\n this.statusCode = statusCode;\n this.responseBody = responseBody;\n }\n}\n\n/**\n * Error thrown when input validation fails\n */\nexport class PaymoveValidationError extends PaymoveError {\n /** The field that failed validation */\n public readonly field: string;\n\n constructor(message: string, field: string) {\n super(message);\n this.name = 'PaymoveValidationError';\n this.field = field;\n }\n}\n\n/**\n * Error thrown when a network error occurs\n */\nexport class PaymoveNetworkError extends PaymoveError {\n /** The original error that caused this network error */\n public readonly cause: Error;\n\n constructor(message: string, cause: Error) {\n super(message);\n this.name = 'PaymoveNetworkError';\n this.cause = cause;\n }\n}\n","import { ENDPOINTS } from \"./constants.js\";\nimport {\n PaymoveApiError,\n PaymoveNetworkError,\n PaymoveValidationError,\n} from \"./errors.js\";\nimport type {\n ApiErrorResponse,\n CreatePaymentParams,\n PaymoveConfig,\n PaymentResponse,\n} from \"./types.js\";\n\n/**\n * Paymove SDK client for payment integration\n *\n * @example\n * ```typescript\n * const client = new PaymoveClient({\n * apiKey: 'your-api-key',\n * merchantId: 'your-merchant-id',\n * environment: 'sandbox'\n * });\n *\n * const response = await client.createPayment({\n * amount: 1000,\n * currency: 'PLN',\n * orderId: 'order-123',\n * returnUrl: 'https://your-shop.com/success'\n * });\n *\n * console.log(response.redirectUrl);\n * ```\n */\nexport class PaymoveClient {\n private readonly apiKey: string;\n private readonly merchantId: string;\n private readonly baseUrl: string;\n\n constructor(config: PaymoveConfig) {\n this.validateConfig(config);\n\n this.apiKey = config.apiKey;\n this.merchantId = config.merchantId;\n this.baseUrl = ENDPOINTS[config.environment];\n }\n\n /**\n * Creates a new payment and returns the response with redirect URL\n *\n * @param params - Payment parameters\n * @returns Payment response containing redirectUrl\n * @throws {PaymoveValidationError} When required parameters are missing or invalid\n * @throws {PaymoveApiError} When the API returns an error response\n * @throws {PaymoveNetworkError} When a network error occurs\n */\n async createPayment(params: CreatePaymentParams): Promise<PaymentResponse> {\n this.validatePaymentParams(params);\n\n const url = `${this.baseUrl}/api/pay/product/${this.merchantId}/subproduct/pricing`;\n\n const { amount, currency, orderId, returnUrl, description, ...rest } =\n params;\n\n const body = {\n ...rest,\n price: amount,\n externalId: orderId,\n description: description ?? orderId,\n details: JSON.stringify({\n currency,\n redirectUrl: returnUrl,\n }),\n };\n\n try {\n const response = await fetch(url, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n \"X-API-KEY\": this.apiKey,\n },\n body: JSON.stringify(body),\n });\n\n const responseData = await this.parseResponse(response);\n\n if (!response.ok) {\n const errorMessage = this.extractErrorMessage(responseData);\n throw new PaymoveApiError(errorMessage, response.status, responseData);\n }\n\n return responseData as PaymentResponse;\n } catch (error) {\n if (\n error instanceof PaymoveApiError ||\n error instanceof PaymoveValidationError\n ) {\n throw error;\n }\n\n if (error instanceof Error) {\n throw new PaymoveNetworkError(\n `Network error while creating payment: ${error.message}`,\n error\n );\n }\n\n throw new PaymoveNetworkError(\n \"Unknown network error while creating payment\",\n new Error(String(error))\n );\n }\n }\n\n private validateConfig(config: PaymoveConfig): void {\n if (!config.apiKey || typeof config.apiKey !== \"string\") {\n throw new PaymoveValidationError(\n \"apiKey is required and must be a string\",\n \"apiKey\"\n );\n }\n\n if (!config.merchantId || typeof config.merchantId !== \"string\") {\n throw new PaymoveValidationError(\n \"merchantId is required and must be a string\",\n \"merchantId\"\n );\n }\n\n if (\n !config.environment ||\n ![\"sandbox\", \"production\"].includes(config.environment)\n ) {\n throw new PaymoveValidationError(\n 'environment must be either \"sandbox\" or \"production\"',\n \"environment\"\n );\n }\n }\n\n private validatePaymentParams(params: CreatePaymentParams): void {\n if (typeof params.amount !== \"number\" || params.amount <= 0) {\n throw new PaymoveValidationError(\n \"amount is required and must be a positive number\",\n \"amount\"\n );\n }\n\n if (!params.currency || typeof params.currency !== \"string\") {\n throw new PaymoveValidationError(\n \"currency is required and must be a string\",\n \"currency\"\n );\n }\n\n if (!params.orderId || typeof params.orderId !== \"string\") {\n throw new PaymoveValidationError(\n \"orderId is required and must be a string\",\n \"orderId\"\n );\n }\n\n if (!params.returnUrl || typeof params.returnUrl !== \"string\") {\n throw new PaymoveValidationError(\n \"returnUrl is required and must be a string\",\n \"returnUrl\"\n );\n }\n\n try {\n new URL(params.returnUrl);\n } catch {\n throw new PaymoveValidationError(\n \"returnUrl must be a valid URL\",\n \"returnUrl\"\n );\n }\n }\n\n private async parseResponse(response: Response): Promise<unknown> {\n const contentType = response.headers.get(\"content-type\");\n\n if (contentType?.includes(\"application/json\")) {\n try {\n return await response.json();\n } catch {\n throw new PaymoveApiError(\n \"Failed to parse JSON response from API\",\n response.status\n );\n }\n }\n\n const text = await response.text();\n return { message: text };\n }\n\n private extractErrorMessage(responseData: unknown): string {\n if (typeof responseData === \"object\" && responseData !== null) {\n const data = responseData as ApiErrorResponse;\n return data.message || data.error || \"Unknown API error\";\n }\n\n return \"Unknown API error\";\n }\n}\n"],"mappings":"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"}
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@paymove-io/sdk",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"publishConfig": {
|
|
5
|
+
"access": "public"
|
|
6
|
+
},
|
|
7
|
+
"description": "Official Paymove SDK for payment integration",
|
|
8
|
+
"type": "module",
|
|
9
|
+
"main": "./dist/index.cjs",
|
|
10
|
+
"module": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"import": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"default": "./dist/index.js"
|
|
17
|
+
},
|
|
18
|
+
"require": {
|
|
19
|
+
"types": "./dist/index.d.cts",
|
|
20
|
+
"default": "./dist/index.cjs"
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"dist"
|
|
26
|
+
],
|
|
27
|
+
"scripts": {
|
|
28
|
+
"build": "tsdown",
|
|
29
|
+
"dev": "tsdown --watch",
|
|
30
|
+
"prepublishOnly": "npm run build"
|
|
31
|
+
},
|
|
32
|
+
"keywords": [
|
|
33
|
+
"paymove",
|
|
34
|
+
"payment",
|
|
35
|
+
"sdk",
|
|
36
|
+
"api"
|
|
37
|
+
],
|
|
38
|
+
"author": "Paymove",
|
|
39
|
+
"license": "MIT",
|
|
40
|
+
"engines": {
|
|
41
|
+
"node": ">=18.0.0"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@types/node": "^20.10.0",
|
|
45
|
+
"tsdown": "^0.9.0",
|
|
46
|
+
"typescript": "^5.3.0"
|
|
47
|
+
}
|
|
48
|
+
}
|