yookassa 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/main.yml +31 -0
  3. data/.rubocop.yml +16 -9
  4. data/Gemfile +10 -3
  5. data/Gemfile.lock +108 -69
  6. data/README.md +43 -14
  7. data/Rakefile +7 -1
  8. data/bin/console +13 -0
  9. data/bin/rake +29 -0
  10. data/bin/rspec +29 -0
  11. data/bin/rubocop +29 -0
  12. data/bin/setup +8 -0
  13. data/lib/yookassa/client.rb +44 -0
  14. data/lib/yookassa/config.rb +7 -0
  15. data/lib/yookassa/entity/amount.rb +5 -7
  16. data/lib/yookassa/entity/authorization_details.rb +28 -0
  17. data/lib/yookassa/entity/cancellation_details.rb +18 -0
  18. data/lib/yookassa/entity/card.rb +38 -11
  19. data/lib/yookassa/entity/confirmation.rb +7 -9
  20. data/lib/yookassa/entity/error.rb +19 -0
  21. data/lib/yookassa/entity/payment.rb +110 -14
  22. data/lib/yookassa/entity/payment_methods.rb +107 -0
  23. data/lib/yookassa/entity/recipient.rb +12 -0
  24. data/lib/yookassa/entity/refund.rb +11 -7
  25. data/lib/yookassa/entity/transfer.rb +33 -0
  26. data/lib/yookassa/entity/types.rb +9 -0
  27. data/lib/yookassa/payments.rb +35 -0
  28. data/lib/yookassa/refunds.rb +25 -0
  29. data/lib/yookassa/version.rb +1 -1
  30. data/lib/yookassa.rb +29 -11
  31. data/spec/fixtures/refund.json +4 -4
  32. data/spec/spec_helper.rb +3 -8
  33. data/spec/yookassa/config_spec.rb +7 -0
  34. data/spec/yookassa/payments_spec.rb +101 -0
  35. data/spec/yookassa/refunds_spec.rb +54 -0
  36. data/spec/yookassa_spec.rb +38 -1
  37. data/yookassa.gemspec +13 -18
  38. metadata +36 -82
  39. data/.circleci/config.yml +0 -28
  40. data/lib/yookassa/callable.rb +0 -10
  41. data/lib/yookassa/entity/payment_method.rb +0 -19
  42. data/lib/yookassa/error.rb +0 -30
  43. data/lib/yookassa/optional.rb +0 -23
  44. data/lib/yookassa/payment.rb +0 -65
  45. data/lib/yookassa/refund.rb +0 -35
  46. data/lib/yookassa/response.rb +0 -20
  47. data/spec/yookassa/payment_spec.rb +0 -104
  48. data/spec/yookassa/refund_spec.rb +0 -54
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9ac00c134955295ac36c5667a95f1b7c420b42daf1adeeec4f32b3c205620e4b
4
- data.tar.gz: 0eb954e77d47f17d8ed1d567f881f7e5d42846258686f36e4ea57f19cc63adb7
3
+ metadata.gz: a2f2680a651266185ee0576e97e1589ab67b0944930d94af533794c320f6c5ea
4
+ data.tar.gz: fda07e32a04e3482995b1f6c86f74f1c1d7c90d21f6bd41668e63ce93c78c7f0
5
5
  SHA512:
6
- metadata.gz: 57c3384c3237ccc32363578e00d1f84750420981eaeb8cd0e9449989a76c69646a6dabe7b0a6ccea7ebfbe29455f37e4d683215b4074e7456af01c11800fb179
7
- data.tar.gz: 20523024b144dd7929bcd8f401f31cc5db9a8fa3f51af2d49c3e887636000ef4041b115fe650f8966bca831cbee36ed7f1b5a99c8d746a592c62c341038c84c3
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.5
2
+ TargetRubyVersion: 2.6
3
+ NewCops: enable
3
4
 
4
- Metrics/BlockLength:
5
- Exclude:
6
- - 'spec/**/*.rb'
5
+ Style/StringLiterals:
6
+ Enabled: true
7
+ EnforcedStyle: double_quotes
8
+
9
+ Style/StringLiteralsInInterpolation:
10
+ Enabled: true
11
+ EnforcedStyle: double_quotes
7
12
 
8
- Metrics/LineLength:
9
- Max: 100
13
+ Style/Documentation:
14
+ Enabled: false
10
15
 
