dk_payment_gateway 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.
@@ -0,0 +1,314 @@
1
+ # DK Payment Gateway Ruby Gem - Project Overview
2
+
3
+ ## 📋 Project Information
4
+
5
+ **Name:** DK Payment Gateway Ruby Gem
6
+ **Version:** 0.1.0
7
+ **License:** MIT
8
+ **Language:** Ruby (>= 2.7.0)
9
+ **Type:** Client Library / SDK
10
+
11
+ ## 🎯 Purpose
12
+
13
+ This Ruby gem provides a comprehensive, production-ready client library for integrating with the Digital Kidu (DK) Payment Gateway API. It simplifies payment processing, fund transfers, QR code generation, and transaction management for Ruby applications.
14
+
15
+ ## ✨ Key Features
16
+
17
+ ### 🔐 Authentication & Security
18
+ - ✅ OAuth 2.0 token-based authentication
19
+ - ✅ RSA signature generation (RS256)
20
+ - ✅ Automatic request signing
21
+ - ✅ Secure credential management
22
+ - ✅ Nonce-based replay protection
23
+
24
+ ### 💳 Payment Operations
25
+ - ✅ Pull payment authorization with OTP
26
+ - ✅ Debit request processing
27
+ - ✅ Transaction fee support
28
+ - ✅ STAN number generation
29
+
30
+ ### 🏦 Intra-Bank Transfers
31
+ - ✅ Beneficiary account verification
32
+ - ✅ Fund transfer between DK accounts
33
+ - ✅ Real-time validation
34
+ - ✅ Transaction tracking
35
+
36
+ ### 📱 QR Code Payments
37
+ - ✅ Static QR generation (variable amount)
38
+ - ✅ Dynamic QR generation (fixed amount)
39
+ - ✅ Base64 image handling
40
+ - ✅ MCC code support
41
+
42
+ ### 📊 Transaction Management
43
+ - ✅ Current day status verification
44
+ - ✅ Historical transaction lookup
45
+ - ✅ Detailed status information
46
+
47
+ ### 🛠️ Developer Experience
48
+ - ✅ Clean, intuitive API
49
+ - ✅ Comprehensive error handling
50
+ - ✅ Extensive documentation
51
+ - ✅ Example applications
52
+ - ✅ Utility helpers
53
+ - ✅ Test suite
54
+
55
+ ## 📁 Project Structure
56
+
57
+ ```
58
+ dk_payment_gateway/
59
+ ├── lib/ # Source code
60
+ │ ├── dk_payment_gateway/
61
+ │ │ ├── authentication.rb # Token & key management
62
+ │ │ ├── client.rb # Main client class
63
+ │ │ ├── configuration.rb # Configuration management
64
+ │ │ ├── errors.rb # Custom exceptions
65
+ │ │ ├── intra_transaction.rb # Intra-bank operations
66
+ │ │ ├── pull_payment.rb # Pull payment operations
67
+ │ │ ├── qr_payment.rb # QR code generation
68
+ │ │ ├── signature.rb # Request signing
69
+ │ │ ├── transaction_status.rb # Status verification
70
+ │ │ ├── utils.rb # Utility functions
71
+ │ │ └── version.rb # Version info
72
+ │ └── dk_payment_gateway.rb # Main entry point
73
+
74
+ ├── spec/ # Test suite
75
+ │ ├── configuration_spec.rb
76
+ │ ├── dk_payment_gateway_spec.rb
77
+ │ └── spec_helper.rb
78
+
79
+ ├── examples/ # Example applications
80
+ │ ├── simple_payment.rb # Pull payment example
81
+ │ ├── intra_transfer.rb # Transfer example
82
+ │ ├── generate_qr.rb # QR generation example
83
+ │ └── README.md # Examples documentation
84
+
85
+ ├── docs/ # Documentation
86
+ │ ├── README.md # Main documentation
87
+ │ ├── INSTALLATION.md # Installation guide
88
+ │ ├── QUICK_START.md # Quick start guide
89
+ │ ├── EXAMPLES.md # Usage examples
90
+ │ ├── API_REFERENCE.md # API reference
91
+ │ ├── DEVELOPMENT.md # Developer guide
92
+ │ ├── SUMMARY.md # Project summary
93
+ │ └── CHANGELOG.md # Version history
94
+
95
+ ├── Gemfile # Dependencies
96
+ ├── Rakefile # Build tasks
97
+ ├── dk_payment_gateway.gemspec # Gem specification
98
+ ├── LICENSE # MIT License
99
+ └── .gitignore # Git ignore rules
100
+ ```
101
+
102
+ ## 🔧 Technical Stack
103
+
104
+ ### Core Dependencies
105
+ - **Faraday** (~> 2.0) - Modern HTTP client
106
+ - **JWT** (~> 2.7) - JSON Web Token handling
107
+
108
+ ### Development Dependencies
109
+ - **RSpec** (~> 3.0) - Testing framework
110
+ - **WebMock** (~> 3.18) - HTTP request stubbing
111
+ - **VCR** (~> 6.1) - HTTP interaction recording
112
+ - **RuboCop** (~> 1.21) - Code style enforcement
113
+ - **Rake** (~> 13.0) - Build automation
114
+
115
+ ## 📚 Documentation
116
+
117
+ ### User Documentation (7 files)
118
+ 1. **README.md** - Main documentation with installation and usage
119
+ 2. **INSTALLATION.md** - Detailed installation guide
120
+ 3. **QUICK_START.md** - 5-minute quick start
121
+ 4. **EXAMPLES.md** - Comprehensive usage examples
122
+ 5. **API_REFERENCE.md** - Complete API documentation
123
+ 6. **SUMMARY.md** - Project summary
124
+ 7. **CHANGELOG.md** - Version history
125
+
126
+ ### Developer Documentation (1 file)
127
+ 8. **DEVELOPMENT.md** - Development guide and best practices
128
+
129
+ ### Example Code (3 files)
130
+ 9. **examples/simple_payment.rb** - Pull payment flow
131
+ 10. **examples/intra_transfer.rb** - Intra-bank transfer
132
+ 11. **examples/generate_qr.rb** - QR code generation
133
+
134
+ **Total Documentation:** 11 comprehensive files
135
+
136
+ ## 🏗️ Architecture
137
+
138
+ ### Design Pattern
139
+ - **Modular Architecture** - Separate modules for each feature
140
+ - **Dependency Injection** - Client accepts configuration
141
+ - **Factory Pattern** - Client creates feature instances
142
+ - **Strategy Pattern** - Different payment strategies
143
+
144
+ ### Code Organization
145
+ ```
146
+ Client (Main Entry)
147
+ ├── Configuration (Settings)
148
+ ├── Authentication (Token & Keys)
149
+ ├── Signature (Request Signing)
150
+ ├── PullPayment (Payment Gateway)
151
+ ├── IntraTransaction (Transfers)
152
+ ├── QrPayment (QR Codes)
153
+ ├── TransactionStatus (Status Checks)
154
+ └── Utils (Helpers)
155
+ ```
156
+
157
+ ## 🔌 API Coverage
158
+
159
+ ### Implemented Endpoints (9/9)
160
+
161
+ | # | Endpoint | Method | Feature | Status |
162
+ |---|----------|--------|---------|--------|
163
+ | 1 | `/v1/auth/token` | POST | Authentication | ✅ |
164
+ | 2 | `/v1/sign/key` | POST | Key Retrieval | ✅ |
165
+ | 3 | `/v1/account_auth/pull-payment` | POST | Authorization | ✅ |
166
+ | 4 | `/v1/debit_request/pull-payment` | POST | Debit | ✅ |
167
+ | 5 | `/v1/beneficiary/account_inquiry` | POST | Inquiry | ✅ |
168
+ | 6 | `/v1/initiate/transaction` | POST | Transfer | ✅ |
169
+ | 7 | `/v1/generate_qr` | POST | QR Generation | ✅ |
170
+ | 8 | `/v1/transaction/status` | POST | Current Status | ✅ |
171
+ | 9 | `/v1/transactions/status` | POST | Historical Status | ✅ |
172
+
173
+ **Coverage:** 100% of documented API endpoints
174
+
175
+ ## 🧪 Testing
176
+
177
+ ### Test Coverage
178
+ - ✅ Configuration validation tests
179
+ - ✅ Client initialization tests
180
+ - ✅ Error handling tests
181
+ - ✅ Mock API response tests
182
+
183
+ ### Testing Tools
184
+ - RSpec for unit testing
185
+ - WebMock for HTTP mocking
186
+ - VCR for recording real interactions
187
+
188
+ ## 🚀 Quick Start
189
+
190
+ ```ruby
191
+ # 1. Install
192
+ gem install dk_payment_gateway
193
+
194
+ # 2. Configure
195
+ DkPaymentGateway.configure do |config|
196
+ config.api_key = "your_api_key"
197
+ config.username = "your_username"
198
+ config.password = "your_password"
199
+ config.client_id = "your_client_id"
200
+ config.client_secret = "your_client_secret"
201
+ end
202
+
203
+ # 3. Use
204
+ client = DkPaymentGateway.client
205
+ client.authenticate!
206
+
207
+ # Make a payment
208
+ result = client.pull_payment.authorize(...)
209
+ ```
210
+
211
+ ## 📊 Statistics
212
+
213
+ - **Total Files:** 25+
214
+ - **Ruby Files:** 14
215
+ - **Documentation Files:** 11
216
+ - **Example Files:** 3
217
+ - **Test Files:** 3
218
+ - **Lines of Code:** ~2,500+
219
+ - **API Endpoints:** 9 (100% coverage)
220
+ - **Error Classes:** 7
221
+ - **Utility Functions:** 15+
222
+
223
+ ## 🎓 Use Cases
224
+
225
+ ### E-commerce
226
+ - Online payment processing
227
+ - Order payment collection
228
+ - Refund processing
229
+
230
+ ### Financial Services
231
+ - Account-to-account transfers
232
+ - Bulk payment processing
233
+ - Transaction reconciliation
234
+
235
+ ### Retail
236
+ - Point of sale payments
237
+ - QR code payments
238
+ - Invoice payments
239
+
240
+ ### SaaS Applications
241
+ - Subscription payments
242
+ - Usage-based billing
243
+ - Multi-tenant payments
244
+
245
+ ## 🔒 Security Features
246
+
247
+ 1. **Credential Protection**
248
+ - Environment variable support
249
+ - No hardcoded credentials
250
+ - Sensitive data masking
251
+
252
+ 2. **Request Security**
253
+ - RSA signature verification
254
+ - Timestamp validation
255
+ - Nonce for replay protection
256
+
257
+ 3. **Communication Security**
258
+ - HTTPS support
259
+ - Certificate validation
260
+ - Timeout protection
261
+
262
+ ## 📈 Future Enhancements
263
+
264
+ Potential roadmap items:
265
+ - [ ] Webhook support for notifications
266
+ - [ ] Batch payment processing
267
+ - [ ] Recurring payment support
268
+ - [ ] Enhanced logging/monitoring
269
+ - [ ] Rate limiting handling
270
+ - [ ] Automatic retry mechanisms
271
+ - [ ] Response caching
272
+ - [ ] GraphQL support
273
+
274
+ ## 🤝 Contributing
275
+
276
+ Contributions welcome! Please:
277
+ 1. Fork the repository
278
+ 2. Create a feature branch
279
+ 3. Write tests
280
+ 4. Update documentation
281
+ 5. Submit pull request
282
+
283
+ ## 📞 Support
284
+
285
+ - **Documentation:** See docs/ directory
286
+ - **Examples:** See examples/ directory
287
+ - **Issues:** GitHub Issues
288
+ - **API Support:** Contact Digital Kidu
289
+
290
+ ## 📄 License
291
+
292
+ MIT License - See LICENSE file
293
+
294
+ ## 👥 Credits
295
+
296
+ Developed for Digital Kidu Payment Gateway integration.
297
+
298
+ ## 🏆 Quality Metrics
299
+
300
+ - ✅ Production-ready code
301
+ - ✅ Comprehensive documentation
302
+ - ✅ Example applications
303
+ - ✅ Error handling
304
+ - ✅ Test coverage
305
+ - ✅ Code style compliance
306
+ - ✅ Security best practices
307
+ - ✅ Performance optimized
308
+
309
+ ---
310
+
311
+ **Status:** ✅ Production Ready
312
+ **Version:** 0.1.0
313
+ **Last Updated:** October 31, 2025
314
+
data/QUICK_START.md ADDED
@@ -0,0 +1,186 @@
1
+ # Quick Start Guide
2
+
3
+ Get started with DK Payment Gateway in 5 minutes.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ gem install dk_payment_gateway
9
+ ```
10
+
11
+ Or add to your Gemfile:
12
+
13
+ ```ruby
14
+ gem 'dk_payment_gateway'
15
+ ```
16
+
17
+ ## Basic Setup
18
+
19
+ ```ruby
20
+ require 'dk_payment_gateway'
21
+
22
+ # Configure
23
+ DkPaymentGateway.configure do |config|
24
+ config.base_url = "http://internal-gateway.uat.digitalkidu.bt/api/dkpg"
25
+ config.api_key = "your_api_key"
26
+ config.username = "your_username"
27
+ config.password = "your_password"
28
+ config.client_id = "your_client_id"
29
+ config.client_secret = "your_client_secret"
30
+ config.source_app = "SRC_AVS_0201"
31
+ end
32
+
33
+ # Initialize and authenticate
34
+ client = DkPaymentGateway.client
35
+ client.authenticate!
36
+ ```
37
+
38
+ ## Common Use Cases
39
+
40
+ ### 1. Accept Payment (Pull Payment)
41
+
42
+ ```ruby
43
+ # Step 1: Request authorization (sends OTP)
44
+ stan = DkPaymentGateway::PullPayment.generate_stan("0201")
45
+
46
+ auth = client.pull_payment.authorize(
47
+ transaction_datetime: Time.now.utc.strftime("%Y-%m-%dT%H:%M:%SZ"),
48
+ stan_number: stan,
49
+ transaction_amount: 100.00,
50
+ transaction_fee: 5.00,
51
+ payment_desc: "Order #12345",
52
+ account_number: "110158212197",
53
+ account_name: "Your Store",
54
+ phone_number: "17811440",
55
+ remitter_account_number: "770182571",
56
+ remitter_account_name: "Customer Name",
57
+ remitter_bank_id: "1040"
58
+ )
59
+
60
+ # Step 2: Complete with OTP
61
+ result = client.pull_payment.debit(
62
+ request_id: "REQ_#{Time.now.to_i}",
63
+ bfs_txn_id: auth["bfs_txn_id"],
64
+ bfs_remitter_otp: "123456" # OTP from customer
65
+ )
66
+
67
+ puts "Payment #{result['code'] == '00' ? 'successful' : 'failed'}"
68
+ ```
69
+
70
+ ### 2. Transfer Money (Intra-Bank)
71
+
72
+ ```ruby
73
+ # Step 1: Verify account
74
+ inquiry = client.intra_transaction.account_inquiry(
75
+ request_id: "INQ_#{Time.now.to_i}",
76
+ amount: 500.00,
77
+ currency: "BTN",
78
+ bene_bank_code: "1060",
79
+ bene_account_number: "100100148337",
80
+ source_account_number: "100100365856"
81
+ )
82
+
83
+ # Step 2: Transfer funds
84
+ transfer = client.intra_transaction.fund_transfer(
85
+ request_id: "TXN_#{Time.now.to_i}",
86
+ inquiry_id: inquiry["inquiry_id"],
87
+ transaction_datetime: Time.now.utc.strftime("%Y-%m-%dT%H:%M:%SZ"),
88
+ transaction_amount: 500.00,
89
+ currency: "BTN",
90
+ payment_type: "INTRA",
91
+ source_account_number: "100100365856",
92
+ bene_cust_name: inquiry["account_name"],
93
+ bene_account_number: "100100148337",
94
+ bene_bank_code: "1060",
95
+ narration: "Payment for services"
96
+ )
97
+
98
+ puts "Transfer ID: #{transfer['txn_status_id']}"
99
+ ```
100
+
101
+ ### 3. Generate QR Code
102
+
103
+ ```ruby
104
+ # Static QR (customer enters amount)
105
+ qr = client.qr_payment.generate_qr(
106
+ request_id: "QR_#{Time.now.to_i}",
107
+ currency: "BTN",
108
+ bene_account_number: "100100148337",
109
+ amount: 0, # 0 = static
110
+ mcc_code: "5411"
111
+ )
112
+
113
+ # Save QR image
114
+ client.qr_payment.save_qr_image(qr["image"], "payment_qr.png")
115
+ ```
116
+
117
+ ### 4. Check Transaction Status
118
+
119
+ ```ruby
120
+ # Current day
121
+ status = client.transaction_status.check_current_day(
122
+ request_id: "STATUS_#{Time.now.to_i}",
123
+ transaction_id: "txn_12345",
124
+ bene_account_number: "100100365856"
125
+ )
126
+
127
+ puts "Status: #{status['status']['status_desc']}"
128
+ puts "Amount: #{status['status']['amount']}"
129
+ ```
130
+
131
+ ## Error Handling
132
+
133
+ ```ruby
134
+ begin
135
+ client.authenticate!
136
+ # Your payment operations
137
+ rescue DkPaymentGateway::AuthenticationError => e
138
+ puts "Auth failed: #{e.message}"
139
+ rescue DkPaymentGateway::TransactionError => e
140
+ puts "Transaction failed: #{e.message}"
141
+ puts "Code: #{e.response_code}"
142
+ rescue DkPaymentGateway::Error => e
143
+ puts "Error: #{e.message}"
144
+ end
145
+ ```
146
+
147
+ ## Environment Variables (Recommended)
148
+
149
+ Create a `.env` file:
150
+
151
+ ```bash
152
+ DK_BASE_URL=http://internal-gateway.uat.digitalkidu.bt/api/dkpg
153
+ DK_API_KEY=your_api_key
154
+ DK_USERNAME=your_username
155
+ DK_PASSWORD=your_password
156
+ DK_CLIENT_ID=your_client_id
157
+ DK_CLIENT_SECRET=your_client_secret
158
+ DK_SOURCE_APP=SRC_AVS_0201
159
+ ```
160
+
161
+ Then configure:
162
+
163
+ ```ruby
164
+ require 'dotenv/load'
165
+
166
+ DkPaymentGateway.configure do |config|
167
+ config.base_url = ENV['DK_BASE_URL']
168
+ config.api_key = ENV['DK_API_KEY']
169
+ config.username = ENV['DK_USERNAME']
170
+ config.password = ENV['DK_PASSWORD']
171
+ config.client_id = ENV['DK_CLIENT_ID']
172
+ config.client_secret = ENV['DK_CLIENT_SECRET']
173
+ config.source_app = ENV['DK_SOURCE_APP']
174
+ end
175
+ ```
176
+
177
+ ## Next Steps
178
+
179
+ - Read the [README](README.md) for detailed documentation
180
+ - Check [EXAMPLES.md](EXAMPLES.md) for more use cases
181
+ - See [API_REFERENCE.md](API_REFERENCE.md) for complete API documentation
182
+
183
+ ## Support
184
+
185
+ For issues and questions, please refer to the documentation or contact support.
186
+