# mnotify SMS Integration

## Overview
mnotify has been added as an alternative SMS provider alongside BulkSMS Ghana and SMS Online GH. This gives you more flexibility in choosing your SMS service provider.

## Features
- Send SMS notifications to customers
- Support for Ghanaian phone numbers
- Balance checking
- Email fallback when SMS fails
- Detailed logging for debugging

## Configuration

### 1. Get mnotify API Credentials
1. Sign up at [mnotify.com](https://mnotify.com)
2. Navigate to your dashboard
3. Get your API Key
4. Register your Sender ID (if using custom sender)

### 2. Configure in Admin Settings
1. Log in to admin dashboard
2. Go to Settings
3. Under "SMS Configuration":
   - Select **mnotify** as SMS Provider
   - Enter your **API Key**
   - Enter your **Sender ID** (max 11 characters)
   - Enter **Admin Alert Phone** for notifications
   - Enter **Admin Alert Email** for fallback
4. Click "Send Test SMS" to verify configuration
5. Save Settings

### 3. Environment Variables (Optional)
You can also configure via `.env` file:

```env
SMS_PROVIDER=mnotify
BULKSMS_API_KEY=your_mnotify_api_key_here
BULKSMS_SENDER_ID=YourBrand
```

## API Details

### Endpoint
```
POST https://api.mnotify.com/api/sms/quick
```

### Request Format
```php
[
    'key' => 'your_api_key',
    'to' => '+233XXXXXXXXX',
    'msg' => 'Your message here',
    'sender_id' => 'YourBrand'
]
```

### Success Response
```json
{
    "code": "2000",
    "message": "Message sent successfully"
}
```

### Error Response
```json
{
    "code": "4000",
    "message": "Error description",
    "summary": "Additional details"
}
```

## Testing

### Test SMS Function
Use the "Send Test SMS" button in admin settings to verify:
- API credentials are correct
- Sender ID is approved
- Phone number format is valid
- SMS service is working

### Check Logs
If SMS fails, check `storage/logs/laravel.log` for detailed error information:
```bash
tail -f storage/logs/laravel.log | grep mnotify
```

## Common Issues

### 1. Invalid API Key
**Error:** "Authentication failed"
**Solution:** Verify your API key in mnotify dashboard

### 2. Sender ID Not Approved
**Error:** "Invalid sender ID"
**Solution:** 
- Use default sender ID provided by mnotify
- Or request approval for custom sender ID (takes 24-48 hours)

### 3. Insufficient Credits
**Error:** "Insufficient balance"
**Solution:** Top up your mnotify account

### 4. Invalid Phone Format
**Error:** "Invalid recipient"
**Solution:** Ensure phone numbers are in format: +233XXXXXXXXX

## Comparison with Other Providers

| Feature | BulkSMS Ghana | SMS Online GH | mnotify |
|---------|---------------|---------------|---------|
| Setup Speed | Fast | Medium | Fast |
| Sender ID Approval | Not Required | Required | Optional |
| API Simplicity | Simple | Complex | Simple |
| Balance Check | Yes | Yes | Yes |
| Delivery Reports | Basic | Advanced | Basic |
| Cost | Competitive | Competitive | Competitive |

## Email Fallback

If SMS fails, the system automatically:
1. Logs the error
2. Sends email alert to admin
3. Includes original SMS content
4. Provides error details for debugging

## Support

### mnotify Support
- Website: [mnotify.com](https://mnotify.com)
- Email: support@mnotify.com
- Documentation: [mnotify.com/docs](https://mnotify.com/docs)

### System Logs
Check Laravel logs for detailed debugging:
```bash
storage/logs/laravel.log
```

## Migration from Other Providers

To switch from BulkSMS Ghana or SMS Online GH to mnotify:

1. Get mnotify API credentials
2. Go to Admin Settings
3. Change SMS Provider to "mnotify"
4. Update API Key and Sender ID
5. Test with "Send Test SMS"
6. Save settings

No code changes required - the system handles provider switching automatically.

## Best Practices

1. **Test First**: Always use "Send Test SMS" before going live
2. **Monitor Credits**: Check your mnotify balance regularly
3. **Sender ID**: Use approved sender ID to avoid delivery issues
4. **Phone Format**: Ensure all phone numbers include country code
5. **Error Handling**: Monitor logs for failed SMS attempts
6. **Email Fallback**: Configure admin email for critical notifications

## Security

- API keys are stored encrypted in database
- Never commit API keys to version control
- Use environment variables for sensitive data
- Restrict admin access to settings page
- Monitor SMS usage for unusual activity