11
- Naming/FileName:
12
- Exclude:
13
- - 'lib/*.rb'
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 'https://rubygems.org'
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 'pry', platform: :mri
12
- gem 'pry-byebug', platform: :mri
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.1.0)
5
- evil-client (~> 3.0)
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.6.0)
11
- public_suffix (>= 2.0.2, < 4.0)
12
- ast (2.4.0)
13
- byebug (11.0.1)
14
- coderay (1.1.2)
15
- concurrent-ruby (1.1.7)
16
- crack (0.4.3)
17
- safe_yaml (~> 1.0.0)
18
- diff-lcs (1.3)
19
- docile (1.3.1)
20
- dry-initializer (3.0.4)
21
- evil-client (3.0.4)
22
- dry-initializer (>= 2.1, < 4)
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
- jaro_winkler (1.5.2)
30
- json (2.2.0)
31
- method_source (0.9.2)
32
- mime-types (3.3.1)
33
- mime-types-data (~> 3.2015)
34
- mime-types-data (3.2020.1104)
35
- parallel (1.17.0)
36
- parser (2.6.3.0)
37
- ast (~> 2.4.0)
38
- pry (0.12.2)
39
- coderay (~> 1.1.0)
40
- method_source (~> 0.9.0)
41
- pry-byebug (3.7.0)
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 (3.1.0)
45
- rack (2.2.3)
72
+ public_suffix (4.0.6)
46
73
  rainbow (3.0.0)
47
- rake (12.3.2)
48
- rspec (3.8.0)
49
- rspec-core (~> 3.8.0)
50
- rspec-expectations (~> 3.8.0)
51
- rspec-mocks (~> 3.8.0)
52
- rspec-core (3.8.0)
53
- rspec-support (~> 3.8.0)
54
- rspec-expectations (3.8.3)
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.8.0)
57
- rspec-mocks (3.8.0)
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.8.0)
60
- rspec-support (3.8.0)
61
- rubocop (0.71.0)
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 (>= 2.6)
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, < 1.7)
68
- ruby-progressbar (1.10.1)
69
- safe_yaml (1.0.5)
70
- simplecov (0.16.1)
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
- json (>= 1.8, < 3)
73
- simplecov-html (~> 0.10.0)
74
- simplecov-html (0.10.2)
75
- tram-policy (2.0.1)
76
- dry-initializer (> 2, < 4)
77
- i18n (~> 1.0)
78
- unicode-display_width (1.6.0)
79
- webmock (3.5.1)
80
- addressable (>= 2.3.6)
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 (>= 10.0)
126
+ pry-byebug (~> 3.8.0)
127
+ rake (~> 13.0)
91
128
  rspec (~> 3.5)
92
- rubocop (~> 0.71)
129
+ rubocop (~> 1.22)
130
+ rubocop-rake (~> 0.6.0)
131
+ rubocop-rspec (~> 2.5)
93
132
  simplecov (~> 0.16)
94
- webmock (~> 3.5)
133
+ webmock (~> 3.14)
95
134
  yookassa!
96
135
 
97
136
  BUNDLED WITH
98
- 1.17.3
137
+ 2.2.22
data/README.md CHANGED
@@ -1,6 +1,5 @@
1
1
  # YooKassa API Ruby Client
2
-
3
- [![Yookassa](https://circleci.com/gh/paderinandrey/yookassa.svg?style=svg)](https://circleci.com/gh/paderinandrey/yookassa)
2
+ [![Github Actions](https://github.com/PaymentInstruments/yookassa/actions/workflows/main.yml/badge.svg)](https://github.com/PaymentInstruments/yookassa/actions/workflows/main.yml)
4
3
  [![Gem Version][gem-badger]][gem]
5
4
  [![License](https://img.shields.io/github/license/paderinandrey/yookassa.svg)](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
- # Payment
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
- client = Yookassa::Payment.new(shop_id: 'shop_id', api_key: 'api_key')
51
+ ### Making Payments
33
52
 
34
- payment = {
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
- client.create(payment: payment)
47
-
48
- client.get_payment_info(payment_id: '12345')
67
+ payment = Yookassa.payments.create(payment: payload)
49
68
 
50
- client.capture(payment_id: '12345')
69
+ # or
51
70
 
52
- client.cancel(payment_id: '12345')
71
+ client = Yookassa::Client.new(shop_id: 'shop_1', api_key: '123')
72
+ payment = client.payments.create(payment: payload)
73
+ ```
53
74
 
54
- # Refund
75
+ #### Other payment requests
55
76
 
56
- client = Yookassa::Refund.new(shop_id: 'shop_id', api_key: 'api_key')
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
- client.create(payload: payload)
83
+ ### Refunds
59
84
 
60
- client.get_refund_info(payment_id: '12345')
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
@@ -1,6 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "bundler/gem_tasks"
2
4
  require "rspec/core/rake_task"
3
5
 
4
6
  RSpec::Core::RakeTask.new(:spec)
5
7
 
6
- task :default => :spec
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[rubocop spec]
data/bin/console ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "yookassa"
6
+
7
+ begin
8
+ require "pry-byebug"
9
+ Pry.start
10
+ rescue LoadError
11
+ require "irb"
12
+ IRB.start
13
+ end
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,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,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
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Yookassa
4
+ class Config
5
+ attr_accessor :shop_id, :api_key
6
+ end
7
+ 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
- extend Dry::Initializer
7
- extend Yookassa::Callable
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