@protocol-offair/gateway-sdk 0.1.1 → 0.1.2
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 +29 -126
- package/README.pt-BR.md +54 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,151 +1,54 @@
|
|
|
1
|
-
#
|
|
1
|
+
# OffAir Gateway SDK
|
|
2
2
|
|
|
3
|
-
SDK TypeScript
|
|
3
|
+
OffAir Gateway SDK is the public TypeScript SDK for integrating external applications with OffAir Gateway.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Portuguese version: [README.pt-BR.md](./README.pt-BR.md)
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
- consulta de intent;
|
|
9
|
-
- registro de webhooks;
|
|
10
|
-
- parsing de QR/link/copia-e-cola compatível com Solana Pay e AirPay;
|
|
11
|
-
- verificação de assinatura HMAC dos webhooks;
|
|
12
|
-
- cliente administrativo opcional para painéis internos.
|
|
13
|
-
|
|
14
|
-
O SDK não implementa swap, stablecoins, custódia de saldo ou promessa de liquidação fiat.
|
|
15
|
-
|
|
16
|
-
## Instalação local
|
|
7
|
+
## Installation
|
|
17
8
|
|
|
18
9
|
```bash
|
|
19
10
|
npm install @protocol-offair/gateway-sdk
|
|
20
11
|
```
|
|
21
12
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
```bash
|
|
25
|
-
npm --workspace @protocol-offair/gateway-sdk run build
|
|
26
|
-
npm --workspace @protocol-offair/gateway-sdk run test
|
|
27
|
-
```
|
|
13
|
+
## Capabilities
|
|
28
14
|
|
|
29
|
-
|
|
15
|
+
- Create Gateway payment intents.
|
|
16
|
+
- Fetch payment intent status.
|
|
17
|
+
- Register webhooks.
|
|
18
|
+
- Verify signed webhook payloads.
|
|
19
|
+
- Parse OffAir/Gateway payment links and Solana Pay-compatible codes.
|
|
20
|
+
- Use merchant and admin clients from server-side applications.
|
|
30
21
|
|
|
31
|
-
|
|
22
|
+
## Basic Usage
|
|
32
23
|
|
|
33
24
|
```ts
|
|
34
25
|
import { createAirPayGatewayClient } from "@protocol-offair/gateway-sdk";
|
|
35
26
|
|
|
36
|
-
const
|
|
37
|
-
apiBaseUrl: process.env.
|
|
38
|
-
apiKey: process.env.
|
|
27
|
+
const gateway = createAirPayGatewayClient({
|
|
28
|
+
apiBaseUrl: process.env.OFFAIR_GATEWAY_API_BASE_URL!,
|
|
29
|
+
apiKey: process.env.OFFAIR_GATEWAY_API_KEY!,
|
|
39
30
|
});
|
|
40
31
|
|
|
41
|
-
const intent = await
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
metadata: {
|
|
47
|
-
orderId: "order-123",
|
|
48
|
-
customerEmail: "cliente@example.com",
|
|
49
|
-
},
|
|
50
|
-
},
|
|
51
|
-
{
|
|
52
|
-
idempotencyKey: "order-123",
|
|
53
|
-
},
|
|
54
|
-
);
|
|
55
|
-
|
|
56
|
-
console.log(intent.intentId);
|
|
57
|
-
console.log(intent.solanaPayUrl);
|
|
58
|
-
console.log(intent.airpayUrl);
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
## Consultar status
|
|
62
|
-
|
|
63
|
-
```ts
|
|
64
|
-
const intent = await airpay.getPaymentIntent("pay_123");
|
|
65
|
-
|
|
66
|
-
if (intent.status === "confirmed") {
|
|
67
|
-
// liberar pedido, atualizar checkout ou aguardar webhook settlement.completed
|
|
68
|
-
}
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
## Registrar webhook
|
|
72
|
-
|
|
73
|
-
```ts
|
|
74
|
-
const webhook = await airpay.registerWebhook({
|
|
75
|
-
endpointUrl: "https://merchant.example/webhooks/airpay",
|
|
76
|
-
events: ["payment.confirmed", "payment.expired", "settlement.completed"],
|
|
77
|
-
secret: process.env.AIRPAY_GATEWAY_WEBHOOK_SECRET,
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
console.log(webhook.webhookId);
|
|
81
|
-
```
|
|
82
|
-
|
|
83
|
-
## Verificar assinatura de webhook
|
|
84
|
-
|
|
85
|
-
O Gateway assina o corpo canônico com:
|
|
86
|
-
|
|
87
|
-
```txt
|
|
88
|
-
sha256 HMAC(secret, `${timestamp}.${body}`)
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
Headers:
|
|
92
|
-
|
|
93
|
-
- `x-signature`
|
|
94
|
-
- `x-timestamp`
|
|
95
|
-
- `x-event-id`
|
|
96
|
-
|
|
97
|
-
Exemplo com Express:
|
|
98
|
-
|
|
99
|
-
```ts
|
|
100
|
-
import { assertGatewayWebhookSignature } from "@protocol-offair/gateway-sdk";
|
|
101
|
-
|
|
102
|
-
app.post("/webhooks/airpay", express.raw({ type: "application/json" }), async (req, res) => {
|
|
103
|
-
const event = await assertGatewayWebhookSignature({
|
|
104
|
-
payload: req.body.toString("utf8"),
|
|
105
|
-
headers: req.headers,
|
|
106
|
-
secret: process.env.AIRPAY_GATEWAY_WEBHOOK_SECRET!,
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
if (event.type === "payment.confirmed") {
|
|
110
|
-
await markOrderAsPaid(event.metadata.orderId, event.txHash);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
res.status(204).send();
|
|
32
|
+
const intent = await gateway.createPaymentIntent({
|
|
33
|
+
amount: "1.5",
|
|
34
|
+
currency: "SOL",
|
|
35
|
+
expiresInSeconds: 3600,
|
|
36
|
+
metadata: { orderId: "order-123" },
|
|
114
37
|
});
|
|
115
|
-
```
|
|
116
38
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
```ts
|
|
120
|
-
import { parseAirPayGatewayPaymentCode } from "@protocol-offair/gateway-sdk";
|
|
121
|
-
|
|
122
|
-
const request = parseAirPayGatewayPaymentCode(copiedOrScannedText);
|
|
123
|
-
|
|
124
|
-
console.log(request.wallet);
|
|
125
|
-
console.log(request.amount);
|
|
126
|
-
console.log(request.reference);
|
|
127
|
-
console.log(request.intentId);
|
|
39
|
+
console.log(intent.intentId);
|
|
128
40
|
```
|
|
129
41
|
|
|
130
|
-
|
|
42
|
+
The exported function names still include legacy `AirPay` wording for API compatibility. New documentation should refer to the product as OffAir.
|
|
131
43
|
|
|
132
|
-
|
|
44
|
+
## Development
|
|
133
45
|
|
|
134
|
-
```
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
apiBaseUrl: process.env.AIRPAY_GATEWAY_API_BASE_URL!,
|
|
139
|
-
adminKey: process.env.AIRPAY_GATEWAY_ADMIN_KEY!,
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
const overview = await admin.getOverview();
|
|
143
|
-
const pending = await admin.listPaymentIntents({ status: "pending", limit: 50 });
|
|
46
|
+
```bash
|
|
47
|
+
npm install
|
|
48
|
+
npm run build
|
|
49
|
+
npm test
|
|
144
50
|
```
|
|
145
51
|
|
|
146
|
-
##
|
|
52
|
+
## Security
|
|
147
53
|
|
|
148
|
-
-
|
|
149
|
-
- O SDK não cria carteiras nem assina transações pelo usuário.
|
|
150
|
-
- O SDK não promete liquidação offline.
|
|
151
|
-
- Chaves merchant/admin devem ficar no servidor do integrador.
|
|
54
|
+
Use merchant API keys only in trusted server-side environments. Do not embed private API keys in public frontend code.
|
package/README.pt-BR.md
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# OffAir Gateway SDK
|
|
2
|
+
|
|
3
|
+
OffAir Gateway SDK é o SDK TypeScript público para integrar aplicações externas ao OffAir Gateway.
|
|
4
|
+
|
|
5
|
+
Versão em inglês: [README.md](./README.md)
|
|
6
|
+
|
|
7
|
+
## Instalação
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @protocol-offair/gateway-sdk
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Funcionalidades
|
|
14
|
+
|
|
15
|
+
- Criar payment intents do Gateway.
|
|
16
|
+
- Consultar status de payment intents.
|
|
17
|
+
- Registrar webhooks.
|
|
18
|
+
- Verificar payloads assinados de webhook.
|
|
19
|
+
- Interpretar links de pagamento OffAir/Gateway e códigos compatíveis com Solana Pay.
|
|
20
|
+
- Usar clientes merchant e admin em aplicações server-side.
|
|
21
|
+
|
|
22
|
+
## Uso Básico
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
import { createAirPayGatewayClient } from "@protocol-offair/gateway-sdk";
|
|
26
|
+
|
|
27
|
+
const gateway = createAirPayGatewayClient({
|
|
28
|
+
apiBaseUrl: process.env.OFFAIR_GATEWAY_API_BASE_URL!,
|
|
29
|
+
apiKey: process.env.OFFAIR_GATEWAY_API_KEY!,
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const intent = await gateway.createPaymentIntent({
|
|
33
|
+
amount: "1.5",
|
|
34
|
+
currency: "SOL",
|
|
35
|
+
expiresInSeconds: 3600,
|
|
36
|
+
metadata: { orderId: "order-123" },
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
console.log(intent.intentId);
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Os nomes exportados ainda contêm `AirPay` por compatibilidade de API. A documentação nova deve tratar o produto como OffAir.
|
|
43
|
+
|
|
44
|
+
## Desenvolvimento
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
npm install
|
|
48
|
+
npm run build
|
|
49
|
+
npm test
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Segurança
|
|
53
|
+
|
|
54
|
+
Use API keys de merchant apenas em ambientes server-side confiáveis. Não embuta chaves privadas de API em frontend público.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@protocol-offair/gateway-sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -30,6 +30,6 @@
|
|
|
30
30
|
},
|
|
31
31
|
"repository": {
|
|
32
32
|
"type": "git",
|
|
33
|
-
"url": "git+https://github.com/protocol-offair/
|
|
33
|
+
"url": "git+https://github.com/protocol-offair/offair-gateway-sdk.git"
|
|
34
34
|
}
|
|
35
35
|
}
|