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/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { O as OwnPayConfig, R as RequestConfig, a as RequestOptions, L as ListTransactionsParams, P as PaginatedList, T as Transaction, C as CreateRefundParams, b as Refund, c as ListRefundsParams, d as CreateCustomerParams, e as Customer, f as ListCustomersParams, A as ApiKey, G as GenerateApiKeyParams, g as GeneratedApiKey, W as WebhookTestResult, h as WebhookDelivery, i as ApiResponse, H as HealthStatus } from './index-XbnGOTNP.js';
2
- export { j as AbortError, k as ApiError, l as ApiErrorDetail, m as ApiErrorResponse, n as ApiKeyScope, o as AuthenticationError, p as CreatePaymentParams, q as CustomerSummary, I as IdempotencyError, N as NetworkError, r as NotFoundError, s as OwnPayError, t as PaginationMeta, u as Payment, v as PaymentIntent, w as PaymentStatus, x as PermissionError, y as RateLimitError, V as ValidationError, z as WebhookPayload, B as WebhookVerificationError, D as WebhookVerificationParams, E as generateSignature, F as parseWebhookPayload, J as verifyWebhookSignature } from './index-XbnGOTNP.js';
1
+ import { O as OwnPayConfig, R as RequestConfig, a as RequestOptions, L as ListTransactionsParams, P as PaginatedList, T as Transaction, C as CreateRefundParams, b as Refund, c as ListRefundsParams, d as CreateCustomerParams, e as Customer, f as ListCustomersParams, A as ApiKey, G as GenerateApiKeyParams, g as GeneratedApiKey, W as WebhookTestResult, h as WebhookDelivery, i as ApiResponse, H as HealthStatus } from './index-DQD3PJ4L.js';
2
+ export { j as AbortError, k as ApiError, l as ApiErrorDetail, m as ApiErrorResponse, n as ApiKeyScope, o as AuthenticationError, p as CreatePaymentParams, q as CustomerSummary, I as IdempotencyError, N as NetworkError, r as NotFoundError, s as OwnPayError, t as PaginationMeta, u as Payment, v as PaymentIntent, w as PaymentStatus, x as PermissionError, y as RateLimitError, V as ValidationError, z as WebhookPayload, B as WebhookVerificationError, D as WebhookVerificationParams, E as generateSignature, F as parseWebhookPayload, J as verifyWebhookSignature } from './index-DQD3PJ4L.js';
3
3
 
4
4
  /**
5
5
  * OwnPay Node.js SDK - HTTP Client
@@ -18,7 +18,7 @@ export { j as AbortError, k as ApiError, l as ApiErrorDetail, m as ApiErrorRespo
18
18
  */
