myclear 0.1.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/.gitignore +9 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +185 -0
- data/Rakefile +10 -0
- data/lib/myclear.rb +31 -0
- data/lib/myclear/service.rb +109 -0
- data/lib/myclear/sign.rb +39 -0
- data/lib/myclear/utils.rb +19 -0
- data/lib/myclear/version.rb +3 -0
- data/myclear.gemspec +31 -0
- metadata +113 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 5259cd992fa04f1a723e18acd3366506d6cecb59
|
|
4
|
+
data.tar.gz: 24c45b728cf30663817e77882ad60ddfcf53edc5
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: c75428ed7582886a23c16b978b0ed9b2f6ba96b3d5948a24fe427fce2afcc253bb9e576831fa37f26315ce8a68798a16d3531573d73a27a3913299704b2815be
|
|
7
|
+
data.tar.gz: d240488fe707542bf4405eb89bed432deeae4a449e0132f635eced6e06d78d656628f1a8ddf64f46298e843bd2c355b8a47c8462ce4705cadc12de308a2ea654
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
|
2
|
+
|
|
3
|
+
## Our Pledge
|
|
4
|
+
|
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
|
10
|
+
orientation.
|
|
11
|
+
|
|
12
|
+
## Our Standards
|
|
13
|
+
|
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
|
15
|
+
include:
|
|
16
|
+
|
|
17
|
+
* Using welcoming and inclusive language
|
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
|
19
|
+
* Gracefully accepting constructive criticism
|
|
20
|
+
* Focusing on what is best for the community
|
|
21
|
+
* Showing empathy towards other community members
|
|
22
|
+
|
|
23
|
+
Examples of unacceptable behavior by participants include:
|
|
24
|
+
|
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
|
26
|
+
advances
|
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
|
28
|
+
* Public or private harassment
|
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
|
30
|
+
address, without explicit permission
|
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
|
32
|
+
professional setting
|
|
33
|
+
|
|
34
|
+
## Our Responsibilities
|
|
35
|
+
|
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
|
38
|
+
response to any instances of unacceptable behavior.
|
|
39
|
+
|
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
|
44
|
+
threatening, offensive, or harmful.
|
|
45
|
+
|
|
46
|
+
## Scope
|
|
47
|
+
|
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
|
49
|
+
when an individual is representing the project or its community. Examples of
|
|
50
|
+
representing a project or community include using an official project e-mail
|
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
|
53
|
+
further defined and clarified by project maintainers.
|
|
54
|
+
|
|
55
|
+
## Enforcement
|
|
56
|
+
|
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
58
|
+
reported by contacting the project team at lance.zyb@gmail.com. All
|
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
|
63
|
+
|
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
|
66
|
+
members of the project's leadership.
|
|
67
|
+
|
|
68
|
+
## Attribution
|
|
69
|
+
|
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
|
72
|
+
|
|
73
|
+
[homepage]: http://contributor-covenant.org
|
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2017 TODO: Write your name
|
|
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
|
|
13
|
+
all 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
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
# Myclear
|
|
2
|
+
|
|
3
|
+
A unofficial myclear ruby gem.
|
|
4
|
+
|
|
5
|
+
Myclear official document: https://fpxexchange.myclear.org.my:8443/MerchantIntegrationKit/
|
|
6
|
+
|
|
7
|
+
note:Password is required when accessing the official document, please go to Myclear for the password.
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
Add this line to your application's Gemfile:
|
|
12
|
+
|
|
13
|
+
```ruby
|
|
14
|
+
gem 'myclear'
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
or
|
|
18
|
+
|
|
19
|
+
```ruby
|
|
20
|
+
gem 'myclear', github: 'lanceyb/myclear'
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
And then execute:
|
|
24
|
+
|
|
25
|
+
$ bundle
|
|
26
|
+
|
|
27
|
+
Or install it yourself as:
|
|
28
|
+
|
|
29
|
+
$ gem install myclear
|
|
30
|
+
|
|
31
|
+
## Configuration
|
|
32
|
+
|
|
33
|
+
```ruby
|
|
34
|
+
Myclear.fpx_version = '7.0'
|
|
35
|
+
Myclear.seller_exchange_id = 'YOUR SELLER EXCHANGE ID'
|
|
36
|
+
Myclear.seller_id = 'YOUR SELLER ID'
|
|
37
|
+
Myclear.private_key = 'YOUR RSA PRIVATE KEY'
|
|
38
|
+
Myclear.fpx_certification = 'THE FPX CERTIFICATION'
|
|
39
|
+
|
|
40
|
+
# Myclear.debug_mode = true # Enable parameter check. Default is true.
|
|
41
|
+
# Myclear.fpx_standby_certification = 'THE STANDBY FPX CERTIFICATIO
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
eg:
|
|
45
|
+
|
|
46
|
+
```ruby
|
|
47
|
+
if Rails.env.production?
|
|
48
|
+
Myclear.fpx_version = '7.0'
|
|
49
|
+
Myclear.seller_exchange_id = 'YOUR SELLER EXCHANGE ID'
|
|
50
|
+
Myclear.seller_id = 'YOUR SELLER ID'
|
|
51
|
+
Myclear.private_key = 'YOUR RSA PRIVATE KEY'
|
|
52
|
+
Myclear.fpx_certification = 'THE FPX CERTIFICATION'
|
|
53
|
+
else
|
|
54
|
+
Myclear.fpx_version = '7.0'
|
|
55
|
+
Myclear.seller_exchange_id = 'EX00000000'
|
|
56
|
+
Myclear.seller_id = 'SE00000000'
|
|
57
|
+
Myclear.private_key = File.read(File.expand_path('./EX00000000.key', Rails.root))
|
|
58
|
+
Myclear.fpx_certification = File.read(File.expand_path('./fpxuat.cer', Rails.root))
|
|
59
|
+
end
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Service
|
|
63
|
+
|
|
64
|
+
### bank list(银行列表)
|
|
65
|
+
|
|
66
|
+
```ruby
|
|
67
|
+
Myclear::Service.bank_list_enquiry
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Authorization Request(申请支付)
|
|
71
|
+
|
|
72
|
+
```ruby
|
|
73
|
+
Myclear::Service.authorization_request_params({ARGUMENTS})
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
#### Example
|
|
77
|
+
```ruby
|
|
78
|
+
Myclear::Service.authorization_request_params({
|
|
79
|
+
fpx_msgToken: '01',
|
|
80
|
+
fpx_sellerExOrderNo: 'EXORDERNO0000',
|
|
81
|
+
fpx_sellerTxnTime: '20170817140102',
|
|
82
|
+
fpx_sellerOrderNo: 'ORDERNO000000',
|
|
83
|
+
fpx_txnCurrency: 'MYR',
|
|
84
|
+
fpx_txnAmount: '1.00',
|
|
85
|
+
fpx_buyerEmail: 'test@example.com',
|
|
86
|
+
fpx_buyerName: '',
|
|
87
|
+
fpx_buyerBankId: 'TEST0021',
|
|
88
|
+
fpx_buyerBankBranch: 'SBI BANK A',
|
|
89
|
+
fpx_buyerAccNo: '',
|
|
90
|
+
fpx_buyerId: '',
|
|
91
|
+
fpx_makerName: '',
|
|
92
|
+
fpx_buyerIban: '',
|
|
93
|
+
fpx_productDesc: '1 goods'
|
|
94
|
+
})
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
#### Arugments
|
|
98
|
+
|
|
99
|
+
| Key | Allow Blank | Description |
|
|
100
|
+
| --- | ----------- | ----------- |
|
|
101
|
+
| fpx_msgToken | N | Indicate business model. 01 - B2C / 02 - B2B1 / 03 - B2B2 |
|
|
102
|
+
| fpx_sellerExOrderNo | N | Unique ID generate by Exchange for each transaction originating form an Exchange. Not Supported: Ampersan (&) and Apostrophe ('). |
|
|
103
|
+
| fpx_sellerTxnTime | N | Date and time transaction originated from Merchant. YYYYMMDDHHmmSS (in MYT). |
|
|
104
|
+
| fpx_sellerOrderNo | N | Order number generated by Merchant. Not Supported: Ampersan (&) and Apostrophe ('). |
|
|
105
|
+
| fpx_txnCurrency | N | Transaction currency. Default value = MYR |
|
|
106
|
+
| fpx_txnAmount | N | Total amount. |
|
|
107
|
+
| fpx_buyerEmail | Y | Buyer email address. Allow blank. |
|
|
108
|
+
| fpx_buyerName | Y | Buyer name. Allow blank. |
|
|
109
|
+
| fpx_buyerBankId | N | Provided by FPX - ties to Bank that Buyer has an account in. |
|
|
110
|
+
| fpx_buyerBankBranch | N | Bank's branch code that Buyer opened his account. Not Supported: Slash(/), Ampesand(&) and Apostrophe('). |
|
|
111
|
+
| fpx_buyerAccNo | Y | Buyer account number |
|
|
112
|
+
| fpx_buyerId | Y | Buyer identification number. Not Supported: Slash(/), Ampersand(&) and Apostrophe('). |
|
|
113
|
+
| fpx_makerName | Y | Buyer representative (Maker) who initiate the transaction. |
|
|
114
|
+
| pfx_buyerIban | Y | Buyer IBAN |
|
|
115
|
+
| fpx_productDesc | Y | Product Description |
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
### Authorization Enquiry
|
|
119
|
+
|
|
120
|
+
```ruby
|
|
121
|
+
Myclear::Service.authorization_enquiry({ARGUMENTS})
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
#### Example
|
|
125
|
+
```ruby
|
|
126
|
+
Myclear::Service.authorization_enquiry({
|
|
127
|
+
fpx_msgToken: '01',
|
|
128
|
+
fpx_sellerExOrderNo: 'EXORDERNO0000',
|
|
129
|
+
fpx_sellerTxnTime: '20170817140102',
|
|
130
|
+
fpx_sellerOrderNo: 'ORDERNO000000',
|
|
131
|
+
fpx_txnCurrency: 'MYR',
|
|
132
|
+
fpx_txnAmount: '1.00',
|
|
133
|
+
fpx_buyerEmail: 'test@example.com',
|
|
134
|
+
fpx_buyerName: '',
|
|
135
|
+
fpx_buyerBankId: 'TEST0021',
|
|
136
|
+
fpx_buyerBankBranch: 'SBI BANK A',
|
|
137
|
+
fpx_buyerAccNo: '',
|
|
138
|
+
fpx_buyerId: '',
|
|
139
|
+
fpx_makerName: '',
|
|
140
|
+
fpx_buyerIban: '',
|
|
141
|
+
fpx_productDesc: '1 goods'
|
|
142
|
+
})
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
note : 请求AE接口的参数,保持与AR时一致
|
|
146
|
+
|
|
147
|
+
#### Arugments
|
|
148
|
+
|
|
149
|
+
| Key | Allow Blank | Description |
|
|
150
|
+
| --- | ----------- | ----------- |
|
|
151
|
+
| fpx_msgToken | N | Indicate business model. 01 - B2C / 02 - B2B1 / 03 - B2B2 |
|
|
152
|
+
| fpx_sellerExOrderNo | N | Unique ID generate by Exchange for each transaction originating form an Exchange. Not Supported: Ampersan (&) and Apostrophe ('). |
|
|
153
|
+
| fpx_sellerTxnTime | N | Date and time transaction originated from Merchant. YYYYMMDDHHmmSS (in MYT). |
|
|
154
|
+
| fpx_sellerOrderNo | N | Order number generated by Merchant. Not Supported: Ampersan (&) and Apostrophe ('). |
|
|
155
|
+
| fpx_txnCurrency | N | Transaction currency. Default value = MYR |
|
|
156
|
+
| fpx_txnAmount | N | Total amount. |
|
|
157
|
+
| fpx_buyerEmail | Y | Buyer email address. Allow blank. |
|
|
158
|
+
| fpx_buyerName | Y | Buyer name. Allow blank. |
|
|
159
|
+
| fpx_buyerBankId | N | Provided by FPX - ties to Bank that Buyer has an account in. |
|
|
160
|
+
| fpx_buyerBankBranch | N | Bank's branch code that Buyer opened his account. Not Supported: Slash(/), Ampesand(&) and Apostrophe('). |
|
|
161
|
+
| fpx_buyerAccNo | Y | Buyer account number |
|
|
162
|
+
| fpx_buyerId | Y | Buyer identification number. Not Supported: Slash(/), Ampersand(&) and Apostrophe('). |
|
|
163
|
+
| fpx_makerName | Y | Buyer representative (Maker) who initiate the transaction. |
|
|
164
|
+
| pfx_buyerIban | Y | Buyer IBAN |
|
|
165
|
+
| fpx_productDesc | Y | Product Description |
|
|
166
|
+
|
|
167
|
+
### Verify callback(验证回调)
|
|
168
|
+
|
|
169
|
+
```ruby
|
|
170
|
+
Myclear::Service.verify_params(params)
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
## Contributing
|
|
174
|
+
|
|
175
|
+
Bug reports and pull requests are welcome.
|
|
176
|
+
|
|
177
|
+
### Make a pull request
|
|
178
|
+
|
|
179
|
+
1. Fork it
|
|
180
|
+
2. Create your feature branch (git checkout -b my-new-feature)
|
|
181
|
+
3. Commit your changes (git commit -am 'Add some feature')
|
|
182
|
+
4. Push to the branch (git push origin my-new-feature)
|
|
183
|
+
5. Create new Pull Request
|
|
184
|
+
|
|
185
|
+
Please write unit test with your code if necessary.
|
data/Rakefile
ADDED
data/lib/myclear.rb
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
require "myclear/version"
|
|
2
|
+
require "myclear/sign"
|
|
3
|
+
require "myclear/utils"
|
|
4
|
+
require "myclear/service"
|
|
5
|
+
require 'openssl'
|
|
6
|
+
|
|
7
|
+
module Myclear
|
|
8
|
+
@debug_mode = true
|
|
9
|
+
@digest_type = 'SHA1'
|
|
10
|
+
@fpx_version = '7.0'
|
|
11
|
+
@uat = true
|
|
12
|
+
|
|
13
|
+
class << self
|
|
14
|
+
attr_accessor :debug_mode, :uat
|
|
15
|
+
attr_accessor :digest_type, :fpx_version
|
|
16
|
+
attr_accessor :private_key, :fpx_certification, :fpx_standby_certification
|
|
17
|
+
attr_accessor :seller_exchange_id, :seller_id
|
|
18
|
+
|
|
19
|
+
def debug_mode?
|
|
20
|
+
!!@debug_mode
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def uat?
|
|
24
|
+
!!@uat
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def service_host
|
|
28
|
+
uat? ? 'https://uat.mepsfpx.com.my' : 'https://mepsfpx.com.my'
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
module Myclear
|
|
2
|
+
module Service
|
|
3
|
+
# BE
|
|
4
|
+
BE_URI = '/FPXMain/RetrieveBankList'
|
|
5
|
+
def self.bank_list_enquiry options = {}
|
|
6
|
+
params = {
|
|
7
|
+
'fpx_msgType' => 'BE',
|
|
8
|
+
'fpx_msgToken' => '01',
|
|
9
|
+
'fpx_sellerExId' => Myclear.seller_exchange_id,
|
|
10
|
+
'fpx_version' => Myclear.fpx_version
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
request(BE_URI, params, options)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def self.be_url
|
|
17
|
+
Myclear.service_host + BE_URI
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# AR
|
|
21
|
+
# fpx_msgToken: B2C => '01', B2B => '02'
|
|
22
|
+
AR_URI = '/FPXMain/seller2DReceiver.jsp'
|
|
23
|
+
AR_REQUIRED_PARAMS = %w(fpx_msgToken fpx_sellerExOrderNo fpx_sellerTxnTime fpx_sellerOrderNo fpx_txnCurrency fpx_txnAmount fpx_buyerEmail fpx_buyerName fpx_buyerBankId fpx_buyerBankBranch fpx_buyerAccNo fpx_buyerId fpx_makerName fpx_buyerIban fpx_productDesc)
|
|
24
|
+
def self.authorization_request_params(params, options = {})
|
|
25
|
+
params = Utils.stringify_keys(params)
|
|
26
|
+
check_params(params, AR_REQUIRED_PARAMS)
|
|
27
|
+
params = {
|
|
28
|
+
'fpx_msgType' => 'AR',
|
|
29
|
+
'fpx_sellerBankCode' => '01',
|
|
30
|
+
'fpx_sellerExId' => Myclear.seller_exchange_id,
|
|
31
|
+
'fpx_version' => Myclear.fpx_version,
|
|
32
|
+
'fpx_sellerId' => Myclear.seller_id
|
|
33
|
+
}.merge(params)
|
|
34
|
+
|
|
35
|
+
# request_uri(params, options)
|
|
36
|
+
sign_params(params, options)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def self.ar_url
|
|
40
|
+
Myclear.service_host + AR_URI
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# AE
|
|
44
|
+
# fpx_msgToken: B2C => '01', B2B => '02'
|
|
45
|
+
AE_URI = '/FPXMain/sellerNVPTxnStatus.jsp'
|
|
46
|
+
AE_REQUIRED_PARAMS = %w(fpx_msgToken fpx_sellerExOrderNo fpx_sellerTxnTime fpx_sellerOrderNo fpx_txnCurrency fpx_txnAmount fpx_buyerEmail fpx_buyerName fpx_buyerBankId fpx_buyerBankBranch fpx_buyerAccNo fpx_buyerId fpx_makerName fpx_buyerIban fpx_productDesc)
|
|
47
|
+
def self.authorization_enquiry(params, options = {})
|
|
48
|
+
params = Utils.stringify_keys(params)
|
|
49
|
+
check_params(params, AE_REQUIRED_PARAMS)
|
|
50
|
+
params = {
|
|
51
|
+
'fpx_msgType' => 'AE',
|
|
52
|
+
'fpx_sellerBankCode' => '01',
|
|
53
|
+
'fpx_sellerExId' => Myclear.seller_exchange_id,
|
|
54
|
+
'fpx_version' => Myclear.fpx_version,
|
|
55
|
+
'fpx_sellerId' => Myclear.seller_id
|
|
56
|
+
}.merge(params)
|
|
57
|
+
|
|
58
|
+
request(AE_URI, params, options)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def self.ae_url
|
|
62
|
+
Myclear.service_host + AE_URI
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
VERIFY_REQUIRED_PARAMS = %w(fpx_buyerBankBranch fpx_buyerBankId fpx_buyerIban fpx_buyerId fpx_buyerName fpx_creditAuthCode fpx_creditAuthNo fpx_debitAuthCode fpx_debitAuthNo fpx_fpxTxnId fpx_fpxTxnTime fpx_makerName fpx_msgToken fpx_msgType fpx_sellerExId fpx_sellerExOrderNo fpx_sellerId fpx_sellerOrderNo fpx_sellerTxnTime fpx_txnAmount fpx_txnCurrency fpx_checkSum)
|
|
66
|
+
def self.verify_params(params, options = {})
|
|
67
|
+
params = Utils.stringify_keys(params)
|
|
68
|
+
check_params(params, VERIFY_REQUIRED_PARAMS)
|
|
69
|
+
Myclear::Sign.verify?(params.delete('fpx_checkSum'), package_params(params))
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def self.request_uri(params, options = {})
|
|
73
|
+
uri = URI(GATEWAY_URL)
|
|
74
|
+
uri.query = URI.encode_www_form(sign_params(params, options))
|
|
75
|
+
uri
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def self.request(uri, params, options = {})
|
|
79
|
+
host_uri = URI(Myclear.service_host)
|
|
80
|
+
http = Net::HTTP.new(host_uri.host, host_uri.port)
|
|
81
|
+
http.use_ssl = true
|
|
82
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
|
83
|
+
req = Net::HTTP::Post.new(uri)
|
|
84
|
+
req['Accept'] = 'application/json'
|
|
85
|
+
req.set_form_data(sign_params(params, options))
|
|
86
|
+
http.request(req)
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def self.sign_params(params, options)
|
|
90
|
+
params.merge(
|
|
91
|
+
'fpx_checkSum' => Myclear::Sign.generate(package_params(params), options)
|
|
92
|
+
)
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def self.package_params(params)
|
|
96
|
+
params.sort_by { |key, value| key }.to_h.values.join("|")
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def self.check_params(params, names)
|
|
100
|
+
return if !Myclear.debug_mode?
|
|
101
|
+
|
|
102
|
+
(params.keys - names).each { |key| warn("Myclear Warn: unknown option: #{key}") }
|
|
103
|
+
|
|
104
|
+
names.each do |name|
|
|
105
|
+
warn("Myclear Warn: missing required option: #{name}") unless params.has_key?(name)
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
end
|
data/lib/myclear/sign.rb
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
module Myclear
|
|
2
|
+
module Sign
|
|
3
|
+
def self.generate(str, options = {})
|
|
4
|
+
key = OpenSSL::PKey::RSA.new(Myclear.private_key)
|
|
5
|
+
digest_type = options[:digest_type] || Myclear.digest_type
|
|
6
|
+
digest = case digest_type
|
|
7
|
+
when 'SHA1'
|
|
8
|
+
OpenSSL::Digest::SHA1.new
|
|
9
|
+
when 'SHA256'
|
|
10
|
+
OpenSSL::Digest::SHA256.new
|
|
11
|
+
when 'SHA512'
|
|
12
|
+
OpenSSL::Digest::SHA512.new
|
|
13
|
+
else
|
|
14
|
+
raise ArgumentError, "invalid digest_type #{digest_type}, allow value: 'SHA1', 'SHA256', 'SHA512'"
|
|
15
|
+
end
|
|
16
|
+
Myclear::Utils.binary_to_hex(key.sign(digest, str))
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def self.verify?(sign, str, options = {})
|
|
20
|
+
cer = OpenSSL::X509::Certificate.new(Myclear.fpx_certification)
|
|
21
|
+
if(cer.not_after < Time.now && !Myclear.fpx_standby_certification.nil?)
|
|
22
|
+
warn("Myclear Warn: the main certification has expired, please replace a new one.")
|
|
23
|
+
cer = Myclear.fpx_standby_certification
|
|
24
|
+
end
|
|
25
|
+
digest_type = options[:digest_type] || Myclear.digest_type
|
|
26
|
+
digest = case digest_type
|
|
27
|
+
when 'SHA1'
|
|
28
|
+
OpenSSL::Digest::SHA1.new
|
|
29
|
+
when 'SHA256'
|
|
30
|
+
OpenSSL::Digest::SHA256.new
|
|
31
|
+
when 'SHA512'
|
|
32
|
+
OpenSSL::Digest::SHA512.new
|
|
33
|
+
else
|
|
34
|
+
raise ArgumentError, "invalid digest_type #{digest_type}, allow value: 'SHA1', 'SHA256', 'SHA512'"
|
|
35
|
+
end
|
|
36
|
+
cer.public_key.verify(digest, Myclear::Utils.hex_to_binary(sign), str)
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module Myclear
|
|
2
|
+
module Utils
|
|
3
|
+
def self.stringify_keys(hash)
|
|
4
|
+
new_hash = {}
|
|
5
|
+
hash.each do |key, value|
|
|
6
|
+
new_hash[(key.to_s rescue key) || key] = value
|
|
7
|
+
end
|
|
8
|
+
new_hash
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def self.binary_to_hex(str)
|
|
12
|
+
str.unpack("H*").first.upcase
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def self.hex_to_binary(str)
|
|
16
|
+
[str.downcase].pack("H*")
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
data/myclear.gemspec
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require "myclear/version"
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "myclear"
|
|
8
|
+
spec.version = Myclear::VERSION
|
|
9
|
+
spec.authors = ["lance"]
|
|
10
|
+
spec.email = ["lance.zyb@gmail.com"]
|
|
11
|
+
|
|
12
|
+
spec.summary = %q{An unofficial simple myclear gem}
|
|
13
|
+
spec.description = %q{An unofficial simple myclear gem}
|
|
14
|
+
spec.homepage = "https://github.com/lanceyb/myclear"
|
|
15
|
+
spec.license = "MIT"
|
|
16
|
+
|
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
|
19
|
+
|
|
20
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
|
21
|
+
f.match(%r{^(test|spec|features)/})
|
|
22
|
+
end
|
|
23
|
+
spec.bindir = "exe"
|
|
24
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
25
|
+
spec.require_paths = ["lib"]
|
|
26
|
+
|
|
27
|
+
spec.add_development_dependency "bundler", "~> 1.15"
|
|
28
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
|
29
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
|
30
|
+
spec.add_development_dependency "webmock", '~> 3.0'
|
|
31
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: myclear
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- lance
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2017-08-18 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: bundler
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '1.15'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.15'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rake
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '10.0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '10.0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: minitest
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '5.0'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '5.0'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: webmock
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - "~>"
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '3.0'
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - "~>"
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '3.0'
|
|
69
|
+
description: An unofficial simple myclear gem
|
|
70
|
+
email:
|
|
71
|
+
- lance.zyb@gmail.com
|
|
72
|
+
executables: []
|
|
73
|
+
extensions: []
|
|
74
|
+
extra_rdoc_files: []
|
|
75
|
+
files:
|
|
76
|
+
- ".gitignore"
|
|
77
|
+
- ".travis.yml"
|
|
78
|
+
- CODE_OF_CONDUCT.md
|
|
79
|
+
- Gemfile
|
|
80
|
+
- LICENSE.txt
|
|
81
|
+
- README.md
|
|
82
|
+
- Rakefile
|
|
83
|
+
- lib/myclear.rb
|
|
84
|
+
- lib/myclear/service.rb
|
|
85
|
+
- lib/myclear/sign.rb
|
|
86
|
+
- lib/myclear/utils.rb
|
|
87
|
+
- lib/myclear/version.rb
|
|
88
|
+
- myclear.gemspec
|
|
89
|
+
homepage: https://github.com/lanceyb/myclear
|
|
90
|
+
licenses:
|
|
91
|
+
- MIT
|
|
92
|
+
metadata: {}
|
|
93
|
+
post_install_message:
|
|
94
|
+
rdoc_options: []
|
|
95
|
+
require_paths:
|
|
96
|
+
- lib
|
|
97
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
98
|
+
requirements:
|
|
99
|
+
- - ">="
|
|
100
|
+
- !ruby/object:Gem::Version
|
|
101
|
+
version: '0'
|
|
102
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
103
|
+
requirements:
|
|
104
|
+
- - ">="
|
|
105
|
+
- !ruby/object:Gem::Version
|
|
106
|
+
version: '0'
|
|
107
|
+
requirements: []
|
|
108
|
+
rubyforge_project:
|
|
109
|
+
rubygems_version: 2.6.11
|
|
110
|
+
signing_key:
|
|
111
|
+
specification_version: 4
|
|
112
|
+
summary: An unofficial simple myclear gem
|
|
113
|
+
test_files: []
|