yaka 0.0.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/Gemfile.lock +37 -2
- data/README.md +55 -1
- data/lib/yaka/basic_struct.rb +30 -0
- data/lib/yaka/class_methods.rb +17 -8
- data/lib/yaka/payment.rb +30 -17
- data/lib/yaka/payment_response.rb +46 -0
- data/lib/yaka/version.rb +3 -1
- data/lib/yaka.rb +23 -6
- data/yaka.gemspec +3 -1
- metadata +33 -7
- data/lib/yaka/amount.rb +0 -15
- data/lib/yaka/receipt.rb +0 -27
- data/lib/yaka/receipt_item.rb +0 -66
- data/lib/yaka/serializable_object.rb +0 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 974f7ba0a3bdd56aaddef4625ee7e57be4235fd09cb310b489b19c21bb59dd20
|
4
|
+
data.tar.gz: 2be2cf7054857aac7575a794ec8b99e4eb822f31362beca6c6e629775d5d38e7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 861fd5d7f14efb25be050277d31a03c6b268f3cf66b79cf18a079bfb2eb56481b2b0497b71148a1cca5a928680730c0010ee7cba227483c50965d73bf367184a
|
7
|
+
data.tar.gz: b9f0ec56e9d7ff01168043f8301984a923ca5bf5e84fcedb10660fa571b1a9097ac77458eb6ec13388dc8ff3f2b78254849b38fbb4c6ce9091ee8a273bfbb7d5
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
yaka (0.0
|
4
|
+
yaka (1.0.0)
|
5
5
|
dry-configurable
|
6
|
-
|
6
|
+
dry-struct
|
7
7
|
faraday
|
8
8
|
oj
|
9
9
|
pry
|
@@ -11,26 +11,54 @@ PATH
|
|
11
11
|
GEM
|
12
12
|
remote: https://rubygems.org/
|
13
13
|
specs:
|
14
|
+
addressable (2.6.0)
|
15
|
+
public_suffix (>= 2.0.2, < 4.0)
|
14
16
|
coderay (1.1.2)
|
15
17
|
concurrent-ruby (1.1.5)
|
18
|
+
crack (0.4.3)
|
19
|
+
safe_yaml (~> 1.0.0)
|
16
20
|
diff-lcs (1.3)
|
17
21
|
dry-configurable (0.8.3)
|
18
22
|
concurrent-ruby (~> 1.0)
|
19
23
|
dry-core (~> 0.4, >= 0.4.7)
|
24
|
+
dry-container (0.7.0)
|
25
|
+
concurrent-ruby (~> 1.0)
|
26
|
+
dry-configurable (~> 0.1, >= 0.1.3)
|
20
27
|
dry-core (0.4.7)
|
21
28
|
concurrent-ruby (~> 1.0)
|
29
|
+
dry-equalizer (0.2.2)
|
30
|
+
dry-inflector (0.1.2)
|
31
|
+
dry-logic (1.0.0)
|
32
|
+
concurrent-ruby (~> 1.0)
|
33
|
+
dry-core (~> 0.2)
|
34
|
+
dry-equalizer (~> 0.2)
|
35
|
+
dry-struct (1.0.0)
|
36
|
+
dry-core (~> 0.4, >= 0.4.3)
|
37
|
+
dry-equalizer (~> 0.2)
|
38
|
+
dry-types (~> 1.0)
|
39
|
+
ice_nine (~> 0.11)
|
40
|
+
dry-types (1.0.0)
|
41
|
+
concurrent-ruby (~> 1.0)
|
42
|
+
dry-container (~> 0.3)
|
43
|
+
dry-core (~> 0.4, >= 0.4.4)
|
44
|
+
dry-equalizer (~> 0.2, >= 0.2.2)
|
45
|
+
dry-inflector (~> 0.1, >= 0.1.2)
|
46
|
+
dry-logic (~> 1.0)
|
22
47
|
faker (1.9.3)
|
23
48
|
i18n (>= 0.7)
|
24
49
|
faraday (0.15.4)
|
25
50
|
multipart-post (>= 1.2, < 3)
|
51
|
+
hashdiff (0.4.0)
|
26
52
|
i18n (1.6.0)
|
27
53
|
concurrent-ruby (~> 1.0)
|
54
|
+
ice_nine (0.11.2)
|
28
55
|
method_source (0.9.2)
|
29
56
|
multipart-post (2.1.1)
|
30
57
|
oj (3.7.12)
|
31
58
|
pry (0.12.2)
|
32
59
|
coderay (~> 1.1.0)
|
33
60
|
method_source (~> 0.9.0)
|
61
|
+
public_suffix (3.1.0)
|
34
62
|
rake (10.5.0)
|
35
63
|
rspec (3.8.0)
|
36
64
|
rspec-core (~> 3.8.0)
|
@@ -45,14 +73,21 @@ GEM
|
|
45
73
|
diff-lcs (>= 1.2.0, < 2.0)
|
46
74
|
rspec-support (~> 3.8.0)
|
47
75
|
rspec-support (3.8.0)
|
76
|
+
safe_yaml (1.0.5)
|
77
|
+
webmock (3.5.1)
|
78
|
+
addressable (>= 2.3.6)
|
79
|
+
crack (>= 0.3.2)
|
80
|
+
hashdiff
|
48
81
|
|
49
82
|
PLATFORMS
|
50
83
|
ruby
|
51
84
|
|
52
85
|
DEPENDENCIES
|
53
86
|
bundler (~> 1.17)
|
87
|
+
faker
|
54
88
|
rake (~> 10.0)
|
55
89
|
rspec (~> 3.0)
|
90
|
+
webmock
|
56
91
|
yaka!
|
57
92
|
|
58
93
|
BUNDLED WITH
|
data/README.md
CHANGED
@@ -20,7 +20,61 @@ Or install it yourself as:
|
|
20
20
|
|
21
21
|
## Usage
|
22
22
|
|
23
|
-
|
23
|
+
1. Attach gem for your project
|
24
|
+
2. Create initializer for your project that will set `shop_id` and `private_key`.
|
25
|
+
```ruby
|
26
|
+
# yaka.rb
|
27
|
+
|
28
|
+
Yaka.config.shop_id = ENV['YANDEX_SHOP_ID']
|
29
|
+
Yaka.config.private_key = ENV['YANDEX_PRIVATE_KEY']
|
30
|
+
```
|
31
|
+
3. Create payment at client side:
|
32
|
+
```html
|
33
|
+
<script src="https://static.yandex.net/checkout/js/v1/"></script>
|
34
|
+
<script src="https://static.yandex.net/checkout/ui/v1/"></script>
|
35
|
+
<button class="btn" onclick="$checkout.open()">Pay 100</button>
|
36
|
+
<script>
|
37
|
+
const $checkout = YandexCheckoutUI(<%= Yaka.config.shop_id %>, {amount: 100});
|
38
|
+
$checkout.on('yc_success', function(response) {
|
39
|
+
$.ajax({
|
40
|
+
url: "/route_for_yandex_kassa",
|
41
|
+
type: 'POST',
|
42
|
+
dataType: "json",
|
43
|
+
contentType: "application/json; charset=utf-8",
|
44
|
+
data: JSON.stringify({
|
45
|
+
redirect_url: 'https://example.com',
|
46
|
+
token: response.data.response.paymentToken,
|
47
|
+
amount: 100,
|
48
|
+
json_data: {ololo: 4}
|
49
|
+
})
|
50
|
+
}).then(x => {
|
51
|
+
if (x.status === "succeeded") {
|
52
|
+
$checkout.chargeSuccessful();
|
53
|
+
} else {
|
54
|
+
if (x.status === "pending") {
|
55
|
+
window.location = x.confirmation.confirmation_url;
|
56
|
+
} else {
|
57
|
+
$checkout.chargeFailful();
|
58
|
+
}
|
59
|
+
}
|
60
|
+
}
|
61
|
+
);
|
62
|
+
});
|
63
|
+
```
|
64
|
+
4. Create payment at backend side:
|
65
|
+
|
66
|
+
Token is received from front-end(`token` from the code above).
|
67
|
+
```ruby
|
68
|
+
payment = Yaka::Payment.new(amount: params[:amount], description: "Пополнение счета через карту", payment_token: params[:token], metadata: params[:json_data], client_ip: request.remote_ip, confirmation: { type: "redirect", return_url: params[:redirect_url]})
|
69
|
+
response = Yaka.publish_payment(payment, SecureRandom.uuid)
|
70
|
+
```
|
71
|
+
If payment is successful - you will receive status `succeeded`.
|
72
|
+
If pending - in `confirmation.confirmation_url` you will have a 3ds confirmation URL. Use it!
|
73
|
+
|
74
|
+
5. Then you will receive a callback about payment attempt(callback is configured at yandex site).
|
75
|
+
|
76
|
+
You can use `Yaka.yandex_ip?(ip)` to check remote ip of received request to avoid scams and cheatings.
|
77
|
+
|
24
78
|
|
25
79
|
## Development
|
26
80
|
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Yaka
|
4
|
+
module Types
|
5
|
+
include Dry::Types.module
|
6
|
+
end
|
7
|
+
|
8
|
+
class BasicStruct < Dry::Struct
|
9
|
+
|
10
|
+
def self.primitive
|
11
|
+
Types::Hash
|
12
|
+
end
|
13
|
+
|
14
|
+
transform_types do |type|
|
15
|
+
if type.default?
|
16
|
+
type.constructor do |value|
|
17
|
+
value.nil? ? Dry::Types::Undefined : value
|
18
|
+
end
|
19
|
+
else
|
20
|
+
type
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
transform_keys(&:to_sym)
|
25
|
+
|
26
|
+
def to_json(_args = {})
|
27
|
+
attributes.to_json
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/yaka/class_methods.rb
CHANGED
@@ -2,25 +2,34 @@
|
|
2
2
|
|
3
3
|
module Yaka
|
4
4
|
module ClassMethods
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
def publish_payment(payment, token = nil)
|
9
|
-
raise Yaka::Error, 'Only payment should be sent to API' unless payment.is_a?(Yaka::Payment)
|
5
|
+
def publish_payment(data, token = nil)
|
6
|
+
payment = data.is_a?(Yaka::Payment) ? data : Yaka::Payment.new(data)
|
10
7
|
|
11
8
|
data = payment.to_json
|
12
9
|
|
13
|
-
conn = Faraday.new(url: HOST_URL) # create a new Connection with base URL
|
10
|
+
conn = Faraday.new(url: Yaka::HOST_URL) # create a new Connection with base URL
|
14
11
|
conn.basic_auth(Yaka.config.shop_id, Yaka.config.private_key) # set the Authentication header
|
15
12
|
|
16
13
|
@result = conn.post do |req|
|
17
|
-
req.url PAYMENTS_URL
|
14
|
+
req.url Yaka::PAYMENTS_URL
|
18
15
|
req.headers['Content-Type'] = 'application/json'
|
19
16
|
req.headers['Idempotence-Key'] = token
|
20
17
|
req.body = data
|
21
18
|
end
|
22
19
|
|
23
|
-
JSON.parse(@result.body)
|
20
|
+
Yaka::PaymentResponse.new(JSON.parse(@result.body))
|
21
|
+
end
|
22
|
+
|
23
|
+
def yandex_ip?(ip)
|
24
|
+
addr = IPAddr.new(ip)
|
25
|
+
|
26
|
+
if addr.ipv4?
|
27
|
+
Yaka::ALLOWED_YANDEX_V4_MASKS.any? { |mask, length| addr.mask(length) == mask }
|
28
|
+
elsif addr.ipv6?
|
29
|
+
Yaka::ALLOWED_YANDEX_V6_MASKS.any? { |mask, length| addr.mask(length) == mask }
|
30
|
+
else
|
31
|
+
raise Yaka::Error, 'Invalid request ip address'
|
32
|
+
end
|
24
33
|
end
|
25
34
|
end
|
26
35
|
end
|
data/lib/yaka/payment.rb
CHANGED
@@ -1,23 +1,36 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Yaka
|
4
|
-
class Payment <
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
4
|
+
class Payment < BasicStruct
|
5
|
+
# This class is used for sending payments to Yandex Kassa.
|
6
|
+
attribute :amount, BasicStruct do
|
7
|
+
attribute :value, Types::String
|
8
|
+
attribute :currency, Types::String
|
9
|
+
end
|
10
|
+
attribute :confirmation, BasicStruct do
|
11
|
+
attribute :type, Types::String.default('redirect')
|
12
|
+
attribute :return_url, Types::Strict::String
|
13
|
+
end
|
14
|
+
attribute :capture, Types::Bool.default(true)
|
15
|
+
attribute :description, Types::Strict::String
|
16
|
+
attribute :receipt, BasicStruct.meta(omittable: true) do
|
17
|
+
attribute :items, Types::Array.of(BasicStruct).default([]) do
|
18
|
+
attribute :description, Types::String
|
19
|
+
attribute :amount, BasicStruct.meta(omittable: true) do
|
20
|
+
attribute :value, Types::String.meta(omittable: true)
|
21
|
+
attribute :currency, Types::String.meta(omittable: true)
|
22
|
+
end
|
23
|
+
attribute :quantity, Types::Integer
|
24
|
+
attribute :vat_code, Types::String
|
25
|
+
attribute :payment_mode, Types::Strict::String.meta(omittable: true)
|
26
|
+
attribute :payment_subject, Types::String.meta(omittable: true)
|
27
|
+
end
|
28
|
+
attribute :phone, Types::String.meta(omittable: true)
|
29
|
+
attribute :email, Types::String.meta(omittable: true)
|
30
|
+
attribute :tax_system_code, Types::String.meta(omittable: true)
|
21
31
|
end
|
32
|
+
attribute :payment_token, Types::String
|
33
|
+
attribute :metadata, Types::Hash
|
34
|
+
attribute :client_ip, Types::String
|
22
35
|
end
|
23
36
|
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Yaka
|
4
|
+
class PaymentResponse < BasicStruct
|
5
|
+
# This class is used to wrap response from Yandex Kassa about necessary actions to complete/process if it's required
|
6
|
+
|
7
|
+
attribute :id, Types::String
|
8
|
+
attribute :status, Types::String
|
9
|
+
attribute :paid, Types::Bool
|
10
|
+
attribute :amount, BasicStruct do
|
11
|
+
attribute :value, Types::String
|
12
|
+
attribute :currency, Types::String
|
13
|
+
end
|
14
|
+
attribute :authorization_details, BasicStruct do
|
15
|
+
attribute :rrn, Types::String
|
16
|
+
attribute :auth_code, Types::String
|
17
|
+
end
|
18
|
+
attribute :captured_at, Types::DateTime
|
19
|
+
attribute :created_at, Types::DateTime
|
20
|
+
attribute :description, Types::String
|
21
|
+
attribute :metadata, Types::Hash
|
22
|
+
attribute :payment_method, BasicStruct do
|
23
|
+
attribute :id, Types::String
|
24
|
+
attribute :type, Types::String
|
25
|
+
attribute :saved, Types::String
|
26
|
+
attribute :title, Types::String
|
27
|
+
attribute :card, BasicStruct do
|
28
|
+
attribute :first6, Types::String
|
29
|
+
attribute :last4, Types::String
|
30
|
+
attribute :expiry_month, Types::String
|
31
|
+
attribute :expiry_year, Types::String
|
32
|
+
attribute :card_type, Types::String
|
33
|
+
end
|
34
|
+
end
|
35
|
+
attribute :recipient, BasicStruct do
|
36
|
+
attribute :account_id, Types::String
|
37
|
+
attribute :gateway_id, Types::String
|
38
|
+
end
|
39
|
+
attribute :refundable, Types::Bool
|
40
|
+
attribute :refunded_amount, BasicStruct do
|
41
|
+
attribute :value, Types::String
|
42
|
+
attribute :currency, Types::String
|
43
|
+
end
|
44
|
+
attribute :test, Types::Bool
|
45
|
+
end
|
46
|
+
end
|
data/lib/yaka/version.rb
CHANGED
data/lib/yaka.rb
CHANGED
@@ -1,16 +1,35 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'dry-configurable'
|
4
|
+
require 'dry-struct'
|
5
|
+
require 'ipaddr'
|
6
|
+
require 'date'
|
7
|
+
|
4
8
|
require 'yaka/version'
|
5
|
-
require 'yaka/
|
6
|
-
require 'yaka/amount'
|
9
|
+
require 'yaka/basic_struct'
|
7
10
|
require 'yaka/class_methods'
|
8
11
|
require 'yaka/payment'
|
9
|
-
require 'yaka/
|
10
|
-
|
12
|
+
require 'yaka/payment_response'
|
13
|
+
|
11
14
|
require 'faraday'
|
12
15
|
|
13
16
|
module Yaka
|
17
|
+
HOST_URL = 'https://payment.yandex.net'
|
18
|
+
PAYMENTS_URL = '/api/v3/payments'
|
19
|
+
ALLOWED_YANDEX_V4_MASKS = {
|
20
|
+
'185.71.76.0' => 27,
|
21
|
+
'185.71.77.0' => 27,
|
22
|
+
'77.75.153.0' => 25,
|
23
|
+
'77.75.154.128' => 25
|
24
|
+
}.freeze
|
25
|
+
|
26
|
+
ALLOWED_YANDEX_V6_MASKS = {
|
27
|
+
'2a02:5180:0:1509::' => 64,
|
28
|
+
'2a02:5180:0:2655::' => 64,
|
29
|
+
'2a02:5180:0:1533::' => 64,
|
30
|
+
'2a02:5180:0:2669::' => 64
|
31
|
+
}.freeze
|
32
|
+
|
14
33
|
class Error < StandardError; end
|
15
34
|
|
16
35
|
extend Dry::Configurable
|
@@ -19,7 +38,5 @@ module Yaka
|
|
19
38
|
|
20
39
|
setting :private_key, 'ololo'
|
21
40
|
|
22
|
-
setting :redirect_url, 'example.com/callbacks'
|
23
|
-
|
24
41
|
extend ClassMethods
|
25
42
|
end
|
data/yaka.gemspec
CHANGED
@@ -39,9 +39,11 @@ Gem::Specification.new do |spec|
|
|
39
39
|
spec.add_development_dependency "bundler", "~> 1.17"
|
40
40
|
spec.add_development_dependency "rake", "~> 10.0"
|
41
41
|
spec.add_development_dependency "rspec", "~> 3.0"
|
42
|
+
spec.add_development_dependency "webmock"
|
42
43
|
spec.add_dependency "pry"
|
43
44
|
spec.add_dependency 'dry-configurable'
|
45
|
+
spec.add_dependency 'dry-struct'
|
44
46
|
spec.add_dependency 'oj'
|
45
47
|
spec.add_dependency 'faraday'
|
46
|
-
spec.
|
48
|
+
spec.add_development_dependency 'faker'
|
47
49
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yaka
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Igor Pavlov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-06-
|
11
|
+
date: 2019-06-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: webmock
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: pry
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -80,6 +94,20 @@ dependencies:
|
|
80
94
|
- - ">="
|
81
95
|
- !ruby/object:Gem::Version
|
82
96
|
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: dry-struct
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
83
111
|
- !ruby/object:Gem::Dependency
|
84
112
|
name: oj
|
85
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -115,7 +143,7 @@ dependencies:
|
|
115
143
|
- - ">="
|
116
144
|
- !ruby/object:Gem::Version
|
117
145
|
version: '0'
|
118
|
-
type: :
|
146
|
+
type: :development
|
119
147
|
prerelease: false
|
120
148
|
version_requirements: !ruby/object:Gem::Requirement
|
121
149
|
requirements:
|
@@ -143,12 +171,10 @@ files:
|
|
143
171
|
- bin/console
|
144
172
|
- bin/setup
|
145
173
|
- lib/yaka.rb
|
146
|
-
- lib/yaka/
|
174
|
+
- lib/yaka/basic_struct.rb
|
147
175
|
- lib/yaka/class_methods.rb
|
148
176
|
- lib/yaka/payment.rb
|
149
|
-
- lib/yaka/
|
150
|
-
- lib/yaka/receipt_item.rb
|
151
|
-
- lib/yaka/serializable_object.rb
|
177
|
+
- lib/yaka/payment_response.rb
|
152
178
|
- lib/yaka/version.rb
|
153
179
|
- yaka.gemspec
|
154
180
|
homepage: https://github.com/beastia/yaka
|
data/lib/yaka/amount.rb
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Yaka
|
4
|
-
class Amount < SerializableObject
|
5
|
-
REQUIRED_FIELDS = %i[value currency].freeze
|
6
|
-
OPTIONAL_FIELDS = %i[].freeze
|
7
|
-
|
8
|
-
attr_accessor(*REQUIRED_FIELDS)
|
9
|
-
|
10
|
-
def initialize(value:, currency: 'RUB')
|
11
|
-
@value = value
|
12
|
-
@currency = currency
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
data/lib/yaka/receipt.rb
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Yaka
|
4
|
-
class Receipt < SerializableObject
|
5
|
-
# Tax system codes
|
6
|
-
# 1: Общая система налогообложения
|
7
|
-
# 2: Упрощенная (УСН, доходы)
|
8
|
-
# 3: Упрощенная (УСН, доходы минус расходы)
|
9
|
-
# 4: Единый налог на вмененный доход (ЕНВД)
|
10
|
-
# 5: Единый сельскохозяйственный налог (ЕСН)
|
11
|
-
# 6: Патентная система налогообложения
|
12
|
-
|
13
|
-
REQUIRED_FIELDS = %i[items].freeze
|
14
|
-
OPTIONAL_FIELDS = %i[phone email tax_system_code].freeze
|
15
|
-
|
16
|
-
attr_accessor(*REQUIRED_FIELDS)
|
17
|
-
attr_accessor(*OPTIONAL_FIELDS)
|
18
|
-
|
19
|
-
def initialize(items: [], phone: nil, email: nil, tax_system_code: nil)
|
20
|
-
@items = items
|
21
|
-
@phone = phone
|
22
|
-
@email = email
|
23
|
-
@tax_system_code = tax_system_code
|
24
|
-
raise Yaka::Error, 'Invalid input parameters: phone or email should be present' if @phone.nil? && @email.nil?
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
data/lib/yaka/receipt_item.rb
DELETED
@@ -1,66 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Yaka
|
4
|
-
class ReceiptItem < SerializableObject
|
5
|
-
# Vat codes
|
6
|
-
#
|
7
|
-
# 1: Без НДС
|
8
|
-
# 2: НДС по ставке 0%
|
9
|
-
# 3: НДС по ставке 10%
|
10
|
-
# 4: НДС чека по ставке 20%
|
11
|
-
# 5: НДС чека по расчетной ставке 10/110
|
12
|
-
# 6: НДС чека по расчетной ставке 20/120
|
13
|
-
#
|
14
|
-
# Payment subjects
|
15
|
-
# commodity: Товар
|
16
|
-
# excise: Подакцизный товар
|
17
|
-
# job: Работа
|
18
|
-
# service: Услуга
|
19
|
-
# gambling_bet: Ставка в азартной игре
|
20
|
-
# gambling_prize: Выигрыш в азартной игре
|
21
|
-
# lottery: Лотерейный билет
|
22
|
-
# lottery_prize: Выигрыш в лотерею
|
23
|
-
# intellectual_activity: Результаты интеллектуальной деятельности
|
24
|
-
# payment: Платеж
|
25
|
-
# agent_commission: Агентское вознаграждение
|
26
|
-
# property_right: Имущественные права
|
27
|
-
# non_operating_gain: Внереализационный доход
|
28
|
-
# insurance_premium: Страховой сбор
|
29
|
-
# sales_tax: Торговый сбор
|
30
|
-
# resort_fee: Курортный сбор
|
31
|
-
# composite: Несколько вариантов
|
32
|
-
# another: Другое
|
33
|
-
#
|
34
|
-
# Payment mode
|
35
|
-
# full_prepayment: Полная предоплата
|
36
|
-
# partial_prepayment: Частичная предоплата
|
37
|
-
# advance: Аванс
|
38
|
-
# full_payment: Полный расчет
|
39
|
-
# partial_payment: Частичный расчет и кредит
|
40
|
-
# credit: Кредит
|
41
|
-
# credit_payment: Выплата по кредиту
|
42
|
-
REQUIRED_FIELDS = %i[description amount quantity vat_code].freeze
|
43
|
-
OPTIONAL_FIELDS = %i[payment_subject payment_mode].freeze
|
44
|
-
|
45
|
-
attr_accessor(*REQUIRED_FIELDS)
|
46
|
-
attr_accessor(*OPTIONAL_FIELDS)
|
47
|
-
|
48
|
-
def initialize(description:, amount:, quantity:, vat_code:, payment_subject: nil, payment_mode: nil)
|
49
|
-
@description = description
|
50
|
-
@amount = amount
|
51
|
-
@quantity = quantity
|
52
|
-
@vat_code = vat_code
|
53
|
-
@payment_subject = payment_subject
|
54
|
-
@payment_mode = payment_mode
|
55
|
-
end
|
56
|
-
|
57
|
-
def to_json(*_args)
|
58
|
-
{
|
59
|
-
description: @description,
|
60
|
-
amount: @amount,
|
61
|
-
quantity: @quantity,
|
62
|
-
vat_code: @vat_code
|
63
|
-
}.to_json
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
module Yaka
|
2
|
-
class SerializableObject
|
3
|
-
def to_json(*_args)
|
4
|
-
required_fields = self.class.const_get(:REQUIRED_FIELDS)
|
5
|
-
initial = required_fields.each_with_object({}) do |field_name, result|
|
6
|
-
result[field_name] = public_send(field_name)
|
7
|
-
end
|
8
|
-
|
9
|
-
optional_fields = self.class.const_get(:OPTIONAL_FIELDS)
|
10
|
-
|
11
|
-
optional_fields.each do |field_name|
|
12
|
-
value = public_send(field_name)
|
13
|
-
initial[field_name] = value unless value.nil?
|
14
|
-
end
|
15
|
-
|
16
|
-
initial.to_json
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|