pycer-sdk 1.0.2 → 1.0.3
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 +21 -11
- package/dist/{index-XbnGOTNP.d.cts → index-DQD3PJ4L.d.cts} +4 -2
- package/dist/{index-XbnGOTNP.d.ts → index-DQD3PJ4L.d.ts} +4 -2
- package/dist/index.cjs +20 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -5
- package/dist/index.d.ts +5 -5
- package/dist/index.js +20 -17
- package/dist/index.js.map +1 -1
- package/dist/webhooks/index.d.cts +1 -1
- package/dist/webhooks/index.d.ts +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
[](https://opensource.org/licenses/MIT)
|
|
5
5
|
[](https://nodejs.org/)
|
|
6
6
|
|
|
7
|
-
Official Node.js SDK for
|
|
7
|
+
Official Node.js SDK for Pycer Pay. A TypeScript SDK with zero runtime dependencies.
|
|
8
8
|
|
|
9
9
|
## Features
|
|
10
10
|
|
|
@@ -38,21 +38,31 @@ pnpm add pycer-sdk
|
|
|
38
38
|
|
|
39
39
|
## Quick Start
|
|
40
40
|
|
|
41
|
-
### Initialize the
|
|
41
|
+
### Initialize the client
|
|
42
|
+
|
|
43
|
+
Set these variables in your backend environment. If using a `.env` file, load it before initializing the SDK.
|
|
44
|
+
|
|
45
|
+
```dotenv
|
|
46
|
+
PYCER_API_KEY=op_REPLACE_WITH_YOUR_MERCHANT_API_KEY
|
|
47
|
+
PYCER_ENV=sandbox
|
|
48
|
+
```
|
|
42
49
|
|
|
43
50
|
```typescript
|
|
44
|
-
import
|
|
51
|
+
import Pycer from 'pycer-sdk';
|
|
45
52
|
|
|
46
|
-
|
|
47
|
-
const client = new OwnPay({
|
|
48
|
-
apiKey: 'op_your_api_key_here',
|
|
49
|
-
baseUrl: 'https://your-apisix-gateway.example/ownpay',
|
|
50
|
-
checkoutBaseUrl: 'https://your-ownpay-brand.example',
|
|
51
|
-
timeout: 30000, // Request timeout in ms (default: 30000)
|
|
52
|
-
maxRetries: 2, // Max retry attempts (default: 2)
|
|
53
|
-
});
|
|
53
|
+
const client = new Pycer();
|
|
54
54
|
```
|
|
55
55
|
|
|
56
|
+
Sandbox and production both default to `https://pycer.quantivogroup.com`.
|
|
57
|
+
Enable Sandbox Mode for the payment gateway in the portal before making test
|
|
58
|
+
payments. `PYCER_ENV` chooses SDK endpoint settings. The portal controls whether
|
|
59
|
+
payments use the sandbox.
|
|
60
|
+
|
|
61
|
+
Override the URL with `baseUrl`, `PYCER_SANDBOX_BASE_URL` or
|
|
62
|
+
`PYCER_PRODUCTION_BASE_URL`, or the shared `PYCER_BASE_URL`. The legacy
|
|
63
|
+
`OWNPAY_BASE_URL` remains a fallback. Set `checkoutBaseUrl` for a separate
|
|
64
|
+
public checkout host. You can also pass `apiKey` and `environment` explicitly.
|
|
65
|
+
|
|
56
66
|
### Initiate a rail payment
|
|
57
67
|
|
|
58
68
|
```typescript
|
|
@@ -9,8 +9,10 @@
|
|
|
9
9
|
*/
|
|
10
10
|
interface OwnPayConfig {
|
|
11
11
|
/** API key starting with 'op_' prefix */
|
|
12
|
-
apiKey
|
|
13
|
-
/**
|
|
12
|
+
apiKey?: string;
|
|
13
|
+
/** Endpoint environment. Defaults to PYCER_ENV, then the key prefix or production. */
|
|
14
|
+
environment?: 'sandbox' | 'production';
|
|
15
|
+
/** Pycer APISIX base URL. Overrides environment settings. */
|
|
14
16
|
baseUrl?: string;
|
|
15
17
|
/** Public OwnPay-branded browser checkout URL when the API uses a gateway. */
|
|
16
18
|
checkoutBaseUrl?: string;
|
|
@@ -9,8 +9,10 @@
|
|
|
9
9
|
*/
|
|
10
10
|
interface OwnPayConfig {
|
|
11
11
|
/** API key starting with 'op_' prefix */
|
|
12
|
-
apiKey
|
|
13
|
-
/**
|
|
12
|
+
apiKey?: string;
|
|
13
|
+
/** Endpoint environment. Defaults to PYCER_ENV, then the key prefix or production. */
|
|
14
|
+
environment?: 'sandbox' | 'production';
|
|
15
|
+
/** Pycer APISIX base URL. Overrides environment settings. */
|
|
14
16
|
baseUrl?: string;
|
|
15
17
|
/** Public OwnPay-branded browser checkout URL when the API uses a gateway. */
|
|
16
18
|
checkoutBaseUrl?: string;
|
package/dist/index.cjs
CHANGED
|
@@ -181,11 +181,15 @@ function calculateBackoff(attempt, baseDelay = 1e3, maxDelay = 3e4) {
|
|
|
181
181
|
}
|
|
182
182
|
|
|
183
183
|
// src/core/client.ts
|
|
184
|
+
var PORTAL_BASE_URLS = {
|
|
185
|
+
sandbox: "https://pycer.quantivogroup.com",
|
|
186
|
+
production: "https://pycer.quantivogroup.com"
|
|
187
|
+
};
|
|
184
188
|
var DEFAULT_CONFIG = {
|
|
185
189
|
TIMEOUT: 3e4,
|
|
186
190
|
MAX_RETRIES: 2,
|
|
187
191
|
API_VERSION: "v1",
|
|
188
|
-
USER_AGENT: "
|
|
192
|
+
USER_AGENT: "Pycer-SDK/1.0.3"
|
|
189
193
|
};
|
|
190
194
|
var RETRYABLE_STATUS_CODES = /* @__PURE__ */ new Set([429, 500, 502, 503, 504]);
|
|
191
195
|
var HttpClient = class {
|
|
@@ -196,22 +200,21 @@ var HttpClient = class {
|
|
|
196
200
|
apiVersion;
|
|
197
201
|
defaultHeaders;
|
|
198
202
|
constructor(config, auth = "ownpay") {
|
|
199
|
-
|
|
203
|
+
const apiKey = config.apiKey ?? (auth === "ownpay" ? process.env.PYCER_API_KEY : void 0);
|
|
204
|
+
if (auth === "platform" && (!apiKey || /\s/.test(apiKey) || !config.baseUrl)) {
|
|
200
205
|
throw new chunkANI325UM_cjs.OwnPayError("Platform services require a base URL and a bearer token.", "INVALID_CONFIG");
|
|
201
206
|
}
|
|
202
|
-
if (auth === "ownpay" && !isValidApiKeyFormat(
|
|
203
|
-
throw new chunkANI325UM_cjs.OwnPayError(
|
|
204
|
-
'Invalid API key format. API key must start with "op_" and be at least 12 characters.',
|
|
205
|
-
"INVALID_CONFIG"
|
|
206
|
-
);
|
|
207
|
+
if (!apiKey || auth === "ownpay" && !isValidApiKeyFormat(apiKey)) {
|
|
208
|
+
throw new chunkANI325UM_cjs.OwnPayError("Set PYCER_API_KEY or pass a valid Pycer merchant API key.", "INVALID_CONFIG");
|
|
207
209
|
}
|
|
208
|
-
this.apiKey =
|
|
209
|
-
const
|
|
210
|
-
if (
|
|
211
|
-
throw new chunkANI325UM_cjs.OwnPayError(
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
210
|
+
this.apiKey = apiKey;
|
|
211
|
+
const environment = config.environment ?? (auth === "ownpay" ? process.env.PYCER_ENV : void 0) ?? (apiKey.startsWith("op_test_") ? "sandbox" : "production");
|
|
212
|
+
if (environment !== "sandbox" && environment !== "production") {
|
|
213
|
+
throw new chunkANI325UM_cjs.OwnPayError("PYCER_ENV must be sandbox or production.", "INVALID_CONFIG");
|
|
214
|
+
}
|
|
215
|
+
const configuredBaseUrl = config.baseUrl ?? process.env[`PYCER_${environment.toUpperCase()}_BASE_URL`] ?? process.env.PYCER_BASE_URL ?? process.env.OWNPAY_BASE_URL ?? PORTAL_BASE_URLS[environment];
|
|
216
|
+
if (!isValidUrl(configuredBaseUrl)) {
|
|
217
|
+
throw new chunkANI325UM_cjs.OwnPayError("Set a valid HTTP/HTTPS Pycer base URL.", "INVALID_CONFIG");
|
|
215
218
|
}
|
|
216
219
|
let normalizedBaseUrl = configuredBaseUrl;
|
|
217
220
|
while (normalizedBaseUrl.endsWith("/")) {
|
|
@@ -1226,7 +1229,7 @@ var OwnPay = class {
|
|
|
1226
1229
|
* });
|
|
1227
1230
|
* ```
|
|
1228
1231
|
*/
|
|
1229
|
-
constructor(apiKeyOrConfig) {
|
|
1232
|
+
constructor(apiKeyOrConfig = {}) {
|
|
1230
1233
|
const config = typeof apiKeyOrConfig === "string" ? { apiKey: apiKeyOrConfig } : apiKeyOrConfig;
|
|
1231
1234
|
this.client = new HttpClient(config);
|
|
1232
1235
|
this.payments = new PaymentsResource(this.client);
|
|
@@ -1239,7 +1242,7 @@ var OwnPay = class {
|
|
|
1239
1242
|
this.health = new HealthResource(this.client);
|
|
1240
1243
|
this.merchant = new MerchantResource(this.client);
|
|
1241
1244
|
this.cards = new CardsResource(this.client);
|
|
1242
|
-
this.checkout = new CheckoutResource(this.client, config.checkoutBaseUrl ??
|
|
1245
|
+
this.checkout = new CheckoutResource(this.client, config.checkoutBaseUrl ?? this.client.baseUrl);
|
|
1243
1246
|
}
|
|
1244
1247
|
};
|
|
1245
1248
|
var src_default = OwnPay;
|
|
@@ -1314,6 +1317,7 @@ exports.MerchantResource = MerchantResource;
|
|
|
1314
1317
|
exports.Notifications = Notifications;
|
|
1315
1318
|
exports.OwnPay = OwnPay;
|
|
1316
1319
|
exports.PaymentsResource = PaymentsResource;
|
|
1320
|
+
exports.Pycer = OwnPay;
|
|
1317
1321
|
exports.RefundsResource = RefundsResource;
|
|
1318
1322
|
exports.SwitchResource = SwitchResource;
|
|
1319
1323
|
exports.TransactionsResource = TransactionsResource;
|