yookassa 0.1.0 → 0.2.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.
- checksums.yaml +4 -4
- data/.github/workflows/main.yml +31 -0
- data/.rubocop.yml +16 -9
- data/Gemfile +10 -3
- data/Gemfile.lock +108 -69
- data/README.md +43 -14
- data/Rakefile +7 -1
- data/bin/console +13 -0
- data/bin/rake +29 -0
- data/bin/rspec +29 -0
- data/bin/rubocop +29 -0
- data/bin/setup +8 -0
- data/lib/yookassa/client.rb +44 -0
- data/lib/yookassa/config.rb +7 -0
- data/lib/yookassa/entity/amount.rb +5 -7
- data/lib/yookassa/entity/authorization_details.rb +28 -0
- data/lib/yookassa/entity/cancellation_details.rb +18 -0
- data/lib/yookassa/entity/card.rb +38 -11
- data/lib/yookassa/entity/confirmation.rb +7 -9
- data/lib/yookassa/entity/error.rb +19 -0
- data/lib/yookassa/entity/payment.rb +110 -14
- data/lib/yookassa/entity/payment_methods.rb +107 -0
- data/lib/yookassa/entity/recipient.rb +12 -0
- data/lib/yookassa/entity/refund.rb +11 -7
- data/lib/yookassa/entity/transfer.rb +33 -0
- data/lib/yookassa/entity/types.rb +9 -0
- data/lib/yookassa/payments.rb +35 -0
- data/lib/yookassa/refunds.rb +25 -0
- data/lib/yookassa/version.rb +1 -1
- data/lib/yookassa.rb +29 -11
- data/spec/fixtures/refund.json +4 -4
- data/spec/spec_helper.rb +3 -8
- data/spec/yookassa/config_spec.rb +7 -0
- data/spec/yookassa/payments_spec.rb +101 -0
- data/spec/yookassa/refunds_spec.rb +54 -0
- data/spec/yookassa_spec.rb +38 -1
- data/yookassa.gemspec +13 -18
- metadata +36 -82
- data/.circleci/config.yml +0 -28
- data/lib/yookassa/callable.rb +0 -10
- data/lib/yookassa/entity/payment_method.rb +0 -19
- data/lib/yookassa/error.rb +0 -30
- data/lib/yookassa/optional.rb +0 -23
- data/lib/yookassa/payment.rb +0 -65
- data/lib/yookassa/refund.rb +0 -35
- data/lib/yookassa/response.rb +0 -20
- data/spec/yookassa/payment_spec.rb +0 -104
- data/spec/yookassa/refund_spec.rb +0 -54
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a2f2680a651266185ee0576e97e1589ab67b0944930d94af533794c320f6c5ea
|
4
|
+
data.tar.gz: fda07e32a04e3482995b1f6c86f74f1c1d7c90d21f6bd41668e63ce93c78c7f0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5793beb1aff216c9c0bceb8324b58c8253b361390b0f8b1d57a143d286acff581a4a9059525b28d9ce314e714a86e1671ef3fa2a48dcb82c664dc09fc9366ab1
|
7
|
+
data.tar.gz: a882ed8cef54f185a519d84c10f2a0699a5dea6a77e444f4c4e00e50b1494e30c67c4febf101eacf9e79a6a323d7769daf18c7fe19ec0cd88bfa6a000f361268
|
@@ -0,0 +1,31 @@
|
|
1
|
+
name: CI
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches:
|
6
|
+
- main
|
7
|
+
|
8
|
+
pull_request:
|
9
|
+
|
10
|
+
jobs:
|
11
|
+
build:
|
12
|
+
runs-on: ubuntu-latest
|
13
|
+
|
14
|
+
strategy:
|
15
|
+
matrix:
|
16
|
+
ruby:
|
17
|
+
- 2.6
|
18
|
+
- 2.7
|
19
|
+
- 3.0
|
20
|
+
|
21
|
+
steps:
|
22
|
+
- uses: actions/checkout@v2
|
23
|
+
- name: Set up Ruby
|
24
|
+
uses: ruby/setup-ruby@v1
|
25
|
+
with:
|
26
|
+
ruby-version: ${{ matrix.ruby }}
|
27
|
+
bundler-cache: true
|
28
|
+
- name: Rubocop
|
29
|
+
run: bundle exec rubocop
|
30
|
+
- name: Rspec
|
31
|
+
run: bundle exec rspec
|
data/.rubocop.yml
CHANGED
@@ -1,13 +1,20 @@
|
|
1
1
|
AllCops:
|
2
|
-
TargetRubyVersion: 2.
|
2
|
+
TargetRubyVersion: 2.6
|
3
|
+
NewCops: enable
|
3
4
|
|
4
|
-
|
5
|
-
|
6
|
-
|
5
|
+
Style/StringLiterals:
|
6
|
+
Enabled: true
|
7
|
+
EnforcedStyle: double_quotes
|
8
|
+
|
9
|
+
Style/StringLiteralsInInterpolation:
|
10
|
+
Enabled: true
|
11
|
+
EnforcedStyle: double_quotes
|
7
12
|
|
8
|
-
|
9
|
-
|
13
|
+
Style/Documentation:
|
14
|
+
Enabled: false
|
10
15
|
|
11
|
-
|
12
|
-
|
13
|
-
|
16
|
+
Layout/LineLength:
|
17
|
+
Max: 150
|
18
|
+
|
19
|
+
Metrics/BlockLength:
|
20
|
+
IgnoredMethods: ['describe', 'context', 'shared_examples']
|
data/Gemfile
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
source
|
3
|
+
source "https://rubygems.org"
|
4
4
|
|
5
5
|
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
|
6
6
|
|
@@ -8,6 +8,13 @@ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
|
|
8
8
|
gemspec
|
9
9
|
|
10
10
|
group :development, :test do
|
11
|
-
gem
|
12
|
-
gem
|
11
|
+
gem "pry"
|
12
|
+
gem "pry-byebug", "~> 3.8.0"
|
13
|
+
gem "rake", "~> 13.0"
|
14
|
+
gem "rspec", "~> 3.5"
|
15
|
+
gem "rubocop", "~> 1.22"
|
16
|
+
gem "rubocop-rake", "~> 0.6.0"
|
17
|
+
gem "rubocop-rspec", "~> 2.5"
|
18
|
+
gem "simplecov", "~> 0.16"
|
19
|
+
gem "webmock", "~> 3.14"
|
13
20
|
end
|
data/Gemfile.lock
CHANGED
@@ -1,98 +1,137 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
yookassa (0.
|
5
|
-
|
4
|
+
yookassa (0.2.0)
|
5
|
+
dry-struct
|
6
|
+
http (~> 5.0.1)
|
6
7
|
|
7
8
|
GEM
|
8
9
|
remote: https://rubygems.org/
|
9
10
|
specs:
|
10
|
-
addressable (2.
|
11
|
-
public_suffix (>= 2.0.2, <
|
12
|
-
ast (2.4.
|
13
|
-
byebug (11.
|
14
|
-
coderay (1.1.
|
15
|
-
concurrent-ruby (1.1.
|
16
|
-
crack (0.4.
|
17
|
-
|
18
|
-
diff-lcs (1.
|
19
|
-
docile (1.
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
mime-types (~> 3.1)
|
24
|
-
rack (~> 2)
|
25
|
-
tram-policy (>= 0.3.1, < 3)
|
26
|
-
hashdiff (0.4.0)
|
27
|
-
i18n (1.8.5)
|
11
|
+
addressable (2.8.0)
|
12
|
+
public_suffix (>= 2.0.2, < 5.0)
|
13
|
+
ast (2.4.2)
|
14
|
+
byebug (11.1.3)
|
15
|
+
coderay (1.1.3)
|
16
|
+
concurrent-ruby (1.1.9)
|
17
|
+
crack (0.4.5)
|
18
|
+
rexml
|
19
|
+
diff-lcs (1.4.4)
|
20
|
+
docile (1.4.0)
|
21
|
+
domain_name (0.5.20190701)
|
22
|
+
unf (>= 0.0.5, < 1.0.0)
|
23
|
+
dry-configurable (0.13.0)
|
28
24
|
concurrent-ruby (~> 1.0)
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
25
|
+
dry-core (~> 0.6)
|
26
|
+
dry-container (0.9.0)
|
27
|
+
concurrent-ruby (~> 1.0)
|
28
|
+
dry-configurable (~> 0.13, >= 0.13.0)
|
29
|
+
dry-core (0.7.1)
|
30
|
+
concurrent-ruby (~> 1.0)
|
31
|
+
dry-inflector (0.2.1)
|
32
|
+
dry-logic (1.2.0)
|
33
|
+
concurrent-ruby (~> 1.0)
|
34
|
+
dry-core (~> 0.5, >= 0.5)
|
35
|
+
dry-struct (1.4.0)
|
36
|
+
dry-core (~> 0.5, >= 0.5)
|
37
|
+
dry-types (~> 1.5)
|
38
|
+
ice_nine (~> 0.11)
|
39
|
+
dry-types (1.5.1)
|
40
|
+
concurrent-ruby (~> 1.0)
|
41
|
+
dry-container (~> 0.3)
|
42
|
+
dry-core (~> 0.5, >= 0.5)
|
43
|
+
dry-inflector (~> 0.1, >= 0.1.2)
|
44
|
+
dry-logic (~> 1.0, >= 1.0.2)
|
45
|
+
ffi (1.15.4)
|
46
|
+
ffi-compiler (1.0.1)
|
47
|
+
ffi (>= 1.0.0)
|
48
|
+
rake
|
49
|
+
hashdiff (1.0.1)
|
50
|
+
http (5.0.4)
|
51
|
+
addressable (~> 2.8)
|
52
|
+
http-cookie (~> 1.0)
|
53
|
+
http-form_data (~> 2.2)
|
54
|
+
llhttp-ffi (~> 0.4.0)
|
55
|
+
http-cookie (1.0.4)
|
56
|
+
domain_name (~> 0.5)
|
57
|
+
http-form_data (2.3.0)
|
58
|
+
ice_nine (0.11.2)
|
59
|
+
llhttp-ffi (0.4.0)
|
60
|
+
ffi-compiler (~> 1.0)
|
61
|
+
rake (~> 13.0)
|
62
|
+
method_source (1.0.0)
|
63
|
+
parallel (1.21.0)
|
64
|
+
parser (3.0.2.0)
|
65
|
+
ast (~> 2.4.1)
|
66
|
+
pry (0.14.1)
|
67
|
+
coderay (~> 1.1)
|
68
|
+
method_source (~> 1.0)
|
69
|
+
pry-byebug (3.8.0)
|
42
70
|
byebug (~> 11.0)
|
43
71
|
pry (~> 0.10)
|
44
|
-
public_suffix (
|
45
|
-
rack (2.2.3)
|
72
|
+
public_suffix (4.0.6)
|
46
73
|
rainbow (3.0.0)
|
47
|
-
rake (
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
rspec-
|
52
|
-
|
53
|
-
rspec-
|
54
|
-
rspec-
|
74
|
+
rake (13.0.6)
|
75
|
+
regexp_parser (2.1.1)
|
76
|
+
rexml (3.2.5)
|
77
|
+
rspec (3.10.0)
|
78
|
+
rspec-core (~> 3.10.0)
|
79
|
+
rspec-expectations (~> 3.10.0)
|
80
|
+
rspec-mocks (~> 3.10.0)
|
81
|
+
rspec-core (3.10.1)
|
82
|
+
rspec-support (~> 3.10.0)
|
83
|
+
rspec-expectations (3.10.1)
|
55
84
|
diff-lcs (>= 1.2.0, < 2.0)
|
56
|
-
rspec-support (~> 3.
|
57
|
-
rspec-mocks (3.
|
85
|
+
rspec-support (~> 3.10.0)
|
86
|
+
rspec-mocks (3.10.2)
|
58
87
|
diff-lcs (>= 1.2.0, < 2.0)
|
59
|
-
rspec-support (~> 3.
|
60
|
-
rspec-support (3.
|
61
|
-
rubocop (
|
62
|
-
jaro_winkler (~> 1.5.1)
|
88
|
+
rspec-support (~> 3.10.0)
|
89
|
+
rspec-support (3.10.2)
|
90
|
+
rubocop (1.22.3)
|
63
91
|
parallel (~> 1.10)
|
64
|
-
parser (>=
|
92
|
+
parser (>= 3.0.0.0)
|
65
93
|
rainbow (>= 2.2.2, < 4.0)
|
94
|
+
regexp_parser (>= 1.8, < 3.0)
|
95
|
+
rexml
|
96
|
+
rubocop-ast (>= 1.12.0, < 2.0)
|
66
97
|
ruby-progressbar (~> 1.7)
|
67
|
-
unicode-display_width (>= 1.4.0, <
|
68
|
-
|
69
|
-
|
70
|
-
|
98
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
99
|
+
rubocop-ast (1.12.0)
|
100
|
+
parser (>= 3.0.1.1)
|
101
|
+
rubocop-rake (0.6.0)
|
102
|
+
rubocop (~> 1.0)
|
103
|
+
rubocop-rspec (2.5.0)
|
104
|
+
rubocop (~> 1.19)
|
105
|
+
ruby-progressbar (1.11.0)
|
106
|
+
simplecov (0.21.2)
|
71
107
|
docile (~> 1.1)
|
72
|
-
|
73
|
-
|
74
|
-
simplecov-html (0.
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
108
|
+
simplecov-html (~> 0.11)
|
109
|
+
simplecov_json_formatter (~> 0.1)
|
110
|
+
simplecov-html (0.12.3)
|
111
|
+
simplecov_json_formatter (0.1.3)
|
112
|
+
unf (0.1.4)
|
113
|
+
unf_ext
|
114
|
+
unf_ext (0.0.8)
|
115
|
+
unicode-display_width (2.1.0)
|
116
|
+
webmock (3.14.0)
|
117
|
+
addressable (>= 2.8.0)
|
81
118
|
crack (>= 0.3.2)
|
82
|
-
hashdiff
|
119
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
83
120
|
|
84
121
|
PLATFORMS
|
85
122
|
ruby
|
86
123
|
|
87
124
|
DEPENDENCIES
|
88
125
|
pry
|
89
|
-
pry-byebug
|
90
|
-
rake (
|
126
|
+
pry-byebug (~> 3.8.0)
|
127
|
+
rake (~> 13.0)
|
91
128
|
rspec (~> 3.5)
|
92
|
-
rubocop (~>
|
129
|
+
rubocop (~> 1.22)
|
130
|
+
rubocop-rake (~> 0.6.0)
|
131
|
+
rubocop-rspec (~> 2.5)
|
93
132
|
simplecov (~> 0.16)
|
94
|
-
webmock (~> 3.
|
133
|
+
webmock (~> 3.14)
|
95
134
|
yookassa!
|
96
135
|
|
97
136
|
BUNDLED WITH
|
98
|
-
|
137
|
+
2.2.22
|
data/README.md
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
# YooKassa API Ruby Client
|
2
|
-
|
3
|
-
[](https://circleci.com/gh/paderinandrey/yookassa)
|
2
|
+
[](https://github.com/PaymentInstruments/yookassa/actions/workflows/main.yml)
|
4
3
|
[![Gem Version][gem-badger]][gem]
|
5
4
|
[](https://github.com/paderinandrey/yookassa)
|
6
5
|
|
@@ -26,12 +25,34 @@ Or install it yourself as:
|
|
26
25
|
|
27
26
|
## Usage
|
28
27
|
|
28
|
+
### Configuration
|
29
|
+
|
30
|
+
First of all you need to setup credentials to use Yookassa.
|
31
|
+
You can configure your instance of Yookassa once in a application booting time. Ex. if you use rails, just put these lines into initializer file
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
# config/initializers/yookassa.rb
|
35
|
+
|
36
|
+
Yookassa.configure do |config|
|
37
|
+
config.shop_id = ENV.fetch('YOOKASSA_SHOP_ID') # or put your shop_id and api_key here directly
|
38
|
+
config.api_key = ENV.fetch('YOOKASSA_API_KEY') # can be taken from Rails.credentials too
|
39
|
+
end
|
40
|
+
```
|
41
|
+
|
42
|
+
There are some cases, when you need to connect to different Yookassa accounts (say, your clients need to connect to Yookassa). That probably means that you run a marketplace or multitenant system. There is a solution for this one from Yookassa, see https://yookassa.ru/en/developers/special-solutions/checkout-for-platforms/basics or https://yookassa.ru/en/developers/partners-api/basics
|
43
|
+
|
44
|
+
If that is not your case, and you still have multiple shop_ids and api_keys, and need to handle all of them under one application, then you need to instantiate clients inline
|
45
|
+
|
29
46
|
```ruby
|
30
|
-
|
47
|
+
client1 = Yookassa::Client.new(shop_id: 'shop_1', api_key: '123')
|
48
|
+
client2 = Yookassa::Client.new(shop_id: 'shop_2', api_key: '456')
|
49
|
+
```
|
31
50
|
|
32
|
-
|
51
|
+
### Making Payments
|
33
52
|
|
34
|
-
|
53
|
+
#### Creating payment
|
54
|
+
```ruby
|
55
|
+
payload = {
|
35
56
|
amount: {
|
36
57
|
value: 100,
|
37
58
|
currency: 'RUB'
|
@@ -43,23 +64,31 @@ payment = {
|
|
43
64
|
}
|
44
65
|
}
|
45
66
|
|
46
|
-
|
47
|
-
|
48
|
-
client.get_payment_info(payment_id: '12345')
|
67
|
+
payment = Yookassa.payments.create(payment: payload)
|
49
68
|
|
50
|
-
|
69
|
+
# or
|
51
70
|
|
52
|
-
client.
|
71
|
+
client = Yookassa::Client.new(shop_id: 'shop_1', api_key: '123')
|
72
|
+
payment = client.payments.create(payment: payload)
|
73
|
+
```
|
53
74
|
|
54
|
-
|
75
|
+
#### Other payment requests
|
55
76
|
|
56
|
-
|
77
|
+
```ruby
|
78
|
+
Yookassa.payments.find(payment_id: '12345')
|
79
|
+
Yookassa.payments.capture(payment_id: '12345')
|
80
|
+
Yookassa.payments.cancel(payment_id: '12345')
|
81
|
+
```
|
57
82
|
|
58
|
-
|
83
|
+
### Refunds
|
59
84
|
|
60
|
-
|
85
|
+
```ruby
|
86
|
+
payment = Yookassa.refunds.create(payment: payload)
|
61
87
|
|
88
|
+
# or
|
62
89
|
|
90
|
+
client = Yookassa::Client.new(shop_id: 'shop_1', api_key: '123')
|
91
|
+
payment = client.refunds.create(payment: payload)
|
63
92
|
```
|
64
93
|
|
65
94
|
## Contributing
|
data/Rakefile
CHANGED
data/bin/console
ADDED
data/bin/rake
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
#
|
5
|
+
# This file was generated by Bundler.
|
6
|
+
#
|
7
|
+
# The application 'rake' is installed as part of a gem, and
|
8
|
+
# this file is here to facilitate running it.
|
9
|
+
#
|
10
|
+
|
11
|
+
require "pathname"
|
12
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
13
|
+
Pathname.new(__FILE__).realpath)
|
14
|
+
|
15
|
+
bundle_binstub = File.expand_path("bundle", __dir__)
|
16
|
+
|
17
|
+
if File.file?(bundle_binstub)
|
18
|
+
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
|
19
|
+
load(bundle_binstub)
|
20
|
+
else
|
21
|
+
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
22
|
+
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
require "rubygems"
|
27
|
+
require "bundler/setup"
|
28
|
+
|
29
|
+
load Gem.bin_path("rake", "rake")
|
data/bin/rspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
#
|
5
|
+
# This file was generated by Bundler.
|
6
|
+
#
|
7
|
+
# The application 'rspec' is installed as part of a gem, and
|
8
|
+
# this file is here to facilitate running it.
|
9
|
+
#
|
10
|
+
|
11
|
+
require "pathname"
|
12
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
13
|
+
Pathname.new(__FILE__).realpath)
|
14
|
+
|
15
|
+
bundle_binstub = File.expand_path("bundle", __dir__)
|
16
|
+
|
17
|
+
if File.file?(bundle_binstub)
|
18
|
+
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
|
19
|
+
load(bundle_binstub)
|
20
|
+
else
|
21
|
+
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
22
|
+
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
require "rubygems"
|
27
|
+
require "bundler/setup"
|
28
|
+
|
29
|
+
load Gem.bin_path("rspec-core", "rspec")
|
data/bin/rubocop
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
#
|
5
|
+
# This file was generated by Bundler.
|
6
|
+
#
|
7
|
+
# The application 'rubocop' is installed as part of a gem, and
|
8
|
+
# this file is here to facilitate running it.
|
9
|
+
#
|
10
|
+
|
11
|
+
require "pathname"
|
12
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
13
|
+
Pathname.new(__FILE__).realpath)
|
14
|
+
|
15
|
+
bundle_binstub = File.expand_path("bundle", __dir__)
|
16
|
+
|
17
|
+
if File.file?(bundle_binstub)
|
18
|
+
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
|
19
|
+
load(bundle_binstub)
|
20
|
+
else
|
21
|
+
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
22
|
+
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
require "rubygems"
|
27
|
+
require "bundler/setup"
|
28
|
+
|
29
|
+
load Gem.bin_path("rubocop", "rubocop")
|
data/bin/setup
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "http"
|
4
|
+
require_relative "./payments"
|
5
|
+
require_relative "./refunds"
|
6
|
+
require_relative "./entity/error"
|
7
|
+
|
8
|
+
module Yookassa
|
9
|
+
class Client
|
10
|
+
API_URL = "https://api.yookassa.ru/v3/"
|
11
|
+
|
12
|
+
attr_reader :http
|
13
|
+
|
14
|
+
def initialize(shop_id:, api_key:)
|
15
|
+
@http = HTTP.basic_auth(user: shop_id, pass: api_key).headers(accept: "application/json")
|
16
|
+
end
|
17
|
+
|
18
|
+
def payments
|
19
|
+
@payments ||= Payments.new(self)
|
20
|
+
end
|
21
|
+
|
22
|
+
def refunds
|
23
|
+
@refunds ||= Refunds.new(self)
|
24
|
+
end
|
25
|
+
|
26
|
+
def get(endpoint, query: {})
|
27
|
+
api_call { http.get("#{API_URL}#{endpoint}", params: query) }
|
28
|
+
end
|
29
|
+
|
30
|
+
def post(endpoint, idempotency_key:, payload: {})
|
31
|
+
api_call { http.headers("Idempotence-Key" => idempotency_key).post("#{API_URL}#{endpoint}", json: payload) }
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def api_call
|
37
|
+
response = yield if block_given?
|
38
|
+
body = JSON.parse(response.body.to_s, symbolize_names: true)
|
39
|
+
return body if response.status.success?
|
40
|
+
|
41
|
+
Entity::Error.new(**body)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -1,14 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative "./types"
|
4
|
+
|
3
5
|
module Yookassa
|
4
6
|
module Entity
|
5
|
-
class Amount
|
6
|
-
|
7
|
-
|
8
|
-
include Yookassa::Optional
|
9
|
-
|
10
|
-
option :value, proc(&:to_f), optional: true
|
11
|
-
option :currency, proc(&:to_s), optional: true
|
7
|
+
class Amount < Dry::Struct
|
8
|
+
attribute :value, Types::Coercible::Float
|
9
|
+
attribute :currency, Types::String
|
12
10
|
end
|
13
11
|
end
|
14
12
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "./types"
|
4
|
+
|
5
|
+
module Yookassa
|
6
|
+
module Entity
|
7
|
+
class AuthorizationDetails < Dry::Struct
|
8
|
+
# rrn [string, optional]
|
9
|
+
# Retrieval Reference Number is a unique identifier of a transaction in the issuer's system. Used for payments via bank card.
|
10
|
+
attribute? :rrn, Types::String
|
11
|
+
|
12
|
+
# auth_code [string, optional]
|
13
|
+
# Bank card's authorization code. Provided by the issuer to confirm authorization.
|
14
|
+
attribute? :auth_code, Types::String
|
15
|
+
|
16
|
+
# three_d_secure [object, optional]
|
17
|
+
# Information about user’s 3‑D Secure authentication for confirming the payment.
|
18
|
+
attribute? :three_d_secure, Types::Hash.schema(
|
19
|
+
|
20
|
+
# applied [boolean, required]
|
21
|
+
# Information on whether the 3-D Secure authentication form is displayed to the user for confirming the payment or not.
|
22
|
+
# true: YooMoney displayed the form to the user, so that they could complete 3-D Secure authentication;
|
23
|
+
# false: payment was processed without 3-D Secure authentication.
|
24
|
+
applied: Types::Bool
|
25
|
+
).with_key_transform(&:to_sym)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "./types"
|
4
|
+
|
5
|
+
module Yookassa
|
6
|
+
module Entity
|
7
|
+
class CancellationDetails < Dry::Struct
|
8
|
+
# party [string, required]
|
9
|
+
# The participant of the payment process that made the decision to cancel the payment.
|
10
|
+
# Possible values are yoo_money, payment_network, and merchant. More about initiators of payment cancelation
|
11
|
+
attribute :party, Types::String.enum("yoo_money", "payment_network", "merchant")
|
12
|
+
|
13
|
+
# reason [string, required]
|
14
|
+
# Reason behind the cancelation. Possible values https://yookassa.ru/en/developers/payments/declined-payments#cancellation-details-reason
|
15
|
+
attribute :reason, Types::String
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|