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.
- checksums.yaml +7 -0
- data/.rspec +4 -0
- data/.rspec_status +11 -0
- data/API_REFERENCE.md +458 -0
- data/CHANGELOG.md +64 -0
- data/DEVELOPMENT.md +380 -0
- data/EXAMPLES.md +491 -0
- data/FILE_STRUCTURE.md +407 -0
- data/Gemfile +13 -0
- data/INSTALLATION.md +460 -0
- data/LICENSE +22 -0
- data/PROJECT_OVERVIEW.md +314 -0
- data/QUICK_START.md +186 -0
- data/README.md +296 -0
- data/Rakefile +9 -0
- data/SUMMARY.md +285 -0
- data/dk_payment_gateway.gemspec +40 -0
- data/examples/README.md +199 -0
- data/examples/generate_qr.rb +110 -0
- data/examples/intra_transfer.rb +114 -0
- data/examples/simple_payment.rb +102 -0
- data/lib/dk_payment_gateway/authentication.rb +102 -0
- data/lib/dk_payment_gateway/client.rb +139 -0
- data/lib/dk_payment_gateway/configuration.rb +32 -0
- data/lib/dk_payment_gateway/errors.rb +39 -0
- data/lib/dk_payment_gateway/intra_transaction.rb +147 -0
- data/lib/dk_payment_gateway/pull_payment.rb +155 -0
- data/lib/dk_payment_gateway/qr_payment.rb +98 -0
- data/lib/dk_payment_gateway/signature.rb +72 -0
- data/lib/dk_payment_gateway/transaction_status.rb +127 -0
- data/lib/dk_payment_gateway/utils.rb +161 -0
- data/lib/dk_payment_gateway/version.rb +5 -0
- data/lib/dk_payment_gateway.rb +28 -0
- metadata +160 -0
data/INSTALLATION.md
ADDED
|
@@ -0,0 +1,460 @@
|
|
|
1
|
+
# Installation Guide
|
|
2
|
+
|
|
3
|
+
Complete installation and setup guide for the DK Payment Gateway Ruby gem.
|
|
4
|
+
|
|
5
|
+
## Table of Contents
|
|
6
|
+
|
|
7
|
+
1. [System Requirements](#system-requirements)
|
|
8
|
+
2. [Installation Methods](#installation-methods)
|
|
9
|
+
3. [Configuration](#configuration)
|
|
10
|
+
4. [Verification](#verification)
|
|
11
|
+
5. [Troubleshooting](#troubleshooting)
|
|
12
|
+
|
|
13
|
+
## System Requirements
|
|
14
|
+
|
|
15
|
+
### Ruby Version
|
|
16
|
+
|
|
17
|
+
- Ruby >= 2.7.0
|
|
18
|
+
- Recommended: Ruby 3.0 or higher
|
|
19
|
+
|
|
20
|
+
Check your Ruby version:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
ruby -v
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### Dependencies
|
|
27
|
+
|
|
28
|
+
The gem will automatically install these dependencies:
|
|
29
|
+
|
|
30
|
+
- faraday (~> 2.0)
|
|
31
|
+
- jwt (~> 2.7)
|
|
32
|
+
|
|
33
|
+
## Installation Methods
|
|
34
|
+
|
|
35
|
+
### Method 1: Using Bundler (Recommended)
|
|
36
|
+
|
|
37
|
+
Add to your `Gemfile`:
|
|
38
|
+
|
|
39
|
+
```ruby
|
|
40
|
+
gem 'dk_payment_gateway'
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Then run:
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
bundle install
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Method 2: Using RubyGems
|
|
50
|
+
|
|
51
|
+
Install directly:
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
gem install dk_payment_gateway
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Method 3: From Source (Development)
|
|
58
|
+
|
|
59
|
+
Clone and install from source:
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
# Clone the repository
|
|
63
|
+
git clone https://github.com/dcplbt/dk_payment_gateway.git
|
|
64
|
+
cd dk_payment_gateway
|
|
65
|
+
|
|
66
|
+
# Install dependencies
|
|
67
|
+
bundle install
|
|
68
|
+
|
|
69
|
+
# Build and install the gem
|
|
70
|
+
gem build dk_payment_gateway.gemspec
|
|
71
|
+
gem install ./dk_payment_gateway-0.1.0.gem
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Configuration
|
|
75
|
+
|
|
76
|
+
### Step 1: Obtain API Credentials
|
|
77
|
+
|
|
78
|
+
Contact Digital Kidu to obtain:
|
|
79
|
+
|
|
80
|
+
- API Key (X-gravitee-api-key)
|
|
81
|
+
- Username
|
|
82
|
+
- Password
|
|
83
|
+
- Client ID
|
|
84
|
+
- Client Secret
|
|
85
|
+
- Source App ID
|
|
86
|
+
|
|
87
|
+
### Step 2: Set Up Environment Variables
|
|
88
|
+
|
|
89
|
+
Create a `.env` file in your project root:
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
# DK Payment Gateway Configuration
|
|
93
|
+
DK_BASE_URL=https://internal-gateway.uat.digitalkidu.bt/api/dkpg
|
|
94
|
+
DK_API_KEY=your_api_key_here
|
|
95
|
+
DK_USERNAME=your_username_here
|
|
96
|
+
DK_PASSWORD=your_password_here
|
|
97
|
+
DK_CLIENT_ID=your_client_id_here
|
|
98
|
+
DK_CLIENT_SECRET=your_client_secret_here
|
|
99
|
+
DK_SOURCE_APP=SRC_AVS_0201
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
**Important:** Add `.env` to your `.gitignore`:
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
echo ".env" >> .gitignore
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### Step 3: Install dotenv (Optional but Recommended)
|
|
109
|
+
|
|
110
|
+
Add to your `Gemfile`:
|
|
111
|
+
|
|
112
|
+
```ruby
|
|
113
|
+
gem 'dotenv'
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
Then:
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
bundle install
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### Step 4: Configure the Gem
|
|
123
|
+
|
|
124
|
+
In your application initialization file (e.g., `config/initializers/dk_payment_gateway.rb` for Rails):
|
|
125
|
+
|
|
126
|
+
```ruby
|
|
127
|
+
require 'dotenv/load' # Load environment variables
|
|
128
|
+
require 'dk_payment_gateway'
|
|
129
|
+
|
|
130
|
+
DkPaymentGateway.configure do |config|
|
|
131
|
+
config.base_url = ENV['DK_BASE_URL']
|
|
132
|
+
config.api_key = ENV['DK_API_KEY']
|
|
133
|
+
config.username = ENV['DK_USERNAME']
|
|
134
|
+
config.password = ENV['DK_PASSWORD']
|
|
135
|
+
config.client_id = ENV['DK_CLIENT_ID']
|
|
136
|
+
config.client_secret = ENV['DK_CLIENT_SECRET']
|
|
137
|
+
config.source_app = ENV['DK_SOURCE_APP']
|
|
138
|
+
|
|
139
|
+
# Optional: Customize timeouts
|
|
140
|
+
config.timeout = 30
|
|
141
|
+
config.open_timeout = 10
|
|
142
|
+
end
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
## Verification
|
|
146
|
+
|
|
147
|
+
### Test Your Installation
|
|
148
|
+
|
|
149
|
+
Create a test script `test_installation.rb`:
|
|
150
|
+
|
|
151
|
+
```ruby
|
|
152
|
+
require 'dk_payment_gateway'
|
|
153
|
+
|
|
154
|
+
# Configure
|
|
155
|
+
DkPaymentGateway.configure do |config|
|
|
156
|
+
config.base_url = ENV['DK_BASE_URL']
|
|
157
|
+
config.api_key = ENV['DK_API_KEY']
|
|
158
|
+
config.username = ENV['DK_USERNAME']
|
|
159
|
+
config.password = ENV['DK_PASSWORD']
|
|
160
|
+
config.client_id = ENV['DK_CLIENT_ID']
|
|
161
|
+
config.client_secret = ENV['DK_CLIENT_SECRET']
|
|
162
|
+
config.source_app = ENV['DK_SOURCE_APP']
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
# Test configuration
|
|
166
|
+
puts "Testing DK Payment Gateway installation..."
|
|
167
|
+
puts
|
|
168
|
+
|
|
169
|
+
# Check configuration
|
|
170
|
+
config = DkPaymentGateway.configuration
|
|
171
|
+
if config.valid?
|
|
172
|
+
puts "✓ Configuration is valid"
|
|
173
|
+
else
|
|
174
|
+
puts "✗ Configuration is invalid"
|
|
175
|
+
puts " Missing fields: #{config.missing_fields.join(', ')}"
|
|
176
|
+
exit 1
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
# Test authentication
|
|
180
|
+
begin
|
|
181
|
+
client = DkPaymentGateway.client
|
|
182
|
+
puts "✓ Client initialized"
|
|
183
|
+
|
|
184
|
+
client.authenticate!
|
|
185
|
+
puts "✓ Authentication successful"
|
|
186
|
+
puts
|
|
187
|
+
puts "Installation verified successfully!"
|
|
188
|
+
|
|
189
|
+
rescue DkPaymentGateway::ConfigurationError => e
|
|
190
|
+
puts "✗ Configuration error: #{e.message}"
|
|
191
|
+
exit 1
|
|
192
|
+
rescue DkPaymentGateway::AuthenticationError => e
|
|
193
|
+
puts "✗ Authentication error: #{e.message}"
|
|
194
|
+
exit 1
|
|
195
|
+
rescue => e
|
|
196
|
+
puts "✗ Unexpected error: #{e.message}"
|
|
197
|
+
exit 1
|
|
198
|
+
end
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
Run the test:
|
|
202
|
+
|
|
203
|
+
```bash
|
|
204
|
+
ruby test_installation.rb
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
Expected output:
|
|
208
|
+
|
|
209
|
+
```
|
|
210
|
+
Testing DK Payment Gateway installation...
|
|
211
|
+
|
|
212
|
+
✓ Configuration is valid
|
|
213
|
+
✓ Client initialized
|
|
214
|
+
✓ Authentication successful
|
|
215
|
+
|
|
216
|
+
Installation verified successfully!
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
## Framework-Specific Setup
|
|
220
|
+
|
|
221
|
+
### Ruby on Rails
|
|
222
|
+
|
|
223
|
+
1. Add to `Gemfile`:
|
|
224
|
+
|
|
225
|
+
```ruby
|
|
226
|
+
gem 'dk_payment_gateway'
|
|
227
|
+
gem 'dotenv-rails'
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
2. Create `config/initializers/dk_payment_gateway.rb`:
|
|
231
|
+
|
|
232
|
+
```ruby
|
|
233
|
+
DkPaymentGateway.configure do |config|
|
|
234
|
+
config.base_url = ENV['DK_BASE_URL']
|
|
235
|
+
config.api_key = ENV['DK_API_KEY']
|
|
236
|
+
config.username = ENV['DK_USERNAME']
|
|
237
|
+
config.password = ENV['DK_PASSWORD']
|
|
238
|
+
config.client_id = ENV['DK_CLIENT_ID']
|
|
239
|
+
config.client_secret = ENV['DK_CLIENT_SECRET']
|
|
240
|
+
config.source_app = ENV['DK_SOURCE_APP']
|
|
241
|
+
end
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
3. Use in controllers:
|
|
245
|
+
|
|
246
|
+
```ruby
|
|
247
|
+
class PaymentsController < ApplicationController
|
|
248
|
+
def create
|
|
249
|
+
client = DkPaymentGateway.client
|
|
250
|
+
client.authenticate!
|
|
251
|
+
|
|
252
|
+
# Your payment logic
|
|
253
|
+
end
|
|
254
|
+
end
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
### Sinatra
|
|
258
|
+
|
|
259
|
+
```ruby
|
|
260
|
+
require 'sinatra'
|
|
261
|
+
require 'dk_payment_gateway'
|
|
262
|
+
require 'dotenv/load'
|
|
263
|
+
|
|
264
|
+
# Configure
|
|
265
|
+
configure do
|
|
266
|
+
DkPaymentGateway.configure do |config|
|
|
267
|
+
config.base_url = ENV['DK_BASE_URL']
|
|
268
|
+
config.api_key = ENV['DK_API_KEY']
|
|
269
|
+
# ... other config
|
|
270
|
+
end
|
|
271
|
+
end
|
|
272
|
+
|
|
273
|
+
# Use in routes
|
|
274
|
+
post '/payment' do
|
|
275
|
+
client = DkPaymentGateway.client
|
|
276
|
+
client.authenticate!
|
|
277
|
+
|
|
278
|
+
# Your payment logic
|
|
279
|
+
end
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
### Plain Ruby Script
|
|
283
|
+
|
|
284
|
+
```ruby
|
|
285
|
+
#!/usr/bin/env ruby
|
|
286
|
+
require 'bundler/setup'
|
|
287
|
+
require 'dk_payment_gateway'
|
|
288
|
+
require 'dotenv/load'
|
|
289
|
+
|
|
290
|
+
DkPaymentGateway.configure do |config|
|
|
291
|
+
config.base_url = ENV['DK_BASE_URL']
|
|
292
|
+
# ... other config
|
|
293
|
+
end
|
|
294
|
+
|
|
295
|
+
client = DkPaymentGateway.client
|
|
296
|
+
client.authenticate!
|
|
297
|
+
|
|
298
|
+
# Your code here
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
## Troubleshooting
|
|
302
|
+
|
|
303
|
+
### Issue: Gem Not Found
|
|
304
|
+
|
|
305
|
+
**Error:**
|
|
306
|
+
|
|
307
|
+
```
|
|
308
|
+
Could not find gem 'dk_payment_gateway'
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
**Solution:**
|
|
312
|
+
|
|
313
|
+
```bash
|
|
314
|
+
# Update gem sources
|
|
315
|
+
gem sources --update
|
|
316
|
+
|
|
317
|
+
# Install the gem
|
|
318
|
+
gem install dk_payment_gateway
|
|
319
|
+
|
|
320
|
+
# Or with bundler
|
|
321
|
+
bundle update
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
### Issue: LoadError
|
|
325
|
+
|
|
326
|
+
**Error:**
|
|
327
|
+
|
|
328
|
+
```
|
|
329
|
+
LoadError: cannot load such file -- dk_payment_gateway
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
**Solution:**
|
|
333
|
+
|
|
334
|
+
```ruby
|
|
335
|
+
# Make sure to require the gem
|
|
336
|
+
require 'dk_payment_gateway'
|
|
337
|
+
|
|
338
|
+
# Or in Gemfile
|
|
339
|
+
gem 'dk_payment_gateway'
|
|
340
|
+
# Then run: bundle install
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
### Issue: Configuration Error
|
|
344
|
+
|
|
345
|
+
**Error:**
|
|
346
|
+
|
|
347
|
+
```
|
|
348
|
+
DkPaymentGateway::ConfigurationError: Missing required configuration fields
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
**Solution:**
|
|
352
|
+
|
|
353
|
+
1. Check your `.env` file exists
|
|
354
|
+
2. Verify all required fields are set
|
|
355
|
+
3. Make sure dotenv is loaded before configuration
|
|
356
|
+
|
|
357
|
+
```ruby
|
|
358
|
+
require 'dotenv/load' # Add this before configuration
|
|
359
|
+
require 'dk_payment_gateway'
|
|
360
|
+
```
|
|
361
|
+
|
|
362
|
+
### Issue: Authentication Failed
|
|
363
|
+
|
|
364
|
+
**Error:**
|
|
365
|
+
|
|
366
|
+
```
|
|
367
|
+
DkPaymentGateway::AuthenticationError: Token request failed
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
**Solution:**
|
|
371
|
+
|
|
372
|
+
1. Verify credentials are correct
|
|
373
|
+
2. Check API endpoint is accessible
|
|
374
|
+
3. Ensure API key is valid
|
|
375
|
+
4. Contact DK support if credentials are correct
|
|
376
|
+
|
|
377
|
+
### Issue: SSL Certificate Error
|
|
378
|
+
|
|
379
|
+
**Error:**
|
|
380
|
+
|
|
381
|
+
```
|
|
382
|
+
SSL_connect returned=1 errno=0 state=error
|
|
383
|
+
```
|
|
384
|
+
|
|
385
|
+
**Solution:**
|
|
386
|
+
|
|
387
|
+
```ruby
|
|
388
|
+
# For development/testing only - NOT for production
|
|
389
|
+
require 'openssl'
|
|
390
|
+
OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
|
|
391
|
+
```
|
|
392
|
+
|
|
393
|
+
Better solution: Update SSL certificates
|
|
394
|
+
|
|
395
|
+
```bash
|
|
396
|
+
# On macOS
|
|
397
|
+
brew install openssl
|
|
398
|
+
|
|
399
|
+
# On Ubuntu/Debian
|
|
400
|
+
sudo apt-get install ca-certificates
|
|
401
|
+
```
|
|
402
|
+
|
|
403
|
+
### Issue: Timeout Errors
|
|
404
|
+
|
|
405
|
+
**Error:**
|
|
406
|
+
|
|
407
|
+
```
|
|
408
|
+
DkPaymentGateway::NetworkError: execution expired
|
|
409
|
+
```
|
|
410
|
+
|
|
411
|
+
**Solution:**
|
|
412
|
+
Increase timeout values:
|
|
413
|
+
|
|
414
|
+
```ruby
|
|
415
|
+
DkPaymentGateway.configure do |config|
|
|
416
|
+
# ... other config
|
|
417
|
+
config.timeout = 60 # Increase from default 30
|
|
418
|
+
config.open_timeout = 30 # Increase from default 10
|
|
419
|
+
end
|
|
420
|
+
```
|
|
421
|
+
|
|
422
|
+
## Environment-Specific Configuration
|
|
423
|
+
|
|
424
|
+
### Development
|
|
425
|
+
|
|
426
|
+
```ruby
|
|
427
|
+
# config/environments/development.rb
|
|
428
|
+
DkPaymentGateway.configure do |config|
|
|
429
|
+
config.base_url = "http://internal-gateway.uat.digitalkidu.bt/api/dkpg"
|
|
430
|
+
# ... UAT credentials
|
|
431
|
+
end
|
|
432
|
+
```
|
|
433
|
+
|
|
434
|
+
### Production
|
|
435
|
+
|
|
436
|
+
```ruby
|
|
437
|
+
# config/environments/production.rb
|
|
438
|
+
DkPaymentGateway.configure do |config|
|
|
439
|
+
config.base_url = ENV['DK_BASE_URL'] # Production URL
|
|
440
|
+
# ... production credentials from environment
|
|
441
|
+
end
|
|
442
|
+
```
|
|
443
|
+
|
|
444
|
+
## Next Steps
|
|
445
|
+
|
|
446
|
+
After successful installation:
|
|
447
|
+
|
|
448
|
+
1. Read the [Quick Start Guide](QUICK_START.md)
|
|
449
|
+
2. Review [Usage Examples](EXAMPLES.md)
|
|
450
|
+
3. Check [API Reference](API_REFERENCE.md)
|
|
451
|
+
4. Run example applications in `examples/` directory
|
|
452
|
+
|
|
453
|
+
## Support
|
|
454
|
+
|
|
455
|
+
For installation issues:
|
|
456
|
+
|
|
457
|
+
- Check this troubleshooting guide
|
|
458
|
+
- Review the [README](README.md)
|
|
459
|
+
- Contact DK support for credential issues
|
|
460
|
+
- Open an issue on GitHub for gem-specific problems
|
data/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 DK Payment Gateway
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|