@paymove-io/sdk 0.1.3 → 0.1.5
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 +39 -30
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -0
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -33,10 +33,12 @@ try {
|
|
|
33
33
|
returnUrl: 'https://your-shop.com/success',
|
|
34
34
|
// optional: description
|
|
35
35
|
description: 'Payment for order #123',
|
|
36
|
-
// optional: any additional custom fields
|
|
37
|
-
customField: 'custom-value',
|
|
38
36
|
// optional: locale
|
|
39
37
|
locale: 'pl-PL'
|
|
38
|
+
//optional: Iban account
|
|
39
|
+
bankAccount: 'PL10105000997623123456789123'
|
|
40
|
+
// optional: any additional custom fields
|
|
41
|
+
customField: 'custom-value',
|
|
40
42
|
});
|
|
41
43
|
|
|
42
44
|
// Redirect user to payment page
|
|
@@ -58,11 +60,11 @@ try {
|
|
|
58
60
|
new PaymoveClient(config: PaymoveConfig)
|
|
59
61
|
```
|
|
60
62
|
|
|
61
|
-
| Parameter
|
|
62
|
-
|
|
63
|
-
| `config.apiKey`
|
|
64
|
-
| `config.merchantId`
|
|
65
|
-
| `config.environment` | `'sandbox' \| 'production'` | API environment
|
|
63
|
+
| Parameter | Type | Description |
|
|
64
|
+
| -------------------- | --------------------------- | -------------------- |
|
|
65
|
+
| `config.apiKey` | `string` | Your Paymove API key |
|
|
66
|
+
| `config.merchantId` | `string` | Your merchant ID |
|
|
67
|
+
| `config.environment` | `'sandbox' \| 'production'` | API environment |
|
|
66
68
|
|
|
67
69
|
#### Methods
|
|
68
70
|
|
|
@@ -74,15 +76,16 @@ Creates a new payment and returns the response with redirect URL.
|
|
|
74
76
|
client.createPayment(params: CreatePaymentParams): Promise<PaymentResponse>
|
|
75
77
|
```
|
|
76
78
|
|
|
77
|
-
| Parameter
|
|
78
|
-
|
|
79
|
-
| `amount`
|
|
80
|
-
| `currency`
|
|
81
|
-
| `orderId`
|
|
82
|
-
| `returnUrl`
|
|
83
|
-
| `description` | `string`
|
|
84
|
-
| `locale`
|
|
85
|
-
| `
|
|
79
|
+
| Parameter | Type | Required | Description |
|
|
80
|
+
| ------------- | --------- | -------- | ---------------------------------------- |
|
|
81
|
+
| `amount` | `number` | Yes | Payment amount in smallest currency unit |
|
|
82
|
+
| `currency` | `string` | Yes | Currency code (e.g., 'PLN', 'EUR') |
|
|
83
|
+
| `orderId` | `string` | Yes | Your unique order identifier |
|
|
84
|
+
| `returnUrl` | `string` | Yes | URL to redirect after payment |
|
|
85
|
+
| `description` | `string` | No | Payment description |
|
|
86
|
+
| `locale` | `string` | No | Locale |
|
|
87
|
+
| `bankAccount` | `string` | No | Iban account |
|
|
88
|
+
| `[key]` | `unknown` | No | Additional custom fields |
|
|
86
89
|
|
|
87
90
|
**Returns:** `Promise<PaymentResponse>` - Response containing `redirectUrl` and other API fields.
|
|
88
91
|
|
|
@@ -95,14 +98,16 @@ The SDK provides custom error classes for different error scenarios:
|
|
|
95
98
|
Thrown when input validation fails.
|
|
96
99
|
|
|
97
100
|
```typescript
|
|
98
|
-
import { PaymoveValidationError } from
|
|
101
|
+
import { PaymoveValidationError } from "@paymove-io/sdk";
|
|
99
102
|
|
|
100
103
|
try {
|
|
101
|
-
await client.createPayment({
|
|
104
|
+
await client.createPayment({
|
|
105
|
+
/* invalid params */
|
|
106
|
+
});
|
|
102
107
|
} catch (error) {
|
|
103
108
|
if (error instanceof PaymoveValidationError) {
|
|
104
|
-
console.error(
|
|
105
|
-
console.error(
|
|
109
|
+
console.error("Validation failed for field:", error.field);
|
|
110
|
+
console.error("Message:", error.message);
|
|
106
111
|
}
|
|
107
112
|
}
|
|
108
113
|
```
|
|
@@ -112,15 +117,17 @@ try {
|
|
|
112
117
|
Thrown when the API returns an error response.
|
|
113
118
|
|
|
114
119
|
```typescript
|
|
115
|
-
import { PaymoveApiError } from
|
|
120
|
+
import { PaymoveApiError } from "@paymove-io/sdk";
|
|
116
121
|
|
|
117
122
|
try {
|
|
118
|
-
await client.createPayment({
|
|
123
|
+
await client.createPayment({
|
|
124
|
+
/* params */
|
|
125
|
+
});
|
|
119
126
|
} catch (error) {
|
|
120
127
|
if (error instanceof PaymoveApiError) {
|
|
121
|
-
console.error(
|
|
122
|
-
console.error(
|
|
123
|
-
console.error(
|
|
128
|
+
console.error("Status code:", error.statusCode);
|
|
129
|
+
console.error("Message:", error.message);
|
|
130
|
+
console.error("Response body:", error.responseBody);
|
|
124
131
|
}
|
|
125
132
|
}
|
|
126
133
|
```
|
|
@@ -130,14 +137,16 @@ try {
|
|
|
130
137
|
Thrown when a network error occurs.
|
|
131
138
|
|
|
132
139
|
```typescript
|
|
133
|
-
import { PaymoveNetworkError } from
|
|
140
|
+
import { PaymoveNetworkError } from "@paymove-io/sdk";
|
|
134
141
|
|
|
135
142
|
try {
|
|
136
|
-
await client.createPayment({
|
|
143
|
+
await client.createPayment({
|
|
144
|
+
/* params */
|
|
145
|
+
});
|
|
137
146
|
} catch (error) {
|
|
138
147
|
if (error instanceof PaymoveNetworkError) {
|
|
139
|
-
console.error(
|
|
140
|
-
console.error(
|
|
148
|
+
console.error("Network error:", error.message);
|
|
149
|
+
console.error("Original error:", error.cause);
|
|
141
150
|
}
|
|
142
151
|
}
|
|
143
152
|
```
|
|
@@ -152,7 +161,7 @@ import type {
|
|
|
152
161
|
CreatePaymentParams,
|
|
153
162
|
PaymentResponse,
|
|
154
163
|
Environment,
|
|
155
|
-
} from
|
|
164
|
+
} from "@paymove-io/sdk";
|
|
156
165
|
```
|
|
157
166
|
|
|
158
167
|
## License
|
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";const e={sandbox:`https://gateway-api.sandbox.paymove.io`,production:`https://
|
|
1
|
+
"use strict";const e={sandbox:`https://gateway-api.sandbox.paymove.io`,production:`https://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,orderId:o,returnUrl:s,description:c,bankAccount:l,...u}=e,d={price:a,externalId:o,description:c,bankAccount:l,details:{orderId:o,redirectUrl:s,...u}};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`);if(!e.email||typeof e.email!=`string`)throw new r(`email is required and must be a string`,`email`);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
2
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +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, orderId, returnUrl, description, ...rest } = params;\n\n const body = {\n price: amount,\n externalId: orderId,\n description,\n details: {\n orderId,\n redirectUrl: returnUrl,\n ...rest,\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 if (!params.email || typeof params.email !== \"string\") {\n throw new PaymoveValidationError(\n \"email is required and must be a string\",\n \"email\"\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":"aAEA,MAAaA,EAAyC,CACpD,QAAS,yCACT,WAAY,gCACb,EE6BD,ID/Ba,EAAb,cAAkC,KAAM,CACtC,YAAYC,EAAiB,CAG3B,AAFA,MAAM,EAAQ,CACd,KAAK,KAAO,eACZ,OAAO,eAAe,KAAM,IAAI,OAAO,UAAU,AAClD,CACF,EAKY,EAAb,cAAqC,CAAa,CAEhD,WAEA,aAEA,YAAYA,EAAiBC,EAAoBC,EAAwB,CAIvE,AAHA,MAAM,EAAQ,CACd,KAAK,KAAO,kBACZ,KAAK,WAAa,EAClB,KAAK,aAAe,CACrB,CACF,EAKY,EAAb,cAA4C,CAAa,CAEvD,MAEA,YAAYF,EAAiBG,EAAe,CAG1C,AAFA,MAAM,EAAQ,CACd,KAAK,KAAO,yBACZ,KAAK,MAAQ,CACd,CACF,EAKY,EAAb,cAAyC,CAAa,CAEpD,MAEA,YAAYH,EAAiBI,EAAc,CAGzC,AAFA,MAAM,EAAQ,CACd,KAAK,KAAO,sBACZ,KAAK,MAAQ,CACd,CACF,ECpBY,EAAb,KAA2B,CACzB,OACA,WACA,QAEA,YAAYC,EAAuB,CAKjC,AAJA,KAAK,eAAe,EAAO,CAE3B,KAAK,OAAS,EAAO,OACrB,KAAK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EAAO,gBAAkB,EAAO,SAAY,SAC/C,MAAM,IAAI,EACR,2CACA,WAIJ,IAAK,EAAO,kBAAoB,EAAO,WAAc,SACnD,MAAM,IAAI,EACR,6CACA,aAIJ,IAAK,EAAO,cAAgB,EAAO,OAAU,SAC3C,MAAM,IAAI,EACR,yCACA,SAIJ,GAAI,CACF,IAAI,IAAI,EAAO,UAChB,MAAO,CACN,MAAM,IAAI,EACR,gCACA,YAEH,CACF,CAED,MAAc,cAAcC,EAAsC,CAChE,IAAM,EAAc,EAAS,QAAQ,IAAI,eAAe,CAExD,GAAI,GAAa,SAAS,mBAAmB,CAC3C,GAAI,CACF,OAAO,KAAM,GAAS,MAAM,AAC7B,MAAO,CACN,MAAM,IAAI,EACR,yCACA,EAAS,OAEZ,CAGH,IAAM,EAAO,KAAM,GAAS,MAAM,CAClC,MAAO,CAAE,QAAS,CAAM,CACzB,CAED,oBAA4BC,EAA+B,CACzD,UAAW,GAAiB,UAAY,EAAuB,CAC7D,IAAM,EAAO,EACb,OAAO,EAAK,SAAW,EAAK,OAAS,mBACtC,CAED,MAAO,mBACR,CACF"}
|
|
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://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, orderId, returnUrl, description, bankAccount, ...rest } = params;\n\n const body = {\n price: amount,\n externalId: orderId,\n description,\n bankAccount,\n details: {\n orderId,\n redirectUrl: returnUrl,\n ...rest,\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 if (!params.email || typeof params.email !== \"string\") {\n throw new PaymoveValidationError(\n \"email is required and must be a string\",\n \"email\"\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":"aAEA,MAAaA,EAAyC,CACpD,QAAS,yCACT,WAAY,wBACb,EE6BD,ID/Ba,EAAb,cAAkC,KAAM,CACtC,YAAYC,EAAiB,CAG3B,AAFA,MAAM,EAAQ,CACd,KAAK,KAAO,eACZ,OAAO,eAAe,KAAM,IAAI,OAAO,UAAU,AAClD,CACF,EAKY,EAAb,cAAqC,CAAa,CAEhD,WAEA,aAEA,YAAYA,EAAiBC,EAAoBC,EAAwB,CAIvE,AAHA,MAAM,EAAQ,CACd,KAAK,KAAO,kBACZ,KAAK,WAAa,EAClB,KAAK,aAAe,CACrB,CACF,EAKY,EAAb,cAA4C,CAAa,CAEvD,MAEA,YAAYF,EAAiBG,EAAe,CAG1C,AAFA,MAAM,EAAQ,CACd,KAAK,KAAO,yBACZ,KAAK,MAAQ,CACd,CACF,EAKY,EAAb,cAAyC,CAAa,CAEpD,MAEA,YAAYH,EAAiBI,EAAc,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vD,MAAM,IAAI,EACR,uDACA,cAGL,CAED,sBAA8BC,EAAmC,CAC/D,UAAW,EAAO,QAAW,UAAY,EAAO,QAAU,EACxD,MAAM,IAAI,EACR,mDACA,UAIJ,IAAK,EAAO,iBAAmB,EAAO,UAAa,SACjD,MAAM,IAAI,EACR,4CACA,YAIJ,IAAK,EAAO,gBAAkB,EAAO,SAAY,SAC/C,MAAM,IAAI,EACR,2CACA,WAIJ,IAAK,EAAO,kBAAoB,EAAO,WAAc,SACnD,MAAM,IAAI,EACR,6CACA,aAIJ,IAAK,EAAO,cAAgB,EAAO,OAAU,SAC3C,MAAM,IAAI,EACR,yCACA,SAIJ,GAAI,CACF,IAAI,IAAI,EAAO,UAChB,MAAO,CACN,MAAM,IAAI,EACR,gCACA,YAEH,CACF,CAED,MAAc,cAAcC,EAAsC,CAChE,IAAM,EAAc,EAAS,QAAQ,IAAI,eAAe,CAExD,GAAI,GAAa,SAAS,mBAAmB,CAC3C,GAAI,CACF,OAAO,KAAM,GAAS,MAAM,AAC7B,MAAO,CACN,MAAM,IAAI,EACR,yCACA,EAAS,OAEZ,CAGH,IAAM,EAAO,KAAM,GAAS,MAAM,CAClC,MAAO,CAAE,QAAS,CAAM,CACzB,CAED,oBAA4BC,EAA+B,CACzD,UAAW,GAAiB,UAAY,EAAuB,CAC7D,IAAM,EAAO,EACb,OAAO,EAAK,SAAW,EAAK,OAAS,mBACtC,CAED,MAAO,mBACR,CACF"}
|
package/dist/index.d.cts
CHANGED
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +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;;;
|
|
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;;;AA+Bf;;UAzBiB,mBAAA;;;;;;;;;;;;;;;;;;;;;;;ACcJ,UDWI,eAAA,CCXS;EAAA;EAAA,WAKJ,EAAA,MAAA;EAAa;EAiBc,CAAA,GAAW,EAAA,MAAA,CAAA,EAAA,OAAA;CAAe;;;AAAhB;;;;;;ADrD3D;;;;AAKA;;;;AAYA;;;;AAyBA;;;;;;cCXa,aAAA;;;;sBAKS;;;;;;;;;;wBAiBQ,sBAAsB,QAAQ;;;;;AAtB5D;;;;;;;;cC/Ba,YAAA,SAAqB,KAAK;EFA3B,WAAA,CAAA,OAAW,EAAA,MAAA;;;;AAKvB;cEMa,eAAA,SAAwB,YAAY;;;EFMhC;;;;AAyBjB;;;cEda,sBAAA,SAA+B,YAAY;;;;;;;;cAc3C,mBAAA,SAA4B,YAAA;;kBAEhB;sCAEa"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +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;;;
|
|
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;;;AA+Bf;;UAzBiB,mBAAA;;;;;;;;;;;;;;;;;;;;;;;ACcJ,UDWI,eAAA,CCXS;EAAA;EAAA,WAKJ,EAAA,MAAA;EAAa;EAiBc,CAAA,GAAW,EAAA,MAAA,CAAA,EAAA,OAAA;CAAe;;;AAAhB;;;;;;ADrD3D;;;;AAKA;;;;AAYA;;;;AAyBA;;;;;;cCXa,aAAA;;;;sBAKS;;;;;;;;;;wBAiBQ,sBAAsB,QAAQ;;;;;AAtB5D;;;;;;;;cC/Ba,YAAA,SAAqB,KAAK;EFA3B,WAAA,CAAA,OAAW,EAAA,MAAA;;;;AAKvB;cEMa,eAAA,SAAwB,YAAY;;;EFMhC;;;;AAyBjB;;;cEda,sBAAA,SAA+B,YAAY;;;;;;;;cAc3C,mBAAA,SAA4B,YAAA;;kBAEhB;sCAEa"}
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e={sandbox:`https://gateway-api.sandbox.paymove.io`,production:`https://
|
|
1
|
+
const e={sandbox:`https://gateway-api.sandbox.paymove.io`,production:`https://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,orderId:o,returnUrl:s,description:c,bankAccount:l,...u}=e,d={price:a,externalId:o,description:c,bankAccount:l,details:{orderId:o,redirectUrl:s,...u}};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`);if(!e.email||typeof e.email!=`string`)throw new r(`email is required and must be a string`,`email`);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
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +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, orderId, returnUrl, description, ...rest } = params;\n\n const body = {\n price: amount,\n externalId: orderId,\n description,\n details: {\n orderId,\n redirectUrl: returnUrl,\n ...rest,\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 if (!params.email || typeof params.email !== \"string\") {\n throw new PaymoveValidationError(\n \"email is required and must be a string\",\n \"email\"\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":"AAEA,MAAaA,EAAyC,CACpD,QAAS,yCACT,WAAY,gCACb,EE6BD,ID/Ba,EAAb,cAAkC,KAAM,CACtC,YAAYC,EAAiB,CAG3B,AAFA,MAAM,EAAQ,CACd,KAAK,KAAO,eACZ,OAAO,eAAe,KAAM,IAAI,OAAO,UAAU,AAClD,CACF,EAKY,EAAb,cAAqC,CAAa,CAEhD,WAEA,aAEA,YAAYA,EAAiBC,EAAoBC,EAAwB,CAIvE,AAHA,MAAM,EAAQ,CACd,KAAK,KAAO,kBACZ,KAAK,WAAa,EAClB,KAAK,aAAe,CACrB,CACF,EAKY,EAAb,cAA4C,CAAa,CAEvD,MAEA,YAAYF,EAAiBG,EAAe,CAG1C,AAFA,MAAM,EAAQ,CACd,KAAK,KA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AI,EACR,8CACA,cAIJ,IACG,EAAO,cACP,CAAC,UAAW,YAAa,EAAC,SAAS,EAAO,YAAY,CAEvD,MAAM,IAAI,EACR,uDACA,cAGL,CAED,sBAA8BC,EAAmC,CAC/D,UAAW,EAAO,QAAW,UAAY,EAAO,QAAU,EACxD,MAAM,IAAI,EACR,mDACA,UAIJ,IAAK,EAAO,iBAAmB,EAAO,UAAa,SACjD,MAAM,IAAI,EACR,4CACA,YAIJ,IAAK,EAAO,gBAAkB,EAAO,SAAY,SAC/C,MAAM,IAAI,EACR,2CACA,WAIJ,IAAK,EAAO,kBAAoB,EAAO,WAAc,SACnD,MAAM,IAAI,EACR,6CACA,aAIJ,IAAK,EAAO,cAAgB,EAAO,OAAU,SAC3C,MAAM,IAAI,EACR,yCACA,SAIJ,GAAI,CACF,IAAI,IAAI,EAAO,UAChB,MAAO,CACN,MAAM,IAAI,EACR,gCACA,YAEH,CACF,CAED,MAAc,cAAcC,EAAsC,CAChE,IAAM,EAAc,EAAS,QAAQ,IAAI,eAAe,CAExD,GAAI,GAAa,SAAS,mBAAmB,CAC3C,GAAI,CACF,OAAO,KAAM,GAAS,MAAM,AAC7B,MAAO,CACN,MAAM,IAAI,EACR,yCACA,EAAS,OAEZ,CAGH,IAAM,EAAO,KAAM,GAAS,MAAM,CAClC,MAAO,CAAE,QAAS,CAAM,CACzB,CAED,oBAA4BC,EAA+B,CACzD,UAAW,GAAiB,UAAY,EAAuB,CAC7D,IAAM,EAAO,EACb,OAAO,EAAK,SAAW,EAAK,OAAS,mBACtC,CAED,MAAO,mBACR,CACF"}
|
|
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://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, orderId, returnUrl, description, bankAccount, ...rest } = params;\n\n const body = {\n price: amount,\n externalId: orderId,\n description,\n bankAccount,\n details: {\n orderId,\n redirectUrl: returnUrl,\n ...rest,\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 if (!params.email || typeof params.email !== \"string\") {\n throw new PaymoveValidationError(\n \"email is required and must be a string\",\n \"email\"\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":"AAEA,MAAaA,EAAyC,CACpD,QAAS,yCACT,WAAY,wBACb,EE6BD,ID/Ba,EAAb,cAAkC,KAAM,CACtC,YAAYC,EAAiB,CAG3B,AAFA,MAAM,EAAQ,CACd,KAAK,KAAO,eACZ,OAAO,eAAe,KAAM,IAAI,OAAO,UAAU,AAClD,CACF,EAKY,EAAb,cAAqC,CAAa,CAEhD,WAEA,aAEA,YAAYA,EAAiBC,EAAoBC,EAA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