paytm-merchant 0.1.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 +7 -0
- data/.gitignore +9 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +144 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/paytm/merchant.rb +160 -0
- data/lib/paytm/merchant/encryption_new_p_g.rb +221 -0
- data/lib/paytm/merchant/generators/paytm_setup_generator.rb +15 -0
- data/lib/paytm/merchant/version.rb +5 -0
- data/paytm-merchant.gemspec +34 -0
- metadata +85 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: e4a499b9d32a0ae534d4962b1ccbcadab48fa6c0
|
|
4
|
+
data.tar.gz: 337bd82a94f5989d41ef05ea0a3b6a3f7fb3bb27
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 7239598b7f787b7523c279e3081d9f9fe8a81ca4f42f40d43464eeba16ae9f6661f57a6cbea9460a02c33accd23daf0cd2d1bfc6dd4c25dc8ed48d61c8f4b086
|
|
7
|
+
data.tar.gz: 1ad2ab76368be71d21c73c40e3e938ae84ea5fce786d64683e887053e8fb6997d94c9a4a63eb9a49072adcc63f8d96f549676a0460bf17a5f6f2c3d18453ffd9
|
data/.gitignore
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 schnmudgal@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 Sachin
|
|
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,144 @@
|
|
|
1
|
+
# Paytm Merchant
|
|
2
|
+
|
|
3
|
+
This is a ruby library(and not just rails gem) for PayTM Merchant transactions API. You can easily integrate you application to pay your users/winners by calling `Paytm.new({amount: 110, phone: '7777777777'}).transfer`
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Add this line to your application's Gemfile:
|
|
8
|
+
|
|
9
|
+
```ruby
|
|
10
|
+
gem 'paytm-merchant'
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
And then execute:
|
|
14
|
+
|
|
15
|
+
$ bundle
|
|
16
|
+
|
|
17
|
+
Or install it yourself as:
|
|
18
|
+
|
|
19
|
+
$ gem install paytm-merchant
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
To setup, first initialize the library with credentials.
|
|
24
|
+
|
|
25
|
+
```ruby
|
|
26
|
+
Paytm.config do |paytm|
|
|
27
|
+
# paytm.base_uri = 'Some Base URI' # Default is staging api URI fpr paytm
|
|
28
|
+
paytm.merchant_guid = 'Paytm Merchant Guid'
|
|
29
|
+
paytm.aes_key = 'Paytm AES Key'
|
|
30
|
+
paytm.sales_wallet_id = 'Paytm Sales Wallet Id'
|
|
31
|
+
end
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
For Rails:
|
|
35
|
+
|
|
36
|
+
$ rails generate paytm_setup
|
|
37
|
+
|
|
38
|
+
The above line will create a `paytm.rb` file initializes directory where you can update the credentials.
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
### Funtionality
|
|
42
|
+
|
|
43
|
+
Create paytm object of `Paytm` class.
|
|
44
|
+
|
|
45
|
+
```ruby
|
|
46
|
+
paytm_obj = Paytm.new(
|
|
47
|
+
amount: 120,
|
|
48
|
+
recipient: User.last,
|
|
49
|
+
phone: '7777777777',
|
|
50
|
+
email: 'user@example.com'
|
|
51
|
+
)
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
#### Transfer
|
|
55
|
+
```ruby
|
|
56
|
+
paytm_obj.transfer # Returns the HTTParty response object
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
You can specify different options for transfer
|
|
60
|
+
|
|
61
|
+
```ruby
|
|
62
|
+
paytm_obj.transfer(
|
|
63
|
+
request_type: nil, # +nil+ for normal transfer request
|
|
64
|
+
merchant_order_id: 'Unique id per transaction', # Default order id is made using phone number and current timestamp
|
|
65
|
+
sales_wallet_name: 'As per your paytm credentials', # Leave blank if not known
|
|
66
|
+
payee_sso_id: 'As per your paytm credentials', # Leave blank if not known
|
|
67
|
+
applied_to_new_users: 'Y', # 'Y' or 'N'; Whether to create paytm account for new phone no.
|
|
68
|
+
amount: 150,
|
|
69
|
+
currency_code: 'INR' # Currency code specified by Paytm. Default 'INR'
|
|
70
|
+
metadata: 'Test Transaction', # Extra details to be sent for transaction
|
|
71
|
+
ip_address: '127.0.0.1', # As you want
|
|
72
|
+
)
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Response
|
|
76
|
+
```ruby
|
|
77
|
+
{"type"=>nil,
|
|
78
|
+
"requestGuid"=>nil,
|
|
79
|
+
"orderId"=>"7777777777-1485612494",
|
|
80
|
+
"status"=>"SUCCESS",
|
|
81
|
+
"statusCode"=>"SUCCESS",
|
|
82
|
+
"statusMessage"=>"SUCCESS",
|
|
83
|
+
"response"=>{"walletSysTransactionId"=>"515571"},
|
|
84
|
+
"metadata"=>""}
|
|
85
|
+
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
#### Check Transaction
|
|
89
|
+
```ruby
|
|
90
|
+
paytm_obj.new.check_transaction_status_for('515571') # First agrument is paytm wallet txn id recieved in txn response
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
You can specify different options
|
|
94
|
+
```ruby
|
|
95
|
+
paytm_obj.new.check_transaction_status_for(
|
|
96
|
+
'515571', # This id is the id as per in +transaction_id_type+ option
|
|
97
|
+
{
|
|
98
|
+
transaction_id_type: :paytm_transaction_id, # Possible values, :paytm_transaction_id, :merchant_order_id, :refund_reference_id. Default is :paytm_transaction_id
|
|
99
|
+
transaction_type: 'salestouser', # Possible values as per Paytm API
|
|
100
|
+
|
|
101
|
+
}
|
|
102
|
+
)
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Response
|
|
106
|
+
|
|
107
|
+
```ruby
|
|
108
|
+
{
|
|
109
|
+
"type"=>nil,
|
|
110
|
+
"requestGuid"=>nil,
|
|
111
|
+
"orderId"=>nil,
|
|
112
|
+
"status"=>"SUCCESS",
|
|
113
|
+
"statusCode"=>"SS_001",
|
|
114
|
+
"statusMessage"=>"SUCCESS",
|
|
115
|
+
"response"=>
|
|
116
|
+
{"txnList"=>
|
|
117
|
+
[{
|
|
118
|
+
"txnGuid"=>"515323",
|
|
119
|
+
"txnAmount"=>110,
|
|
120
|
+
"status"=>1,
|
|
121
|
+
"message"=>"SUCCESS",
|
|
122
|
+
"txnErrorCode"=>nil,
|
|
123
|
+
"ssoId"=>"11065108",
|
|
124
|
+
"txnType"=>"SALES_TO_USER_CREDIT",
|
|
125
|
+
"merchantOrderId"=>"7777777777-1485604732",
|
|
126
|
+
"pgTxnId"=>"\"null\"",
|
|
127
|
+
"pgRefundId"=>"\"null\"",
|
|
128
|
+
"cashbackTxnId"=>nil,
|
|
129
|
+
"isLimitPending"=>false
|
|
130
|
+
}]
|
|
131
|
+
},
|
|
132
|
+
"metadata"=>nil
|
|
133
|
+
}
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
## Contributing
|
|
137
|
+
|
|
138
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/schnmudgal/paytm. 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.
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
## License
|
|
142
|
+
|
|
143
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
|
144
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "paytm/merchant"
|
|
5
|
+
|
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
8
|
+
|
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
10
|
+
# require "pry"
|
|
11
|
+
# Pry.start
|
|
12
|
+
|
|
13
|
+
require "irb"
|
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
require "paytm/merchant/version"
|
|
2
|
+
require 'paytm/merchant/encryption_new_p_g'
|
|
3
|
+
require 'httparty'
|
|
4
|
+
|
|
5
|
+
module PayTM
|
|
6
|
+
module Merchant
|
|
7
|
+
include EncryptionNewPG
|
|
8
|
+
include HTTParty
|
|
9
|
+
extend EncryptionNewPG
|
|
10
|
+
|
|
11
|
+
# Class Variables
|
|
12
|
+
@@base_uri = nil
|
|
13
|
+
@@merchant_guid = nil
|
|
14
|
+
@@aes_key = nil
|
|
15
|
+
@@sales_wallet_id = nil
|
|
16
|
+
|
|
17
|
+
# Constants
|
|
18
|
+
Staging_Base_Uri = 'http://trust-uat.paytm.in'
|
|
19
|
+
End_Points = {
|
|
20
|
+
salestouser: '/wallet-web/salesToUserCredit',
|
|
21
|
+
checkstatus: '/wallet-web/checkStatus'
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
# Attr_accessors
|
|
25
|
+
attr_accessor :amount, :recipient, :phone, :email, :metadata
|
|
26
|
+
|
|
27
|
+
# Class Methods
|
|
28
|
+
class << self
|
|
29
|
+
|
|
30
|
+
def base_uri=(value)
|
|
31
|
+
@@base_uri = value
|
|
32
|
+
end
|
|
33
|
+
def merchant_guid=(value)
|
|
34
|
+
@@merchant_guid = value
|
|
35
|
+
end
|
|
36
|
+
def aes_key=(value)
|
|
37
|
+
@@aes_key = value
|
|
38
|
+
end
|
|
39
|
+
def sales_wallet_id=(value)
|
|
40
|
+
@@sales_wallet_id = value
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def config(&block)
|
|
44
|
+
instance_eval(&block)
|
|
45
|
+
set_httparty_base_uri
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# Base URI for HTTParty requests
|
|
49
|
+
def set_httparty_base_uri
|
|
50
|
+
base_uri(@@base_uri || Staging_Base_Uri)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def check_transaction_status_for(transaction_id, options = {})
|
|
54
|
+
new.check_transaction_status_for transaction_id, options
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
# Instance Methods
|
|
60
|
+
def initialize(data = {})
|
|
61
|
+
@amount = data[:amount]
|
|
62
|
+
@recipient = data[:recipient]
|
|
63
|
+
@phone = data[:phone]
|
|
64
|
+
@email = data[:email]
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def transfer(options = {})
|
|
68
|
+
@amount = amount if options[:amount]
|
|
69
|
+
|
|
70
|
+
@response = self.class.post(
|
|
71
|
+
End_Points[:salestouser],
|
|
72
|
+
{ body: paytm_request_body(options).to_json, headers: paytm_request_headers }
|
|
73
|
+
)
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def check_transaction_status_for(transaction_id, options = {})
|
|
77
|
+
check_transaction_body = paytm_check_transation_status_body(transaction_id, options)
|
|
78
|
+
@response = self.class.post(
|
|
79
|
+
End_Points[:checkstatus],
|
|
80
|
+
{
|
|
81
|
+
body: check_transaction_body.to_json,
|
|
82
|
+
headers: paytm_check_transation_status_header(check_transaction_body)
|
|
83
|
+
}
|
|
84
|
+
)
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
private
|
|
89
|
+
|
|
90
|
+
def paytm_check_transation_status_body(transaction_id, options = {})
|
|
91
|
+
case options[:transaction_id_type]
|
|
92
|
+
when :paytm_transaction_id
|
|
93
|
+
request_type = 'wallettxnid' # Default
|
|
94
|
+
when :merchant_order_id
|
|
95
|
+
request_type = 'merchanttxnid'
|
|
96
|
+
when :refund_reference_id
|
|
97
|
+
request_type = 'refundreftxnid'
|
|
98
|
+
else
|
|
99
|
+
request_type = 'wallettxnid'
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
transaction_type = options[:transaction_type] || 'salestouser'
|
|
103
|
+
|
|
104
|
+
{
|
|
105
|
+
request: {
|
|
106
|
+
requestType: request_type,
|
|
107
|
+
txnType: transaction_type,
|
|
108
|
+
txnId: transaction_id,
|
|
109
|
+
merchantGuid: @@merchant_guid
|
|
110
|
+
},
|
|
111
|
+
platformName: 'PayTM',
|
|
112
|
+
operationType: 'CHECK_TXN_STATUS'
|
|
113
|
+
}
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
def paytm_check_transation_status_header(check_transaction_body)
|
|
117
|
+
paytm_request_headers(check_transaction_body)
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
def paytm_request_body(options = {})
|
|
121
|
+
{
|
|
122
|
+
request: {
|
|
123
|
+
requestType: options[:request_type],
|
|
124
|
+
merchantGuid: @@merchant_guid,
|
|
125
|
+
merchantOrderId: options[:merchant_order_id] || "#{ @phone }-#{ Time.current.to_i }",
|
|
126
|
+
salesWalletName: options[:sales_wallet_name],
|
|
127
|
+
salesWalletGuid: @@sales_wallet_id,
|
|
128
|
+
payeeEmailId: @email,
|
|
129
|
+
payeePhoneNumber: @phone,
|
|
130
|
+
payeeSsoId: options[:payee_sso_id] || '',
|
|
131
|
+
appliedToNewUsers: options[:applied_to_new_users] || 'Y',
|
|
132
|
+
amount: @amount,
|
|
133
|
+
currencyCode: options[:currency_code] || 'INR'
|
|
134
|
+
},
|
|
135
|
+
metadata: options[:metadata] || '',
|
|
136
|
+
ipAddress: options[:ip_address] || '127.0.0.1',
|
|
137
|
+
platformName: 'PayTM',
|
|
138
|
+
operationType: 'SALES_TO_USER_CREDIT'
|
|
139
|
+
}
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
def paytm_request_headers(request_body = paytm_request_body)
|
|
143
|
+
{
|
|
144
|
+
'Content-Type' => 'application/json',
|
|
145
|
+
'Accept' => 'application/json',
|
|
146
|
+
'mid' => @@merchant_guid,
|
|
147
|
+
'checksumhash' => generate_hash(@@aes_key, request_body)
|
|
148
|
+
}
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
def generate_hash(key, params={})
|
|
152
|
+
@checksum = Paytm.new_pg_checksum_by_str(params.to_json, key).gsub("\n",'')
|
|
153
|
+
end
|
|
154
|
+
end
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
class Paytm
|
|
159
|
+
include PayTM::Merchant
|
|
160
|
+
end
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
module EncryptionNewPG
|
|
2
|
+
|
|
3
|
+
require 'openssl'
|
|
4
|
+
require 'base64'
|
|
5
|
+
require 'digest'
|
|
6
|
+
require 'securerandom'
|
|
7
|
+
|
|
8
|
+
### function returns dictionary of encrypted data ###
|
|
9
|
+
### accepts a dictionary with data and key to encrypt with ###
|
|
10
|
+
### can accept multiple key value pairs in the dictionary ###
|
|
11
|
+
def new_pg_encrypt(params)
|
|
12
|
+
if (params.class != Hash) || (params.keys == [])
|
|
13
|
+
return false
|
|
14
|
+
end
|
|
15
|
+
if !params.has_key?(:key)
|
|
16
|
+
return false
|
|
17
|
+
end
|
|
18
|
+
encrypted_data = Hash[]
|
|
19
|
+
key = params.delete(:key)
|
|
20
|
+
keys = params.keys
|
|
21
|
+
aes = OpenSSL::Cipher::Cipher.new("aes-128-cbc")
|
|
22
|
+
begin
|
|
23
|
+
keys.each do |k|
|
|
24
|
+
data = params[k]
|
|
25
|
+
aes.encrypt
|
|
26
|
+
aes.key = key
|
|
27
|
+
aes.iv = '@@@@&&&&####$$$$'
|
|
28
|
+
encrypted_k = aes.update(k.to_s) + aes.final
|
|
29
|
+
encrypted_k = Base64.encode64(encrypted_k.to_s)
|
|
30
|
+
aes.encrypt
|
|
31
|
+
aes.key = key
|
|
32
|
+
aes.iv = '@@@@&&&&####$$$$'
|
|
33
|
+
encrypted_data[encrypted_k] = aes.update(data.to_s) + aes.final
|
|
34
|
+
encrypted_data[encrypted_k] = Base64.encode64(encrypted_data[encrypted_k])
|
|
35
|
+
end
|
|
36
|
+
rescue Exception => e
|
|
37
|
+
return false
|
|
38
|
+
end
|
|
39
|
+
return encrypted_data
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
### function returns a single encrypted value ###
|
|
43
|
+
### input data -> value to be encrypted ###
|
|
44
|
+
### key -> key to use for encryption ###
|
|
45
|
+
def new_pg_encrypt_variable(data, key)
|
|
46
|
+
aes = OpenSSL::Cipher::Cipher.new("aes-128-cbc")
|
|
47
|
+
aes.encrypt
|
|
48
|
+
aes.key = key
|
|
49
|
+
aes.iv = '@@@@&&&&####$$$$'
|
|
50
|
+
encrypted_data = nil
|
|
51
|
+
begin
|
|
52
|
+
encrypted_data = aes.update(data.to_s) + aes.final
|
|
53
|
+
encrypted_data = Base64.encode64(encrypted_data)
|
|
54
|
+
rescue Exception => e
|
|
55
|
+
return false
|
|
56
|
+
end
|
|
57
|
+
return encrypted_data
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
### function returns dictionary of decrypted data ###
|
|
62
|
+
### accepts a dictionary with data and key to decrypt with ###
|
|
63
|
+
### can accept multiple key value pairs in the dictionary ###
|
|
64
|
+
def new_pg_decrypt(params)
|
|
65
|
+
if (params.class != Hash) || (params.keys == [])
|
|
66
|
+
return false
|
|
67
|
+
end
|
|
68
|
+
if !params.has_key?(:key)
|
|
69
|
+
return false
|
|
70
|
+
end
|
|
71
|
+
decrypted_data = Hash[]
|
|
72
|
+
key = params.delete(:key)
|
|
73
|
+
keys = params.keys
|
|
74
|
+
aes = OpenSSL::Cipher::Cipher.new("aes-128-cbc")
|
|
75
|
+
begin
|
|
76
|
+
keys.each do |k|
|
|
77
|
+
data = params[k]
|
|
78
|
+
aes.decrypt
|
|
79
|
+
aes.key = key
|
|
80
|
+
aes.iv = '@@@@&&&&####$$$$'
|
|
81
|
+
decrypted_k = Base64.decode64(k.to_s)
|
|
82
|
+
decrypted_k = aes.update(decrypted_k.to_s) + aes.final
|
|
83
|
+
if data.empty?
|
|
84
|
+
decrypted_data[decrypted_k] = ""
|
|
85
|
+
next
|
|
86
|
+
end
|
|
87
|
+
aes.decrypt
|
|
88
|
+
aes.key = key
|
|
89
|
+
aes.iv = '@@@@&&&&####$$$$'
|
|
90
|
+
data = Base64.decode64(data)
|
|
91
|
+
decrypted_data[decrypted_k] = aes.update(data) + aes.final
|
|
92
|
+
end
|
|
93
|
+
rescue Exception => e
|
|
94
|
+
return false
|
|
95
|
+
end
|
|
96
|
+
return decrypted_data
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
### function returns a single decrypted value ###
|
|
101
|
+
### input data -> value to be decrypted ###
|
|
102
|
+
### key -> key to use for decryption ###
|
|
103
|
+
def new_pg_decrypt_variable(data, key)
|
|
104
|
+
aes = OpenSSL::Cipher::Cipher.new("aes-128-cbc")
|
|
105
|
+
aes.decrypt
|
|
106
|
+
aes.key = key
|
|
107
|
+
aes.iv = '@@@@&&&&####$$$$'
|
|
108
|
+
decrypted_data = nil
|
|
109
|
+
begin
|
|
110
|
+
decrypted_data = Base64.decode64(data.to_s)
|
|
111
|
+
decrypted_data = aes.update(decrypted_data) + aes.final
|
|
112
|
+
rescue Exception => e
|
|
113
|
+
return false
|
|
114
|
+
end
|
|
115
|
+
return decrypted_data
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def new_pg_generate_salt(length)
|
|
120
|
+
salt = SecureRandom.urlsafe_base64(length*(3.0/4.0))
|
|
121
|
+
return salt.to_s
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
### function returns checksum of given key value pairs ###
|
|
126
|
+
### accepts a hash with key value pairs ###
|
|
127
|
+
### calculates sha256 checksum of given values ###
|
|
128
|
+
def new_pg_checksum(params, key, salt_length = 4)
|
|
129
|
+
if params.class != Hash
|
|
130
|
+
return false
|
|
131
|
+
end
|
|
132
|
+
if key.empty?
|
|
133
|
+
return false
|
|
134
|
+
end
|
|
135
|
+
salt = new_pg_generate_salt(salt_length)
|
|
136
|
+
keys = params.keys
|
|
137
|
+
str = nil
|
|
138
|
+
keys = keys.sort
|
|
139
|
+
keys.each do |k|
|
|
140
|
+
if str.nil?
|
|
141
|
+
str = params[k].to_s
|
|
142
|
+
next
|
|
143
|
+
end
|
|
144
|
+
str = str + '|' + params[k].to_s
|
|
145
|
+
end
|
|
146
|
+
str = str + '|' + salt
|
|
147
|
+
check_sum = Digest::SHA256.hexdigest(str)
|
|
148
|
+
check_sum = check_sum + salt
|
|
149
|
+
### encrypting checksum ###
|
|
150
|
+
check_sum = new_pg_encrypt_variable(check_sum, key)
|
|
151
|
+
return check_sum
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
def new_pg_checksum_by_str(paramstr, key, salt_length = 4)
|
|
156
|
+
|
|
157
|
+
salt = new_pg_generate_salt(salt_length)
|
|
158
|
+
|
|
159
|
+
str = nil
|
|
160
|
+
|
|
161
|
+
str = paramstr + '|' + salt
|
|
162
|
+
check_sum = Digest::SHA256.hexdigest(str)
|
|
163
|
+
check_sum = check_sum + salt
|
|
164
|
+
### encrypting checksum ###
|
|
165
|
+
check_sum = new_pg_encrypt_variable(check_sum, key)
|
|
166
|
+
return check_sum
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
### function returns checksum of given key value pairs (must contain the :checksum key) ###
|
|
171
|
+
### accepts a hash with key value pairs ###
|
|
172
|
+
### calculates sha256 checksum of given values ###
|
|
173
|
+
### returns true if checksum is consistent ###
|
|
174
|
+
### returns false in case of inconsistency ###
|
|
175
|
+
def new_pg_verify_checksum(params, check_sum, key, salt_length = 4)
|
|
176
|
+
|
|
177
|
+
if params.class != Hash
|
|
178
|
+
return false
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
if key.empty?
|
|
182
|
+
return false
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
if check_sum.nil? || check_sum.empty?
|
|
186
|
+
return false
|
|
187
|
+
end
|
|
188
|
+
|
|
189
|
+
generated_check_sum = nil
|
|
190
|
+
check_sum = new_pg_decrypt_variable(check_sum, key)
|
|
191
|
+
|
|
192
|
+
if check_sum == false
|
|
193
|
+
return false
|
|
194
|
+
end
|
|
195
|
+
begin
|
|
196
|
+
salt = check_sum[(check_sum.length-salt_length), (check_sum.length)]
|
|
197
|
+
keys = params.keys
|
|
198
|
+
str = nil
|
|
199
|
+
keys = keys.sort
|
|
200
|
+
keys.each do |k|
|
|
201
|
+
if str.nil?
|
|
202
|
+
str = params[k].to_s
|
|
203
|
+
next
|
|
204
|
+
end
|
|
205
|
+
str = str + '|' + params[k].to_s
|
|
206
|
+
end
|
|
207
|
+
str = str + '|' + salt
|
|
208
|
+
generated_check_sum = Digest::SHA256.hexdigest(str)
|
|
209
|
+
generated_check_sum = generated_check_sum + salt
|
|
210
|
+
rescue Exception => e
|
|
211
|
+
return false
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
if check_sum == generated_check_sum
|
|
215
|
+
return true
|
|
216
|
+
else
|
|
217
|
+
return false
|
|
218
|
+
end
|
|
219
|
+
end
|
|
220
|
+
|
|
221
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
InitializerContent = "# Paytm initializer to setup with configurations
|
|
2
|
+
Paytm.config do |paytm|
|
|
3
|
+
# paytm.base_uri = 'Some Base URI' # Default is staging api URI fpr paytm
|
|
4
|
+
paytm.merchant_guid = 'Paytm Merchant Guid'
|
|
5
|
+
paytm.aes_key = 'Paytm AES Key'
|
|
6
|
+
paytm.sales_wallet_id = 'Paytm Sales Wallet Id'
|
|
7
|
+
end
|
|
8
|
+
"
|
|
9
|
+
|
|
10
|
+
class PaytmSetupGenerator < Rails::Generators::Base
|
|
11
|
+
desc "This generator creates an initializer file at config/initializers"
|
|
12
|
+
def create_initializer_file
|
|
13
|
+
create_file("config/initializers/paytm.rb", InitializerContent)
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'paytm/merchant/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = 'paytm-merchant'
|
|
8
|
+
spec.version = PayTM::Merchant::VERSION
|
|
9
|
+
spec.authors = ['Sachin']
|
|
10
|
+
spec.email = ['schnmudgal@gmail.com']
|
|
11
|
+
|
|
12
|
+
spec.summary = %q{Paytm: Merchant to User waller transfer library.}
|
|
13
|
+
spec.homepage = 'https://github.com/schnmudgal/paytm-merchant.git'
|
|
14
|
+
spec.license = 'MIT'
|
|
15
|
+
|
|
16
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
|
17
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
|
18
|
+
# if spec.respond_to?(:metadata)
|
|
19
|
+
# spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
|
|
20
|
+
# else
|
|
21
|
+
# raise "RubyGems 2.0 or newer is required to protect against " \
|
|
22
|
+
# "public gem pushes."
|
|
23
|
+
# end
|
|
24
|
+
|
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
|
26
|
+
f.match(%r{^(test|spec|features)/})
|
|
27
|
+
end
|
|
28
|
+
spec.bindir = 'exe'
|
|
29
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
30
|
+
spec.require_paths = ['lib']
|
|
31
|
+
|
|
32
|
+
spec.add_development_dependency 'bundler', '~> 1.13'
|
|
33
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
|
34
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: paytm-merchant
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.2
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Sachin
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2017-01-28 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.13'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.13'
|
|
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
|
+
description:
|
|
42
|
+
email:
|
|
43
|
+
- schnmudgal@gmail.com
|
|
44
|
+
executables: []
|
|
45
|
+
extensions: []
|
|
46
|
+
extra_rdoc_files: []
|
|
47
|
+
files:
|
|
48
|
+
- ".gitignore"
|
|
49
|
+
- CODE_OF_CONDUCT.md
|
|
50
|
+
- Gemfile
|
|
51
|
+
- LICENSE.txt
|
|
52
|
+
- README.md
|
|
53
|
+
- Rakefile
|
|
54
|
+
- bin/console
|
|
55
|
+
- bin/setup
|
|
56
|
+
- lib/paytm/merchant.rb
|
|
57
|
+
- lib/paytm/merchant/encryption_new_p_g.rb
|
|
58
|
+
- lib/paytm/merchant/generators/paytm_setup_generator.rb
|
|
59
|
+
- lib/paytm/merchant/version.rb
|
|
60
|
+
- paytm-merchant.gemspec
|
|
61
|
+
homepage: https://github.com/schnmudgal/paytm-merchant.git
|
|
62
|
+
licenses:
|
|
63
|
+
- MIT
|
|
64
|
+
metadata: {}
|
|
65
|
+
post_install_message:
|
|
66
|
+
rdoc_options: []
|
|
67
|
+
require_paths:
|
|
68
|
+
- lib
|
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
70
|
+
requirements:
|
|
71
|
+
- - ">="
|
|
72
|
+
- !ruby/object:Gem::Version
|
|
73
|
+
version: '0'
|
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
75
|
+
requirements:
|
|
76
|
+
- - ">="
|
|
77
|
+
- !ruby/object:Gem::Version
|
|
78
|
+
version: '0'
|
|
79
|
+
requirements: []
|
|
80
|
+
rubyforge_project:
|
|
81
|
+
rubygems_version: 2.4.6
|
|
82
|
+
signing_key:
|
|
83
|
+
specification_version: 4
|
|
84
|
+
summary: 'Paytm: Merchant to User waller transfer library.'
|
|
85
|
+
test_files: []
|