@cosmosapp/pay_sdk 1.2.0 → 1.2.1

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.
@@ -1,7 +1,7 @@
1
1
  # Quickstart
2
2
 
3
3
  ```ts
4
- import { Client, Assets } from '@cosmosapp/pay_sdk';
4
+ import { Client } from '@cosmosapp/pay_sdk';
5
5
 
6
6
  const client = new Client({ apiKey: process.env.COSMOS_PAY_API_KEY });
7
7
 
@@ -9,7 +9,7 @@ const client = new Client({ apiKey: process.env.COSMOS_PAY_API_KEY });
9
9
  const intent = await client.paymentIntents.createPay({
10
10
  destination: 'GCALNQQBXAPZ2WIRSDDBMSTAKCUH5SG6U76YBFLQLIXJTF7FE5AX7AOO',
11
11
  amount: '120.1234567',
12
- asset: Assets.USDC, // fills the verified mainnet issuer for you
12
+ // Omitting asset fields uses native XLM on both testnet and mainnet.
13
13
  msg: 'Order #24',
14
14
  });
15
15
 
@@ -25,14 +25,14 @@ if (outcome.valid) console.log('Settled!', outcome.status);
25
25
 
26
26
  ```ts
27
27
  // ── server.ts ──────────────────────────────────────────────────────
28
- import { Client, Assets } from '@cosmosapp/pay_sdk';
28
+ import { Client } from '@cosmosapp/pay_sdk';
29
29
  const client = new Client({ apiKey: process.env.COSMOS_PAY_API_KEY });
30
30
 
31
31
  export async function createIntent() {
32
32
  const intent = await client.paymentIntents.createPay({
33
33
  destination: 'G...MERCHANT',
34
34
  amount: '10',
35
- asset: Assets.USDC,
35
+ // Native XLM keeps this first example network-independent.
36
36
  });
37
37
  return intent.toJSON(); // send this payload to the browser
38
38
  }
@@ -10,13 +10,17 @@
10
10
  ## Create
11
11
 
12
12
  ```ts
13
- import { Assets } from '@cosmosapp/pay_sdk';
13
+ import { Assets, TestnetAssets } from '@cosmosapp/pay_sdk';
14
+
15
+ const usdc = process.env.COSMOS_PAY_API_KEY?.startsWith('prod_')
16
+ ? Assets.USDC
17
+ : TestnetAssets.USDC;
14
18
 
15
19
  // pay (no source)
16
20
  const pay = await client.paymentIntents.createPay({
17
21
  destination: 'G...', // required — payee (or an address-book name)
18
22
  amount: '10', // optional — omit for an open amount (donations)
19
- asset: Assets.USDC, // typed asset → fills assetCode + verified issuer
23
+ asset: usdc, // issuer matches the API key network
20
24
  // assetCode: 'USDC', assetIssuer: 'G...', // …or set them explicitly
21
25
  // omit asset entirely for native lumens (XLM)
22
26
  memo: '123456789', // optional MEMO_ID (uint64) — auto-generated if omitted
@@ -3,8 +3,14 @@
3
3
  Copy-paste end-to-end patterns. All server snippets assume:
4
4
 
5
5
  ```ts
6
- import { Client, Assets } from '@cosmosapp/pay_sdk';
7
- const client = new Client({ apiKey: process.env.COSMOS_PAY_API_KEY });
6
+ import { Assets, Client, TestnetAssets } from '@cosmosapp/pay_sdk';
7
+
8
+ const apiKey = process.env.COSMOS_PAY_API_KEY;
9
+ const merchantAccount = process.env.MERCHANT_ACCOUNT;
10
+ if (!apiKey || !merchantAccount) throw new Error('Missing Cosmos Pay configuration');
11
+
12
+ const client = new Client({ apiKey });
13
+ const usdc = apiKey.startsWith('prod_') ? Assets.USDC : TestnetAssets.USDC;
8
14
  ```
9
15
 
10
16
  ## 1. Checkout (server creates, browser pays, webhook confirms)
@@ -13,12 +19,12 @@ const client = new Client({ apiKey: process.env.COSMOS_PAY_API_KEY });
13
19
  // server: create the intent for an order
14
20
  export async function startCheckout(orderId: string, total: string) {
15
21
  const intent = await client.paymentIntents.createPay({
16
- destination: process.env.MERCHANT_ACCOUNT,
22
+ destination: merchantAccount,
17
23
  amount: total,
18
- asset: Assets.USDC,
19
- reference: orderId, // ties the intent to your order
24
+ asset: usdc,
20
25
  msg: `Order ${orderId}`,
21
26
  });
27
+ await intent.edit({ reference: orderId }); // reference is set through PATCH
22
28
  return intent.toJSON(); // → send to the browser
23
29
  }
24
30
  ```
