@agentpay-global/sdk 0.0.0-stage → 0.3.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 CHANGED
@@ -1,3 +1,110 @@
1
- # Temporary Holding Version
1
+ # @agentpay-global/sdk
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The official AgentPay SDK. Issue capped virtual cards and let your agent complete real checkouts. Card controls, 3DS, and fraud caps are handled for you.
4
+
5
+ ## Install
6
+
7
+ ```
8
+ npm install @agentpay-global/sdk
9
+ ```
10
+
11
+ Requires Node 18+ (uses the built-in `fetch`).
12
+
13
+ ## Quickstart
14
+
15
+ ```ts
16
+ import { AgentPay } from '@agentpay-global/sdk';
17
+
18
+ const agentpay = new AgentPay(process.env.AGENTPAY_API_KEY!); // key looks like mk_live_...
19
+
20
+ // Issue a single-use card capped at $20
21
+ const card = await agentpay.cards.create({
22
+ amount: 20,
23
+ merchant: 'namecheap',
24
+ single_use: true,
25
+ });
26
+ console.log(card.id, card.last4, card.spend_limit);
27
+ ```
28
+
29
+ Get your API key from the AgentPay console (Developer -> API keys). Keep it server-side; never commit it.
30
+
31
+ ## Tools
32
+
33
+ ### Cards
34
+
35
+ ```ts
36
+ const card = await agentpay.cards.create({ amount: 20, merchant: 'namecheap', single_use: true });
37
+ const full = await agentpay.cards.reveal(card.id); // { number, cvc, exp, ... }: use at the moment of purchase
38
+ const closed = await agentpay.cards.close(card.id); // release the unused reserve back to your wallet
39
+ ```
40
+
41
+ ### Spend status
42
+
43
+ ```ts
44
+ const spend = await agentpay.spend.get(card.spend_request_id!);
45
+ // spend.status: 'not_started' | 'authorized' | 'cleared' | 'declined'
46
+ ```
47
+
48
+ ### Checkout (AgentPay drives the buy)
49
+
50
+ ```ts
51
+ const run = await agentpay.checkout.create({
52
+ task: 'buy the domain example.click for 1 year',
53
+ merchant: 'namecheap',
54
+ amount: 20,
55
+ confirm_pay: false, // dry run: stops at the final review. true = pay up to the cap.
56
+ });
57
+
58
+ // poll until it finishes
59
+ let status = await agentpay.checkout.get(run.checkout_id);
60
+ // status.status: 'queued' | 'running' | 'awaiting_approval' | 'needs_login' | 'submitted' | 'blocked'
61
+ ```
62
+
63
+ ### Connections (login-gated merchants)
64
+
65
+ ```ts
66
+ const conn = await agentpay.connections.create({ merchant: 'namecheap', user_ref: 'user-123' });
67
+ // open conn.connect_url so the user signs in, then:
68
+ await agentpay.connections.complete(conn.connection_id);
69
+ // now pass connection_id to checkout.create to run signed-in
70
+ ```
71
+
72
+ ## Errors
73
+
74
+ Any non-2xx response throws a `AgentPayError` with the HTTP status, the AgentPay error code, and the request id.
75
+
76
+ ```ts
77
+ import { AgentPay, AgentPayError } from '@agentpay-global/sdk';
78
+
79
+ try {
80
+ await agentpay.cards.create({ amount: 999999, merchant: 'namecheap' });
81
+ } catch (e) {
82
+ if (e instanceof AgentPayError) {
83
+ console.error(e.status, e.code, e.requestId, e.message);
84
+ // e.g. 402 insufficient_funds
85
+ }
86
+ }
87
+ ```
88
+
89
+ ## Configuration
90
+
91
+ ```ts
92
+ new AgentPay({
93
+ apiKey: process.env.AGENTPAY_API_KEY!,
94
+ baseUrl: 'https://api.joomjoo.com', // optional override
95
+ });
96
+ ```
97
+
98
+ ## Docs
99
+
100
+ ## The wallet
101
+
102
+ ```ts
103
+ const w = await agentpay.wallet.get(); // balance, available, reserved, pending, in dollars
104
+ const s = await agentpay.wallet.createFundingSession({ amount: 50, success_url: "https://yourapp.example/funded" });
105
+ // open s.url for the person; the wallet is credited when Stripe confirms (webhook event money.funded)
106
+ const t = await agentpay.wallet.declareBankTransfer({ amount: 500, rail: "wire_domestic" });
107
+ // t.instructions holds the account to send to and t.reference_code goes in the memo
108
+ ```
109
+
110
+ Full API reference: https://app.agentpay.global (Developer, Docs)
@@ -0,0 +1,203 @@
1
+ /**
2
+ * @agentpay-global/sdk: the official AgentPay SDK.
3
+ *
4
+ * A thin, typed wrapper over the AgentPay REST API (v1). Issue capped virtual cards and let your
5
+ * agent complete real checkouts; card controls, 3DS, and fraud caps are handled for you.
6
+ *
7
+ * import { AgentPay } from '@agentpay-global/sdk';
8
+ * const agentpay = new AgentPay(process.env.AGENTPAY_API_KEY!);
9
+ * const card = await agentpay.cards.create({ amount: 20, merchant: 'namecheap', single_use: true });
10
+ */
11
+ export interface AgentPayOptions {
12
+ /** Your secret API key, e.g. "mk_live_...". Create one in the AgentPay console. */
13
+ apiKey: string;
14
+ /** Override the API base URL (defaults to the live AgentPay gateway). */
15
+ baseUrl?: string;
16
+ /** Provide a custom fetch implementation (defaults to global fetch, Node 18+). */
17
+ fetch?: typeof fetch;
18
+ }
19
+ /** Thrown on any non-2xx response. Carries the HTTP status, the AgentPay error code, and the request id. */
20
+ export declare class AgentPayError extends Error {
21
+ readonly status: number;
22
+ readonly code?: string;
23
+ readonly requestId?: string;
24
+ constructor(message: string, status: number, code?: string, requestId?: string);
25
+ }
26
+ export interface Card {
27
+ id: string;
28
+ brand: string;
29
+ last4: string;
30
+ exp_month: number;
31
+ exp_year: number;
32
+ spend_limit: number;
33
+ single_use: boolean;
34
+ status: string;
35
+ spend_request_id: string | null;
36
+ }
37
+ export interface RevealedCard {
38
+ id: string;
39
+ last4: string;
40
+ number: string;
41
+ number_formatted: string;
42
+ cvc: string;
43
+ exp: string;
44
+ }
45
+ export interface ClosedCard {
46
+ id: string;
47
+ status: string;
48
+ released_display: string;
49
+ available_to_issue_display: string;
50
+ }
51
+ export interface SpendStatus {
52
+ spend_request_id: string;
53
+ merchant: string;
54
+ decision: string;
55
+ status: 'not_started' | 'authorized' | 'cleared' | 'declined' | string;
56
+ settled: boolean;
57
+ amount: number;
58
+ }
59
+ export interface Checkout {
60
+ checkout_id: string;
61
+ status: 'queued' | 'running' | 'needs_login' | 'needs_answer' | 'awaiting_approval' | 'paying' | 'submitted' | 'canceled' | 'blocked' | 'error' | string;
62
+ poll?: string;
63
+ /** Whether AgentPay will pay without a human yes. Your confirm_pay can only be narrowed by the agent's own approval mode. */
64
+ confirm_pay?: boolean;
65
+ /** The site the run opened, once known. */
66
+ host?: string | null;
67
+ task?: string;
68
+ merchant?: string;
69
+ amount?: number;
70
+ card_last4?: string;
71
+ /** The shop's own total as a display string, e.g. "60.90 AED" or "1.98 USD". */
72
+ review_total?: string | null;
73
+ order_id?: string | null;
74
+ /** The paid total as a display string, e.g. "60.90 AED". */
75
+ order_total?: string | null;
76
+ needs_login?: boolean;
77
+ error_reason?: string | null;
78
+ }
79
+ export interface Connection {
80
+ connection_id: string;
81
+ connect_url?: string;
82
+ status: 'pending' | 'connected' | string;
83
+ }
84
+ export interface CreateCardParams {
85
+ /** Spend cap in US dollars. Per-card ceiling is $5,000. */
86
+ amount: number;
87
+ merchant: string;
88
+ /** Default true. Auto-freezes after the first charge. */
89
+ single_use?: boolean;
90
+ network?: 'auto' | 'visa' | 'mastercard';
91
+ card_name?: string;
92
+ }
93
+ export interface CreateCheckoutParams {
94
+ task: string;
95
+ merchant: string;
96
+ /** Maximum USD to spend (becomes the card cap). */
97
+ amount: number;
98
+ /** false (default) = dry run, stops at review. true = pay autonomously up to the cap. */
99
+ confirm_pay?: boolean;
100
+ connection_id?: string;
101
+ card_holder_name?: string;
102
+ start_url?: string;
103
+ /** Your own key for this checkout; a retry with the same key returns the same checkout instead of a second run. */
104
+ idempotency_key?: string;
105
+ }
106
+ export interface CreateConnectionParams {
107
+ merchant: string;
108
+ user_ref?: string;
109
+ }
110
+ /** The wallet every card and checkout draws on. Amounts in dollars; the display strings are what the console shows. */
111
+ export interface Wallet {
112
+ currency: string;
113
+ onboarded: boolean;
114
+ balance: number | null;
115
+ available: number | null;
116
+ reserved: number | null;
117
+ pending: number | null;
118
+ balance_display?: string | null;
119
+ available_display?: string | null;
120
+ reserved_display?: string | null;
121
+ pending_display?: string | null;
122
+ }
123
+ export interface CreateFundingSessionParams {
124
+ /** Dollars to add. */
125
+ amount: number;
126
+ /** Where the person lands after paying (https). Defaults to the AgentPay console. */
127
+ success_url?: string;
128
+ /** Where the person lands if they cancel (https). Defaults to the AgentPay console. */
129
+ cancel_url?: string;
130
+ }
131
+ /** A Stripe Checkout page: open `url` for the person. The wallet is credited when Stripe confirms; subscribe to `money.funded`. */
132
+ export interface FundingSession {
133
+ funding_session_id: string;
134
+ url: string;
135
+ amount: number | null;
136
+ amount_display?: string | null;
137
+ status: 'open' | string;
138
+ }
139
+ export interface DeclareBankTransferParams {
140
+ /** Amount in the transfer currency. */
141
+ amount: number;
142
+ /** ach (default), wire_domestic, wire_international or uae_local. */
143
+ rail?: 'ach' | 'wire_domestic' | 'wire_international' | 'uae_local';
144
+ /** USD, or AED for uae_local. Defaults by rail. */
145
+ currency?: string;
146
+ /** yyyy-MM-dd, the day the transfer was sent. */
147
+ sent_on?: string;
148
+ sender_bank_name?: string;
149
+ sender_account_name?: string;
150
+ sender_reference?: string;
151
+ /** Your own key; a retry with the same key returns the same declaration. */
152
+ idempotency_key?: string;
153
+ }
154
+ /** A declared bank transfer, pending until the money lands, with the account to send it to and the reference code to put in the memo. */
155
+ export interface BankTransfer {
156
+ funding_event_id: string;
157
+ status: 'pending' | string;
158
+ already_recorded: boolean;
159
+ amount: number;
160
+ currency: string;
161
+ rail: string;
162
+ reference_code: string | null;
163
+ pending_balance: number | null;
164
+ instructions: Record<string, string | null>;
165
+ }
166
+ export declare class AgentPay {
167
+ private readonly apiKey;
168
+ private readonly baseUrl;
169
+ private readonly _fetch;
170
+ constructor(options: AgentPayOptions | string);
171
+ private request;
172
+ /** Virtual cards: issue, reveal the PAN, and close. */
173
+ readonly cards: {
174
+ create: (params: CreateCardParams) => Promise<Card>;
175
+ reveal: (id: string) => Promise<RevealedCard>;
176
+ close: (id: string) => Promise<ClosedCard>;
177
+ };
178
+ /** Spend status for a card issued with cards.create (pass the spend_request_id). */
179
+ readonly spend: {
180
+ get: (spendRequestId: string) => Promise<SpendStatus>;
181
+ };
182
+ /** Let AgentPay drive a full checkout. create() is async; poll with get(). */
183
+ readonly checkout: {
184
+ create: (params: CreateCheckoutParams) => Promise<Checkout>;
185
+ get: (checkoutId: string) => Promise<Checkout>;
186
+ };
187
+ /** Reusable merchant logins for login-gated stores. */
188
+ readonly connections: {
189
+ create: (params: CreateConnectionParams) => Promise<Connection>;
190
+ complete: (id: string) => Promise<Connection>;
191
+ list: () => Promise<Connection[] | {
192
+ connections?: Connection[];
193
+ }>;
194
+ get: (id: string) => Promise<Connection>;
195
+ };
196
+ /** The wallet: balance, a top-up link (Stripe Checkout, card or stablecoin), a declared bank transfer. */
197
+ readonly wallet: {
198
+ get: () => Promise<Wallet>;
199
+ createFundingSession: (params: CreateFundingSessionParams) => Promise<FundingSession>;
200
+ declareBankTransfer: (params: DeclareBankTransferParams) => Promise<BankTransfer>;
201
+ };
202
+ }
203
+ export default AgentPay;
package/dist/index.js ADDED
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+ /**
3
+ * @agentpay-global/sdk: the official AgentPay SDK.
4
+ *
5
+ * A thin, typed wrapper over the AgentPay REST API (v1). Issue capped virtual cards and let your
6
+ * agent complete real checkouts; card controls, 3DS, and fraud caps are handled for you.
7
+ *
8
+ * import { AgentPay } from '@agentpay-global/sdk';
9
+ * const agentpay = new AgentPay(process.env.AGENTPAY_API_KEY!);
10
+ * const card = await agentpay.cards.create({ amount: 20, merchant: 'namecheap', single_use: true });
11
+ */
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.AgentPay = exports.AgentPayError = void 0;
14
+ const DEFAULT_BASE_URL = 'https://api.joomjoo.com';
15
+ /** Thrown on any non-2xx response. Carries the HTTP status, the AgentPay error code, and the request id. */
16
+ class AgentPayError extends Error {
17
+ constructor(message, status, code, requestId) {
18
+ super(message);
19
+ this.name = 'AgentPayError';
20
+ this.status = status;
21
+ this.code = code;
22
+ this.requestId = requestId;
23
+ }
24
+ }
25
+ exports.AgentPayError = AgentPayError;
26
+ class AgentPay {
27
+ constructor(options) {
28
+ /** Virtual cards: issue, reveal the PAN, and close. */
29
+ this.cards = {
30
+ create: (params) => this.request('POST', '/v1/cards', params),
31
+ reveal: (id) => this.request('GET', `/v1/cards/${encodeURIComponent(id)}`),
32
+ close: (id) => this.request('POST', `/v1/cards/${encodeURIComponent(id)}/close`),
33
+ };
34
+ /** Spend status for a card issued with cards.create (pass the spend_request_id). */
35
+ this.spend = {
36
+ get: (spendRequestId) => this.request('GET', `/v1/spend/${encodeURIComponent(spendRequestId)}`),
37
+ };
38
+ /** Let AgentPay drive a full checkout. create() is async; poll with get(). */
39
+ this.checkout = {
40
+ create: (params) => this.request('POST', '/v1/checkout', params),
41
+ get: (checkoutId) => this.request('GET', `/v1/checkout/${encodeURIComponent(checkoutId)}`),
42
+ };
43
+ /** Reusable merchant logins for login-gated stores. */
44
+ this.connections = {
45
+ create: (params) => this.request('POST', '/v1/connections', params),
46
+ complete: (id) => this.request('POST', `/v1/connections/${encodeURIComponent(id)}/complete`),
47
+ list: () => this.request('GET', '/v1/connections'),
48
+ get: (id) => this.request('GET', `/v1/connections/${encodeURIComponent(id)}`),
49
+ };
50
+ /** The wallet: balance, a top-up link (Stripe Checkout, card or stablecoin), a declared bank transfer. */
51
+ this.wallet = {
52
+ get: () => this.request('GET', '/v1/wallet'),
53
+ createFundingSession: (params) => this.request('POST', '/v1/wallet/funding-sessions', params),
54
+ declareBankTransfer: (params) => this.request('POST', '/v1/wallet/bank-transfers', params),
55
+ };
56
+ const o = typeof options === 'string' ? { apiKey: options } : options;
57
+ if (!o || !o.apiKey)
58
+ throw new Error('AgentPay: apiKey is required');
59
+ this.apiKey = o.apiKey;
60
+ this.baseUrl = (o.baseUrl || DEFAULT_BASE_URL).replace(/\/+$/, '');
61
+ const f = o.fetch || globalThis.fetch;
62
+ if (!f)
63
+ throw new Error('AgentPay: no fetch available. Use Node 18+ or pass options.fetch.');
64
+ this._fetch = f;
65
+ }
66
+ async request(method, path, body) {
67
+ const res = await this._fetch(`${this.baseUrl}${path}`, {
68
+ method,
69
+ headers: {
70
+ Authorization: `Bearer ${this.apiKey}`,
71
+ ...(body !== undefined ? { 'Content-Type': 'application/json' } : {}),
72
+ },
73
+ body: body !== undefined ? JSON.stringify(body) : undefined,
74
+ });
75
+ const requestId = res.headers.get('X-Mooj-Request-Id') || undefined;
76
+ const text = await res.text();
77
+ let data = null;
78
+ if (text) {
79
+ try {
80
+ data = JSON.parse(text);
81
+ }
82
+ catch {
83
+ data = text;
84
+ }
85
+ }
86
+ if (!res.ok) {
87
+ const d = (data ?? {});
88
+ const message = d.message || d.error || `AgentPay API error ${res.status}`;
89
+ throw new AgentPayError(message, res.status, d.error, d.request_id || requestId);
90
+ }
91
+ return data;
92
+ }
93
+ }
94
+ exports.AgentPay = AgentPay;
95
+ exports.default = AgentPay;
package/package.json CHANGED
@@ -1,6 +1,36 @@
1
1
  {
2
2
  "name": "@agentpay-global/sdk",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.3.0",
4
+ "description": "Official AgentPay SDK. Issue capped virtual cards and let your agent complete real checkouts. 3DS handled.",
5
+ "main": "./dist/index.js",
6
+ "types": "./dist/index.d.ts",
7
+ "files": [
8
+ "dist",
9
+ "README.md"
10
+ ],
11
+ "scripts": {
12
+ "build": "tsc",
13
+ "prepublishOnly": "npm run build"
14
+ },
15
+ "keywords": [
16
+ "agentpay",
17
+ "payments",
18
+ "ai-agents",
19
+ "virtual-cards",
20
+ "checkout",
21
+ "3ds"
22
+ ],
23
+ "author": "AgentPay",
24
+ "license": "MIT",
25
+ "homepage": "https://agentpay.global",
26
+ "engines": {
27
+ "node": ">=18"
28
+ },
29
+ "devDependencies": {
30
+ "typescript": "^5.4.5"
31
+ },
32
+ "repository": {
33
+ "type": "git",
34
+ "url": "https://github.com/Kato-Official/agentpay-skills.git"
35
+ }
36
+ }