module_pos-fiscalization 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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: '035096be2eb2940643fea88d9adfafc58398cc15ff3342a911e1a3e0ce00d58a'
4
+ data.tar.gz: 5d97c95845e358b773410a4ab76c1450b0d8482cdb85cbcdc461abf4f0efa8be
5
+ SHA512:
6
+ metadata.gz: e3dcfab30df2821ff26e536b9e23445306f0ef49de4da979e9f3b7c1ac3ce829e515f54c3f042924683b5c40da7baebad9901f42b8edc72a7846ac6552cd8b89
7
+ data.tar.gz: d994b9243d9a57c4e17189d0e67895e063b8364526f4cf73bc6085e438b66ccda7d80019765c35d8f033446857b15a1c613b66982154cb3e9e3d344c8b2a4a60
@@ -0,0 +1,30 @@
1
+ name: Ruby
2
+
3
+ on:
4
+ push:
5
+ branches: [ master ]
6
+ pull_request:
7
+ branches: [ master ]
8
+
9
+ jobs:
10
+ build:
11
+ runs-on: ubuntu-latest
12
+
13
+ steps:
14
+ - uses: actions/checkout@v2
15
+ - uses: actions/cache@v1.1.2
16
+ with:
17
+ path: vendor/bundle
18
+ key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}
19
+ restore-keys: |
20
+ ${{ runner.os }}-gems-
21
+ - name: Set up Ruby 2.5
22
+ uses: actions/setup-ruby@v1
23
+ with:
24
+ ruby-version: 2.5.x
25
+ - name: Build and test with Rake
26
+ run: |
27
+ gem install bundler
28
+ bundle config path vendor/bundle
29
+ bundle install --jobs 4 --retry 3
30
+ bundle exec rspec
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ .idea
10
+ Gemfile.lock
11
+
12
+ # rspec failure tracking
13
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.7.1
6
+ before_install: gem install bundler -v 2.1.4
@@ -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 skiline.alex@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 [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in modul-pos.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "rspec", "~> 3.0"
8
+ gem "pry"
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Alexander Shvaykin
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.
@@ -0,0 +1,87 @@
1
+ ![Ruby](https://github.com/AlexanderShvaykin/module_pos/workflows/Ruby/badge.svg)
2
+
3
+ # ModulePos::Fiscalization
4
+ Simple lib, wrapped https://modulkassa.ru API for fiscalization online receipts
5
+ version API v1.4
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem ' module_pos-fiscalization'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install module_pos-fiscalization
22
+
23
+ ## Usage
24
+
25
+ ```ruby
26
+ receipt = Order.find("some_id").receipt
27
+ host = "https://modulepos.test.server"
28
+ secrets = ModulePos::Fiscalization::Client.new(host: host).associate('you_uid').create(login: "login", secret: "secret")
29
+ user_name = secrets.user_name
30
+ pass = secrets.password
31
+
32
+ ModulePos::Fiscalization::Client.new(host: host, username: user_name, pass: pass) do |client|
33
+ if client.status.ready?
34
+ doc = ModulePos::Fiscalization::Doc.create(
35
+ doc_num: "Order-1",
36
+ id: "dda2911b-5681-4a02-bd3d-3f0d0df849da",
37
+ doc_type: "SALE",
38
+ checkout_date_time: "2019-08-16T15:45:17+07:00",
39
+ email: "example@example.com",
40
+ print_receipt: false,
41
+ responseURL: "https://internet.shop.ru/order/982340931/checkout?completed=1",
42
+ tax_mode: "COMMON",
43
+ invent_positions: [
44
+ {
45
+ barcode: "10001",
46
+ name: "Молоко Лебедевское, 2,5%",
47
+ price: 52,
48
+ discSum: "5.2",
49
+ quantity: 1,
50
+ vatTag: 1102,
51
+ payment_object: "commodity",
52
+ payment_method: "full_payment",
53
+ }
54
+ ],
55
+ moneyPositions: [{ paymentType: "CARD", sum: "46.8" }]
56
+ )
57
+
58
+ client.docs.save(doc)
59
+ client.docs.re_queue(doc.id) if client.docs.status(doc.id).failed?
60
+ until client.docs.status(doc.id).success? # may be background job
61
+ end
62
+ receipt.update(fiscal_info: client.docs.status(doc.id).as_json)
63
+ end
64
+ end
65
+
66
+ ```
67
+
68
+ Full available fields you find in documentation v1.4 ModuleBank POS Api, you can use snake_case and camelCase
69
+
70
+ ## Development
71
+
72
+ 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.
73
+
74
+ 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).
75
+
76
+ ## Contributing
77
+
78
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/modul-pos. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/modul-pos/blob/master/CODE_OF_CONDUCT.md).
79
+
80
+
81
+ ## License
82
+
83
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
84
+
85
+ ## Code of Conduct
86
+
87
+ Everyone interacting in the Modul::Pos project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/modul-pos/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "module_pos/fiscalization"
5
+ require "pry"
6
+
7
+ Pry.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,26 @@
1
+ require 'api_utils'
2
+ require "module_pos/fiscalization/version"
3
+ require "module_pos/fiscalization/types"
4
+ require "module_pos/fiscalization/json_request"
5
+ require "module_pos/fiscalization/client"
6
+ require "module_pos/fiscalization/entities/base"
7
+ require "module_pos/fiscalization/entities/secret"
8
+ require "module_pos/fiscalization/entities/agent_info"
9
+ require "module_pos/fiscalization/entities/position"
10
+ require "module_pos/fiscalization/entities/doc"
11
+ require "module_pos/fiscalization/entities/doc_status"
12
+ require "module_pos/fiscalization/entities/pos_status"
13
+
14
+ module ModulePos
15
+ module Fiscalization
16
+ ResponseError = Class.new(StandardError)
17
+
18
+ module Doc
19
+ module_function
20
+
21
+ def create(args)
22
+ Entities::Doc.new(args)
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,128 @@
1
+ require "date"
2
+ require 'faraday'
3
+
4
+ module ModulePos::Fiscalization
5
+ # Http client for Module POS api
6
+ class Client
7
+ ASSOCIATE_PATH = "api/fn/v1/associate"
8
+ STATUS_PATH = "api/fn/v1/status"
9
+ CREATE_DOC_PATH = "/api/fn/v2/doc"
10
+ DOC_PATH = "/api/fn/v1/doc"
11
+
12
+ module Scopes
13
+ class Base
14
+ def initialize(path, http, pass: nil, username: nil)
15
+ @path = path
16
+ @username = username
17
+ @pass = pass
18
+ @http = http
19
+ end
20
+
21
+ private
22
+ attr_reader :path, :username, :pass, :http
23
+ end
24
+
25
+ # Associate actions scope
26
+ class Associate < Base
27
+ # @param [String] client_id
28
+ # @return [ModulePos::V1::Entities::Secret]
29
+ # @param [String] login
30
+ # @param [String] secret
31
+ def create(login:, secret:, client_id: nil)
32
+ resp = http.call(login, secret) do |conn|
33
+ conn.post(path) do |req|
34
+ req.params["clientId"] = client_id if client_id
35
+ end
36
+ end
37
+
38
+ ModulePos::Fiscalization::Entities::Secret.new(resp)
39
+ end
40
+
41
+ # @return [NilClass]
42
+ # @param [String] username
43
+ # @param [String] password
44
+ def delete(username:, password:)
45
+ http.call(username, password) { |conn| conn.delete(path) }
46
+ nil
47
+ end
48
+ end
49
+
50
+ # Docs actions scope
51
+ class Docs < Base
52
+ # Send doc to modulpose
53
+ # @param [ModulePos::Fiscalization::Entities::Doc] doc
54
+ # @return [ModulePos::Fiscalization::Entities::DocStatus]
55
+ def save(doc)
56
+ resp = http.call(username, pass) do |conn|
57
+ conn.post(CREATE_DOC_PATH) do |req|
58
+ req.body = doc.to_json
59
+ end
60
+ end
61
+
62
+ ModulePos::Fiscalization::Entities::DocStatus.new(resp)
63
+ end
64
+
65
+ # @param [String] id
66
+ # @return [ModulePos::Fiscalization::Entities::DocStatus]
67
+ def status(id)
68
+ resp = http.call(username, pass) do |conn|
69
+ conn.get("#{path}/#{id}/status")
70
+ end
71
+
72
+ ModulePos::Fiscalization::Entities::DocStatus.new(resp)
73
+ end
74
+
75
+ # @param [String] id
76
+ # @return [ModulePos::Fiscalization::Entities::DocStatus]
77
+ def re_queue(id)
78
+ resp = http.call(username, pass) do |conn|
79
+ conn.put("#{path}/#{id}/re-queue")
80
+ end
81
+
82
+ ModulePos::Fiscalization::Entities::DocStatus.new(resp)
83
+ end
84
+ end
85
+ end
86
+
87
+ # Return associate scope, for actions to associate recourse
88
+ # @param [String] uid
89
+ # @return [ModulePos::V1::Client::Scopes::Associate]
90
+ def associate(uid)
91
+ Scopes::Associate.new("#{ASSOCIATE_PATH}/#{uid}", http)
92
+ end
93
+
94
+ # Return associate scope, for actions to doc
95
+ # @return [ModulePos::V1::Client::Scopes::Docs]
96
+ def docs
97
+ Scopes::Docs.new(DOC_PATH, http, username: username, pass: pass)
98
+ end
99
+
100
+ # Request POS status, return
101
+ # { status: "READY|ASSOCIATED|FAILED", date_time: <DateTime> }
102
+ # @return [Hash]
103
+ def status
104
+ res = http.call(username, pass) { |conn| conn.get(STATUS_PATH) }
105
+ ModulePos::Fiscalization::Entities::PosStatus.new(res)
106
+ end
107
+
108
+ private
109
+
110
+ attr_reader :http, :username, :pass
111
+
112
+ def initialize(
113
+ host:,
114
+ username: nil,
115
+ pass: nil,
116
+ conn: Faraday.new(
117
+ url: host,
118
+ headers: { 'Content-Type' => 'application/json' }
119
+ ),
120
+ logger: nil
121
+ )
122
+ @http = JsonRequest.new(conn, logger)
123
+ @username = username
124
+ @pass = pass
125
+ yield(self) if block_given?
126
+ end
127
+ end
128
+ end
@@ -0,0 +1,28 @@
1
+ require "dry-struct"
2
+
3
+ module ModulePos::Fiscalization
4
+ module Entities
5
+ class AgentInfo < Base
6
+ class Agent < Base
7
+ attribute? :operation, Types::String.constrained(max_size: 24)
8
+ attribute? :phones, Types::Array.of(Types::Coercible::String)
9
+ end
10
+
11
+ class PaymentsOperator < Base
12
+ attribute? :phones, Types::Array.of(Types::Coercible::String)
13
+ end
14
+
15
+ class TransferOperator < Base
16
+ attribute? :phones, Types::Array.of(Types::Coercible::String)
17
+ attribute? :name, Types::String.constrained(max_size: 64)
18
+ attribute? :address, Types::String.constrained(max_size: 255)
19
+ attribute? :inn, Types::TaxId
20
+ end
21
+
22
+ attribute? :types, Types::Array.of(Types::AgentType)
23
+ attribute? :paying_agent, Agent
24
+ attribute? :money_transfer_operator, TransferOperator
25
+ attribute? :receive_payments_operator, PaymentsOperator
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,39 @@
1
+ require "dry-struct"
2
+
3
+ module ModulePos::Fiscalization
4
+ module Entities
5
+ class Base < Dry::Struct
6
+ transform_keys ->(key) {
7
+ key.to_s
8
+ .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
9
+ .gsub(/([a-z\d])([A-Z])/, '\1_\2')
10
+ .tr('-', '_')
11
+ .gsub(/\s/, '_')
12
+ .gsub(/__+/, '_')
13
+ .downcase
14
+ .to_sym
15
+ }
16
+
17
+ # Return camelize hash for request
18
+ # @return [Hash]
19
+ def as_json(*)
20
+ ApiUtils.camelize_keys attributes, ->(val) {
21
+ case val
22
+ when Base
23
+ val.as_json
24
+ when BigDecimal
25
+ val.to_f
26
+ else
27
+ val
28
+ end
29
+ }
30
+ end
31
+ alias_method :to_h, :as_json
32
+
33
+ def to_json
34
+ to_h.to_json
35
+ end
36
+ end
37
+ end
38
+ end
39
+
@@ -0,0 +1,29 @@
1
+ module ModulePos::Fiscalization
2
+ module Entities
3
+ class Doc < Base
4
+ class MoneyPosition < Base
5
+ attribute :payment_type, Types::PaymentType
6
+ attribute :sum, ModulePos::Fiscalization::Types::Coercible::Decimal
7
+ end
8
+
9
+ attribute :id, Types::Coercible::String
10
+ attribute :checkout_date_time, Types::JSON::DateTime
11
+ attribute :doc_num, Types::Coercible::String
12
+ attribute :doc_type, Types::DocType
13
+ attribute :email, Types::Email
14
+ attribute :money_positions, Types::Array.of(MoneyPosition)
15
+ attribute :invent_positions, Types::Array.of(Position)
16
+
17
+ attribute? :print_receipt, Types::Strict::Bool
18
+ attribute? :text_to_print, Types::Coercible::String
19
+ attribute? :cashier_name, Types::Coercible::String
20
+ attribute? :cashier_inn, Types::TaxId
21
+ attribute? :cashier_position, Types::String.constrained(max_size: 64)
22
+ attribute? :response_url, Types::String
23
+ attribute? :tax_mode, Types::TaxMode
24
+ attribute? :client_name, Types::String
25
+ attribute? :client_inn, Types::TaxId
26
+ attribute? :agent_info, AgentInfo
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,49 @@
1
+ module ModulePos::Fiscalization
2
+ module Entities
3
+ class DocStatus < Base
4
+ class FiscalInfo < Base
5
+ attribute :shift_number, Types::Coercible::Integer
6
+ attribute :check_number, Types::Coercible::Integer
7
+ attribute :kkt_number, Types::String
8
+ attribute :fn_number, Types::String
9
+ attribute :fn_doc_number, Types::Coercible::Integer
10
+ attribute :fn_doc_mark, Types::Coercible::Integer
11
+ attribute :date, Types::String
12
+ attribute :sum, ModulePos::Fiscalization::Types::Coercible::Decimal
13
+ attribute :check_type, Types::String
14
+ attribute :qr, Types::String
15
+ attribute :ecr_registration_number, Types::String
16
+ end
17
+
18
+ class FailureInfo < Base
19
+ attribute :type, Types::String
20
+ attribute :message, Types::String
21
+ end
22
+
23
+ attribute :status, Types::DocStatus
24
+ attribute :fn_state, Types::String
25
+ attribute? :fiscal_info, FiscalInfo
26
+ attribute? :failure_info, FailureInfo
27
+ attribute? :message, Types::String
28
+ attribute? :time_status_changed, Types::String
29
+
30
+ def failed?
31
+ status == "FAILED"
32
+ end
33
+
34
+ def pending?
35
+ status == "PENDING"
36
+ end
37
+
38
+ def printed?
39
+ status == "PRINTED"
40
+ end
41
+ alias_method :success?, :printed?
42
+
43
+ def completed?
44
+ status == "COMPLETED"
45
+ end
46
+ end
47
+ end
48
+ end
49
+
@@ -0,0 +1,13 @@
1
+ module ModulePos::Fiscalization
2
+ module Entities
3
+ class PosStatus < Base
4
+ attribute :status, Types::PosStatus
5
+ attribute :date_time, Types::String
6
+
7
+ def ready?
8
+ status == "READY"
9
+ end
10
+ end
11
+ end
12
+ end
13
+
@@ -0,0 +1,28 @@
1
+ module ModulePos::Fiscalization
2
+ module Entities
3
+ class Position < Base
4
+ class SupplierInfo < Base
5
+ attribute? :phones, Types::Array.of(Types::Coercible::String)
6
+ attribute? :name, Types::String.constrained(max_size: 255)
7
+ attribute? :inn, Types::TaxId
8
+ end
9
+
10
+ attribute :name, Types::String.constrained(max_size: 128)
11
+ attribute :price, ModulePos::Fiscalization::Types::Coercible::Decimal
12
+ attribute :quantity, ModulePos::Fiscalization::Types::Coercible::Decimal
13
+ attribute :vat_tag, Types::VatTag
14
+
15
+ attribute? :barcode, Types::Coercible::String
16
+ attribute? :product_mark, Types::String.constrained(max_size: 255)
17
+ attribute? :nomenclature_code, Types::String
18
+ attribute? :vat_sum, Types::String
19
+ attribute? :payment_object, Types::PaymentObject
20
+ attribute? :payment_method, Types::PaymentMethod
21
+ attribute? :disc_sum, ModulePos::Fiscalization::Types::Coercible::Decimal
22
+ attribute? :origin_country_code, Types::Integer
23
+ attribute? :customs_declaration_number, Types::String.constrained(max_size: 32)
24
+ attribute? :agent_info, AgentInfo
25
+ attribute? :supplier_info, SupplierInfo
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,15 @@
1
+ module ModulePos::Fiscalization
2
+ module Entities
3
+ # Credentials for protect api methods
4
+ # :user_name - [String]
5
+ # :password - [String]
6
+ # :name - [String]
7
+ # :address - [String]
8
+ class Secret < Base
9
+ attribute :user_name, Types::String
10
+ attribute :password, Types::String
11
+ attribute? :name, Types::String
12
+ attribute? :address, Types::String
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,26 @@
1
+ require 'json'
2
+
3
+ module ModulePos::Fiscalization
4
+ class JsonRequest
5
+ InvalidResponse = Class.new(StandardError)
6
+
7
+ def call(user = nil, pass = nil)
8
+ @conn.basic_auth(user, pass) if user && pass
9
+ response = yield @conn
10
+ if response.status.to_s.match?(/2[0-9][0-9]/)
11
+ JSON.parse!(response.body).compact unless response.body.empty?
12
+ else
13
+ raise ResponseError, "Status: #{response.status} Response: #{response.body}"
14
+ end
15
+ rescue JSON::ParserError
16
+ raise InvalidResponse
17
+ end
18
+
19
+ private
20
+
21
+ def initialize(conn, logger = nil)
22
+ @conn = conn
23
+ @conn.response(:logger, logger) if logger
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,43 @@
1
+ require "dry-types"
2
+
3
+ module ModulePos::Fiscalization
4
+ class Types
5
+ include Dry.Types()
6
+
7
+ PosStatus = Types::String.enum('READY', 'ASSOCIATED', 'FAILED')
8
+
9
+ DocStatus = Types::String.enum(
10
+ 'QUEUED', 'PENDING', 'PRINTED', 'WAIT_FOR_CALLBACK', 'COMPLETED', 'FAILED'
11
+ )
12
+
13
+ PaymentMethod = Types::Coercible::String.enum(
14
+ 'full_prepayment', 'prepayment', 'advance', 'full_payment', 'partial_payment', 'credit',
15
+ 'credit_payment'
16
+ )
17
+ PaymentObject = Types::Coercible::String.enum(
18
+ 'commodity', 'excise', 'job', 'service', 'gambling_bet', 'gambling_prize', 'lottery',
19
+ 'lottery_prize', 'intellectual_activity', 'payment', 'agent_commission', 'composite',
20
+ 'another', 'property_right', 'non-operating_gain', 'insurance_premium', 'sales_tax',
21
+ 'resort_fee'
22
+ )
23
+ VatTag = Types::Integer.enum(
24
+ 1104 => :zero,
25
+ 1103 => :percent10,
26
+ 1102 => :percent20,
27
+ 1105 => :no_tax,
28
+ 1107 => :delay10,
29
+ 1106 => :delay20
30
+ )
31
+ PaymentType = Types::String.enum('CARD', 'CASH', 'PREPAID', 'POSTPAY', 'OTHER')
32
+ AgentType = Types::Coercible::String.enum(
33
+ 'bank_paying_agent', 'bank_paying_subagent', 'paying_agent', 'paying_subagent', 'attorney',
34
+ 'commission_agent', 'another'
35
+ )
36
+ DocType = Types::String.enum('SALE', 'RETURN', 'BUY', 'BUY_RETURN')
37
+ TaxMode = Types::String.enum(
38
+ 'COMMON', 'SIMPLIFIED', 'SIMPLIFIED_WITH_EXPENSE', 'ENVD', 'PATENT', 'COMMON_AGRICULTURAL'
39
+ )
40
+ Email = Types::String.constrained(format: /^.*@.*$/)
41
+ TaxId = Types::Coercible::String.constrained(format: /^[0-9]{10,12}$/)
42
+ end
43
+ end
@@ -0,0 +1,5 @@
1
+ module ModulePos
2
+ module Fiscalization
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,31 @@
1
+ require_relative 'lib/module_pos/fiscalization/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "module_pos-fiscalization"
5
+ spec.version = ModulePos::Fiscalization::VERSION
6
+ spec.authors = ["Alexander Shvaykin"]
7
+ spec.email = ["skiline.alex@gmail.com"]
8
+
9
+ spec.summary = "API wrapper for Module Bank POS"
10
+ spec.description = "API wrapper for Module Bank POS"
11
+ spec.homepage = "http://github.com/AlexanderShvaykin/module_pos"
12
+ spec.license = "MIT"
13
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.5.5")
14
+
15
+ spec.metadata["homepage_uri"] = spec.homepage
16
+ spec.metadata["source_code_uri"] = "http://github.com/AlexanderShvaykin/module_pos"
17
+ spec.metadata["changelog_uri"] = "http://github.com/AlexanderShvaykin/module_pos/CHANGELOG.md"
18
+
19
+ # Specify which files should be added to the gem when it is released.
20
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
21
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
22
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
23
+ end
24
+ spec.bindir = "exe"
25
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
+ spec.require_paths = ["lib"]
27
+ spec.add_dependency "faraday", "1.0.1"
28
+ spec.add_dependency "api_utils", "0.1.1"
29
+ spec.add_dependency "dry-types", "1.4.0"
30
+ spec.add_dependency "dry-struct", "1.3.0"
31
+ end
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: module_pos-fiscalization
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Alexander Shvaykin
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-06-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 1.0.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 1.0.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: api_utils
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 0.1.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 0.1.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: dry-types
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '='
46
+ - !ruby/object:Gem::Version
47
+ version: 1.4.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '='
53
+ - !ruby/object:Gem::Version
54
+ version: 1.4.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: dry-struct
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: 1.3.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '='
67
+ - !ruby/object:Gem::Version
68
+ version: 1.3.0
69
+ description: API wrapper for Module Bank POS
70
+ email:
71
+ - skiline.alex@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".github/workflows/ruby.yml"
77
+ - ".gitignore"
78
+ - ".rspec"
79
+ - ".travis.yml"
80
+ - CODE_OF_CONDUCT.md
81
+ - Gemfile
82
+ - LICENSE.txt
83
+ - README.md
84
+ - Rakefile
85
+ - bin/console
86
+ - bin/setup
87
+ - lib/module_pos/fiscalization.rb
88
+ - lib/module_pos/fiscalization/client.rb
89
+ - lib/module_pos/fiscalization/entities/agent_info.rb
90
+ - lib/module_pos/fiscalization/entities/base.rb
91
+ - lib/module_pos/fiscalization/entities/doc.rb
92
+ - lib/module_pos/fiscalization/entities/doc_status.rb
93
+ - lib/module_pos/fiscalization/entities/pos_status.rb
94
+ - lib/module_pos/fiscalization/entities/position.rb
95
+ - lib/module_pos/fiscalization/entities/secret.rb
96
+ - lib/module_pos/fiscalization/json_request.rb
97
+ - lib/module_pos/fiscalization/types.rb
98
+ - lib/module_pos/fiscalization/version.rb
99
+ - module_pos-fiscalization.gemspec
100
+ homepage: http://github.com/AlexanderShvaykin/module_pos
101
+ licenses:
102
+ - MIT
103
+ metadata:
104
+ homepage_uri: http://github.com/AlexanderShvaykin/module_pos
105
+ source_code_uri: http://github.com/AlexanderShvaykin/module_pos
106
+ changelog_uri: http://github.com/AlexanderShvaykin/module_pos/CHANGELOG.md
107
+ post_install_message:
108
+ rdoc_options: []
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: 2.5.5
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ requirements: []
122
+ rubygems_version: 3.1.2
123
+ signing_key:
124
+ specification_version: 4
125
+ summary: API wrapper for Module Bank POS
126
+ test_files: []