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.
data/DEVELOPMENT.md ADDED
@@ -0,0 +1,380 @@
1
+ # Development Guide
2
+
3
+ Guide for developers working on the DK Payment Gateway gem.
4
+
5
+ ## Setup Development Environment
6
+
7
+ ### Prerequisites
8
+
9
+ - Ruby >= 2.7.0
10
+ - Bundler
11
+
12
+ ### Installation
13
+
14
+ ```bash
15
+ # Clone the repository
16
+ git clone https://github.com/yourusername/dk_payment_gateway.git
17
+ cd dk_payment_gateway
18
+
19
+ # Install dependencies
20
+ bundle install
21
+ ```
22
+
23
+ ## Project Structure
24
+
25
+ ```
26
+ dk_payment_gateway/
27
+ ├── lib/
28
+ │ ├── dk_payment_gateway/
29
+ │ │ ├── authentication.rb # Token and key fetching
30
+ │ │ ├── client.rb # Main client class
31
+ │ │ ├── configuration.rb # Configuration management
32
+ │ │ ├── errors.rb # Custom exceptions
33
+ │ │ ├── intra_transaction.rb # Intra-bank operations
34
+ │ │ ├── pull_payment.rb # Pull payment operations
35
+ │ │ ├── qr_payment.rb # QR code generation
36
+ │ │ ├── signature.rb # Request signing
37
+ │ │ ├── transaction_status.rb # Status verification
38
+ │ │ └── version.rb # Gem version
39
+ │ └── dk_payment_gateway.rb # Main entry point
40
+ ├── spec/
41
+ │ ├── configuration_spec.rb # Configuration tests
42
+ │ ├── dk_payment_gateway_spec.rb # Main module tests
43
+ │ └── spec_helper.rb # Test configuration
44
+ ├── API_REFERENCE.md # Complete API documentation
45
+ ├── CHANGELOG.md # Version history
46
+ ├── EXAMPLES.md # Usage examples
47
+ ├── QUICK_START.md # Quick start guide
48
+ ├── README.md # Main documentation
49
+ ├── Gemfile # Dependencies
50
+ ├── Rakefile # Rake tasks
51
+ └── dk_payment_gateway.gemspec # Gem specification
52
+ ```
53
+
54
+ ## Running Tests
55
+
56
+ ### Run all tests
57
+
58
+ ```bash
59
+ bundle exec rspec
60
+ ```
61
+
62
+ ### Run specific test file
63
+
64
+ ```bash
65
+ bundle exec rspec spec/configuration_spec.rb
66
+ ```
67
+
68
+ ### Run with coverage
69
+
70
+ ```bash
71
+ COVERAGE=true bundle exec rspec
72
+ ```
73
+
74
+ ## Code Style
75
+
76
+ This project uses RuboCop for code style enforcement.
77
+
78
+ ```bash
79
+ # Check code style
80
+ bundle exec rubocop
81
+
82
+ # Auto-fix issues
83
+ bundle exec rubocop -a
84
+ ```
85
+
86
+ ## Testing Against Live API
87
+
88
+ ### Setup Test Credentials
89
+
90
+ Create a `.env.test` file:
91
+
92
+ ```bash
93
+ DK_BASE_URL=http://internal-gateway.uat.digitalkidu.bt/api/dkpg
94
+ DK_API_KEY=your_test_api_key
95
+ DK_USERNAME=your_test_username
96
+ DK_PASSWORD=your_test_password
97
+ DK_CLIENT_ID=your_test_client_id
98
+ DK_CLIENT_SECRET=your_test_client_secret
99
+ DK_SOURCE_APP=SRC_AVS_0201
100
+ ```
101
+
102
+ ### Manual Testing Script
103
+
104
+ Create `test_script.rb`:
105
+
106
+ ```ruby
107
+ require 'bundler/setup'
108
+ require 'dk_payment_gateway'
109
+ require 'dotenv/load'
110
+
111
+ # Configure
112
+ DkPaymentGateway.configure do |config|
113
+ config.base_url = ENV['DK_BASE_URL']
114
+ config.api_key = ENV['DK_API_KEY']
115
+ config.username = ENV['DK_USERNAME']
116
+ config.password = ENV['DK_PASSWORD']
117
+ config.client_id = ENV['DK_CLIENT_ID']
118
+ config.client_secret = ENV['DK_CLIENT_SECRET']
119
+ config.source_app = ENV['DK_SOURCE_APP']
120
+ end
121
+
122
+ # Test authentication
123
+ client = DkPaymentGateway.client
124
+ puts "Authenticating..."
125
+ client.authenticate!
126
+ puts "✓ Authentication successful"
127
+
128
+ # Test other operations...
129
+ ```
130
+
131
+ Run with:
132
+
133
+ ```bash
134
+ ruby test_script.rb
135
+ ```
136
+
137
+ ## Adding New Features
138
+
139
+ ### 1. Create Feature Branch
140
+
141
+ ```bash
142
+ git checkout -b feature/new-feature-name
143
+ ```
144
+
145
+ ### 2. Implement Feature
146
+
147
+ Add your implementation in the appropriate file under `lib/dk_payment_gateway/`.
148
+
149
+ ### 3. Add Tests
150
+
151
+ Create or update test files in `spec/`.
152
+
153
+ ```ruby
154
+ # spec/new_feature_spec.rb
155
+ RSpec.describe DkPaymentGateway::NewFeature do
156
+ describe "#method_name" do
157
+ it "does something" do
158
+ # Test implementation
159
+ end
160
+ end
161
+ end
162
+ ```
163
+
164
+ ### 4. Update Documentation
165
+
166
+ - Update README.md with usage examples
167
+ - Add to API_REFERENCE.md
168
+ - Update CHANGELOG.md
169
+
170
+ ### 5. Run Tests
171
+
172
+ ```bash
173
+ bundle exec rspec
174
+ bundle exec rubocop
175
+ ```
176
+
177
+ ### 6. Commit and Push
178
+
179
+ ```bash
180
+ git add .
181
+ git commit -m "Add new feature: description"
182
+ git push origin feature/new-feature-name
183
+ ```
184
+
185
+ ## Debugging
186
+
187
+ ### Enable Debug Logging
188
+
189
+ ```ruby
190
+ # Add to client.rb connection method
191
+ conn.response :logger, Logger.new(STDOUT), bodies: true
192
+ ```
193
+
194
+ ### Inspect Requests
195
+
196
+ ```ruby
197
+ # Use Faraday middleware
198
+ conn.use Faraday::Response::Logger
199
+ ```
200
+
201
+ ### Debug Signature Generation
202
+
203
+ ```ruby
204
+ # In signature.rb, add debugging
205
+ def sign_request(request_body, timestamp, nonce)
206
+ puts "Request Body: #{request_body.inspect}"
207
+ puts "Timestamp: #{timestamp}"
208
+ puts "Nonce: #{nonce}"
209
+
210
+ # ... rest of method
211
+ end
212
+ ```
213
+
214
+ ## Common Development Tasks
215
+
216
+ ### Update Version
217
+
218
+ Edit `lib/dk_payment_gateway/version.rb`:
219
+
220
+ ```ruby
221
+ module DkPaymentGateway
222
+ VERSION = "0.2.0"
223
+ end
224
+ ```
225
+
226
+ Update CHANGELOG.md with changes.
227
+
228
+ ### Build Gem
229
+
230
+ ```bash
231
+ gem build dk_payment_gateway.gemspec
232
+ ```
233
+
234
+ ### Install Locally
235
+
236
+ ```bash
237
+ gem install ./dk_payment_gateway-0.1.0.gem
238
+ ```
239
+
240
+ ### Publish to RubyGems
241
+
242
+ ```bash
243
+ # First time setup
244
+ gem signin
245
+
246
+ # Publish
247
+ gem push dk_payment_gateway-0.1.0.gem
248
+ ```
249
+
250
+ ## Troubleshooting
251
+
252
+ ### Issue: Authentication Fails
253
+
254
+ **Check:**
255
+ - Credentials are correct
256
+ - API key is valid
257
+ - Network connectivity to API endpoint
258
+
259
+ **Debug:**
260
+ ```ruby
261
+ begin
262
+ client.authenticate!
263
+ rescue DkPaymentGateway::AuthenticationError => e
264
+ puts "Error: #{e.message}"
265
+ puts "Check credentials and API endpoint"
266
+ end
267
+ ```
268
+
269
+ ### Issue: Signature Validation Fails
270
+
271
+ **Check:**
272
+ - Private key is correctly fetched
273
+ - Request body is properly serialized
274
+ - Timestamp is in correct format
275
+
276
+ **Debug:**
277
+ ```ruby
278
+ # Enable signature debugging
279
+ signature = DkPaymentGateway::Signature.new(private_key)
280
+ headers = signature.generate_headers(request_body)
281
+ puts "Signature Headers: #{headers.inspect}"
282
+ ```
283
+
284
+ ### Issue: Network Timeouts
285
+
286
+ **Solution:**
287
+ Increase timeout values:
288
+
289
+ ```ruby
290
+ DkPaymentGateway.configure do |config|
291
+ # ... other config
292
+ config.timeout = 60
293
+ config.open_timeout = 30
294
+ end
295
+ ```
296
+
297
+ ## Best Practices
298
+
299
+ ### 1. Error Handling
300
+
301
+ Always wrap API calls in error handling:
302
+
303
+ ```ruby
304
+ begin
305
+ result = client.pull_payment.authorize(params)
306
+ rescue DkPaymentGateway::Error => e
307
+ # Handle error appropriately
308
+ logger.error("Payment failed: #{e.message}")
309
+ # Notify user, retry, or rollback
310
+ end
311
+ ```
312
+
313
+ ### 2. Request IDs
314
+
315
+ Generate unique request IDs:
316
+
317
+ ```ruby
318
+ request_id = "#{operation}_#{Time.now.to_i}_#{SecureRandom.hex(4)}"
319
+ ```
320
+
321
+ ### 3. Logging
322
+
323
+ Log important operations:
324
+
325
+ ```ruby
326
+ logger.info("Initiating payment: #{transaction_id}")
327
+ result = client.pull_payment.authorize(params)
328
+ logger.info("Payment authorized: #{result['bfs_txn_id']}")
329
+ ```
330
+
331
+ ### 4. Testing
332
+
333
+ Mock external API calls in tests:
334
+
335
+ ```ruby
336
+ RSpec.describe "Payment" do
337
+ before do
338
+ stub_request(:post, /.*\/v1\/account_auth\/pull-payment/)
339
+ .to_return(status: 200, body: mock_response.to_json)
340
+ end
341
+
342
+ it "processes payment" do
343
+ # Test implementation
344
+ end
345
+ end
346
+ ```
347
+
348
+ ### 5. Configuration
349
+
350
+ Use environment variables for sensitive data:
351
+
352
+ ```ruby
353
+ # Never commit credentials
354
+ # Use .env files (add to .gitignore)
355
+ # Use environment-specific configs
356
+ ```
357
+
358
+ ## Contributing
359
+
360
+ 1. Fork the repository
361
+ 2. Create your feature branch
362
+ 3. Write tests for your changes
363
+ 4. Ensure all tests pass
364
+ 5. Update documentation
365
+ 6. Submit a pull request
366
+
367
+ ## Resources
368
+
369
+ - [Faraday Documentation](https://lostisland.github.io/faraday/)
370
+ - [JWT Ruby Gem](https://github.com/jwt/ruby-jwt)
371
+ - [RSpec Documentation](https://rspec.info/)
372
+ - [RuboCop Documentation](https://docs.rubocop.org/)
373
+
374
+ ## Support
375
+
376
+ For development questions or issues:
377
+ - Check existing issues on GitHub
378
+ - Review documentation
379
+ - Contact the development team
380
+