@applite/duticotac 0.0.1 → 0.0.3
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 +108 -87
- package/package.json +1 -2
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @applite/duticotac
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
SDK JavaScript/TypeScript pour intégrer les paiements Duticotac (mobile money, offres, transactions).
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -8,148 +8,169 @@ A lightweight JavaScript SDK for interacting with Duticotac platform APIs.
|
|
|
8
8
|
pnpm add @applite/duticotac
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
##
|
|
12
|
-
|
|
13
|
-
Each method accepts a **single object** that always includes `apiKey`, plus fields required by the specific route.
|
|
14
|
-
|
|
15
|
-
### Instantiate the client
|
|
11
|
+
## Démarrage rapide
|
|
16
12
|
|
|
17
13
|
```ts
|
|
18
14
|
import { DuticotacSDK } from "@applite/duticotac";
|
|
19
15
|
|
|
20
16
|
const duticotac = new DuticotacSDK({
|
|
21
|
-
|
|
17
|
+
apiKey: "your_api_key",
|
|
18
|
+
appId: "your_app_id", // optionnel
|
|
22
19
|
});
|
|
23
20
|
```
|
|
24
21
|
|
|
25
|
-
|
|
22
|
+
Le SDK se connecte par défaut à `https://api.applite.freddydro.dev`. Vous pouvez passer un `baseUrl` personnalisé si nécessaire.
|
|
23
|
+
|
|
24
|
+
## Modules
|
|
25
|
+
|
|
26
|
+
### Balance
|
|
26
27
|
|
|
27
28
|
```ts
|
|
28
|
-
await duticotac.balance.balance(
|
|
29
|
-
apiKey: "api_key_abc",
|
|
30
|
-
appId: "app_123", // optional
|
|
31
|
-
});
|
|
29
|
+
const { data: balance } = await duticotac.balance.balance();
|
|
32
30
|
```
|
|
33
31
|
|
|
34
|
-
###
|
|
32
|
+
### Offres
|
|
35
33
|
|
|
36
34
|
```ts
|
|
37
|
-
//
|
|
35
|
+
// Créer une offre
|
|
38
36
|
await duticotac.offer.create({
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
ref: "offer-ref",
|
|
43
|
-
price: 1000,
|
|
37
|
+
name: "Forfait Premium",
|
|
38
|
+
ref: "premium-monthly",
|
|
39
|
+
price: 5000,
|
|
44
40
|
platform: "DUTICOTAC",
|
|
45
|
-
type: "STATIC",
|
|
46
|
-
description: "
|
|
41
|
+
type: "STATIC",
|
|
42
|
+
description: "Accès premium mensuel",
|
|
47
43
|
});
|
|
48
44
|
|
|
49
|
-
//
|
|
50
|
-
await duticotac.offer.list(
|
|
51
|
-
apiKey: "api_key_abc",
|
|
52
|
-
appId: "app_123", // optional
|
|
53
|
-
});
|
|
45
|
+
// Lister les offres
|
|
46
|
+
const { data: offers } = await duticotac.offer.list();
|
|
54
47
|
|
|
55
|
-
//
|
|
56
|
-
await duticotac.offer.get({
|
|
57
|
-
apiKey: "api_key_abc",
|
|
58
|
-
ref: "offer-ref",
|
|
59
|
-
appId: "app_123", // optional
|
|
60
|
-
});
|
|
48
|
+
// Récupérer une offre
|
|
49
|
+
const { data: offer } = await duticotac.offer.get({ ref: "premium-monthly" });
|
|
61
50
|
|
|
62
|
-
//
|
|
63
|
-
await duticotac.offer.update({
|
|
64
|
-
apiKey: "api_key_abc",
|
|
65
|
-
ref: "offer-ref",
|
|
66
|
-
appId: "app_123", // optional
|
|
67
|
-
name: "Updated Name", // optional
|
|
68
|
-
price: 1500, // optional
|
|
69
|
-
});
|
|
51
|
+
// Modifier une offre
|
|
52
|
+
await duticotac.offer.update({ ref: "premium-monthly", price: 7500 });
|
|
70
53
|
|
|
71
|
-
//
|
|
72
|
-
await duticotac.offer.delete({
|
|
73
|
-
apiKey: "api_key_abc",
|
|
74
|
-
ref: "offer-ref",
|
|
75
|
-
appId: "app_123", // optional
|
|
76
|
-
});
|
|
54
|
+
// Supprimer une offre
|
|
55
|
+
await duticotac.offer.delete({ ref: "premium-monthly" });
|
|
77
56
|
```
|
|
78
57
|
|
|
79
|
-
### Mobile
|
|
58
|
+
### Paiements Mobile Money
|
|
80
59
|
|
|
81
60
|
```ts
|
|
82
|
-
//
|
|
61
|
+
// Encaissement (cash in)
|
|
83
62
|
await duticotac.mobileMoney.cashin({
|
|
84
|
-
|
|
85
|
-
appId: "app_123", // optional
|
|
86
|
-
amount: 1000,
|
|
63
|
+
amount: 5000,
|
|
87
64
|
phone: "+2250700000000",
|
|
88
65
|
paymentMethod: "OM_CI",
|
|
89
66
|
password: "password123",
|
|
90
67
|
});
|
|
91
68
|
|
|
92
|
-
//
|
|
69
|
+
// Décaissement (cash out)
|
|
93
70
|
await duticotac.mobileMoney.cashout({
|
|
94
|
-
apiKey: "api_key_abc",
|
|
95
|
-
appId: "app_123", // optional
|
|
96
71
|
transactionId: "txn_123",
|
|
97
72
|
ref: "ref_123",
|
|
98
73
|
phone: "+2250700000000",
|
|
99
|
-
name: "
|
|
100
|
-
email: "
|
|
74
|
+
name: "Jean Dupont",
|
|
75
|
+
email: "jean@example.com",
|
|
101
76
|
paymentMethod: "OM_CI",
|
|
102
|
-
|
|
103
|
-
otp: "1234", // optional
|
|
77
|
+
otp: "1234", // requis pour Orange Money
|
|
104
78
|
});
|
|
105
79
|
```
|
|
106
80
|
|
|
107
|
-
|
|
81
|
+
**Providers supportés :** `OM_CI` (Orange Money), `MTN_CI`, `MOOV_CI`, `WAVE_CI`, `CREDIT_CARD`, `CASH`, `IAP`
|
|
82
|
+
|
|
83
|
+
### Transactions
|
|
108
84
|
|
|
109
85
|
```ts
|
|
110
|
-
//
|
|
111
|
-
await duticotac.
|
|
112
|
-
|
|
113
|
-
|
|
86
|
+
// Récupérer le statut d'une transaction
|
|
87
|
+
const { data: tx } = await duticotac.transaction.get({ id: "transaction_id" });
|
|
88
|
+
|
|
89
|
+
// Polling avec backoff exponentiel (idéal pour paiements asynchrones)
|
|
90
|
+
const { data: confirmed } = await duticotac.transaction.poll("transaction_id", {
|
|
91
|
+
intervalMs: 2000, // intervalle minimum (défaut: 2s)
|
|
92
|
+
timeoutMs: 90_000, // timeout global (défaut: 90s)
|
|
93
|
+
onPoll: (attempt, elapsed) => {
|
|
94
|
+
console.log(`Tentative ${attempt} (${elapsed}ms)`);
|
|
95
|
+
},
|
|
96
|
+
signal: abortController.signal, // annulation externe
|
|
114
97
|
});
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Le polling utilise un backoff exponentiel (1s → 2s → 3s → 5s → 8s) et se termine quand la transaction passe en `CONFIRMED`, `CANCELLED` ou `FAILED`.
|
|
101
|
+
|
|
102
|
+
### Méthodes de paiement
|
|
103
|
+
|
|
104
|
+
```ts
|
|
105
|
+
// Récupérer les méthodes configurées
|
|
106
|
+
const { data: methods } = await duticotac.paymentMethod.get();
|
|
115
107
|
|
|
116
|
-
//
|
|
108
|
+
// Configurer les méthodes
|
|
117
109
|
await duticotac.paymentMethod.set({
|
|
118
|
-
|
|
119
|
-
appId: "app_123", // optional
|
|
120
|
-
providers: ["OM_CI", "MTN_CI"],
|
|
110
|
+
providers: ["OM_CI", "MTN_CI", "WAVE_CI"],
|
|
121
111
|
});
|
|
122
112
|
```
|
|
123
113
|
|
|
124
114
|
### Webhooks
|
|
125
115
|
|
|
126
116
|
```ts
|
|
127
|
-
//
|
|
128
|
-
await duticotac.webhook.get(
|
|
129
|
-
apiKey: "api_key_abc",
|
|
130
|
-
appId: "app_123", // optional
|
|
131
|
-
});
|
|
117
|
+
// Récupérer l'URL du webhook
|
|
118
|
+
const { data: url } = await duticotac.webhook.get();
|
|
132
119
|
|
|
133
|
-
//
|
|
134
|
-
await duticotac.webhook.set({
|
|
135
|
-
apiKey: "api_key_abc",
|
|
136
|
-
appId: "app_123", // optional
|
|
137
|
-
url: "https://example.com/webhook",
|
|
138
|
-
});
|
|
120
|
+
// Configurer l'URL
|
|
121
|
+
await duticotac.webhook.set({ url: "https://example.com/webhook" });
|
|
139
122
|
```
|
|
140
123
|
|
|
141
|
-
|
|
124
|
+
## Types exportés
|
|
142
125
|
|
|
143
126
|
```ts
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
127
|
+
import type {
|
|
128
|
+
// Enums
|
|
129
|
+
TransactionStatus, // "PENDING" | "CONFIRMED" | "CANCELLED" | "FAILED"
|
|
130
|
+
PlatformType, // "STORE" | "TRANSPORT" | "RESTAURATION" | ...
|
|
131
|
+
PaymentProvider, // "OM_CI" | "MTN_CI" | "MOOV_CI" | "WAVE_CI" | ...
|
|
132
|
+
Currency, // "USD" | "EUR" | "XOF" | "XAF"
|
|
133
|
+
CoreApp, // "XORAIA" | "MONSMSPRO" | "FREE"
|
|
134
|
+
DuTicOTacOfferType, // "STATIC" | "DYNAMIC"
|
|
135
|
+
|
|
136
|
+
// Modèles
|
|
137
|
+
TransactionModel,
|
|
138
|
+
OfferModel,
|
|
139
|
+
OfferAppModel,
|
|
140
|
+
DuticotacSettingModel,
|
|
141
|
+
PaymentLinksCountModel,
|
|
142
|
+
} from "@applite/duticotac";
|
|
148
143
|
```
|
|
149
144
|
|
|
150
|
-
##
|
|
145
|
+
## Gestion des erreurs
|
|
151
146
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
147
|
+
Le SDK lève des `DuticotacError` avec un `code` correspondant aux erreurs de l'API :
|
|
148
|
+
|
|
149
|
+
```ts
|
|
150
|
+
import { DuticotacError } from "@applite/duticotac";
|
|
151
|
+
|
|
152
|
+
try {
|
|
153
|
+
await duticotac.mobileMoney.cashout({ ... });
|
|
154
|
+
} catch (e) {
|
|
155
|
+
if (e instanceof DuticotacError) {
|
|
156
|
+
console.log(e.code); // ex: "otp-required"
|
|
157
|
+
console.log(e.message); // ex: "Code OTP requis pour les paiements Orange Money"
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
## Utilitaires
|
|
163
|
+
|
|
164
|
+
```ts
|
|
165
|
+
import {
|
|
166
|
+
getProviderName, // "OM_CI" → "Orange Money"
|
|
167
|
+
getProviderLogo, // "OM_CI" → URL du logo
|
|
168
|
+
getErrorMessage, // "otp-required" → message en français
|
|
169
|
+
ERROR_MESSAGES, // map code → message
|
|
170
|
+
} from "@applite/duticotac";
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
## Scripts
|
|
155
174
|
|
|
175
|
+
- `pnpm build` – build CJS/ESM avec déclarations de types
|
|
176
|
+
- `pnpm dev` – mode watch pour le développement
|