pycer-sdk 1.0.2 → 1.0.4

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 CHANGED
@@ -4,7 +4,7 @@
4
4
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
5
  [![Node.js Version](https://img.shields.io/badge/node-%3E%3D18.0.0-brightgreen)](https://nodejs.org/)
6
6
 
7
- Official Node.js SDK for the [OwnPay](https://ownpay.org) Payment Gateway API. A zero-dependency, TypeScript-first SDK for seamless payment integration.
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 Client
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 OwnPay from 'pycer-sdk';
51
+ import Pycer from 'pycer-sdk';
45
52
 
46
- // Configure the URL of your self-hosted OwnPay instance.
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: string;
13
- /** Base URL for the self-hosted API (or set OWNPAY_BASE_URL) */
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: string;
13
- /** Base URL for the self-hosted API (or set OWNPAY_BASE_URL) */
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
@@ -45,6 +45,20 @@ var SwitchResource = class {
45
45
  partyB: { umid: merchantUmid, accountReference, recipientAccount }
46
46
  }, options);
47
47
  }
48
+ getRules(options) {
49
+ return this.client.request({ method: "GET", path: "/api/v2/switch/rules", options });
50
+ }
51
+ createRule(rule, options) {
52
+ return this.client.request({ method: "POST", path: "/api/v2/switch/rules", body: rule, options });
53
+ }
54
+ getRailHealth(providerId, options) {
55
+ const path = providerId ? `/api/v2/switch/health/${encodeURIComponent(providerId)}` : "/api/v2/switch/health";
56
+ return this.client.request({ method: "GET", path, options });
57
+ }
58
+ getAttempts(transactionId, options) {
59
+ const path = transactionId ? `/api/v2/switch/transactions/${encodeURIComponent(transactionId)}/attempts` : "/api/v2/switch/attempts";
60
+ return this.client.request({ method: "GET", path, options });
61
+ }
48
62
  };
49
63
 
50
64
  // src/resources/cards.ts
@@ -181,11 +195,15 @@ function calculateBackoff(attempt, baseDelay = 1e3, maxDelay = 3e4) {
181
195
  }
182
196
 
183
197
  // src/core/client.ts
198
+ var PORTAL_BASE_URLS = {
199
+ sandbox: "https://pycer.quantivogroup.com",
200
+ production: "https://pycer.quantivogroup.com"
201
+ };
184
202
  var DEFAULT_CONFIG = {
185
203
  TIMEOUT: 3e4,
186
204
  MAX_RETRIES: 2,
187
205
  API_VERSION: "v1",
188
- USER_AGENT: "OwnPay-NodeJS/1.0.0"
206
+ USER_AGENT: "Pycer-SDK/1.0.4"
189
207
  };
190
208
  var RETRYABLE_STATUS_CODES = /* @__PURE__ */ new Set([429, 500, 502, 503, 504]);