@@ -41,8 +47,8 @@ client.webhooks.on('paymentIntentSucceeded', async (event) => {
41
47
 
42
48
  ```ts
43
49
  const intent = await client.paymentIntents.createPay({
44
- destination: process.env.MERCHANT_ACCOUNT,
45
- asset: Assets.USDC, // no amount → the wallet asks the user
50
+ destination: merchantAccount,
51
+ asset: usdc, // no amount → the wallet asks the user
46
52
  msg: 'Support us 💜',
47
53
  });
48
54
  // browser: await new WebClient().pay(intent, { amount: enteredAmount });
@@ -75,7 +81,7 @@ if (!outcome.valid) {
75
81
  import { Assets, TestnetAssets } from '@cosmosapp/pay_sdk';
76
82
  // dv_ key → testnet → use TestnetAssets.USDC
77
83
  // prod_ key → mainnet → use Assets.USDC
78
- const asset = process.env.COSMOS_PAY_API_KEY.startsWith('prod_') ? Assets.USDC : TestnetAssets.USDC;
84
+ const asset = apiKey.startsWith('prod_') ? Assets.USDC : TestnetAssets.USDC;
79
85
  ```
80
86
 
81
87
  ## 6. Catalog: products + customers
@@ -144,7 +144,7 @@ normal integration never sets them.
144
144
  # Quickstart
145
145
 
146
146
  ```ts
147
- import { Client, Assets } from '@cosmosapp/pay_sdk';
147
+ import { Client } from '@cosmosapp/pay_sdk';
148
148
 
149
149
  const client = new Client({ apiKey: process.env.COSMOS_PAY_API_KEY });
150
150
 
@@ -152,7 +152,7 @@ const client = new Client({ apiKey: process.env.COSMOS_PAY_API_KEY });
152
152
  const intent = await client.paymentIntents.createPay({
153
153
  destination: 'GCALNQQBXAPZ2WIRSDDBMSTAKCUH5SG6U76YBFLQLIXJTF7FE5AX7AOO',
154
154
  amount: '120.1234567',
155
- asset: Assets.USDC, // fills the verified mainnet issuer for you
155
+ // Omitting asset fields uses native XLM on both testnet and mainnet.
156
156
  msg: 'Order #24',
157
157
  });
158
158
 
@@ -168,14 +168,14 @@ if (outcome.valid) console.log('Settled!', outcome.status);
168
168
 
169
169
  ```ts
170
170
  // ── server.ts ──────────────────────────────────────────────────────
171
- import { Client, Assets } from '@cosmosapp/pay_sdk';
171
+ import { Client } from '@cosmosapp/pay_sdk';
172
172
  const client = new Client({ apiKey: process.env.COSMOS_PAY_API_KEY });
173
173
 
174
174
  export async function createIntent() {
175
175
  const intent = await client.paymentIntents.createPay({
176
176
  destination: 'G...MERCHANT',
177
177
  amount: '10',
178
- asset: Assets.USDC,
178
+ // Native XLM keeps this first example network-independent.
179
179
  });
180
180
  return intent.toJSON(); // send this payload to the browser
181
181
  }
@@ -270,13 +270,17 @@ e.g. `intent.isPay`, `intent.assetLabel`, `await intent.validate(txHash)`,
270
270
  ## Create
271
271
 
272
272
  ```ts
273
- import { Assets } from '@cosmosapp/pay_sdk';
273
+ import { Assets, TestnetAssets } from '@cosmosapp/pay_sdk';
274
+
275
+ const usdc = process.env.COSMOS_PAY_API_KEY?.startsWith('prod_')
276
+ ? Assets.USDC
277
+ : TestnetAssets.USDC;
274
278
 
275
279
  // pay (no source)
276
280
  const pay = await client.paymentIntents.createPay({
277
281
  destination: 'G...', // required — payee (or an address-book name)
278
282
  amount: '10', // optional — omit for an open amount (donations)
279
- asset: Assets.USDC, // typed asset → fills assetCode + verified issuer
283
+ asset: usdc, // issuer matches the API key network
280
284
  // assetCode: 'USDC', assetIssuer: 'G...', // …or set them explicitly
281
285
  // omit asset entirely for native lumens (XLM)
282
286
  memo: '123456789', // optional MEMO_ID (uint64) — auto-generated if omitted
@@ -893,8 +897,14 @@ Pagination wrappers (`list` / `fetchDeliveries`) return
893
897
  Copy-paste end-to-end patterns. All server snippets assume:
894
898
 
895
899
  ```ts
896
- import { Client, Assets } from '@cosmosapp/pay_sdk';
897
- const client = new Client({ apiKey: process.env.COSMOS_PAY_API_KEY });
900
+ import { Assets, Client, TestnetAssets } from '@cosmosapp/pay_sdk';
901
+
902
+ const apiKey = process.env.COSMOS_PAY_API_KEY;
903
+ const merchantAccount = process.env.MERCHANT_ACCOUNT;
904
+ if (!apiKey || !merchantAccount) throw new Error('Missing Cosmos Pay configuration');
905
+
906
+ const client = new Client({ apiKey });
907
+ const usdc = apiKey.startsWith('prod_') ? Assets.USDC : TestnetAssets.USDC;
898
908
  ```
899
909
 
900
910
  ## 1. Checkout (server creates, browser pays, webhook confirms)
@@ -903,12 +913,12 @@ const client = new Client({ apiKey: process.env.COSMOS_PAY_API_KEY });
903
913
  // server: create the intent for an order
904
914
  export async function startCheckout(orderId: string, total: string) {
905
915
  const intent = await client.paymentIntents.createPay({
906
- destination: process.env.MERCHANT_ACCOUNT,
916
+ destination: merchantAccount,
907
917
  amount: total,
908
- asset: Assets.USDC,
909
- reference: orderId, // ties the intent to your order
918
+ asset: usdc,
910
919
  msg: `Order ${orderId}`,
911
920
  });
921
+ await intent.edit({ reference: orderId }); // reference is set through PATCH
912
922
  return intent.toJSON(); // → send to the browser
913
923
  }
914
924
  ```
@@ -931,8 +941,8 @@ client.webhooks.on('paymentIntentSucceeded', async (event) => {
931
941
 
932
942
  ```ts
933
943
  const intent = await client.paymentIntents.createPay({
934
- destination: process.env.MERCHANT_ACCOUNT,
935
- asset: Assets.USDC, // no amount → the wallet asks the user
944
+ destination: merchantAccount,
945
+ asset: usdc, // no amount → the wallet asks the user
936
946
  msg: 'Support us 💜',
937
947
  });
938
948
  // browser: await new WebClient().pay(intent, { amount: enteredAmount });
@@ -965,7 +975,7 @@ if (!outcome.valid) {
965
975
  import { Assets, TestnetAssets } from '@cosmosapp/pay_sdk';
966
976
  // dv_ key → testnet → use TestnetAssets.USDC
967
977
  // prod_ key → mainnet → use Assets.USDC
968
- const asset = process.env.COSMOS_PAY_API_KEY.startsWith('prod_') ? Assets.USDC : TestnetAssets.USDC;
978
+ const asset = apiKey.startsWith('prod_') ? Assets.USDC : TestnetAssets.USDC;
969
979
  ```
970
980
 
971
981
  ## 6. Catalog: products + customers
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cosmosapp/pay_sdk",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "description": "A powerful, object-oriented JavaScript/TypeScript SDK for the Cosmos Pay Payments API — server SDK (Stellar SEP-7 payment intents, webhooks, products, customers, analytics) plus a browser web client that auto-detects Freighter, xBull, Rabet, LOBSTR & Albedo wallets and signs transactions for you.",
5
5
  "keywords": [
6
6
  "cosmos",