19
19
  declare class HttpClient {
20
20
  private readonly apiKey;
21
- private readonly baseUrl;
21
+ readonly baseUrl: string;
22
22
  private readonly timeout;
23
23
  private readonly maxRetries;
24
24
  private readonly apiVersion;
@@ -159,6 +159,10 @@ declare class SwitchResource {
159
159
  constructor(client: HttpClient);
160
160
  initiate(params: RailPaymentParams, options?: RequestOptions): Promise<SwitchChargeResult>;
161
161
  charge(params: SwitchChargeParams, options?: RequestOptions): Promise<SwitchChargeResult>;
162
+ getRules(options?: RequestOptions): Promise<unknown>;
163
+ createRule(rule: Record<string, unknown>, options?: RequestOptions): Promise<unknown>;
164
+ getRailHealth(providerId?: string, options?: RequestOptions): Promise<unknown>;
165
+ getAttempts(transactionId?: string, options?: RequestOptions): Promise<unknown>;
162
166
  }
163
167
 
164
168
  interface PaymentDetails {
@@ -659,6 +663,10 @@ declare class MerchantResource {
659
663
  create: (body: Fields$1, options?: RequestOptions) => Promise<ApiResponse<unknown> | undefined>;
660
664
  update: (id: string, body: Fields$1, options?: RequestOptions) => Promise<ApiResponse<unknown> | undefined>;
661
665
  remove: (id: string, options?: RequestOptions) => Promise<ApiResponse<unknown> | undefined>;
666
+ lookup: (query: {
667
+ umi: string;
668
+ accountNumber?: string;
669
+ }, options?: RequestOptions) => Promise<ApiResponse<unknown> | undefined>;
662
670
  };
663
671
  readonly commerce: {
664
672
  listProducts: (query?: Query$1, options?: RequestOptions) => Promise<ApiResponse<unknown> | undefined>;
@@ -809,6 +817,7 @@ declare class OwnPay {
809
817
  readonly merchant: MerchantResource;
810
818
  readonly cards: CardsResource;
811
819
  readonly checkout: CheckoutResource;
820
+ readonly virtualAccounts: MerchantResource['virtualAccounts'];
812
821
  /**
813
822
  * Creates a new OwnPay client instance.
814
823
  *
@@ -825,7 +834,7 @@ declare class OwnPay {
825
834
  * });
826
835
  * ```
827
836
  */
828
- constructor(apiKeyOrConfig: string | OwnPayConfig);
837
+ constructor(apiKeyOrConfig?: string | OwnPayConfig);
829
838
  }
830
839
 
831
- export { ApiKey, ApiKeysResource, ApiResponse, Banking, Billing, CardsResource, CheckoutResource, type CheckoutSession, type CheckoutStatus, OwnPay as Client, type CreateCheckoutParams, CreateCustomerParams, CreateRefundParams, Customer, CustomersResource, DeveloperTools, type DisbursementParams, ForeignExchange, GenerateApiKeyParams, GeneratedApiKey, HealthResource, HealthStatus, ListCustomersParams, ListRefundsParams, ListTransactionsParams, MerchantResource, Notifications, OwnPay, OwnPayConfig, PaginatedList, type PaymentDetails, PaymentsResource, type PlatformServiceConfig, type RailPaymentParams, Refund, RefundsResource, RequestOptions, type SwitchChargeParams, type SwitchChargeResult, SwitchResource, Transaction, TransactionsResource, type VaultCardParams, type VaultedCard, WebhookDelivery, WebhookTestResult, WebhooksResource, OwnPay as default };
840
+ export { ApiKey, ApiKeysResource, ApiResponse, Banking, Billing, CardsResource, CheckoutResource, type CheckoutSession, type CheckoutStatus, OwnPay as Client, type CreateCheckoutParams, CreateCustomerParams, CreateRefundParams, Customer, CustomersResource, DeveloperTools, type DisbursementParams, ForeignExchange, GenerateApiKeyParams, GeneratedApiKey, HealthResource, HealthStatus, ListCustomersParams, ListRefundsParams, ListTransactionsParams, MerchantResource, Notifications, OwnPay, OwnPayConfig, PaginatedList, type PaymentDetails, PaymentsResource, type PlatformServiceConfig, OwnPay as Pycer, type RailPaymentParams, Refund, RefundsResource, RequestOptions, type SwitchChargeParams, type SwitchChargeResult, SwitchResource, Transaction, TransactionsResource, type VaultCardParams, type VaultedCard, type VirtualAccount, WebhookDelivery, WebhookTestResult, WebhooksResource, OwnPay as default };
package/dist/index.js CHANGED
@@ -42,6 +42,20 @@ var SwitchResource = class {
42
42
  partyB: { umid: merchantUmid, accountReference, recipientAccount }
43
43
  }, options);
44
44
  }
45
+ getRules(options) {
46
+ return this.client.request({ method: "GET", path: "/api/v2/switch/rules", options });
47
+ }
48
+ createRule(rule, options) {
49
+ return this.client.request({ method: "POST", path: "/api/v2/switch/rules", body: rule, options });
50
+ }
51
+ getRailHealth(providerId, options) {
52
+ const path = providerId ? `/api/v2/switch/health/${encodeURIComponent(providerId)}` : "/api/v2/switch/health";
53
+ return this.client.request({ method: "GET", path, options });
54
+ }
55
+ getAttempts(transactionId, options) {
56
+ const path = transactionId ? `/api/v2/switch/transactions/${encodeURIComponent(transactionId)}/attempts` : "/api/v2/switch/attempts";
57
+ return this.client.request({ method: "GET", path, options });
58
+ }
45
59
  };
