momo_pay 2.0 → 2.0.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 643839942d3b6571ca400f5039952dfc3918d7013585c33e16bdadf09d1109a1
4
- data.tar.gz: a2b1534be8afd77c8d435e9a95826711195133d70e0e5c6dd4493b18613eca18
3
+ metadata.gz: 4ad989c70a7c3e43d7727a262748e12f6fc369ac6fd07333bcfcada3fc2fc517
4
+ data.tar.gz: eb1566c60fe7b08d8e6ff7619fcd0231d400c857242705113df6a48678fa6ed8
5
5
  SHA512:
6
- metadata.gz: bf0332013009c0ea9697e86940935375386b24569ef81759100f2a12ecccedd814dbdef54c7cb97b2b14c0dd7c878e945e0ef44b3f7d8a64b45ff2c8bfafd630
7
- data.tar.gz: 645384cf12afc022848982110418ae316d2277123b6f8f77753e326525b3e020a9028f87beb748674c8592b534f88e7cb3e88cebfb10d16bf037d8e4af6f921c
6
+ metadata.gz: 7e3ea5f1a3828784886d4e958f810ee5aec218d2d855395bdfefd26840c76f7c3c879c92938d67207336b166373b880105d5b2cb81d58fa6c21b1e34c3d1084d
7
+ data.tar.gz: 0af952cd4c19e9db38c2a640019fbf2b4e946abd760c3e076efa61dbb8ec42318627e4a536d79493d621a1817ad21aabc614b9c680281ef846b1ec312659a4e2
data/README.md CHANGED
@@ -1,8 +1,5 @@
1
- # MomoPay
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
- TODO: Write usage instructions here
26
-
27
- ## Development
28
-
29
- 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.
30
-
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
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
- Everyone interacting in the MomoPay project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/momo_pay/blob/master/CODE_OF_CONDUCT.md).
67
+ ### To be continued...
@@ -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"
@@ -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 :signature_verify_keys
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
@@ -1,8 +1,49 @@
1
1
  module MomoPay
2
2
  class Default
3
3
 
4
- SIGNATURE_VERIFY_KEYS = %w(status message amount transid)
5
- SIGNATURE_CONFIRM_KEYS = %w(partnerCode partnerRefId requestType requestId momoTransId)
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
@@ -10,5 +10,9 @@ module MomoPay
10
10
  response.parse
11
11
  end
12
12
 
13
+ def self.random_id
14
+ "#{Time.now.strftime("%Y%m%d%H%M%S")}#{SecureRandom.hex(2)}"
15
+ end
16
+
13
17
  end
14
18
  end
@@ -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.signature_verify_keys).to_s
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 != data_signature
8
- raise MomoPay::SignatureError.new("#{momo_signature} vs #{data_signature}")
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)
@@ -1,3 +1,3 @@
1
1
  module MomoPay
2
- VERSION = "2.0"
2
+ VERSION = "2.0.2"
3
3
  end
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: '2.0'
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-01 00:00:00.000000000 Z
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.6
107
+ rubygems_version: 3.0.3
107
108
  signing_key:
108
109
  specification_version: 4
109
110
  summary: Momo wallet SDK for RUBY