rma-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/CHANGELOG.md +60 -0
- data/CODE_OF_CONDUCT.md +132 -0
- data/README.md +446 -0
- data/Rakefile +12 -0
- data/docs/API.md +339 -0
- data/docs/EXAMPLES.md +650 -0
- data/docs/FLOW_DIAGRAM.md +440 -0
- data/docs/QUICK_REFERENCE.md +323 -0
- data/docs/README.md +259 -0
- data/docs/SECURITY.md +506 -0
- data/docs/USAGE_GUIDE.md +522 -0
- data/lib/rma/payment/gateway/account_inquiry.rb +69 -0
- data/lib/rma/payment/gateway/authorization.rb +81 -0
- data/lib/rma/payment/gateway/client.rb +124 -0
- data/lib/rma/payment/gateway/configuration.rb +42 -0
- data/lib/rma/payment/gateway/debit_request.rb +65 -0
- data/lib/rma/payment/gateway/errors.rb +42 -0
- data/lib/rma/payment/gateway/utils.rb +130 -0
- data/lib/rma/payment/gateway/version.rb +9 -0
- data/lib/rma/payment/gateway.rb +24 -0
- data/sig/rma/payment/gateway.rbs +8 -0
- metadata +65 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: db28ad0604ff2c4059955f10b342d1b3b0646f6c7a356659c1fa92e6a223bfb5
|
|
4
|
+
data.tar.gz: 055de1e3a1b750b7087db7dff5c3a93352b0f376beec3406300456ef290d565b
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 8c76f60d57151def8dea62e8e306b9249fd3ae6b9d6d2d786423ee94c7a0980ec146786d8c214e54eee8c7f622c21185e7665703d77420b7ed641afcd5ca86b4
|
|
7
|
+
data.tar.gz: 185416f5968e942cc855151733cf7493f31bfc07af6bf8df0db1009e9416f7b7e8adf6456d037fa547ccedd424c5e698c0afc40de23bf5696e435e14b88a1b19
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [Unreleased]
|
|
9
|
+
|
|
10
|
+
## [1.0.0] - 2025-11-03
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- Initial release of RMA Payment Gateway Ruby gem
|
|
15
|
+
- Payment Authorization functionality (AR message type)
|
|
16
|
+
- Account Inquiry functionality (AE message type)
|
|
17
|
+
- Debit Request functionality (DR message type)
|
|
18
|
+
- Comprehensive error handling with custom exception classes
|
|
19
|
+
- `ConfigurationError` for configuration issues
|
|
20
|
+
- `AuthenticationError` for authentication failures
|
|
21
|
+
- `InvalidParameterError` for validation errors
|
|
22
|
+
- `NetworkError` for network-related issues
|
|
23
|
+
- `APIError` for API-level errors
|
|
24
|
+
- `SignatureError` for signature validation
|
|
25
|
+
- `TransactionError` for transaction-specific errors
|
|
26
|
+
- Utility methods for validation and formatting
|
|
27
|
+
- Email validation
|
|
28
|
+
- Amount validation and formatting
|
|
29
|
+
- Bank code validation
|
|
30
|
+
- Account number validation
|
|
31
|
+
- Phone number validation (Bhutan format)
|
|
32
|
+
- Timestamp generation
|
|
33
|
+
- Sensitive data masking
|
|
34
|
+
- Configuration management via environment variables
|
|
35
|
+
- Support for all major banks in Bhutan (BOBL, BNBL, DPNBL, TBank, BDBL, DK Bank)
|
|
36
|
+
- Comprehensive documentation
|
|
37
|
+
- README with installation and usage instructions
|
|
38
|
+
- API documentation
|
|
39
|
+
- Usage guide with Rails and Sinatra examples
|
|
40
|
+
- Security guide
|
|
41
|
+
- Code examples
|
|
42
|
+
- RSpec test suite
|
|
43
|
+
- RuboCop linting configuration
|
|
44
|
+
- GitHub Actions CI/CD pipeline
|
|
45
|
+
|
|
46
|
+
### Security
|
|
47
|
+
|
|
48
|
+
- RSA key-based authentication
|
|
49
|
+
- HTTPS-only communication
|
|
50
|
+
- Input validation for all parameters
|
|
51
|
+
- Sensitive data masking in logs
|
|
52
|
+
|
|
53
|
+
### Documentation
|
|
54
|
+
|
|
55
|
+
- Complete README with examples
|
|
56
|
+
- API reference documentation
|
|
57
|
+
- Security best practices guide
|
|
58
|
+
- Usage guide for Rails and Sinatra
|
|
59
|
+
- Comprehensive code examples
|
|
60
|
+
- Inline code documentation
|
data/CODE_OF_CONDUCT.md
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
|
2
|
+
|
|
3
|
+
## Our Pledge
|
|
4
|
+
|
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our
|
|
6
|
+
community a harassment-free experience for everyone, regardless of age, body
|
|
7
|
+
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
|
8
|
+
identity and expression, level of experience, education, socio-economic status,
|
|
9
|
+
nationality, personal appearance, race, caste, color, religion, or sexual
|
|
10
|
+
identity and orientation.
|
|
11
|
+
|
|
12
|
+
We pledge to act and interact in ways that contribute to an open, welcoming,
|
|
13
|
+
diverse, inclusive, and healthy community.
|
|
14
|
+
|
|
15
|
+
## Our Standards
|
|
16
|
+
|
|
17
|
+
Examples of behavior that contributes to a positive environment for our
|
|
18
|
+
community include:
|
|
19
|
+
|
|
20
|
+
* Demonstrating empathy and kindness toward other people
|
|
21
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
|
22
|
+
* Giving and gracefully accepting constructive feedback
|
|
23
|
+
* Accepting responsibility and apologizing to those affected by our mistakes,
|
|
24
|
+
and learning from the experience
|
|
25
|
+
* Focusing on what is best not just for us as individuals, but for the overall
|
|
26
|
+
community
|
|
27
|
+
|
|
28
|
+
Examples of unacceptable behavior include:
|
|
29
|
+
|
|
30
|
+
* The use of sexualized language or imagery, and sexual attention or advances of
|
|
31
|
+
any kind
|
|
32
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
|
33
|
+
* Public or private harassment
|
|
34
|
+
* Publishing others' private information, such as a physical or email address,
|
|
35
|
+
without their explicit permission
|
|
36
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
|
37
|
+
professional setting
|
|
38
|
+
|
|
39
|
+
## Enforcement Responsibilities
|
|
40
|
+
|
|
41
|
+
Community leaders are responsible for clarifying and enforcing our standards of
|
|
42
|
+
acceptable behavior and will take appropriate and fair corrective action in
|
|
43
|
+
response to any behavior that they deem inappropriate, threatening, offensive,
|
|
44
|
+
or harmful.
|
|
45
|
+
|
|
46
|
+
Community leaders have the right and responsibility to remove, edit, or reject
|
|
47
|
+
comments, commits, code, wiki edits, issues, and other contributions that are
|
|
48
|
+
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
|
49
|
+
decisions when appropriate.
|
|
50
|
+
|
|
51
|
+
## Scope
|
|
52
|
+
|
|
53
|
+
This Code of Conduct applies within all community spaces, and also applies when
|
|
54
|
+
an individual is officially representing the community in public spaces.
|
|
55
|
+
Examples of representing our community include using an official email address,
|
|
56
|
+
posting via an official social media account, or acting as an appointed
|
|
57
|
+
representative at an online or offline event.
|
|
58
|
+
|
|
59
|
+
## Enforcement
|
|
60
|
+
|
|
61
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
62
|
+
reported to the community leaders responsible for enforcement at
|
|
63
|
+
[INSERT CONTACT METHOD].
|
|
64
|
+
All complaints will be reviewed and investigated promptly and fairly.
|
|
65
|
+
|
|
66
|
+
All community leaders are obligated to respect the privacy and security of the
|
|
67
|
+
reporter of any incident.
|
|
68
|
+
|
|
69
|
+
## Enforcement Guidelines
|
|
70
|
+
|
|
71
|
+
Community leaders will follow these Community Impact Guidelines in determining
|
|
72
|
+
the consequences for any action they deem in violation of this Code of Conduct:
|
|
73
|
+
|
|
74
|
+
### 1. Correction
|
|
75
|
+
|
|
76
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed
|
|
77
|
+
unprofessional or unwelcome in the community.
|
|
78
|
+
|
|
79
|
+
**Consequence**: A private, written warning from community leaders, providing
|
|
80
|
+
clarity around the nature of the violation and an explanation of why the
|
|
81
|
+
behavior was inappropriate. A public apology may be requested.
|
|
82
|
+
|
|
83
|
+
### 2. Warning
|
|
84
|
+
|
|
85
|
+
**Community Impact**: A violation through a single incident or series of
|
|
86
|
+
actions.
|
|
87
|
+
|
|
88
|
+
**Consequence**: A warning with consequences for continued behavior. No
|
|
89
|
+
interaction with the people involved, including unsolicited interaction with
|
|
90
|
+
those enforcing the Code of Conduct, for a specified period of time. This
|
|
91
|
+
includes avoiding interactions in community spaces as well as external channels
|
|
92
|
+
like social media. Violating these terms may lead to a temporary or permanent
|
|
93
|
+
ban.
|
|
94
|
+
|
|
95
|
+
### 3. Temporary Ban
|
|
96
|
+
|
|
97
|
+
**Community Impact**: A serious violation of community standards, including
|
|
98
|
+
sustained inappropriate behavior.
|
|
99
|
+
|
|
100
|
+
**Consequence**: A temporary ban from any sort of interaction or public
|
|
101
|
+
communication with the community for a specified period of time. No public or
|
|
102
|
+
private interaction with the people involved, including unsolicited interaction
|
|
103
|
+
with those enforcing the Code of Conduct, is allowed during this period.
|
|
104
|
+
Violating these terms may lead to a permanent ban.
|
|
105
|
+
|
|
106
|
+
### 4. Permanent Ban
|
|
107
|
+
|
|
108
|
+
**Community Impact**: Demonstrating a pattern of violation of community
|
|
109
|
+
standards, including sustained inappropriate behavior, harassment of an
|
|
110
|
+
individual, or aggression toward or disparagement of classes of individuals.
|
|
111
|
+
|
|
112
|
+
**Consequence**: A permanent ban from any sort of public interaction within the
|
|
113
|
+
community.
|
|
114
|
+
|
|
115
|
+
## Attribution
|
|
116
|
+
|
|
117
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
|
118
|
+
version 2.1, available at
|
|
119
|
+
[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
|
|
120
|
+
|
|
121
|
+
Community Impact Guidelines were inspired by
|
|
122
|
+
[Mozilla's code of conduct enforcement ladder][Mozilla CoC].
|
|
123
|
+
|
|
124
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
|
125
|
+
[https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
|
|
126
|
+
[https://www.contributor-covenant.org/translations][translations].
|
|
127
|
+
|
|
128
|
+
[homepage]: https://www.contributor-covenant.org
|
|
129
|
+
[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
|
|
130
|
+
[Mozilla CoC]: https://github.com/mozilla/diversity
|
|
131
|
+
[FAQ]: https://www.contributor-covenant.org/faq
|
|
132
|
+
[translations]: https://www.contributor-covenant.org/translations
|
data/README.md
ADDED
|
@@ -0,0 +1,446 @@
|
|
|
1
|
+
# RMA Payment Gateway Ruby Gem
|
|
2
|
+
|
|
3
|
+
[](https://badge.fury.io/rb/rma-payment-gateway)
|
|
4
|
+
[](https://www.ruby-lang.org/en/)
|
|
5
|
+
|
|
6
|
+
A Ruby gem for integrating with the RMA (Royal Monetary Authority of Bhutan) Payment Gateway API. This gem provides a simple and intuitive interface for processing payments through the RMA Payment Gateway system.
|
|
7
|
+
|
|
8
|
+
## Features
|
|
9
|
+
|
|
10
|
+
- 🔐 **Payment Authorization** - Initiate payment requests with order details
|
|
11
|
+
- 🏦 **Account Inquiry** - Verify customer bank account information
|
|
12
|
+
- 💳 **Debit Request** - Complete payment transactions with OTP confirmation
|
|
13
|
+
- ✅ **Input Validation** - Built-in validation for amounts, emails, and account numbers
|
|
14
|
+
- 🛡️ **Error Handling** - Comprehensive error handling with custom exceptions
|
|
15
|
+
- 🔧 **Configurable** - Easy configuration via environment variables or code
|
|
16
|
+
- 📝 **Well Documented** - Extensive documentation and examples
|
|
17
|
+
|
|
18
|
+
## Table of Contents
|
|
19
|
+
|
|
20
|
+
- [Installation](#installation)
|
|
21
|
+
- [Configuration](#configuration)
|
|
22
|
+
- [Usage](#usage)
|
|
23
|
+
- [Payment Flow](#payment-flow)
|
|
24
|
+
- [Step 1: Payment Authorization](#step-1-payment-authorization)
|
|
25
|
+
- [Step 2: Account Inquiry](#step-2-account-inquiry)
|
|
26
|
+
- [Step 3: Debit Request](#step-3-debit-request)
|
|
27
|
+
- [Error Handling](#error-handling)
|
|
28
|
+
- [Utilities](#utilities)
|
|
29
|
+
- [Development](#development)
|
|
30
|
+
- [Testing](#testing)
|
|
31
|
+
- [Contributing](#contributing)
|
|
32
|
+
- [License](#license)
|
|
33
|
+
|
|
34
|
+
## Installation
|
|
35
|
+
|
|
36
|
+
Add this line to your application's Gemfile:
|
|
37
|
+
|
|
38
|
+
```ruby
|
|
39
|
+
gem 'rma-payment-gateway'
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
And then execute:
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
bundle install
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Or install it yourself as:
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
gem install rma-payment-gateway
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Configuration
|
|
55
|
+
|
|
56
|
+
### Environment Variables
|
|
57
|
+
|
|
58
|
+
Create a `.env` file in your project root with the following variables:
|
|
59
|
+
|
|
60
|
+
```env
|
|
61
|
+
RMA_BASE_URL=https://your-rma-gateway-url.com
|
|
62
|
+
RMA_RSA_KEY_PATH=/path/to/your/rsa_private_key.pem
|
|
63
|
+
RMA_BENEFICIARY_ID=your_beneficiary_id
|
|
64
|
+
RMA_PAYMENT_DESCRIPTION=Payment for services
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Configuration Block
|
|
68
|
+
|
|
69
|
+
Alternatively, configure the gem in your application:
|
|
70
|
+
|
|
71
|
+
```ruby
|
|
72
|
+
require 'rma/payment/gateway'
|
|
73
|
+
|
|
74
|
+
Rma::Payment::Gateway.configure do |config|
|
|
75
|
+
config.base_url = 'https://your-rma-gateway-url.com'
|
|
76
|
+
config.rsa_key_path = '/path/to/your/rsa_private_key.pem'
|
|
77
|
+
config.beneficiary_id = 'your_beneficiary_id'
|
|
78
|
+
config.payment_description = 'Payment for services'
|
|
79
|
+
config.timeout = 30 # Optional: default is 30 seconds
|
|
80
|
+
config.open_timeout = 10 # Optional: default is 10 seconds
|
|
81
|
+
end
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### Configuration Options
|
|
85
|
+
|
|
86
|
+
| Option | Required | Description | Default |
|
|
87
|
+
| --------------------- | -------- | -------------------------------- | ------- |
|
|
88
|
+
| `base_url` | Yes | RMA Payment Gateway API base URL | - |
|
|
89
|
+
| `rsa_key_path` | Yes | Path to RSA private key file | - |
|
|
90
|
+
| `beneficiary_id` | Yes | Your merchant/beneficiary ID | - |
|
|
91
|
+
| `payment_description` | Yes | Default payment description | - |
|
|
92
|
+
| `timeout` | No | Request timeout in seconds | 30 |
|
|
93
|
+
| `open_timeout` | No | Connection timeout in seconds | 10 |
|
|
94
|
+
|
|
95
|
+
## Usage
|
|
96
|
+
|
|
97
|
+
### Payment Flow
|
|
98
|
+
|
|
99
|
+
The RMA Payment Gateway follows a three-step payment flow:
|
|
100
|
+
|
|
101
|
+
```
|
|
102
|
+
1. Payment Authorization → 2. Account Inquiry → 3. Debit Request
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
1. **Payment Authorization**: Initiate a payment request with order details
|
|
106
|
+
2. **Account Inquiry**: Customer provides bank details and receives OTP
|
|
107
|
+
3. **Debit Request**: Complete payment by submitting the OTP
|
|
108
|
+
|
|
109
|
+
### Step 1: Payment Authorization
|
|
110
|
+
|
|
111
|
+
Initiate a payment request:
|
|
112
|
+
|
|
113
|
+
```ruby
|
|
114
|
+
require 'rma/payment/gateway'
|
|
115
|
+
|
|
116
|
+
# Initialize the client
|
|
117
|
+
client = Rma::Payment::Gateway::Client.new
|
|
118
|
+
|
|
119
|
+
# Request payment authorization
|
|
120
|
+
begin
|
|
121
|
+
response = client.authorization.call(
|
|
122
|
+
"ORDER123", # order_no: Unique order number
|
|
123
|
+
100.50, # amount: Payment amount
|
|
124
|
+
"customer@email.com" # email: Customer email
|
|
125
|
+
)
|
|
126
|
+
|
|
127
|
+
# Extract transaction ID for next steps
|
|
128
|
+
transaction_id = response["bfs_bfsTxnId"]
|
|
129
|
+
|
|
130
|
+
puts "Authorization successful!"
|
|
131
|
+
puts "Transaction ID: #{transaction_id}"
|
|
132
|
+
puts "Response: #{response}"
|
|
133
|
+
rescue Rma::Payment::Gateway::AuthenticationError => e
|
|
134
|
+
puts "Authorization failed: #{e.message}"
|
|
135
|
+
rescue Rma::Payment::Gateway::InvalidParameterError => e
|
|
136
|
+
puts "Invalid parameters: #{e.message}"
|
|
137
|
+
end
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
**Response Example:**
|
|
141
|
+
|
|
142
|
+
```ruby
|
|
143
|
+
{
|
|
144
|
+
"bfs_bfsTxnId" => "TXN123456789",
|
|
145
|
+
"bfs_responseCode" => "00",
|
|
146
|
+
"bfs_responseDesc" => "Success",
|
|
147
|
+
"bfs_orderNo" => "ORDER123",
|
|
148
|
+
"bfs_txnAmount" => "100.50"
|
|
149
|
+
}
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
### Step 2: Account Inquiry
|
|
153
|
+
|
|
154
|
+
Verify customer's bank account and trigger OTP:
|
|
155
|
+
|
|
156
|
+
```ruby
|
|
157
|
+
# Customer provides their bank details
|
|
158
|
+
transaction_id = "TXN123456789" # From authorization step
|
|
159
|
+
bank_id = "1010" # Bank code (see supported banks below)
|
|
160
|
+
account_no = "12345678" # Customer's account number
|
|
161
|
+
|
|
162
|
+
begin
|
|
163
|
+
response = client.account_inquiry.call(
|
|
164
|
+
transaction_id,
|
|
165
|
+
bank_id,
|
|
166
|
+
account_no
|
|
167
|
+
)
|
|
168
|
+
|
|
169
|
+
puts "Account inquiry successful!"
|
|
170
|
+
puts "OTP sent to customer's registered mobile"
|
|
171
|
+
puts "Account Name: #{response["bfs_remitterName"]}"
|
|
172
|
+
rescue Rma::Payment::Gateway::AuthenticationError => e
|
|
173
|
+
puts "Account inquiry failed: #{e.message}"
|
|
174
|
+
end
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
**Supported Banks:**
|
|
178
|
+
|
|
179
|
+
| Bank Code | Bank Name |
|
|
180
|
+
| --------- | -------------------------------------- |
|
|
181
|
+
| 1010 | Bank of Bhutan (BOBL) |
|
|
182
|
+
| 1020 | Bhutan National Bank (BNBL) |
|
|
183
|
+
| 1030 | Druk PNB Bank Limited (DPNBL) |
|
|
184
|
+
| 1040 | Tashi Bank (TBank) |
|
|
185
|
+
| 1050 | Bhutan Development Bank Limited (BDBL) |
|
|
186
|
+
| 1060 | Digital Kidu (DK Bank) |
|
|
187
|
+
|
|
188
|
+
**Response Example:**
|
|
189
|
+
|
|
190
|
+
```ruby
|
|
191
|
+
{
|
|
192
|
+
"bfs_bfsTxnId" => "TXN123456789",
|
|
193
|
+
"bfs_responseCode" => "00",
|
|
194
|
+
"bfs_responseDesc" => "Success",
|
|
195
|
+
"bfs_remitterName" => "John Doe",
|
|
196
|
+
"bfs_remitterAccNo" => "12345678"
|
|
197
|
+
}
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
### Step 3: Debit Request
|
|
201
|
+
|
|
202
|
+
Complete the payment with OTP:
|
|
203
|
+
|
|
204
|
+
```ruby
|
|
205
|
+
# Customer provides the OTP received on their mobile
|
|
206
|
+
transaction_id = "TXN123456789" # From authorization step
|
|
207
|
+
otp = "123456" # OTP from customer
|
|
208
|
+
|
|
209
|
+
begin
|
|
210
|
+
response = client.debit_request.call(
|
|
211
|
+
transaction_id,
|
|
212
|
+
otp
|
|
213
|
+
)
|
|
214
|
+
|
|
215
|
+
puts "Payment successful!"
|
|
216
|
+
puts "Transaction completed"
|
|
217
|
+
puts "Response: #{response}"
|
|
218
|
+
rescue Rma::Payment::Gateway::AuthenticationError => e
|
|
219
|
+
puts "Payment failed: #{e.message}"
|
|
220
|
+
end
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
**Response Example:**
|
|
224
|
+
|
|
225
|
+
```ruby
|
|
226
|
+
{
|
|
227
|
+
"bfs_bfsTxnId" => "TXN123456789",
|
|
228
|
+
"bfs_responseCode" => "00",
|
|
229
|
+
"bfs_responseDesc" => "Transaction Successful",
|
|
230
|
+
"bfs_txnAmount" => "100.50",
|
|
231
|
+
"bfs_orderNo" => "ORDER123"
|
|
232
|
+
}
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
### Complete Payment Flow Example
|
|
236
|
+
|
|
237
|
+
```ruby
|
|
238
|
+
require 'rma/payment/gateway'
|
|
239
|
+
|
|
240
|
+
# Initialize client
|
|
241
|
+
client = Rma::Payment::Gateway::Client.new
|
|
242
|
+
|
|
243
|
+
# Step 1: Authorization
|
|
244
|
+
puts "Step 1: Initiating payment authorization..."
|
|
245
|
+
auth_response = client.authorization.call("ORDER123", 100.50, "customer@email.com")
|
|
246
|
+
transaction_id = auth_response["bfs_bfsTxnId"]
|
|
247
|
+
puts "✓ Authorization successful. Transaction ID: #{transaction_id}"
|
|
248
|
+
|
|
249
|
+
# Step 2: Account Inquiry
|
|
250
|
+
puts "\nStep 2: Verifying account and sending OTP..."
|
|
251
|
+
# In a real application, you would collect these from the customer
|
|
252
|
+
bank_id = "1010"
|
|
253
|
+
account_no = "12345678"
|
|
254
|
+
|
|
255
|
+
inquiry_response = client.account_inquiry.call(transaction_id, bank_id, account_no)
|
|
256
|
+
puts "✓ Account verified. OTP sent to customer."
|
|
257
|
+
puts " Account holder: #{inquiry_response["bfs_remitterName"]}"
|
|
258
|
+
|
|
259
|
+
# Step 3: Debit Request
|
|
260
|
+
puts "\nStep 3: Completing payment with OTP..."
|
|
261
|
+
# In a real application, you would collect the OTP from the customer
|
|
262
|
+
otp = "123456"
|
|
263
|
+
|
|
264
|
+
debit_response = client.debit_request.call(transaction_id, otp)
|
|
265
|
+
puts "✓ Payment completed successfully!"
|
|
266
|
+
puts " Amount: #{debit_response["bfs_txnAmount"]} BTN"
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
## Error Handling
|
|
270
|
+
|
|
271
|
+
The gem provides specific exception classes for different error scenarios:
|
|
272
|
+
|
|
273
|
+
```ruby
|
|
274
|
+
begin
|
|
275
|
+
client.authorization.call(order_no, amount, email)
|
|
276
|
+
rescue Rma::Payment::Gateway::ConfigurationError => e
|
|
277
|
+
# Missing or invalid configuration
|
|
278
|
+
puts "Configuration error: #{e.message}"
|
|
279
|
+
rescue Rma::Payment::Gateway::InvalidParameterError => e
|
|
280
|
+
# Invalid input parameters
|
|
281
|
+
puts "Invalid parameters: #{e.message}"
|
|
282
|
+
puts "Response code: #{e.response_code}"
|
|
283
|
+
rescue Rma::Payment::Gateway::AuthenticationError => e
|
|
284
|
+
# Authentication or authorization failed
|
|
285
|
+
puts "Authentication error: #{e.message}"
|
|
286
|
+
rescue Rma::Payment::Gateway::NetworkError => e
|
|
287
|
+
# Network connectivity issues
|
|
288
|
+
puts "Network error: #{e.message}"
|
|
289
|
+
rescue Rma::Payment::Gateway::APIError => e
|
|
290
|
+
# API-level errors
|
|
291
|
+
puts "API error: #{e.message}"
|
|
292
|
+
puts "Response code: #{e.response_code}"
|
|
293
|
+
rescue Rma::Payment::Gateway::Error => e
|
|
294
|
+
# Generic gateway error
|
|
295
|
+
puts "Gateway error: #{e.message}"
|
|
296
|
+
end
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
### Exception Hierarchy
|
|
300
|
+
|
|
301
|
+
```
|
|
302
|
+
Rma::Payment::Gateway::Error (base class)
|
|
303
|
+
├── ConfigurationError
|
|
304
|
+
├── AuthenticationError
|
|
305
|
+
├── InvalidParameterError
|
|
306
|
+
├── NetworkError
|
|
307
|
+
├── SignatureError
|
|
308
|
+
└── APIError
|
|
309
|
+
└── TransactionError
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
## Utilities
|
|
313
|
+
|
|
314
|
+
The gem includes utility methods for validation and formatting:
|
|
315
|
+
|
|
316
|
+
### Validation Methods
|
|
317
|
+
|
|
318
|
+
```ruby
|
|
319
|
+
# Email validation
|
|
320
|
+
Rma::Payment::Gateway::Utils.valid_email?("user@example.com")
|
|
321
|
+
# => true
|
|
322
|
+
|
|
323
|
+
# Amount validation
|
|
324
|
+
Rma::Payment::Gateway::Utils.valid_amount?(100.50)
|
|
325
|
+
# => true
|
|
326
|
+
|
|
327
|
+
# Bank code validation
|
|
328
|
+
Rma::Payment::Gateway::Utils.valid_bank_code?("1010")
|
|
329
|
+
# => true
|
|
330
|
+
|
|
331
|
+
# Account number validation (8-15 digits)
|
|
332
|
+
Rma::Payment::Gateway::Utils.valid_account_number?("12345678")
|
|
333
|
+
# => true
|
|
334
|
+
|
|
335
|
+
# Phone number validation (Bhutan format - 8 digits)
|
|
336
|
+
Rma::Payment::Gateway::Utils.valid_phone_number?("17123456")
|
|
337
|
+
# => true
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
### Formatting Methods
|
|
341
|
+
|
|
342
|
+
```ruby
|
|
343
|
+
# Format amount to 2 decimal places
|
|
344
|
+
Rma::Payment::Gateway::Utils.format_amount(100.5)
|
|
345
|
+
# => "100.50"
|
|
346
|
+
|
|
347
|
+
# Generate timestamp
|
|
348
|
+
Rma::Payment::Gateway::Utils.generate_timestamp
|
|
349
|
+
# => "20231215143022"
|
|
350
|
+
|
|
351
|
+
# Mask sensitive data
|
|
352
|
+
Rma::Payment::Gateway::Utils.mask_sensitive("1234567890", 2)
|
|
353
|
+
# => "12******90"
|
|
354
|
+
|
|
355
|
+
# Get bank name from code
|
|
356
|
+
Rma::Payment::Gateway::Utils.bank_name("1010")
|
|
357
|
+
# => "Bank of Bhutan (BOBL)"
|
|
358
|
+
```
|
|
359
|
+
|
|
360
|
+
## Development
|
|
361
|
+
|
|
362
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
363
|
+
|
|
364
|
+
```bash
|
|
365
|
+
# Install dependencies
|
|
366
|
+
bin/setup
|
|
367
|
+
|
|
368
|
+
# Run tests
|
|
369
|
+
bundle exec rake spec
|
|
370
|
+
|
|
371
|
+
# Run RuboCop
|
|
372
|
+
bundle exec rubocop
|
|
373
|
+
|
|
374
|
+
# Interactive console
|
|
375
|
+
bin/console
|
|
376
|
+
```
|
|
377
|
+
|
|
378
|
+
## Testing
|
|
379
|
+
|
|
380
|
+
The gem uses RSpec for testing. Run the test suite:
|
|
381
|
+
|
|
382
|
+
```bash
|
|
383
|
+
bundle exec rspec
|
|
384
|
+
```
|
|
385
|
+
|
|
386
|
+
Run with coverage:
|
|
387
|
+
|
|
388
|
+
```bash
|
|
389
|
+
COVERAGE=true bundle exec rspec
|
|
390
|
+
```
|
|
391
|
+
|
|
392
|
+
## API Response Codes
|
|
393
|
+
|
|
394
|
+
Common response codes from the RMA Payment Gateway:
|
|
395
|
+
|
|
396
|
+
| Code | Description |
|
|
397
|
+
| ---- | ------------------- |
|
|
398
|
+
| 00 | Success |
|
|
399
|
+
| 01 | Invalid request |
|
|
400
|
+
| 02 | Invalid beneficiary |
|
|
401
|
+
| 03 | Invalid transaction |
|
|
402
|
+
| 04 | Insufficient funds |
|
|
403
|
+
| 05 | Invalid OTP |
|
|
404
|
+
| 06 | OTP expired |
|
|
405
|
+
| 99 | System error |
|
|
406
|
+
|
|
407
|
+
## Security Considerations
|
|
408
|
+
|
|
409
|
+
1. **Never commit your RSA private key** to version control
|
|
410
|
+
2. **Use environment variables** for sensitive configuration
|
|
411
|
+
3. **Validate all user inputs** before sending to the API
|
|
412
|
+
4. **Log transactions** but mask sensitive data
|
|
413
|
+
5. **Use HTTPS** for all API communications
|
|
414
|
+
6. **Implement rate limiting** to prevent abuse
|
|
415
|
+
7. **Store transaction IDs** securely for reconciliation
|
|
416
|
+
|
|
417
|
+
## Contributing
|
|
418
|
+
|
|
419
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/dcplbt/rma-payment-gateway. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/dcplbt/rma-payment-gateway/blob/main/CODE_OF_CONDUCT.md).
|
|
420
|
+
|
|
421
|
+
### How to Contribute
|
|
422
|
+
|
|
423
|
+
1. Fork the repository
|
|
424
|
+
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
|
|
425
|
+
3. Commit your changes (`git commit -am 'Add some amazing feature'`)
|
|
426
|
+
4. Push to the branch (`git push origin feature/amazing-feature`)
|
|
427
|
+
5. Open a Pull Request
|
|
428
|
+
|
|
429
|
+
## License
|
|
430
|
+
|
|
431
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
|
432
|
+
|
|
433
|
+
## Code of Conduct
|
|
434
|
+
|
|
435
|
+
Everyone interacting in the RMA Payment Gateway project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/dcplbt/rma-payment-gateway/blob/main/CODE_OF_CONDUCT.md).
|
|
436
|
+
|
|
437
|
+
## Support
|
|
438
|
+
|
|
439
|
+
For issues, questions, or contributions, please visit:
|
|
440
|
+
|
|
441
|
+
- GitHub Issues: https://github.com/dcplbt/rma-payment-gateway/issues
|
|
442
|
+
- Email: tashii.dendupp@gmail.com
|
|
443
|
+
|
|
444
|
+
## Changelog
|
|
445
|
+
|
|
446
|
+
See [CHANGELOG.md](CHANGELOG.md) for a list of changes.
|