46
60
 
47
61
  // src/resources/cards.ts
@@ -178,11 +192,15 @@ function calculateBackoff(attempt, baseDelay = 1e3, maxDelay = 3e4) {
178
192
  }
179
193
 
180
194
  // src/core/client.ts
195
+ var PORTAL_BASE_URLS = {
196
+ sandbox: "https://pycer.quantivogroup.com",
197
+ production: "https://pycer.quantivogroup.com"
198
+ };
181
199
  var DEFAULT_CONFIG = {
182
200
  TIMEOUT: 3e4,
183
201
  MAX_RETRIES: 2,
184
202
  API_VERSION: "v1",
185
- USER_AGENT: "OwnPay-NodeJS/1.0.0"
203
+ USER_AGENT: "Pycer-SDK/1.0.4"
186
204
  };
187
205
  var RETRYABLE_STATUS_CODES = /* @__PURE__ */ new Set([429, 500, 502, 503, 504]);
188
206
  var HttpClient = class {
@@ -193,22 +211,21 @@ var HttpClient = class {
193
211
  apiVersion;
194
212
  defaultHeaders;
195
213
  constructor(config, auth = "ownpay") {
196
- if (auth === "platform" && (!config.apiKey || /\s/.test(config.apiKey) || !config.baseUrl)) {
214
+ const apiKey = config.apiKey ?? (auth === "ownpay" ? process.env.PYCER_API_KEY : void 0);
215
+ if (auth === "platform" && (!apiKey || /\s/.test(apiKey) || !config.baseUrl)) {
197
216
  throw new OwnPayError("Platform services require a base URL and a bearer token.", "INVALID_CONFIG");
198
217
  }
199
- if (auth === "ownpay" && !isValidApiKeyFormat(config.apiKey)) {
200
- throw new OwnPayError(
201
- 'Invalid API key format. API key must start with "op_" and be at least 12 characters.',
202
- "INVALID_CONFIG"
203
- );
218
+ if (!apiKey || auth === "ownpay" && !isValidApiKeyFormat(apiKey)) {
219
+ throw new OwnPayError("Set PYCER_API_KEY or pass a valid Pycer merchant API key.", "INVALID_CONFIG");
204
220
  }
205
- this.apiKey = config.apiKey;
206
- const configuredBaseUrl = config.baseUrl ?? process.env.OWNPAY_BASE_URL;
207
- if (!configuredBaseUrl || !isValidUrl(configuredBaseUrl)) {
208
- throw new OwnPayError(
209
- "A valid HTTP/HTTPS base URL is required. Set config.baseUrl or OWNPAY_BASE_URL.",
210
- "INVALID_CONFIG"
211
- );
221
+ this.apiKey = apiKey;
222
+ const environment = config.environment ?? (auth === "ownpay" ? process.env.PYCER_ENV : void 0) ?? (apiKey.startsWith("op_test_") ? "sandbox" : "production");
223
+ if (environment !== "sandbox" && environment !== "production") {
224
+ throw new OwnPayError("PYCER_ENV must be sandbox or production.", "INVALID_CONFIG");
225
+ }
226
+ 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];
227
+ if (!isValidUrl(configuredBaseUrl)) {
228
+ throw new OwnPayError("Set a valid HTTP/HTTPS Pycer base URL.", "INVALID_CONFIG");
212
229
  }
213
230
  let normalizedBaseUrl = configuredBaseUrl;
214
231
  while (normalizedBaseUrl.endsWith("/")) {
@@ -319,10 +336,10 @@ var HttpClient = class {
319
336
  * Builds the full request URL.
320
337
  */
321
338
  buildUrl(path, query) {
322
- const basePath = `/api/${this.apiVersion}`;
323
339
  const fullPath = path.startsWith("/") ? path : `/${path}`;
340
+ const urlPath = fullPath.startsWith("/api/") ? fullPath : `/api/${this.apiVersion}${fullPath}`;
324
341
  const queryString = query ? buildQueryString(query) : "";
325
- return `${this.baseUrl}${basePath}${fullPath}${queryString}`;
342
+ return `${this.baseUrl}${urlPath}${queryString}`;
326
343
  }
327
344
  /**
328
345
  * Builds request headers including authentication.
@@ -1036,7 +1053,11 @@ var MerchantResource = class {
1036
1053
  get: (id, options) => this.call("GET", `/merchants/account-references/${segment(id)}`, options),
1037
1054
  create: (body, options) => this.call("POST", "/merchants/account-references", options, body),
1038
1055
  update: (id, body, options) => this.call("PUT", `/merchants/account-references/${segment(id)}`, options, body),
1039
- remove: (id, options) => this.call("DELETE", `/merchants/account-references/${segment(id)}`, options)
1056
+ remove: (id, options) => this.call("DELETE", `/merchants/account-references/${segment(id)}`, options),
1057
+ lookup: (query, options) => this.call("GET", "/account-references/lookup", options, void 0, {
1058
+ umi: query.umi,
1059
+ account_number: query.accountNumber
1060
+ })
1040
1061
  };
1041
1062
  commerce = {
1042
1063
  listProducts: (query, options) => this.call("GET", "/products", options, void 0, query),
@@ -1207,6 +1228,7 @@ var OwnPay = class {
1207
1228
  merchant;
1208
1229
  cards;
1209
1230
  checkout;
1231
+ virtualAccounts;
1210
1232
  /**
1211
1233
  * Creates a new OwnPay client instance.
1212
1234
  *
@@ -1223,7 +1245,7 @@ var OwnPay = class {
1223
1245
  * });
1224
1246
  * ```
1225
1247
  */
1226
- constructor(apiKeyOrConfig) {
1248
+ constructor(apiKeyOrConfig = {}) {
1227
1249
  const config = typeof apiKeyOrConfig === "string" ? { apiKey: apiKeyOrConfig } : apiKeyOrConfig;
1228
1250
  this.client = new HttpClient(config);
1229
1251
  this.payments = new PaymentsResource(this.client);
@@ -1236,11 +1258,12 @@ var OwnPay = class {
1236
1258
  this.health = new HealthResource(this.client);
1237
1259
  this.merchant = new MerchantResource(this.client);
1238
1260
  this.cards = new CardsResource(this.client);
1239
- this.checkout = new CheckoutResource(this.client, config.checkoutBaseUrl ?? config.baseUrl ?? process.env.OWNPAY_BASE_URL);
1261
+ this.checkout = new CheckoutResource(this.client, config.checkoutBaseUrl ?? this.client.baseUrl);
1262
+ this.virtualAccounts = this.merchant.virtualAccounts;
1240
1263
  }
1241
1264
  };
1242
1265
  var src_default = OwnPay;
1243
1266
 
1244
- export { ApiKeysResource, Banking, Billing, CardsResource, CheckoutResource, OwnPay as Client, CustomersResource, DeveloperTools, ForeignExchange, HealthResource, MerchantResource, Notifications, OwnPay, PaymentsResource, RefundsResource, SwitchResource, TransactionsResource, WebhooksResource, src_default as default };
1267
+ export { ApiKeysResource, Banking, Billing, CardsResource, CheckoutResource, OwnPay as Client, CustomersResource, DeveloperTools, ForeignExchange, HealthResource, MerchantResource, Notifications, OwnPay, PaymentsResource, OwnPay as Pycer, RefundsResource, SwitchResource, TransactionsResource, WebhooksResource, src_default as default };
1245
1268
  //# sourceMappingURL=index.js.map
1246
1269
  //# sourceMappingURL=index.js.map