naspay_rails 0.0.1 → 0.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 +4 -4
- data/.gitignore +0 -1
- data/Gemfile +0 -1
- data/Gemfile.lock +0 -24
- data/README.md +80 -17
- data/bin/naspay_rails +5 -0
- data/exe/naspay_rails_init +24 -0
- data/lib/config_files/naspay.yml +20 -0
- data/lib/initializers/naspay_rails.rb +5 -0
- data/lib/naspay_rails.rb +12 -2
- data/lib/naspay_rails/auth.rb +27 -0
- data/lib/naspay_rails/configuration.rb +6 -0
- data/lib/naspay_rails/transactions.rb +92 -0
- data/lib/naspay_rails/version.rb +1 -1
- data/naspay_rails.gemspec +7 -4
- metadata +24 -5
- data/exe/naspay_rails +0 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b311afec98ab5861fba8fb24a5731b2c44370ef107ed76961cb8ecc560b6f29c
|
4
|
+
data.tar.gz: f465013396e0dea0fb8fec45bcdccfe08ece0a8f7d92581ea32833aa39c4630f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 91556c4998f98b0b4646d726d3bb967fc185dcb6cc44f5188b5bda7dfd3f18f8d762b1bc4c11f5851f4dc3effdc5e503fdcc44b8ff3ad60fcbc8712f211d8806
|
7
|
+
data.tar.gz: 02af568a5fc501552a9c9b061ebaf0ef0156ee162181225d7f966477a3d0994c44a54dfec47d2a3c666feb97c8bc3adaaeb4dc78ec921c23f8ae04edeb2ebe03
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,35 +1,11 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
naspay_rails (0.1.6)
|
5
|
-
|
6
1
|
GEM
|
7
2
|
remote: https://rubygems.org/
|
8
3
|
specs:
|
9
|
-
diff-lcs (1.3)
|
10
|
-
rake (10.5.0)
|
11
|
-
rspec (3.7.0)
|
12
|
-
rspec-core (~> 3.7.0)
|
13
|
-
rspec-expectations (~> 3.7.0)
|
14
|
-
rspec-mocks (~> 3.7.0)
|
15
|
-
rspec-core (3.7.1)
|
16
|
-
rspec-support (~> 3.7.0)
|
17
|
-
rspec-expectations (3.7.0)
|
18
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
19
|
-
rspec-support (~> 3.7.0)
|
20
|
-
rspec-mocks (3.7.0)
|
21
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
22
|
-
rspec-support (~> 3.7.0)
|
23
|
-
rspec-support (3.7.1)
|
24
4
|
|
25
5
|
PLATFORMS
|
26
6
|
ruby
|
27
7
|
|
28
8
|
DEPENDENCIES
|
29
|
-
bundler (~> 1.16)
|
30
|
-
naspay_rails!
|
31
|
-
rake (~> 10.0)
|
32
|
-
rspec (~> 3.0)
|
33
9
|
|
34
10
|
BUNDLED WITH
|
35
11
|
1.16.1
|
data/README.md
CHANGED
@@ -1,38 +1,101 @@
|
|
1
1
|
# NaspayRails
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
**NaspayRails** is a Ruby library for Naspay Client-to-Server API interaction with handful
|
4
|
+
HTTP/JSON/JWT wrappers, access credentials protection through namespaced classes as standalone
|
5
|
+
services reflecting basic API routes, actions and requests.
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
9
|
-
|
9
|
+
NaspayRails is hosted on [rubygems](https://rubygems.org/) and installs with bundler (Gemfile):
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
```
|
11
|
+
gem 'naspay_rails'
|
12
|
+
or manually:
|
14
13
|
|
15
|
-
|
14
|
+
$ gem install naspay_rails
|
16
15
|
|
17
|
-
|
16
|
+
Assuming that the project is run on **Rails (>= 5.1.5)**, please `require 'naspay_rails'` at `application.rb` level and
|
17
|
+
run the below command:
|
18
|
+
|
19
|
+
$ bundle exec naspay_rails_init
|
18
20
|
|
19
|
-
|
21
|
+
It adds the following files to the project:
|
20
22
|
|
21
|
-
|
23
|
+
1. `config/naspay.yml` keeps secure credentials for each environment. Please fill it with data like this:
|
24
|
+
|
25
|
+
development:
|
26
|
+
api_endpoint: https://demo.naspay.net
|
27
|
+
api_login: login
|
28
|
+
api_password: password
|
29
|
+
merchant_login: merchant_login
|
30
|
+
merchant_password: merchant_pass
|
31
|
+
|
32
|
+
2. `config/initializers/naspay_rails.rb` makes us able to run `NaspayRails.configuration` anywhere in our App
|
33
|
+
and receive a dynamically generated class `NaspayRails::Configuration` with the attributes you entered above:
|
34
|
+
|
35
|
+
@secrets=
|
36
|
+
{:api_endpoint=>"https://demo.naspay.net",
|
37
|
+
:api_login=>"login",
|
38
|
+
:api_password=>"password",
|
39
|
+
:merchant_login=>"merchant_login",
|
40
|
+
:merchant_password=>"merchant_pass"
|
41
|
+
|
42
|
+
This how sensitive data processing works
|
22
43
|
|
23
44
|
## Usage
|
45
|
+
### Modules and mixins
|
46
|
+
|
47
|
+
GEM has a dedicated module for each API route namespace along with *module* methods representing actions, e.g. :
|
48
|
+
|
49
|
+
NaspayRails::Auth
|
50
|
+
methods: .get_token
|
51
|
+
NaspayRails::Transactions
|
52
|
+
methods: .get_list, .create_new(endpoint, params, token)
|
53
|
+
|
54
|
+
And separate own master level methods and configuration namespaces:
|
55
|
+
|
56
|
+
NaspayRails
|
57
|
+
methods: .configure, .configuration
|
58
|
+
|
59
|
+
NaspayRails::Configuration
|
60
|
+
attr_accessor :secrets
|
61
|
+
|
62
|
+
### Dealing with Naspay JWT tokens
|
63
|
+
|
64
|
+
First of all, getting 1-time JWT token from Naspay for any further API request looks like this (try out from rails console):
|
65
|
+
|
66
|
+
secrets = NaspayRails.configuration.secrets
|
67
|
+
auth_token = NaspayRails::Auth.get_token(secrets)
|
68
|
+
|
69
|
+
returns string value of a token
|
70
|
+
|
71
|
+
=> "really-long-jwt-string"
|
72
|
+
|
73
|
+
### Transactions
|
74
|
+
|
75
|
+
1. Getting the list of transactions via **GET** `/api/v1/transactions`:
|
76
|
+
|
77
|
+
After `require 'naspay_rails'` on application level, a mixed-in module is available throughout the App. Its
|
78
|
+
`.get_list` method accepts `endpoint` and `token` *strings* as arguments:
|
79
|
+
|
80
|
+
NaspayRails::Transactions.get_list(endpoint, token)
|
81
|
+
|
82
|
+
Response is a parsed **JSON** collection of latest transactions
|
83
|
+
|
84
|
+
2. Creating new transaction via **POST** `/api/v1/transactions`:
|
85
|
+
|
86
|
+
Request for a new payment accepts `endpoint`, `token` *strings* and `params` *hash*
|
24
87
|
|
25
|
-
|
88
|
+
NaspayRails::Transactions.create_new(endpoint, params, token)
|
26
89
|
|
27
|
-
|
90
|
+
Please note that `params` *hash* keys should be `:symbols`. The below keys are required:
|
28
91
|
|
29
|
-
|
92
|
+
:intent, :amount, :currency, :transaction_id, :description
|
30
93
|
|
31
|
-
|
94
|
+
All required keys except `:amount` should contain *string* values. Amount value is `BigDecimal`, e.g. `11.00`
|
32
95
|
|
33
|
-
|
96
|
+
`params` *hash* also takes optional keys:
|
34
97
|
|
35
|
-
|
98
|
+
:customer, :shipping_address
|
36
99
|
|
37
100
|
## License
|
38
101
|
|
data/bin/naspay_rails
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "naspay_rails"
|
4
|
+
|
5
|
+
# get Rails application folder
|
6
|
+
rails_folder = ENV['PWD']
|
7
|
+
|
8
|
+
# add naspay.yml file to the project
|
9
|
+
yaml_file = 'naspay.yml'
|
10
|
+
yaml_folder = File.expand_path('../../lib/config_files',__FILE__)
|
11
|
+
target_yaml_file = File.join(yaml_folder, yaml_file)
|
12
|
+
rails_yaml_file = File.join(rails_folder, 'config', yaml_file)
|
13
|
+
FileUtils.cp_r target_yaml_file, rails_yaml_file
|
14
|
+
|
15
|
+
# add naspay.rb initializer to the project
|
16
|
+
rb_file = 'naspay_rails.rb'
|
17
|
+
rb_folder = File.expand_path('../../lib/initializers',__FILE__)
|
18
|
+
target_rb_file = File.join(rb_folder, rb_file)
|
19
|
+
rails_rb_file = File.join(rails_folder, 'config/initializers', rb_file)
|
20
|
+
FileUtils.cp_r target_rb_file, rails_rb_file
|
21
|
+
|
22
|
+
# gitignore naspay.yml
|
23
|
+
ignore_file = '.gitignore'
|
24
|
+
File.exist?(ignore_file) ? File.open(ignore_file, 'a') { |f| f << "\n# Ignore naspay.yml sensitive data\n/config/naspay.yml\n" } : return
|
data/lib/config_files/naspay.yml
CHANGED
@@ -0,0 +1,20 @@
|
|
1
|
+
development:
|
2
|
+
api_endpoint:
|
3
|
+
api_login:
|
4
|
+
api_password:
|
5
|
+
merchant_login:
|
6
|
+
merchant_password:
|
7
|
+
|
8
|
+
test:
|
9
|
+
api_endpoint:
|
10
|
+
api_login:
|
11
|
+
api_password:
|
12
|
+
merchant_login:
|
13
|
+
merchant_password:
|
14
|
+
|
15
|
+
production:
|
16
|
+
api_endpoint:
|
17
|
+
api_login:
|
18
|
+
api_password:
|
19
|
+
merchant_login:
|
20
|
+
merchant_password:
|
data/lib/naspay_rails.rb
CHANGED
@@ -1,5 +1,15 @@
|
|
1
|
-
require
|
1
|
+
require 'naspay_rails/version'
|
2
|
+
require 'naspay_rails/configuration'
|
3
|
+
require 'naspay_rails/auth'
|
4
|
+
require 'naspay_rails/transactions'
|
2
5
|
|
3
6
|
module NaspayRails
|
4
|
-
|
7
|
+
|
8
|
+
def self.configuration
|
9
|
+
@configuration ||= Configuration.new
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.configure
|
13
|
+
yield configuration
|
14
|
+
end
|
5
15
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'uri'
|
3
|
+
|
4
|
+
module NaspayRails
|
5
|
+
module Auth
|
6
|
+
def self.get_token(params)
|
7
|
+
route_suffix = '/auth/token'
|
8
|
+
target_url = "#{params[:api_endpoint]}#{route_suffix}"
|
9
|
+
request_uri = URI.parse(target_url)
|
10
|
+
request = Net::HTTP::Get.new(request_uri)
|
11
|
+
request.basic_auth(
|
12
|
+
params[:api_login],
|
13
|
+
params[:api_password]
|
14
|
+
)
|
15
|
+
request['Accept'] = 'application/json'
|
16
|
+
request.set_form_data(
|
17
|
+
'grant_type' => 'client_credentials'
|
18
|
+
)
|
19
|
+
req_options = {
|
20
|
+
use_ssl: request_uri.scheme == 'https'
|
21
|
+
}
|
22
|
+
Net::HTTP.start(request_uri.hostname, request_uri.port, req_options) {
|
23
|
+
|http| JSON.parse(http.request(request).body).values.first
|
24
|
+
}
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'uri'
|
3
|
+
|
4
|
+
module NaspayRails
|
5
|
+
module Transactions
|
6
|
+
def self.get_list(endpoint, token)
|
7
|
+
route_suffix = '/api/v1/transactions'
|
8
|
+
target_url = "#{endpoint}#{route_suffix}"
|
9
|
+
request_uri = URI.parse(target_url)
|
10
|
+
request = Net::HTTP::Get.new(request_uri)
|
11
|
+
request["Authorization"] = "Bearer #{token}"
|
12
|
+
req_options = {
|
13
|
+
use_ssl: request_uri.scheme == 'https'
|
14
|
+
}
|
15
|
+
Net::HTTP.start(request_uri.hostname, request_uri.port, req_options) {
|
16
|
+
|http| JSON.parse(http.request(request).body)
|
17
|
+
}
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.create_new(endpoint, params, token)
|
21
|
+
route_suffix = '/api/v1/transactions'
|
22
|
+
target_url = "#{endpoint}#{route_suffix}"
|
23
|
+
request_uri = URI.parse(target_url)
|
24
|
+
request = Net::HTTP::Post.new(request_uri)
|
25
|
+
request["Authorization"] = "Bearer #{token}"
|
26
|
+
request["Content-Type"] = "application/json"
|
27
|
+
request["Accept"] = "application/json"
|
28
|
+
|
29
|
+
request_body =
|
30
|
+
case params.keys.sort
|
31
|
+
when %i[intent amount currency transaction_id description].sort
|
32
|
+
{
|
33
|
+
"intent" => params[:intent],
|
34
|
+
"amount" => params[:amount],
|
35
|
+
"currency" => params[:currency],
|
36
|
+
"merchantTransactionId" => params[:transaction_id],
|
37
|
+
"description" => params[:description]
|
38
|
+
}
|
39
|
+
when %i[intent amount currency transaction_id description customer].sort
|
40
|
+
{
|
41
|
+
"intent" => params[:intent],
|
42
|
+
"amount" => params[:amount],
|
43
|
+
"currency" => params[:currency],
|
44
|
+
"merchantTransactionId" => params[:transaction_id],
|
45
|
+
"description" => params[:description],
|
46
|
+
"customer" => {
|
47
|
+
"email" => params[:customer].try(:[], :email),
|
48
|
+
"phone" => params[:customer].try(:[], :phone),
|
49
|
+
"merchantCustomerId" => params[:customer].try(:[], :customer_id),
|
50
|
+
"locale" => params[:customer].try(:[], :locale),
|
51
|
+
"ip" => params[:customer].try(:[], :ip)
|
52
|
+
}
|
53
|
+
}
|
54
|
+
when %i[intent amount currency transaction_id description customer shipping_address].sort
|
55
|
+
{
|
56
|
+
"intent" => params[:intent],
|
57
|
+
"amount" => params[:amount],
|
58
|
+
"currency" => params[:currency],
|
59
|
+
"merchantTransactionId" => params[:transaction_id],
|
60
|
+
"description" => params[:description],
|
61
|
+
|
62
|
+
"customer" => {
|
63
|
+
"email" => params[:customer].try(:[], :email),
|
64
|
+
"phone" => params[:customer].try(:[], :phone),
|
65
|
+
"merchantCustomerId" => params[:customer].try(:[], :customer_id),
|
66
|
+
"locale" => params[:customer].try(:[], :locale),
|
67
|
+
"ip" => params[:customer].try(:[], :ip)
|
68
|
+
},
|
69
|
+
|
70
|
+
"shippingAddress" => {
|
71
|
+
"line1" => params[:shipping_address].try(:[], :line1),
|
72
|
+
"line2" => params[:shipping_address].try(:[], :line2),
|
73
|
+
"city" => params[:shipping_address].try(:[], :city),
|
74
|
+
"countryCode" => params[:shipping_address].try(:[], :country_code),
|
75
|
+
"postalCode" => params[:shipping_address].try(:[], :postal_code),
|
76
|
+
"state" => params[:shipping_address].try(:[], :state),
|
77
|
+
"phone" => params[:shipping_address].try(:[], :phone),
|
78
|
+
"recipientName" => params[:shipping_address].try(:[], :recipient_name)
|
79
|
+
}
|
80
|
+
}
|
81
|
+
else
|
82
|
+
return 'please check the keys provided in params Hash!'
|
83
|
+
end
|
84
|
+
request.body = JSON.dump(request_body)
|
85
|
+
req_options = {
|
86
|
+
use_ssl: request_uri.scheme == "https",
|
87
|
+
}
|
88
|
+
|
89
|
+
Net::HTTP.start(request_uri.hostname, request_uri.port, req_options) { |http| http.request(request) }
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
data/lib/naspay_rails/version.rb
CHANGED
data/naspay_rails.gemspec
CHANGED
@@ -8,7 +8,6 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = NaspayRails::VERSION
|
9
9
|
spec.authors = ["antonror"]
|
10
10
|
spec.email = ["antonmailingbox@gmail.com"]
|
11
|
-
|
12
11
|
spec.summary = %q{Naspay API interaction tool}
|
13
12
|
spec.description = %q{Ruby library for Naspay API}
|
14
13
|
spec.homepage = "https://naspay.com/"
|
@@ -30,7 +29,11 @@ Gem::Specification.new do |spec|
|
|
30
29
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
31
30
|
spec.require_paths = ["lib"]
|
32
31
|
|
33
|
-
spec.
|
34
|
-
spec.add_development_dependency
|
35
|
-
spec.add_development_dependency
|
32
|
+
spec.required_ruby_version = '>= 2.5.0'
|
33
|
+
spec.add_development_dependency 'bundler', '~> 1.16'
|
34
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
35
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
36
|
+
spec.add_runtime_dependency "thor", "~> 0.19.1"
|
37
|
+
|
38
|
+
spec.executables << 'naspay_rails_init'
|
36
39
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: naspay_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- antonror
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-03-
|
11
|
+
date: 2018-03-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,11 +52,25 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: thor
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.19.1
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.19.1
|
55
69
|
description: Ruby library for Naspay API
|
56
70
|
email:
|
57
71
|
- antonmailingbox@gmail.com
|
58
72
|
executables:
|
59
|
-
-
|
73
|
+
- naspay_rails_init
|
60
74
|
extensions: []
|
61
75
|
extra_rdoc_files: []
|
62
76
|
files:
|
@@ -71,10 +85,15 @@ files:
|
|
71
85
|
- README.md
|
72
86
|
- Rakefile
|
73
87
|
- bin/console
|
88
|
+
- bin/naspay_rails
|
74
89
|
- bin/setup
|
75
|
-
- exe/
|
90
|
+
- exe/naspay_rails_init
|
76
91
|
- lib/config_files/naspay.yml
|
92
|
+
- lib/initializers/naspay_rails.rb
|
77
93
|
- lib/naspay_rails.rb
|
94
|
+
- lib/naspay_rails/auth.rb
|
95
|
+
- lib/naspay_rails/configuration.rb
|
96
|
+
- lib/naspay_rails/transactions.rb
|
78
97
|
- lib/naspay_rails/version.rb
|
79
98
|
- naspay_rails.gemspec
|
80
99
|
homepage: https://naspay.com/
|
@@ -90,7 +109,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
90
109
|
requirements:
|
91
110
|
- - ">="
|
92
111
|
- !ruby/object:Gem::Version
|
93
|
-
version:
|
112
|
+
version: 2.5.0
|
94
113
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
114
|
requirements:
|
96
115
|
- - ">="
|
data/exe/naspay_rails
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require "naspay_rails"
|
4
|
-
|
5
|
-
|
6
|
-
file_name = 'naspay.yml'
|
7
|
-
|
8
|
-
yaml_folder = File.expand_path('../../lib/config_files',__FILE__)
|
9
|
-
yaml_file = File.join(yaml_folder, file_name)
|
10
|
-
|
11
|
-
rails_folder = ENV['PWD']
|
12
|
-
rails_file = File.join(rails_folder, 'config', file_name)
|
13
|
-
|
14
|
-
|
15
|
-
FileUtils.cp_r yaml_file, rails_file
|