191
209
  var HttpClient = class {
@@ -196,22 +214,21 @@ var HttpClient = class {
196
214
  apiVersion;
197
215
  defaultHeaders;
198
216
  constructor(config, auth = "ownpay") {
199
- if (auth === "platform" && (!config.apiKey || /\s/.test(config.apiKey) || !config.baseUrl)) {
217
+ const apiKey = config.apiKey ?? (auth === "ownpay" ? process.env.PYCER_API_KEY : void 0);
218
+ if (auth === "platform" && (!apiKey || /\s/.test(apiKey) || !config.baseUrl)) {
200
219
  throw new chunkANI325UM_cjs.OwnPayError("Platform services require a base URL and a bearer token.", "INVALID_CONFIG");
201
220
  }
202
- if (auth === "ownpay" && !isValidApiKeyFormat(config.apiKey)) {
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
- );
221
+ if (!apiKey || auth === "ownpay" && !isValidApiKeyFormat(apiKey)) {
222
+ throw new chunkANI325UM_cjs.OwnPayError("Set PYCER_API_KEY or pass a valid Pycer merchant API key.", "INVALID_CONFIG");
207
223
  }
208
- this.apiKey = config.apiKey;
209
- const configuredBaseUrl = config.baseUrl ?? process.env.OWNPAY_BASE_URL;
210
- if (!configuredBaseUrl || !isValidUrl(configuredBaseUrl)) {
211
- throw new chunkANI325UM_cjs.OwnPayError(
212
- "A valid HTTP/HTTPS base URL is required. Set config.baseUrl or OWNPAY_BASE_URL.",
213
- "INVALID_CONFIG"
214
- );
224
+ this.apiKey = apiKey;
225
+ const environment = config.environment ?? (auth === "ownpay" ? process.env.PYCER_ENV : void 0) ?? (apiKey.startsWith("op_test_") ? "sandbox" : "production");
226
+ if (environment !== "sandbox" && environment !== "production") {
227
+ throw new chunkANI325UM_cjs.OwnPayError("PYCER_ENV must be sandbox or production.", "INVALID_CONFIG");
228
+ }
229
+ 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];
230
+ if (!isValidUrl(configuredBaseUrl)) {
231
+ throw new chunkANI325UM_cjs.OwnPayError("Set a valid HTTP/HTTPS Pycer base URL.", "INVALID_CONFIG");
215
232
  }
216
233
  let normalizedBaseUrl = configuredBaseUrl;
217
234
  while (normalizedBaseUrl.endsWith("/")) {
@@ -322,10 +339,10 @@ var HttpClient = class {
322
339
  * Builds the full request URL.
323
340
  */
324
341
  buildUrl(path, query) {
325
- const basePath = `/api/${this.apiVersion}`;
326
342
  const fullPath = path.startsWith("/") ? path : `/${path}`;
343
+ const urlPath = fullPath.startsWith("/api/") ? fullPath : `/api/${this.apiVersion}${fullPath}`;
327
344
  const queryString = query ? buildQueryString(query) : "";
328
- return `${this.baseUrl}${basePath}${fullPath}${queryString}`;
345
+ return `${this.baseUrl}${urlPath}${queryString}`;
329
346
  }
330
347
  /**
331
348
  * Builds request headers including authentication.
@@ -1039,7 +1056,11 @@ var MerchantResource = class {
1039
1056
  get: (id, options) => this.call("GET", `/merchants/account-references/${segment(id)}`, options),
1040
1057
  create: (body, options) => this.call("POST", "/merchants/account-references", options, body),
1041
1058
  update: (id, body, options) => this.call("PUT", `/merchants/account-references/${segment(id)}`, options, body),
1042
- remove: (id, options) => this.call("DELETE", `/merchants/account-references/${segment(id)}`, options)
1059
+ remove: (id, options) => this.call("DELETE", `/merchants/account-references/${segment(id)}`, options),
1060
+ lookup: (query, options) => this.call("GET", "/account-references/lookup", options, void 0, {
1061
+ umi: query.umi,
1062
+ account_number: query.accountNumber
1063
+ })
1043
1064
  };
1044
1065
  commerce = {
1045
1066
  listProducts: (query, options) => this.call("GET", "/products", options, void 0, query),
@@ -1210,6 +1231,7 @@ var OwnPay = class {
1210
1231
  merchant;
1211
1232
  cards;
1212
1233
  checkout;
1234
+ virtualAccounts;
1213
1235
  /**
1214
1236
  * Creates a new OwnPay client instance.
1215
1237
  *
@@ -1226,7 +1248,7 @@ var OwnPay = class {
1226
1248
  * });
1227
1249
  * ```
1228
1250
  */
1229
- constructor(apiKeyOrConfig) {
1251
+ constructor(apiKeyOrConfig = {}) {
1230
1252
  const config = typeof apiKeyOrConfig === "string" ? { apiKey: apiKeyOrConfig } : apiKeyOrConfig;
1231
1253
  this.client = new HttpClient(config);
1232
1254
  this.payments = new PaymentsResource(this.client);
@@ -1239,7 +1261,8 @@ var OwnPay = class {
1239
1261
  this.health = new HealthResource(this.client);
1240
1262
  this.merchant = new MerchantResource(this.client);
1241
1263
  this.cards = new CardsResource(this.client);
1242
- this.checkout = new CheckoutResource(this.client, config.checkoutBaseUrl ?? config.baseUrl ?? process.env.OWNPAY_BASE_URL);
1264
+ this.checkout = new CheckoutResource(this.client, config.checkoutBaseUrl ?? this.client.baseUrl);
1265
+ this.virtualAccounts = this.merchant.virtualAccounts;
1243
1266
  }
1244
1267
  };
1245
1268
  var src_default = OwnPay;
@@ -1314,6 +1337,7 @@ exports.MerchantResource = MerchantResource;
1314
1337
  exports.Notifications = Notifications;
1315
1338
  exports.OwnPay = OwnPay;
1316
1339
  exports.PaymentsResource = PaymentsResource;
1340
+ exports.Pycer = OwnPay;
1317
1341
  exports.RefundsResource = RefundsResource;
1318
1342
  exports.SwitchResource = SwitchResource;
1319
1343
  exports.TransactionsResource = TransactionsResource;