mumz-strapi-plugin-coupon 1.1.0 → 2.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 +0 -287
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -12,7 +12,6 @@ A centralized coupon management system for Strapi that handles validation, redem
|
|
|
12
12
|
## Features
|
|
13
13
|
|
|
14
14
|
- ✅ Centralized coupon creation and management
|
|
15
|
-
- ✅ Cross-domain coupon support (Homecare, Nannies, Gear Refresh, etc.)
|
|
16
15
|
- ✅ Flexible discount types (percentage, flat)
|
|
17
16
|
- ✅ Usage limits and validity periods
|
|
18
17
|
- ✅ User eligibility validation
|
|
@@ -23,289 +22,3 @@ A centralized coupon management system for Strapi that handles validation, redem
|
|
|
23
22
|
- ✅ Input validation and sanitization
|
|
24
23
|
- ✅ Rate limiting on public endpoints
|
|
25
24
|
- ✅ TypeScript support with full type definitions
|
|
26
|
-
|
|
27
|
-
## Installation
|
|
28
|
-
|
|
29
|
-
### Using npm (via GitHub)
|
|
30
|
-
|
|
31
|
-
```bash
|
|
32
|
-
npm install github:mumzworld-tech/mumz-services-coupons-strapi-plugin
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
### Using yarn (via GitHub)
|
|
36
|
-
|
|
37
|
-
```bash
|
|
38
|
-
yarn add github:mumzworld-tech/mumz-services-coupons-strapi-plugin
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
## Configuration
|
|
42
|
-
|
|
43
|
-
Add the plugin to your Strapi configuration:
|
|
44
|
-
|
|
45
|
-
**`config/plugins.js`** or **`config/plugins.ts`**:
|
|
46
|
-
|
|
47
|
-
```javascript
|
|
48
|
-
module.exports = {
|
|
49
|
-
'coupon': {
|
|
50
|
-
enabled: true,
|
|
51
|
-
resolve: './node_modules/mumz-strapi-plugin-coupon'
|
|
52
|
-
},
|
|
53
|
-
};
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
## API Endpoints
|
|
57
|
-
|
|
58
|
-
### 1. Validate Coupon
|
|
59
|
-
|
|
60
|
-
**POST** `/api/coupon/validate`
|
|
61
|
-
|
|
62
|
-
Validates a coupon for a user before applying it.
|
|
63
|
-
|
|
64
|
-
**Request Body:**
|
|
65
|
-
```json
|
|
66
|
-
{
|
|
67
|
-
"couponCode": "WELCOME10",
|
|
68
|
-
"phoneNumber": "+97155XXXXXX",
|
|
69
|
-
"orderAmount": 250.00
|
|
70
|
-
}
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
**Success Response:**
|
|
74
|
-
```json
|
|
75
|
-
{
|
|
76
|
-
"isValid": true,
|
|
77
|
-
"discountType": "percentage",
|
|
78
|
-
"discountValue": 10,
|
|
79
|
-
"discountAmount": 25,
|
|
80
|
-
"finalAmount": 225.00,
|
|
81
|
-
"message": "Coupon applied successfully."
|
|
82
|
-
}
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
-
**Error Response:**
|
|
86
|
-
```json
|
|
87
|
-
{
|
|
88
|
-
"isValid": false,
|
|
89
|
-
"errorCode": "COUPON_EXPIRED",
|
|
90
|
-
"message": "This coupon has expired."
|
|
91
|
-
}
|
|
92
|
-
```
|
|
93
|
-
|
|
94
|
-
### 2. Redeem Coupon
|
|
95
|
-
|
|
96
|
-
**POST** `/api/coupon/redeem`
|
|
97
|
-
|
|
98
|
-
Marks a coupon as redeemed once successfully applied.
|
|
99
|
-
|
|
100
|
-
**Request Body:**
|
|
101
|
-
```json
|
|
102
|
-
{
|
|
103
|
-
"couponCode": "WELCOME10",
|
|
104
|
-
"phoneNumber": "+97155XXXXXX",
|
|
105
|
-
"orderId": "order_67890",
|
|
106
|
-
"orderAmount": 250.00
|
|
107
|
-
}
|
|
108
|
-
```
|
|
109
|
-
|
|
110
|
-
**Response:**
|
|
111
|
-
```json
|
|
112
|
-
{
|
|
113
|
-
"success": true,
|
|
114
|
-
"message": "Coupon redeemed successfully.",
|
|
115
|
-
"redemptionId": "redeem_1"
|
|
116
|
-
}
|
|
117
|
-
```
|
|
118
|
-
|
|
119
|
-
### 3. Create Coupon (No Auth Required)
|
|
120
|
-
|
|
121
|
-
**POST** `/api/coupon`
|
|
122
|
-
|
|
123
|
-
Create new coupons. Authentication has been disabled for easier integration.
|
|
124
|
-
|
|
125
|
-
**Request Body:**
|
|
126
|
-
```json
|
|
127
|
-
{
|
|
128
|
-
"code": "SUMMER25",
|
|
129
|
-
"discountType": "flat",
|
|
130
|
-
"discountValue": 25,
|
|
131
|
-
"maxUsage": 1000,
|
|
132
|
-
"validFrom": "2025-05-01T00:00:00Z",
|
|
133
|
-
"validTo": "2025-06-30T23:59:59Z"
|
|
134
|
-
}
|
|
135
|
-
```
|
|
136
|
-
|
|
137
|
-
**Response:**
|
|
138
|
-
```json
|
|
139
|
-
{
|
|
140
|
-
"couponId": "coupon_abc123",
|
|
141
|
-
"message": "Coupon created successfully."
|
|
142
|
-
}
|
|
143
|
-
```
|
|
144
|
-
|
|
145
|
-
## Error Codes
|
|
146
|
-
|
|
147
|
-
| Code | Description |
|
|
148
|
-
|------|-------------|
|
|
149
|
-
| `COUPON_NOT_FOUND` | Coupon code does not exist |
|
|
150
|
-
| `COUPON_EXPIRED` | Coupon validity period has expired |
|
|
151
|
-
| `COUPON_ALREADY_USED` | User has already redeemed this coupon |
|
|
152
|
-
| `USAGE_LIMIT_REACHED` | Coupon usage limit has been reached |
|
|
153
|
-
|
|
154
|
-
## Quick Start
|
|
155
|
-
|
|
156
|
-
### 1. Installation
|
|
157
|
-
|
|
158
|
-
See [INSTALLATION.md](./INSTALLATION.md) for detailed installation instructions.
|
|
159
|
-
|
|
160
|
-
```bash
|
|
161
|
-
# Install from GitHub
|
|
162
|
-
npm install github:mumzworld-tech/mumz-services-coupons-strapi-plugin#v1.0.0
|
|
163
|
-
|
|
164
|
-
# Configure in config/plugins.js
|
|
165
|
-
module.exports = {
|
|
166
|
-
'coupon': {
|
|
167
|
-
enabled: true,
|
|
168
|
-
resolve: './node_modules/mumz-strapi-plugin-coupon',
|
|
169
|
-
},
|
|
170
|
-
};
|
|
171
|
-
|
|
172
|
-
# Build and start Strapi
|
|
173
|
-
npm run build
|
|
174
|
-
npm run develop
|
|
175
|
-
```
|
|
176
|
-
|
|
177
|
-
### 2. Verify Installation
|
|
178
|
-
|
|
179
|
-
Check that the plugin loaded successfully:
|
|
180
|
-
- Admin panel shows **Coupon** and **Redemption** content types
|
|
181
|
-
- Routes are registered: `npx strapi routes:list | grep coupon`
|
|
182
|
-
- See console logs: "Coupon plugin registered" and "Coupon plugin bootstrapped"
|
|
183
|
-
|
|
184
|
-
### 3. Test the Plugin
|
|
185
|
-
|
|
186
|
-
See [TESTING.md](./TESTING.md) for comprehensive testing instructions.
|
|
187
|
-
|
|
188
|
-
```bash
|
|
189
|
-
# Create a test coupon via API
|
|
190
|
-
curl -X POST http://localhost:1337/api/coupon \
|
|
191
|
-
-H "Content-Type: application/json" \
|
|
192
|
-
-d '{
|
|
193
|
-
"code": "WELCOME10",
|
|
194
|
-
"discountType": "percentage",
|
|
195
|
-
"discountValue": 10,
|
|
196
|
-
"maxUsage": 1000,
|
|
197
|
-
"validFrom": "2025-01-01T00:00:00Z",
|
|
198
|
-
"validTo": "2025-12-31T23:59:59Z",
|
|
199
|
-
"description": "Welcome discount - 10% off"
|
|
200
|
-
}'
|
|
201
|
-
|
|
202
|
-
# Validate the coupon
|
|
203
|
-
curl -X POST http://localhost:1337/api/coupon/validate \
|
|
204
|
-
-H "Content-Type: application/json" \
|
|
205
|
-
-d '{
|
|
206
|
-
"couponCode": "WELCOME10",
|
|
207
|
-
"phoneNumber": "+971551234567",
|
|
208
|
-
"orderAmount": 250.00
|
|
209
|
-
}'
|
|
210
|
-
```
|
|
211
|
-
|
|
212
|
-
## Development
|
|
213
|
-
|
|
214
|
-
### Prerequisites
|
|
215
|
-
|
|
216
|
-
- Node.js >= 18.x
|
|
217
|
-
- npm >= 6.x
|
|
218
|
-
|
|
219
|
-
### Setup
|
|
220
|
-
|
|
221
|
-
```bash
|
|
222
|
-
# Install dependencies
|
|
223
|
-
npm install
|
|
224
|
-
|
|
225
|
-
# Build the plugin
|
|
226
|
-
npm run build
|
|
227
|
-
|
|
228
|
-
# Watch mode for development
|
|
229
|
-
npm run watch
|
|
230
|
-
```
|
|
231
|
-
|
|
232
|
-
### Building for Production
|
|
233
|
-
|
|
234
|
-
```bash
|
|
235
|
-
npm run clean
|
|
236
|
-
npm run build
|
|
237
|
-
```
|
|
238
|
-
|
|
239
|
-
## Publishing to GitHub
|
|
240
|
-
|
|
241
|
-
See [PUBLISHING.md](./PUBLISHING.md) for detailed instructions on publishing this plugin internally via GitHub.
|
|
242
|
-
|
|
243
|
-
## TypeScript Usage
|
|
244
|
-
|
|
245
|
-
The plugin is written in TypeScript and provides full type definitions:
|
|
246
|
-
|
|
247
|
-
```typescript
|
|
248
|
-
import type {
|
|
249
|
-
ValidateCouponRequest,
|
|
250
|
-
ValidationResponse,
|
|
251
|
-
RedeemCouponRequest,
|
|
252
|
-
RedemptionResponse,
|
|
253
|
-
CreateCouponRequest,
|
|
254
|
-
CreateResponse
|
|
255
|
-
} from 'strapi-plugin-coupon/dist/services/coupon';
|
|
256
|
-
|
|
257
|
-
// Example: Validate a coupon
|
|
258
|
-
const result: ValidationResponse = await strapi
|
|
259
|
-
.plugin('coupon')
|
|
260
|
-
.service('coupon')
|
|
261
|
-
.validate({
|
|
262
|
-
couponCode: 'WELCOME10',
|
|
263
|
-
service: 'homecare',
|
|
264
|
-
phoneNumber: '+971551234567',
|
|
265
|
-
orderAmount: 250.00,
|
|
266
|
-
});
|
|
267
|
-
|
|
268
|
-
if (result.isValid) {
|
|
269
|
-
console.log(`Discount: ${result.discountAmount}`);
|
|
270
|
-
console.log(`Final Amount: ${result.finalAmount}`);
|
|
271
|
-
}
|
|
272
|
-
```
|
|
273
|
-
|
|
274
|
-
## Rate Limiting
|
|
275
|
-
|
|
276
|
-
The plugin implements rate limiting on public endpoints:
|
|
277
|
-
- `/validate`: 10 requests per minute per IP
|
|
278
|
-
- `/redeem`: 5 requests per minute per IP
|
|
279
|
-
|
|
280
|
-
The plugin uses in-memory rate limiting which is suitable for single-instance deployments.
|
|
281
|
-
|
|
282
|
-
## Security Features
|
|
283
|
-
|
|
284
|
-
- ✅ Input validation on all endpoints
|
|
285
|
-
- ✅ Protection against SQL injection
|
|
286
|
-
- ✅ Race condition prevention using optimistic locking
|
|
287
|
-
- ✅ Phone number validation (E.164 format)
|
|
288
|
-
- ✅ Service and coupon code validation
|
|
289
|
-
- ✅ Rate limiting to prevent abuse
|
|
290
|
-
|
|
291
|
-
## Troubleshooting
|
|
292
|
-
|
|
293
|
-
### Build fails with TypeScript errors
|
|
294
|
-
|
|
295
|
-
Ensure dependencies are installed:
|
|
296
|
-
```bash
|
|
297
|
-
npm install
|
|
298
|
-
npm run build
|
|
299
|
-
```
|
|
300
|
-
|
|
301
|
-
### Plugin not loading in Strapi
|
|
302
|
-
|
|
303
|
-
Verify the plugin configuration in `config/plugins.js` and ensure the plugin is properly installed in `node_modules`.
|
|
304
|
-
|
|
305
|
-
### Rate limit errors (429)
|
|
306
|
-
|
|
307
|
-
Default rate limits are 10 req/min for validate, 5 req/min for redeem. These can be adjusted in the route configuration.
|
|
308
|
-
|
|
309
|
-
## License
|
|
310
|
-
|
|
311
|
-
MIT
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mumz-strapi-plugin-coupon",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Strapi plugin for centralized coupon management across multiple services",
|
|
5
5
|
"strapi": {
|
|
6
6
|
"name": "coupon",
|
|
@@ -21,12 +21,12 @@
|
|
|
21
21
|
},
|
|
22
22
|
"repository": {
|
|
23
23
|
"type": "git",
|
|
24
|
-
"url": "git+https://github.com/mumzworld-tech/strapi-plugin
|
|
24
|
+
"url": "git+https://github.com/mumzworld-tech/mumz-services-coupons-strapi-plugin.git"
|
|
25
25
|
},
|
|
26
26
|
"bugs": {
|
|
27
|
-
"url": "https://github.com/mumzworld-tech/strapi-plugin
|
|
27
|
+
"url": "https://github.com/mumzworld-tech/mumz-services-coupons-strapi-plugin/issues"
|
|
28
28
|
},
|
|
29
|
-
"homepage": "https://github.com/mumzworld-tech/strapi-plugin
|
|
29
|
+
"homepage": "https://github.com/mumzworld-tech/mumz-services-coupons-strapi-plugin#readme",
|
|
30
30
|
"publishConfig": {
|
|
31
31
|
"access": "public"
|
|
32
32
|
},
|
|
@@ -68,4 +68,4 @@
|
|
|
68
68
|
"node": ">=18.0.0",
|
|
69
69
|
"npm": ">=6.0.0"
|
|
70
70
|
}
|
|
71
|
-
}
|
|
71
|
+
}
|