momo_pay 2.0 → 2.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +47 -23
- data/lib/momo_pay.rb +2 -0
- data/lib/momo_pay/config.rb +14 -2
- data/lib/momo_pay/default.rb +43 -2
- data/lib/momo_pay/qr_code.rb +17 -0
- data/lib/momo_pay/request.rb +4 -0
- data/lib/momo_pay/signature.rb +4 -5
- data/lib/momo_pay/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4ad989c70a7c3e43d7727a262748e12f6fc369ac6fd07333bcfcada3fc2fc517
|
4
|
+
data.tar.gz: eb1566c60fe7b08d8e6ff7619fcd0231d400c857242705113df6a48678fa6ed8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7e3ea5f1a3828784886d4e958f810ee5aec218d2d855395bdfefd26840c76f7c3c879c92938d67207336b166373b880105d5b2cb81d58fa6c21b1e34c3d1084d
|
7
|
+
data.tar.gz: 0af952cd4c19e9db38c2a640019fbf2b4e946abd760c3e076efa61dbb8ec42318627e4a536d79493d621a1817ad21aabc614b9c680281ef846b1ec312659a4e2
|
data/README.md
CHANGED
@@ -1,8 +1,5 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/momo_pay`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
1
|
+
# API Caller for https://momo.vn
|
2
|
+
- API documentation: https://developers.momo.vn
|
6
3
|
|
7
4
|
## Installation
|
8
5
|
|
@@ -21,23 +18,50 @@ Or install it yourself as:
|
|
21
18
|
$ gem install momo_pay
|
22
19
|
|
23
20
|
## Usage
|
21
|
+
#### Setup:
|
22
|
+
Add `config/initializers/momo.rb` file with content
|
23
|
+
```ruby
|
24
|
+
MomoPay.setup do |config|
|
25
|
+
config.domain = Rails.application.secrets.momo_domain
|
26
|
+
config.public_key = Rails.application.secrets.momo_public_key
|
27
|
+
config.secret_key = Rails.application.secrets.momo_secret_key
|
28
|
+
config.partner_code = Rails.application.secrets.momo_partner_code
|
29
|
+
config.partner_name = Rails.application.secrets.momo_partner_name
|
30
|
+
end
|
31
|
+
```
|
32
|
+
#### 1. App-In-App:
|
33
|
+
**Request to process transaction:** [detail from Momo](https://developers.momo.vn/#/docs/app_in_app?id=x%e1%bb%ad-l%c3%bd-thanh-to%c3%a1n)
|
34
|
+
```ruby
|
35
|
+
response = MomoPay::Mobile.process(
|
36
|
+
partnerRefId: order_number,
|
37
|
+
amount: order_value,
|
38
|
+
appData: momo_token_from_app,
|
39
|
+
customerNumber: momo_phone_from_app
|
40
|
+
)
|
41
|
+
```
|
42
|
+
=> Example response data
|
43
|
+
```ruby
|
44
|
+
{
|
45
|
+
"status"=>0,
|
46
|
+
"message"=>"Thành công",
|
47
|
+
"amount"=>100000,
|
48
|
+
"transid"=>"230.....289",
|
49
|
+
"feeMoMo"=>0,
|
50
|
+
"signature"=>"2ab844bc9ae52.....0d04d85aef836e9"
|
51
|
+
}
|
52
|
+
```
|
53
|
+
- How to verify response by HMAC-SHA256
|
54
|
+
```ruby
|
55
|
+
MomoPay::Signature.verify!(response)
|
56
|
+
```
|
57
|
+
It will raise `MomoPay::SignatureError` exception when response data is not verified!
|
24
58
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
## Contributing
|
34
|
-
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/momo_pay. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
36
|
-
|
37
|
-
## License
|
38
|
-
|
39
|
-
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
40
|
-
|
41
|
-
## Code of Conduct
|
59
|
+
**Request to confirm transaction:** [detail from Momo](https://developers.momo.vn/#/docs/app_in_app?id=x%c3%a1c-nh%e1%ba%adn-giao-d%e1%bb%8bch)
|
60
|
+
```ruby
|
61
|
+
response = MomoPay::Transaction.confirm(
|
62
|
+
partnerRefId: order_number,
|
63
|
+
momoTransId: transid_from_process_output,
|
64
|
+
)
|
65
|
+
```
|
42
66
|
|
43
|
-
|
67
|
+
### To be continued...
|
data/lib/momo_pay.rb
CHANGED
@@ -2,6 +2,7 @@ require "http"
|
|
2
2
|
require 'openssl'
|
3
3
|
require 'base64'
|
4
4
|
require 'json'
|
5
|
+
require 'securerandom'
|
5
6
|
|
6
7
|
require "momo_pay/version"
|
7
8
|
require "momo_pay/config"
|
@@ -9,6 +10,7 @@ require "momo_pay/default"
|
|
9
10
|
require "momo_pay/error"
|
10
11
|
require "momo_pay/http"
|
11
12
|
require "momo_pay/mobile"
|
13
|
+
require "momo_pay/qr_code"
|
12
14
|
require "momo_pay/query_status"
|
13
15
|
require "momo_pay/query_string"
|
14
16
|
require "momo_pay/request"
|
data/lib/momo_pay/config.rb
CHANGED
@@ -3,12 +3,14 @@ module MomoPay
|
|
3
3
|
|
4
4
|
attr_accessor :domain
|
5
5
|
attr_accessor :public_key
|
6
|
+
attr_accessor :access_key
|
6
7
|
attr_accessor :secret_key
|
7
8
|
attr_accessor :partner_code
|
8
9
|
attr_accessor :partner_name
|
9
10
|
|
10
|
-
attr_accessor :
|
11
|
+
attr_accessor :verify_keys
|
11
12
|
attr_accessor :signature_confirm_keys
|
13
|
+
attr_accessor :signature_qr_code_keys
|
12
14
|
|
13
15
|
def public_key_pem
|
14
16
|
@public_key_pem ||= [
|
@@ -18,9 +20,19 @@ module MomoPay
|
|
18
20
|
].join("\n")
|
19
21
|
end
|
20
22
|
|
23
|
+
def get_verify_keys!(type)
|
24
|
+
keys = self.verify_keys[type]
|
25
|
+
return keys if keys.is_a?(Array)
|
26
|
+
raise MomoPay::SignatureError, "Verify type `#{type}` is not in #{self.verify_keys.keys.join(', ')}"
|
27
|
+
end
|
28
|
+
|
21
29
|
def initialize
|
22
|
-
self.signature_verify_keys = MomoPay::Default::SIGNATURE_VERIFY_KEYS
|
23
30
|
self.signature_confirm_keys = MomoPay::Default::SIGNATURE_CONFIRM_KEYS
|
31
|
+
self.signature_qr_code_keys = MomoPay::Default::SIGNATURE_QR_CODE_KEYS
|
32
|
+
self.verify_keys = {
|
33
|
+
mobile: MomoPay::Default::SIGNATURE_MOBILE_VERIFY_KEYS,
|
34
|
+
ipn: MomoPay::Default::SIGNATURE_IPN_VERIFY_KEYS,
|
35
|
+
}
|
24
36
|
end
|
25
37
|
|
26
38
|
end
|
data/lib/momo_pay/default.rb
CHANGED
@@ -1,8 +1,49 @@
|
|
1
1
|
module MomoPay
|
2
2
|
class Default
|
3
3
|
|
4
|
-
|
5
|
-
|
4
|
+
SIGNATURE_MOBILE_VERIFY_KEYS = [
|
5
|
+
'status',
|
6
|
+
'message',
|
7
|
+
'amount',
|
8
|
+
'transid',
|
9
|
+
]
|
10
|
+
|
11
|
+
SIGNATURE_IPN_VERIFY_KEYS = [
|
12
|
+
'partnerCode',
|
13
|
+
'accessKey',
|
14
|
+
'requestId',
|
15
|
+
'amount',
|
16
|
+
'orderId',
|
17
|
+
'orderInfo',
|
18
|
+
'orderType',
|
19
|
+
'transId',
|
20
|
+
'message',
|
21
|
+
'localMessage',
|
22
|
+
'responseTime',
|
23
|
+
'errorCode',
|
24
|
+
'payType',
|
25
|
+
'extraData',
|
26
|
+
]
|
27
|
+
|
28
|
+
SIGNATURE_CONFIRM_KEYS = [
|
29
|
+
'partnerCode',
|
30
|
+
'partnerRefId',
|
31
|
+
'requestType',
|
32
|
+
'requestId',
|
33
|
+
'momoTransId',
|
34
|
+
]
|
35
|
+
|
36
|
+
SIGNATURE_QR_CODE_KEYS = [
|
37
|
+
'partnerCode',
|
38
|
+
'accessKey',
|
39
|
+
'requestId',
|
40
|
+
'amount',
|
41
|
+
'orderId',
|
42
|
+
'orderInfo',
|
43
|
+
'returnUrl',
|
44
|
+
'notifyUrl',
|
45
|
+
'extraData',
|
46
|
+
]
|
6
47
|
|
7
48
|
end
|
8
49
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module MomoPay
|
2
|
+
class QrCode
|
3
|
+
|
4
|
+
def self.request(data)
|
5
|
+
data.merge!({
|
6
|
+
requestType: 'captureMoMoWallet',
|
7
|
+
accessKey: MomoPay.setup.access_key,
|
8
|
+
partnerCode: MomoPay.setup.partner_code,
|
9
|
+
partnerName: MomoPay.setup.partner_name,
|
10
|
+
})
|
11
|
+
data.merge!(signature: MomoPay::Signature.new(data, MomoPay.setup.signature_qr_code_keys).to_s)
|
12
|
+
|
13
|
+
MomoPay::Request.post('/gw_payment/transactionProcessor', data)
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
data/lib/momo_pay/request.rb
CHANGED
data/lib/momo_pay/signature.rb
CHANGED
@@ -1,12 +1,11 @@
|
|
1
1
|
module MomoPay
|
2
2
|
class Signature
|
3
3
|
|
4
|
-
def self.verify!(data)
|
5
|
-
momo_signature = self.new(data, MomoPay.setup.
|
4
|
+
def self.verify!(data, type)
|
5
|
+
momo_signature = self.new(data, MomoPay.setup.get_verify_keys!(type)).to_s
|
6
6
|
data_signature = data['signature'] || data[:signature]
|
7
|
-
if momo_signature
|
8
|
-
|
9
|
-
end
|
7
|
+
return true if momo_signature == data_signature
|
8
|
+
raise MomoPay::SignatureError, "Gem:#{momo_signature || 'nil'} vs Data:#{data_signature || 'nil'}"
|
10
9
|
end
|
11
10
|
|
12
11
|
def initialize(data, keys)
|
data/lib/momo_pay/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: momo_pay
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- KhoaRB
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-11-
|
11
|
+
date: 2019-11-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -73,6 +73,7 @@ files:
|
|
73
73
|
- lib/momo_pay/error.rb
|
74
74
|
- lib/momo_pay/http.rb
|
75
75
|
- lib/momo_pay/mobile.rb
|
76
|
+
- lib/momo_pay/qr_code.rb
|
76
77
|
- lib/momo_pay/query_status.rb
|
77
78
|
- lib/momo_pay/query_string.rb
|
78
79
|
- lib/momo_pay/request.rb
|
@@ -103,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
103
104
|
- !ruby/object:Gem::Version
|
104
105
|
version: '0'
|
105
106
|
requirements: []
|
106
|
-
rubygems_version: 3.0.
|
107
|
+
rubygems_version: 3.0.3
|
107
108
|
signing_key:
|
108
109
|
specification_version: 4
|
109
110
|
summary: Momo wallet SDK for RUBY
|