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/README.md
ADDED
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
# DK Payment Gateway Ruby Gem
|
|
2
|
+
|
|
3
|
+
A Ruby client library for integrating with the Digital Kidu (DK) Payment Gateway API. This gem provides a clean, easy-to-use interface for:
|
|
4
|
+
|
|
5
|
+
- Pull payments (payment gateway authorization and debit)
|
|
6
|
+
- Intra-bank transactions (DK to DK transfers)
|
|
7
|
+
- QR code generation for payments
|
|
8
|
+
- Transaction status verification
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
Add this line to your application's Gemfile:
|
|
13
|
+
|
|
14
|
+
```ruby
|
|
15
|
+
gem 'dk_payment_gateway'
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
And then execute:
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
bundle install
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Or install it yourself as:
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
gem install dk_payment_gateway
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Configuration
|
|
31
|
+
|
|
32
|
+
Configure the gem with your API credentials:
|
|
33
|
+
|
|
34
|
+
```ruby
|
|
35
|
+
DkPaymentGateway.configure do |config|
|
|
36
|
+
config.base_url = "http://internal-gateway.uat.digitalkidu.bt/api/dkpg"
|
|
37
|
+
config.api_key = "98cf3639-df33-4587-9d36-dae9d2bb974c"
|
|
38
|
+
config.username = "your_username"
|
|
39
|
+
config.password = "your_password"
|
|
40
|
+
config.client_id = "0fefeac4-e969-46ce-8d02-92db4ed8e62e"
|
|
41
|
+
config.client_secret = "your_client_secret"
|
|
42
|
+
config.source_app = "SRC_AVS_0201"
|
|
43
|
+
config.timeout = 30
|
|
44
|
+
config.open_timeout = 10
|
|
45
|
+
end
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Usage
|
|
49
|
+
|
|
50
|
+
### Initialize Client and Authenticate
|
|
51
|
+
|
|
52
|
+
```ruby
|
|
53
|
+
# Create a client instance
|
|
54
|
+
client = DkPaymentGateway.client
|
|
55
|
+
|
|
56
|
+
# Authenticate and fetch private key for signing
|
|
57
|
+
client.authenticate!
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### Pull Payment (Payment Gateway)
|
|
61
|
+
|
|
62
|
+
#### 1. Authorization (Account Inquiry and OTP Request)
|
|
63
|
+
|
|
64
|
+
```ruby
|
|
65
|
+
# Generate STAN number
|
|
66
|
+
stan = DkPaymentGateway::PullPayment.generate_stan("0201")
|
|
67
|
+
|
|
68
|
+
# Request authorization
|
|
69
|
+
response = client.pull_payment.authorize(
|
|
70
|
+
transaction_datetime: Time.now.utc.strftime("%Y-%m-%dT%H:%M:%SZ"),
|
|
71
|
+
stan_number: stan,
|
|
72
|
+
transaction_amount: 100.00,
|
|
73
|
+
transaction_fee: 5.00,
|
|
74
|
+
payment_desc: "Payment for Invoice #123",
|
|
75
|
+
account_number: "110158212197",
|
|
76
|
+
account_name: "John Doe",
|
|
77
|
+
email_id: "customer@example.com",
|
|
78
|
+
phone_number: "17811440",
|
|
79
|
+
remitter_account_number: "770182571",
|
|
80
|
+
remitter_account_name: "Jane Smith",
|
|
81
|
+
remitter_bank_id: "1040"
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
# Response contains:
|
|
85
|
+
# {
|
|
86
|
+
# "bfs_txn_id" => "523400081332",
|
|
87
|
+
# "stan_number" => "020111571912",
|
|
88
|
+
# "account_number" => "110158212197",
|
|
89
|
+
# "remitter_account_number" => "770182571"
|
|
90
|
+
# }
|
|
91
|
+
|
|
92
|
+
bfs_txn_id = response["bfs_txn_id"]
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
#### 2. Debit Request (Complete Payment with OTP)
|
|
96
|
+
|
|
97
|
+
```ruby
|
|
98
|
+
response = client.pull_payment.debit(
|
|
99
|
+
request_id: "REQ_#{Time.now.to_i}",
|
|
100
|
+
bfs_txn_id: bfs_txn_id,
|
|
101
|
+
bfs_remitter_otp: "123456",
|
|
102
|
+
bfs_order_no: "ORDER_12345" # optional
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
# Response contains:
|
|
106
|
+
# {
|
|
107
|
+
# "bfs_txn_id" => "523700081429",
|
|
108
|
+
# "code" => "00",
|
|
109
|
+
# "description" => "Approved"
|
|
110
|
+
# }
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### Intra-Bank Transactions (DK to DK)
|
|
114
|
+
|
|
115
|
+
#### 1. Beneficiary Account Inquiry
|
|
116
|
+
|
|
117
|
+
```ruby
|
|
118
|
+
response = client.intra_transaction.account_inquiry(
|
|
119
|
+
request_id: "REQ_#{Time.now.to_i}",
|
|
120
|
+
amount: 300.00,
|
|
121
|
+
currency: "BTN",
|
|
122
|
+
bene_bank_code: "1060",
|
|
123
|
+
bene_account_number: "100100148337",
|
|
124
|
+
source_account_name: "Rinzin Jamtsho",
|
|
125
|
+
source_account_number: "100100365856"
|
|
126
|
+
)
|
|
127
|
+
|
|
128
|
+
# Response contains:
|
|
129
|
+
# {
|
|
130
|
+
# "inquiry_id" => "DKBT--ptr2aseR2Ch85QY-AufVg-776768",
|
|
131
|
+
# "account_name" => "Rinzin Jamtsho"
|
|
132
|
+
# }
|
|
133
|
+
|
|
134
|
+
inquiry_id = response["inquiry_id"]
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
#### 2. Fund Transfer
|
|
138
|
+
|
|
139
|
+
```ruby
|
|
140
|
+
response = client.intra_transaction.fund_transfer(
|
|
141
|
+
request_id: "REQ_#{Time.now.to_i}",
|
|
142
|
+
inquiry_id: inquiry_id,
|
|
143
|
+
transaction_datetime: Time.now.utc.strftime("%Y-%m-%dT%H:%M:%SZ"),
|
|
144
|
+
transaction_amount: 300.00,
|
|
145
|
+
currency: "BTN",
|
|
146
|
+
payment_type: "INTRA",
|
|
147
|
+
source_account_name: "Rinzin Jamtsho",
|
|
148
|
+
source_account_number: "100100365856",
|
|
149
|
+
bene_cust_name: "Dorji Wangchuk",
|
|
150
|
+
bene_account_number: "100100148337",
|
|
151
|
+
bene_bank_code: "1060",
|
|
152
|
+
narration: "Payment for services"
|
|
153
|
+
)
|
|
154
|
+
|
|
155
|
+
# Response contains:
|
|
156
|
+
# {
|
|
157
|
+
# "inquiry_id" => "DKBT-gllIxZ7rSoqkAOzZj4i2HQ-554567",
|
|
158
|
+
# "txn_status_id" => "6f67d4ca-c8f9-49a5-8c2d-96c8b07c74e5"
|
|
159
|
+
# }
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
### QR Code Generation
|
|
163
|
+
|
|
164
|
+
```ruby
|
|
165
|
+
# Generate Static QR (amount = 0, payer enters amount)
|
|
166
|
+
response = client.qr_payment.generate_qr(
|
|
167
|
+
request_id: "REQ_#{Time.now.to_i}",
|
|
168
|
+
currency: "BTN",
|
|
169
|
+
bene_account_number: "100100148337",
|
|
170
|
+
amount: 0,
|
|
171
|
+
mcc_code: "5411",
|
|
172
|
+
remarks: "Payment for invoice #1234"
|
|
173
|
+
)
|
|
174
|
+
|
|
175
|
+
# Generate Dynamic QR (fixed amount)
|
|
176
|
+
response = client.qr_payment.generate_qr(
|
|
177
|
+
request_id: "REQ_#{Time.now.to_i}",
|
|
178
|
+
currency: "BTN",
|
|
179
|
+
bene_account_number: "100100148337",
|
|
180
|
+
amount: 50.05,
|
|
181
|
+
mcc_code: "5411",
|
|
182
|
+
remarks: "Payment for invoice #1234"
|
|
183
|
+
)
|
|
184
|
+
|
|
185
|
+
# Response contains:
|
|
186
|
+
# {
|
|
187
|
+
# "image" => "base64_encoded_image_data"
|
|
188
|
+
# }
|
|
189
|
+
|
|
190
|
+
# Save QR image to file
|
|
191
|
+
client.qr_payment.save_qr_image(response["image"], "qr_code.png")
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
### Transaction Status Verification
|
|
195
|
+
|
|
196
|
+
#### Check Current Day Transaction
|
|
197
|
+
|
|
198
|
+
```ruby
|
|
199
|
+
response = client.transaction_status.check_current_day(
|
|
200
|
+
request_id: "REQ_#{Time.now.to_i}",
|
|
201
|
+
transaction_id: "test_txn_update23567",
|
|
202
|
+
bene_account_number: "100100365856"
|
|
203
|
+
)
|
|
204
|
+
|
|
205
|
+
# Response contains:
|
|
206
|
+
# {
|
|
207
|
+
# "meta_info" => {...},
|
|
208
|
+
# "status" => {
|
|
209
|
+
# "status" => "0",
|
|
210
|
+
# "status_desc" => "Successfully completed",
|
|
211
|
+
# "txn_ts" => "2025-09-18 12:32:21",
|
|
212
|
+
# "amount" => "150.00",
|
|
213
|
+
# "debit_account" => "200133679",
|
|
214
|
+
# "credit_account" => "100100365856"
|
|
215
|
+
# }
|
|
216
|
+
# }
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
#### Check Previous Days Transaction
|
|
220
|
+
|
|
221
|
+
```ruby
|
|
222
|
+
response = client.transaction_status.check_previous_days(
|
|
223
|
+
request_id: "REQ_#{Time.now.to_i}",
|
|
224
|
+
transaction_id: "test_txn_update23567",
|
|
225
|
+
transaction_date: "2025-09-18",
|
|
226
|
+
bene_account_number: "100100365856"
|
|
227
|
+
)
|
|
228
|
+
|
|
229
|
+
# Response contains array of transaction statuses
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
## Error Handling
|
|
233
|
+
|
|
234
|
+
The gem provides specific exception classes for different error scenarios:
|
|
235
|
+
|
|
236
|
+
```ruby
|
|
237
|
+
begin
|
|
238
|
+
client.authenticate!
|
|
239
|
+
rescue DkPaymentGateway::ConfigurationError => e
|
|
240
|
+
puts "Configuration error: #{e.message}"
|
|
241
|
+
rescue DkPaymentGateway::AuthenticationError => e
|
|
242
|
+
puts "Authentication failed: #{e.message}"
|
|
243
|
+
rescue DkPaymentGateway::InvalidParameterError => e
|
|
244
|
+
puts "Invalid parameters: #{e.message}"
|
|
245
|
+
puts "Response code: #{e.response_code}"
|
|
246
|
+
puts "Response detail: #{e.response_detail}"
|
|
247
|
+
rescue DkPaymentGateway::TransactionError => e
|
|
248
|
+
puts "Transaction failed: #{e.message}"
|
|
249
|
+
puts "Response code: #{e.response_code}"
|
|
250
|
+
rescue DkPaymentGateway::NetworkError => e
|
|
251
|
+
puts "Network error: #{e.message}"
|
|
252
|
+
rescue DkPaymentGateway::SignatureError => e
|
|
253
|
+
puts "Signature generation failed: #{e.message}"
|
|
254
|
+
rescue DkPaymentGateway::APIError => e
|
|
255
|
+
puts "API error: #{e.message}"
|
|
256
|
+
end
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
## Bank Codes Reference
|
|
260
|
+
|
|
261
|
+
Common bank codes for use with the API:
|
|
262
|
+
|
|
263
|
+
- `1010` - Bank of Bhutan
|
|
264
|
+
- `1040` - Bhutan National Bank
|
|
265
|
+
- `1060` - Digital Kidu (for intra-bank transactions)
|
|
266
|
+
|
|
267
|
+
## Merchant Category Codes (MCC)
|
|
268
|
+
|
|
269
|
+
Refer to ISO 18245 standard for complete list. Common examples:
|
|
270
|
+
|
|
271
|
+
- `5411` - Grocery Stores, Supermarkets
|
|
272
|
+
- `5812` - Eating Places, Restaurants
|
|
273
|
+
- `5999` - Miscellaneous and Specialty Retail Stores
|
|
274
|
+
|
|
275
|
+
## Development
|
|
276
|
+
|
|
277
|
+
After checking out the repo, run:
|
|
278
|
+
|
|
279
|
+
```bash
|
|
280
|
+
bundle install
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
To run tests:
|
|
284
|
+
|
|
285
|
+
```bash
|
|
286
|
+
bundle exec rspec
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
## Contributing
|
|
290
|
+
|
|
291
|
+
Bug reports and pull requests are welcome on GitHub.
|
|
292
|
+
|
|
293
|
+
## License
|
|
294
|
+
|
|
295
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
|
296
|
+
|
data/Rakefile
ADDED
data/SUMMARY.md
ADDED
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
# DK Payment Gateway Ruby Gem - Summary
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
The **DK Payment Gateway Ruby Gem** is a comprehensive client library for integrating with the Digital Kidu Payment Gateway API. It provides a clean, object-oriented interface for all payment gateway operations.
|
|
6
|
+
|
|
7
|
+
## Key Features
|
|
8
|
+
|
|
9
|
+
### 1. **Authentication & Security**
|
|
10
|
+
- OAuth 2.0 token-based authentication
|
|
11
|
+
- RSA signature generation (RS256 algorithm)
|
|
12
|
+
- Automatic request signing with DK-Signature headers
|
|
13
|
+
- Secure credential management
|
|
14
|
+
|
|
15
|
+
### 2. **Pull Payment Operations**
|
|
16
|
+
- Payment gateway authorization with OTP
|
|
17
|
+
- Debit request processing
|
|
18
|
+
- STAN number generation utility
|
|
19
|
+
- Support for transaction fees
|
|
20
|
+
|
|
21
|
+
### 3. **Intra-Bank Transactions**
|
|
22
|
+
- Beneficiary account inquiry
|
|
23
|
+
- Fund transfer between DK accounts
|
|
24
|
+
- Real-time account validation
|
|
25
|
+
- Transaction status tracking
|
|
26
|
+
|
|
27
|
+
### 4. **QR Code Payments**
|
|
28
|
+
- Static QR generation (customer enters amount)
|
|
29
|
+
- Dynamic QR generation (fixed amount)
|
|
30
|
+
- Base64 image handling
|
|
31
|
+
- MCC code support
|
|
32
|
+
|
|
33
|
+
### 5. **Transaction Status**
|
|
34
|
+
- Current day transaction verification
|
|
35
|
+
- Historical transaction lookup
|
|
36
|
+
- Detailed status information
|
|
37
|
+
|
|
38
|
+
### 6. **Error Handling**
|
|
39
|
+
- Comprehensive exception hierarchy
|
|
40
|
+
- Detailed error messages
|
|
41
|
+
- Response code mapping
|
|
42
|
+
- Network error handling
|
|
43
|
+
|
|
44
|
+
### 7. **Utilities**
|
|
45
|
+
- Request ID generation
|
|
46
|
+
- Timestamp formatting
|
|
47
|
+
- Data validation helpers
|
|
48
|
+
- Bank code mapping
|
|
49
|
+
- MCC code reference
|
|
50
|
+
|
|
51
|
+
## Architecture
|
|
52
|
+
|
|
53
|
+
```
|
|
54
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
55
|
+
│ Client Application │
|
|
56
|
+
└─────────────────────────────────────────────────────────────┘
|
|
57
|
+
│
|
|
58
|
+
▼
|
|
59
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
60
|
+
│ DkPaymentGateway::Client │
|
|
61
|
+
│ ┌──────────────┬──────────────┬──────────────┬──────────┐ │
|
|
62
|
+
│ │ PullPayment │ IntraTransaction│ QrPayment │ Status │ │
|
|
63
|
+
│ └──────────────┴──────────────┴──────────────┴──────────┘ │
|
|
64
|
+
│ ┌──────────────┬──────────────┐ │
|
|
65
|
+
│ │Authentication│ Signature │ │
|
|
66
|
+
│ └──────────────┴──────────────┘ │
|
|
67
|
+
└─────────────────────────────────────────────────────────────┘
|
|
68
|
+
│
|
|
69
|
+
▼
|
|
70
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
71
|
+
│ Faraday HTTP Client │
|
|
72
|
+
└─────────────────────────────────────────────────────────────┘
|
|
73
|
+
│
|
|
74
|
+
▼
|
|
75
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
76
|
+
│ DK Payment Gateway API (REST) │
|
|
77
|
+
└─────────────────────────────────────────────────────────────┘
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Module Structure
|
|
81
|
+
|
|
82
|
+
### Core Modules
|
|
83
|
+
|
|
84
|
+
1. **DkPaymentGateway::Client**
|
|
85
|
+
- Main entry point
|
|
86
|
+
- HTTP request handling
|
|
87
|
+
- Response processing
|
|
88
|
+
|
|
89
|
+
2. **DkPaymentGateway::Configuration**
|
|
90
|
+
- Credential management
|
|
91
|
+
- API endpoint configuration
|
|
92
|
+
- Timeout settings
|
|
93
|
+
|
|
94
|
+
3. **DkPaymentGateway::Authentication**
|
|
95
|
+
- Token fetching
|
|
96
|
+
- Private key retrieval
|
|
97
|
+
- Credential validation
|
|
98
|
+
|
|
99
|
+
4. **DkPaymentGateway::Signature**
|
|
100
|
+
- RS256 signing
|
|
101
|
+
- Header generation
|
|
102
|
+
- Nonce and timestamp management
|
|
103
|
+
|
|
104
|
+
### Feature Modules
|
|
105
|
+
|
|
106
|
+
5. **DkPaymentGateway::PullPayment**
|
|
107
|
+
- Authorization requests
|
|
108
|
+
- Debit processing
|
|
109
|
+
- STAN generation
|
|
110
|
+
|
|
111
|
+
6. **DkPaymentGateway::IntraTransaction**
|
|
112
|
+
- Account inquiry
|
|
113
|
+
- Fund transfers
|
|
114
|
+
- Intra-bank operations
|
|
115
|
+
|
|
116
|
+
7. **DkPaymentGateway::QrPayment**
|
|
117
|
+
- QR code generation
|
|
118
|
+
- Image handling
|
|
119
|
+
- Static/dynamic QR support
|
|
120
|
+
|
|
121
|
+
8. **DkPaymentGateway::TransactionStatus**
|
|
122
|
+
- Status verification
|
|
123
|
+
- Historical lookups
|
|
124
|
+
- Transaction tracking
|
|
125
|
+
|
|
126
|
+
### Support Modules
|
|
127
|
+
|
|
128
|
+
9. **DkPaymentGateway::Errors**
|
|
129
|
+
- Exception hierarchy
|
|
130
|
+
- Error handling
|
|
131
|
+
- Response mapping
|
|
132
|
+
|
|
133
|
+
10. **DkPaymentGateway::Utils**
|
|
134
|
+
- Helper functions
|
|
135
|
+
- Validation utilities
|
|
136
|
+
- Reference data
|
|
137
|
+
|
|
138
|
+
## API Coverage
|
|
139
|
+
|
|
140
|
+
### Implemented Endpoints
|
|
141
|
+
|
|
142
|
+
| Endpoint | Method | Purpose | Status |
|
|
143
|
+
|----------|--------|---------|--------|
|
|
144
|
+
| `/v1/auth/token` | POST | Fetch authorization token | ✅ |
|
|
145
|
+
| `/v1/sign/key` | POST | Fetch RSA private key | ✅ |
|
|
146
|
+
| `/v1/account_auth/pull-payment` | POST | Payment authorization | ✅ |
|
|
147
|
+
| `/v1/debit_request/pull-payment` | POST | Debit request | ✅ |
|
|
148
|
+
| `/v1/beneficiary/account_inquiry` | POST | Account inquiry | ✅ |
|
|
149
|
+
| `/v1/initiate/transaction` | POST | Fund transfer | ✅ |
|
|
150
|
+
| `/v1/generate_qr` | POST | QR generation | ✅ |
|
|
151
|
+
| `/v1/transaction/status` | POST | Current day status | ✅ |
|
|
152
|
+
| `/v1/transactions/status` | POST | Historical status | ✅ |
|
|
153
|
+
|
|
154
|
+
## Dependencies
|
|
155
|
+
|
|
156
|
+
### Runtime Dependencies
|
|
157
|
+
- **faraday** (~> 2.0) - HTTP client library
|
|
158
|
+
- **jwt** (~> 2.7) - JWT encoding for signatures
|
|
159
|
+
|
|
160
|
+
### Development Dependencies
|
|
161
|
+
- **rake** (~> 13.0) - Build automation
|
|
162
|
+
- **rspec** (~> 3.0) - Testing framework
|
|
163
|
+
- **webmock** (~> 3.18) - HTTP request stubbing
|
|
164
|
+
- **vcr** (~> 6.1) - HTTP interaction recording
|
|
165
|
+
- **rubocop** (~> 1.21) - Code style checker
|
|
166
|
+
|
|
167
|
+
## Documentation
|
|
168
|
+
|
|
169
|
+
### User Documentation
|
|
170
|
+
- **README.md** - Main documentation with installation and basic usage
|
|
171
|
+
- **QUICK_START.md** - 5-minute quick start guide
|
|
172
|
+
- **EXAMPLES.md** - Comprehensive usage examples
|
|
173
|
+
- **API_REFERENCE.md** - Complete API reference
|
|
174
|
+
|
|
175
|
+
### Developer Documentation
|
|
176
|
+
- **DEVELOPMENT.md** - Development guide and best practices
|
|
177
|
+
- **CHANGELOG.md** - Version history and changes
|
|
178
|
+
|
|
179
|
+
### Example Code
|
|
180
|
+
- **examples/simple_payment.rb** - Pull payment example
|
|
181
|
+
- **examples/intra_transfer.rb** - Intra-bank transfer example
|
|
182
|
+
- **examples/generate_qr.rb** - QR code generation example
|
|
183
|
+
|
|
184
|
+
## Testing
|
|
185
|
+
|
|
186
|
+
### Test Coverage
|
|
187
|
+
- Configuration tests
|
|
188
|
+
- Client initialization tests
|
|
189
|
+
- Error handling tests
|
|
190
|
+
- Mock API responses
|
|
191
|
+
|
|
192
|
+
### Test Tools
|
|
193
|
+
- RSpec for unit testing
|
|
194
|
+
- WebMock for HTTP stubbing
|
|
195
|
+
- VCR for recording real API interactions
|
|
196
|
+
|
|
197
|
+
## Security Features
|
|
198
|
+
|
|
199
|
+
1. **Credential Protection**
|
|
200
|
+
- Environment variable support
|
|
201
|
+
- No hardcoded credentials
|
|
202
|
+
- Sensitive data masking in logs
|
|
203
|
+
|
|
204
|
+
2. **Request Signing**
|
|
205
|
+
- RSA-based signatures
|
|
206
|
+
- Timestamp validation
|
|
207
|
+
- Nonce for replay protection
|
|
208
|
+
|
|
209
|
+
3. **HTTPS Support**
|
|
210
|
+
- Secure communication
|
|
211
|
+
- Certificate validation
|
|
212
|
+
- Timeout protection
|
|
213
|
+
|
|
214
|
+
## Usage Patterns
|
|
215
|
+
|
|
216
|
+
### Basic Pattern
|
|
217
|
+
```ruby
|
|
218
|
+
# Configure
|
|
219
|
+
DkPaymentGateway.configure { |c| ... }
|
|
220
|
+
|
|
221
|
+
# Initialize
|
|
222
|
+
client = DkPaymentGateway.client
|
|
223
|
+
|
|
224
|
+
# Authenticate
|
|
225
|
+
client.authenticate!
|
|
226
|
+
|
|
227
|
+
# Use features
|
|
228
|
+
client.pull_payment.authorize(...)
|
|
229
|
+
client.intra_transaction.fund_transfer(...)
|
|
230
|
+
client.qr_payment.generate_qr(...)
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
### Error Handling Pattern
|
|
234
|
+
```ruby
|
|
235
|
+
begin
|
|
236
|
+
result = client.pull_payment.authorize(params)
|
|
237
|
+
rescue DkPaymentGateway::TransactionError => e
|
|
238
|
+
# Handle transaction errors
|
|
239
|
+
rescue DkPaymentGateway::Error => e
|
|
240
|
+
# Handle general errors
|
|
241
|
+
end
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
## Best Practices
|
|
245
|
+
|
|
246
|
+
1. **Always authenticate before operations**
|
|
247
|
+
2. **Use environment variables for credentials**
|
|
248
|
+
3. **Implement proper error handling**
|
|
249
|
+
4. **Generate unique request IDs**
|
|
250
|
+
5. **Log operations for audit trail**
|
|
251
|
+
6. **Validate input before API calls**
|
|
252
|
+
7. **Use utilities for common tasks**
|
|
253
|
+
|
|
254
|
+
## Future Enhancements
|
|
255
|
+
|
|
256
|
+
Potential areas for expansion:
|
|
257
|
+
- Webhook support for async notifications
|
|
258
|
+
- Batch payment processing
|
|
259
|
+
- Recurring payment support
|
|
260
|
+
- Enhanced logging and monitoring
|
|
261
|
+
- Rate limiting handling
|
|
262
|
+
- Retry mechanisms
|
|
263
|
+
- Caching for frequently accessed data
|
|
264
|
+
|
|
265
|
+
## Support & Contribution
|
|
266
|
+
|
|
267
|
+
- GitHub repository for issues and PRs
|
|
268
|
+
- Comprehensive documentation
|
|
269
|
+
- Example applications
|
|
270
|
+
- Active maintenance
|
|
271
|
+
|
|
272
|
+
## License
|
|
273
|
+
|
|
274
|
+
MIT License - See LICENSE file for details
|
|
275
|
+
|
|
276
|
+
## Version
|
|
277
|
+
|
|
278
|
+
Current version: **0.1.0**
|
|
279
|
+
|
|
280
|
+
---
|
|
281
|
+
|
|
282
|
+
**Created:** October 31, 2025
|
|
283
|
+
**Last Updated:** October 31, 2025
|
|
284
|
+
**Status:** Production Ready
|
|
285
|
+
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "lib/dk_payment_gateway/version"
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |spec|
|
|
6
|
+
spec.name = "dk_payment_gateway"
|
|
7
|
+
spec.version = DkPaymentGateway::VERSION
|
|
8
|
+
spec.authors = ["Tashi Dendup"]
|
|
9
|
+
spec.email = ["tashii.dendupp@gmail.com"]
|
|
10
|
+
|
|
11
|
+
spec.summary = "Ruby client for DK Payment Gateway API"
|
|
12
|
+
spec.description = "A Ruby gem for integrating with Digital Kidu Payment Gateway API, supporting pull payments, intra-bank transactions, QR generation, and transaction status verification."
|
|
13
|
+
spec.homepage = "https://github.com/dcplbt/dk_payment_gateway"
|
|
14
|
+
spec.license = "MIT"
|
|
15
|
+
spec.required_ruby_version = ">= 2.7.0"
|
|
16
|
+
|
|
17
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
|
18
|
+
spec.metadata["source_code_uri"] = "https://github.com/dcplbt/dk_payment_gateway"
|
|
19
|
+
spec.metadata["changelog_uri"] = "https://github.com/dcplbt/dk_payment_gateway/blob/main/CHANGELOG.md"
|
|
20
|
+
|
|
21
|
+
# Specify which files should be added to the gem when it is released.
|
|
22
|
+
spec.files = Dir.chdir(__dir__) do
|
|
23
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
|
24
|
+
(File.expand_path(f) == __FILE__) || f.start_with?(*%w[bin/ test/ spec/ features/ .git .circleci appveyor])
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
spec.bindir = "exe"
|
|
28
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
|
29
|
+
spec.require_paths = ["lib"]
|
|
30
|
+
|
|
31
|
+
# Runtime dependencies
|
|
32
|
+
spec.add_dependency "faraday", "~> 2.0"
|
|
33
|
+
spec.add_dependency "jwt", "~> 2.7"
|
|
34
|
+
|
|
35
|
+
# Development dependencies
|
|
36
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
|
37
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
|
38
|
+
spec.add_development_dependency "webmock", "~> 3.18"
|
|
39
|
+
spec.add_development_dependency "vcr", "~> 6.1"
|
|
40
|
+
end
|