pixgo-api 1.0.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 +64 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +5 -0
- package/dist/pix.d.ts +25 -0
- package/dist/pix.js +83 -0
- package/dist/pixgo.d.ts +9 -0
- package/dist/pixgo.js +24 -0
- package/dist/types.d.ts +46 -0
- package/dist/types.js +2 -0
- package/package.json +31 -0
package/README.md
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# PixGo 💸
|
|
2
|
+
|
|
3
|
+
Uma biblioteca simples e moderna para integração com pagamentos via Pix.
|
|
4
|
+
|
|
5
|
+
## 📦 Instalação
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install pixgo-api
|
|
9
|
+
# ou
|
|
10
|
+
yarn add pixgo-api
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## 🔒 Autenticação
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import { PixGo } from "pixgo-api"
|
|
17
|
+
|
|
18
|
+
const pixgo = new PixGo({ apiKey: "SUA_API_KEY_AQUI" })
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## 💰 Criar um pagamento Pix
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
pixgo.pix.create({
|
|
25
|
+
amount: 10,
|
|
26
|
+
customer_address: "Rua das Flores, 123, São Paulo, SP, 01234-567", // opcional
|
|
27
|
+
customer_cpf: "12345678901", // opcional
|
|
28
|
+
customer_email: "cliente@example.com", // opcional
|
|
29
|
+
customer_name: "João Silva", // opcional
|
|
30
|
+
customer_phone: "11999999999", // opcional
|
|
31
|
+
description: "Pagamento de produto", // opcional
|
|
32
|
+
external_id: "pedido_12345" // opcional
|
|
33
|
+
})
|
|
34
|
+
.then((res) => {
|
|
35
|
+
console.log(res)
|
|
36
|
+
})
|
|
37
|
+
.catch((err) => {
|
|
38
|
+
console.error(err)
|
|
39
|
+
})
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## 🔎 Consultar status do pagamento
|
|
43
|
+
|
|
44
|
+
```typescript
|
|
45
|
+
pixgo.pix.status({ payment_id: "019d6f17d7274b38c5f487c60a41aa" })
|
|
46
|
+
.then((res) => {
|
|
47
|
+
console.log(res)
|
|
48
|
+
})
|
|
49
|
+
.catch((err) => {
|
|
50
|
+
console.error(err)
|
|
51
|
+
})
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## 📄 Detalhes do pagamento
|
|
55
|
+
|
|
56
|
+
```typescript
|
|
57
|
+
pixgo.pix.details({ payment_id: "019d6f17d7274b38c5f487c60a41aa" })
|
|
58
|
+
.then((res) => {
|
|
59
|
+
console.log(res)
|
|
60
|
+
})
|
|
61
|
+
.catch((err) => {
|
|
62
|
+
console.error(err)
|
|
63
|
+
})
|
|
64
|
+
```
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { PixGo } from "./pixgo";
|
package/dist/index.js
ADDED
package/dist/pix.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { PixCreateResponse, PixStatusResponse, PixDetailsResponse } from "./types";
|
|
2
|
+
interface PixCreateParams {
|
|
3
|
+
amount: number;
|
|
4
|
+
customer_name?: string;
|
|
5
|
+
customer_cpf?: string;
|
|
6
|
+
customer_email?: string;
|
|
7
|
+
customer_phone?: string;
|
|
8
|
+
customer_address?: string;
|
|
9
|
+
external_id?: string;
|
|
10
|
+
description?: string;
|
|
11
|
+
}
|
|
12
|
+
interface PixStatusParams {
|
|
13
|
+
payment_id: string;
|
|
14
|
+
}
|
|
15
|
+
export declare class Pix {
|
|
16
|
+
private config;
|
|
17
|
+
constructor(config: {
|
|
18
|
+
apiKey: string;
|
|
19
|
+
apiBase: string;
|
|
20
|
+
});
|
|
21
|
+
create(params: PixCreateParams): Promise<PixCreateResponse>;
|
|
22
|
+
details(params: PixStatusParams): Promise<PixDetailsResponse>;
|
|
23
|
+
status(params: PixStatusParams): Promise<PixStatusResponse>;
|
|
24
|
+
}
|
|
25
|
+
export {};
|
package/dist/pix.js
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Pix = void 0;
|
|
7
|
+
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
class Pix {
|
|
9
|
+
config;
|
|
10
|
+
constructor(config) {
|
|
11
|
+
this.config = config;
|
|
12
|
+
}
|
|
13
|
+
async create(params) {
|
|
14
|
+
const { amount, customer_name, customer_cpf, customer_email, customer_phone, customer_address, external_id, description } = params;
|
|
15
|
+
if (!amount) {
|
|
16
|
+
throw new Error("Amount is required");
|
|
17
|
+
}
|
|
18
|
+
try {
|
|
19
|
+
const response = await axios_1.default.post(`${this.config.apiBase}/payment/create`, { amount, customer_name, customer_cpf, customer_email, customer_phone, customer_address, external_id, description }, {
|
|
20
|
+
headers: {
|
|
21
|
+
"Content-Type": "application/json",
|
|
22
|
+
"X-API-Key": `${this.config.apiKey}`,
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
return response.data;
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
if (axios_1.default.isAxiosError(error) && error.response) {
|
|
29
|
+
return error.response.data;
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
throw new Error("An unexpected error occurred");
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
async details(params) {
|
|
37
|
+
const { payment_id } = params;
|
|
38
|
+
if (!payment_id) {
|
|
39
|
+
throw new Error("Payment ID is required");
|
|
40
|
+
}
|
|
41
|
+
try {
|
|
42
|
+
const response = await axios_1.default.get(`${this.config.apiBase}/payment/${payment_id}/`, {
|
|
43
|
+
headers: {
|
|
44
|
+
"Content-Type": "application/json",
|
|
45
|
+
"X-API-Key": `${this.config.apiKey}`,
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
return response.data;
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
if (axios_1.default.isAxiosError(error) && error.response) {
|
|
52
|
+
return error.response.data;
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
throw new Error("An unexpected error occurred");
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
async status(params) {
|
|
60
|
+
const { payment_id } = params;
|
|
61
|
+
if (!payment_id) {
|
|
62
|
+
throw new Error("Payment ID is required");
|
|
63
|
+
}
|
|
64
|
+
try {
|
|
65
|
+
const response = await axios_1.default.get(`${this.config.apiBase}/payment/${payment_id}/status`, {
|
|
66
|
+
headers: {
|
|
67
|
+
"Content-Type": "application/json",
|
|
68
|
+
"X-API-Key": `${this.config.apiKey}`,
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
return response.data;
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
if (axios_1.default.isAxiosError(error) && error.response) {
|
|
75
|
+
return error.response.data;
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
throw new Error("An unexpected error occurred");
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
exports.Pix = Pix;
|
package/dist/pixgo.d.ts
ADDED
package/dist/pixgo.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PixGo = void 0;
|
|
4
|
+
const pix_1 = require("./pix");
|
|
5
|
+
class InternalConfig {
|
|
6
|
+
apiKey;
|
|
7
|
+
apiBase;
|
|
8
|
+
constructor(config) {
|
|
9
|
+
this.apiKey = config.apiKey;
|
|
10
|
+
this.apiBase = "https://pixgo.org/api/v1";
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
class PixGo {
|
|
14
|
+
config;
|
|
15
|
+
pix;
|
|
16
|
+
constructor(config) {
|
|
17
|
+
if (!config.apiKey) {
|
|
18
|
+
throw new Error("API Key is required");
|
|
19
|
+
}
|
|
20
|
+
this.config = new InternalConfig(config);
|
|
21
|
+
this.pix = new pix_1.Pix(this.config);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.PixGo = PixGo;
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
export interface PixCreateResponse {
|
|
2
|
+
"success": boolean;
|
|
3
|
+
"data": {
|
|
4
|
+
"payment_id": string;
|
|
5
|
+
"external_id": string;
|
|
6
|
+
"amount": number;
|
|
7
|
+
"status": string;
|
|
8
|
+
"qr_code": string;
|
|
9
|
+
"qr_image_url": string;
|
|
10
|
+
"expires_at": string;
|
|
11
|
+
"created_at": string;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export interface PixStatusResponse {
|
|
15
|
+
"success": boolean;
|
|
16
|
+
"data": {
|
|
17
|
+
"payment_id": string;
|
|
18
|
+
"external_id": string;
|
|
19
|
+
"amount": number;
|
|
20
|
+
"status": string;
|
|
21
|
+
"customer_name": string;
|
|
22
|
+
"customer_cpf": string;
|
|
23
|
+
"customer_phone": string;
|
|
24
|
+
"created_at": string;
|
|
25
|
+
"updated_at": string;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
export interface PixDetailsResponse {
|
|
29
|
+
"success": boolean;
|
|
30
|
+
"data": {
|
|
31
|
+
"payment_id": string;
|
|
32
|
+
"external_id": string;
|
|
33
|
+
"amount": number;
|
|
34
|
+
"status": string;
|
|
35
|
+
"customer_name": string;
|
|
36
|
+
"customer_cpf": string;
|
|
37
|
+
"customer_phone": string;
|
|
38
|
+
"customer_address": string;
|
|
39
|
+
"description": string;
|
|
40
|
+
"qr_code": string;
|
|
41
|
+
"qr_image_url": string;
|
|
42
|
+
"created_at": string;
|
|
43
|
+
"updated_at": string;
|
|
44
|
+
"expires_at": string;
|
|
45
|
+
};
|
|
46
|
+
}
|
package/dist/types.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "pixgo-api",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"main": "dist/index.js",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"build": "tsc"
|
|
7
|
+
},
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": ""
|
|
11
|
+
},
|
|
12
|
+
"keywords": [
|
|
13
|
+
"pixgo",
|
|
14
|
+
"api-pix",
|
|
15
|
+
"pix"
|
|
16
|
+
],
|
|
17
|
+
"author": "b7k3",
|
|
18
|
+
"license": "ISC",
|
|
19
|
+
"description": "Biblioteca simples para integrar com a API da PixGo",
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@types/node": "^22.19.17",
|
|
22
|
+
"typescript": "^5.9.3"
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"dist",
|
|
26
|
+
"README.md"
|
|
27
|
+
],
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"axios": "^1.15.0"
|
|
30
|
+
}
|
|
31
|
+
}
|