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
@@ -0,0 +1,101 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe Yookassa::Payments do
4
+ let(:config) { { shop_id: "SHOP_ID", api_key: "API_KEY" } }
5
+ let(:client) { Yookassa::Client.new(**config) }
6
+ let(:idempotency_key) { SecureRandom.hex(1) }
7
+
8
+ let(:payment) { client.payments }
9
+ let(:body) { File.read("spec/fixtures/payment_response.json") }
10
+
11
+ before { stub_request(:any, //).to_return(body: body, headers: { "Content-Type" => "application/json" }) }
12
+
13
+ shared_examples "returns_payment_object" do
14
+ it "returns success" do
15
+ expect(subject).to be_a Yookassa::Entity::Payment
16
+ expect(subject.id).to eq "2490ded1-000f-5000-8000-1f64111bc63e"
17
+ expect(subject.test).to eq true
18
+ expect(subject.paid).to eq false
19
+ expect(subject.status).to eq "pending"
20
+ expect(subject.captured_at).to eq nil
21
+ expect(subject.created_at).to eq DateTime.parse("2019-06-10T21:26:41.395Z")
22
+ expect(subject.description).to eq nil
23
+ expect(subject.expires_at).to eq nil
24
+ expect(subject.metadata).to eq({})
25
+
26
+ expect(subject.amount).to be_a Yookassa::Entity::Amount
27
+ expect(subject.amount.currency).to eq "RUB"
28
+ expect(subject.amount.value).to eq 10.0
29
+
30
+ expect(subject.confirmation).to be_a Yookassa::Entity::Confirmation
31
+ expect(subject.confirmation.confirmation_url).to eq "https://money.yookassa.ru/payments/external/confirmation?orderId=2490ded1-000f-5000-8000-1f64111bc63e"
32
+ expect(subject.confirmation.type).to eq "redirect"
33
+ expect(subject.confirmation.return_url).to eq "https://url.test"
34
+ expect(subject.confirmation.enforce).to eq nil
35
+
36
+ expect(Yookassa::Entity::PaymentMethods.valid?(subject.payment_method)).to be_truthy
37
+ expect(subject.payment_method).to be_a(Yookassa::Entity::PaymentMethod::BankCard)
38
+ expect(subject.payment_method.card).to eq nil
39
+ expect(subject.payment_method.id).to eq "2490ded1-000f-5000-8000-1f64111bc63e"
40
+ expect(subject.payment_method.saved).to eq false
41
+ expect(subject.payment_method.type).to eq "bank_card"
42
+ expect(subject.payment_method.title).to eq nil
43
+ end
44
+ end
45
+
46
+ describe "#create" do
47
+ let(:params) { JSON.parse(File.read("spec/fixtures/payment.json")) }
48
+ let(:url) { "https://api.yookassa.ru/v3/payments" }
49
+
50
+ subject { payment.create(payment: params, idempotency_key: idempotency_key) }
51
+
52
+ it "sends a request" do
53
+ subject
54
+ expect(a_request(:post, url)).to have_been_made
55
+ end
56
+
57
+ it_behaves_like "returns_payment_object"
58
+ end
59
+
60
+ describe "#find" do
61
+ let(:payment_id) { "2490ded1-000f-5000-8000-1f64111bc63e" }
62
+ let(:url) { "https://api.yookassa.ru/v3/payments/#{payment_id}" }
63
+
64
+ subject { payment.find(payment_id: payment_id) }
65
+
66
+ it "sends a request" do
67
+ subject
68
+ expect(a_request(:get, url)).to have_been_made
69
+ end
70
+
71
+ it_behaves_like "returns_payment_object"
72
+ end
73
+
74
+ describe "#capture" do
75
+ let(:payment_id) { "2490ded1-000f-5000-8000-1f64111bc63e" }
76
+ let(:url) { "https://api.yookassa.ru/v3/payments/#{payment_id}/capture" }
77
+
78
+ subject { payment.capture(payment_id: payment_id, idempotency_key: idempotency_key) }
79
+
80
+ it "sends a request" do
81
+ subject
82
+ expect(a_request(:post, url)).to have_been_made
83
+ end
84
+
85
+ it_behaves_like "returns_payment_object"
86
+ end
87
+
88
+ describe "#cancel" do
89
+ let(:payment_id) { "2490ded1-000f-5000-8000-1f64111bc63e" }
90
+ let(:url) { "https://api.yookassa.ru/v3/payments/#{payment_id}/cancel" }
91
+
92
+ subject { payment.cancel(payment_id: payment_id, idempotency_key: idempotency_key) }
93
+
94
+ it "sends a request" do
95
+ subject
96
+ expect(a_request(:post, url)).to have_been_made
97
+ end
98
+
99
+ it_behaves_like "returns_payment_object"
100
+ end
101
+ end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe Yookassa::Refunds do
4
+ let(:config) { { shop_id: "SHOP_ID", api_key: "API_KEY" } }
5
+ let(:client) { Yookassa::Client.new(**config) }
6
+ let(:idempotency_key) { SecureRandom.hex(1) }
7
+ let(:refund) { client.refunds }
8
+ let(:body) { File.read("spec/fixtures/refund_response.json") }
9
+
10
+ before { stub_request(:any, //).to_return(body: body, headers: { "Content-Type" => "application/json" }) }
11
+
12
+ shared_examples "returns_refund_object" do
13
+ it "returns success" do
14
+ expect(subject).to be_a Yookassa::Entity::Refund
15
+ expect(subject.id).to eq "2491ab0c-0015-5000-9000-1640c7f1a6f0"
16
+ expect(subject.payment_id).to eq "2491a6e2-000f-5000-9000-1480e820ae17"
17
+ expect(subject.status).to eq "succeeded"
18
+ expect(subject.created_at).to eq "2019-06-11T11:58:04.502Z"
19
+ expect(subject.description).to eq "test refund, idem-key 78c95366-ec4b-4284-a0fd-41e694bcdf11"
20
+
21
+ expect(subject.amount).to be_kind_of Yookassa::Entity::Amount
22
+ expect(subject.amount.currency).to eq "RUB"
23
+ expect(subject.amount.value).to eq 8.0
24
+ end
25
+ end
26
+
27
+ describe "#create" do
28
+ let(:payload) { JSON.parse(File.read("spec/fixtures/refund.json")) }
29
+ let(:url) { "https://api.yookassa.ru/v3/refunds" }
30
+
31
+ subject { refund.create(payload: payload, idempotency_key: idempotency_key) }
32
+
33
+ it "sends a request" do
34
+ subject
35
+ expect(a_request(:post, url)).to have_been_made
36
+ end
37
+
38
+ it_behaves_like "returns_refund_object"
39
+ end
40
+
41
+ describe "#find" do
42
+ let(:payment_id) { "2490ded1-000f-5000-8000-1f64111bc63e" }
43
+ let(:url) { "https://api.yookassa.ru/v3/refunds/#{payment_id}" }
44
+
45
+ subject { refund.find(payment_id: payment_id) }
46
+
47
+ it "sends a request" do
48
+ subject
49
+ expect(a_request(:get, url)).to have_been_made
50
+ end
51
+
52
+ it_behaves_like "returns_refund_object"
53
+ end
54
+ end
@@ -1,7 +1,44 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  RSpec.describe Yookassa do
4
- it 'has a version number' do
4
+ it "has a version number" do
5
5
  expect(Yookassa::VERSION).not_to be nil
6
6
  end
7
+
8
+ before do
9
+ Yookassa.configure do |config|
10
+ config.shop_id = 123
11
+ config.api_key = "test_321"
12
+ end
13
+ end
14
+
15
+ describe ".configure" do
16
+ it "stores settings and provides access to credentials" do
17
+ expect(Yookassa.config.shop_id).to eq(123)
18
+ expect(Yookassa.config.api_key).to eq("test_321")
19
+ end
20
+ end
21
+
22
+ describe ".client" do
23
+ context "when no settings are provided" do
24
+ before { Yookassa.instance_variable_set(:@config, nil) }
25
+
26
+ it "raises an error" do
27
+ expect { Yookassa.client }.to raise_error(Yookassa::ConfigError)
28
+ end
29
+ end
30
+
31
+ context "when instance configured" do
32
+ it "creates and stores client" do
33
+ expect(Yookassa.client).to be_a(Yookassa::Client)
34
+ expect(Yookassa.client).to eq(Yookassa.client)
35
+ end
36
+ end
37
+ end
38
+
39
+ describe ".payments" do
40
+ it "delegates request to client and creates an instance" do
41
+ expect(Yookassa.payments).to be_a(Yookassa::Payments)
42
+ end
43
+ end
7
44
  end
data/yookassa.gemspec CHANGED
@@ -1,32 +1,27 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- lib = File.expand_path('lib', __dir__)
3
+ lib = File.expand_path("lib", __dir__)
4
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
- require 'yookassa/version'
5
+ require "yookassa/version"
6
6
 
7
7
  Gem::Specification.new do |spec|
8
- spec.name = 'yookassa'
8
+ spec.name = "yookassa"
9
9
  spec.version = Yookassa::VERSION
10
- spec.authors = 'Andrey Paderin'
11
- spec.email = 'andy.paderin@gmail.com'
10
+ spec.authors = "Andrey Paderin"
11
+ spec.email = "andy.paderin@gmail.com"
12
12
 
13
- spec.summary = 'This product is used for managing payments under The Yookassa API For usage by those who implemented Yookassa using the API method.'
14
- spec.homepage = 'https://github.com/paderinandrey/yookassa'
15
- spec.license = 'MIT'
13
+ spec.summary = "Yookassa API SDK for Ruby"
14
+ spec.homepage = "https://github.com/paderinandrey/yookassa"
15
+ spec.license = "MIT"
16
16
 
17
17
  spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
18
18
  spec.test_files = spec.files.grep(/^spec/)
19
- spec.extra_rdoc_files = Dir['README.md', 'LICENSE', 'CHANGELOG.md']
19
+ spec.extra_rdoc_files = Dir["README.md", "LICENSE", "CHANGELOG.md"]
20
20
 
21
- spec.require_paths = ['lib']
21
+ spec.require_paths = ["lib"]
22
22
 
23
- spec.required_ruby_version = '>= 2.5'
23
+ spec.required_ruby_version = ">= 2.6"
24
24
 
25
- spec.add_runtime_dependency 'evil-client', '~> 3.0'
26
-
27
- spec.add_development_dependency 'rake', '>= 10.0'
28
- spec.add_development_dependency 'rspec', '~> 3.5'
29
- spec.add_development_dependency 'rubocop', '~> 0.71'
30
- spec.add_development_dependency 'simplecov', '~> 0.16'
31
- spec.add_development_dependency 'webmock', '~> 3.5'
25
+ spec.add_runtime_dependency "dry-struct"
26
+ spec.add_runtime_dependency "http", "~> 5.0.1"
32
27
  end
metadata CHANGED
@@ -1,99 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yookassa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrey Paderin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-07 00:00:00.000000000 Z
11
+ date: 2021-11-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: evil-client
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '3.0'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '3.0'
27
- - !ruby/object:Gem::Dependency
28
- name: rake
14
+ name: dry-struct
29
15
  requirement: !ruby/object:Gem::Requirement
30
16
  requirements:
31
17
  - - ">="
32
18
  - !ruby/object:Gem::Version
33
- version: '10.0'
34
- type: :development
19
+ version: '0'
20
+ type: :runtime
35
21
  prerelease: false
36
22
  version_requirements: !ruby/object:Gem::Requirement
37
23
  requirements:
38
24
  - - ">="
39
25
  - !ruby/object:Gem::Version
40
- version: '10.0'
41
- - !ruby/object:Gem::Dependency
42
- name: rspec
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '3.5'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '3.5'
26
+ version: '0'
55
27
  - !ruby/object:Gem::Dependency
56
- name: rubocop
28
+ name: http
57
29
  requirement: !ruby/object:Gem::Requirement
58
30
  requirements:
59
31
  - - "~>"
60
32
  - !ruby/object:Gem::Version
61
- version: '0.71'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: '0.71'
69
- - !ruby/object:Gem::Dependency
70
- name: simplecov
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - "~>"
74
- - !ruby/object:Gem::Version
75
- version: '0.16'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - "~>"
81
- - !ruby/object:Gem::Version
82
- version: '0.16'
83
- - !ruby/object:Gem::Dependency
84
- name: webmock
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - "~>"
88
- - !ruby/object:Gem::Version
89
- version: '3.5'
90
- type: :development
33
+ version: 5.0.1
34
+ type: :runtime
91
35
  prerelease: false
92
36
  version_requirements: !ruby/object:Gem::Requirement
93
37
  requirements:
94
38
  - - "~>"
95
39
  - !ruby/object:Gem::Version
96
- version: '3.5'
40
+ version: 5.0.1
97
41
  description:
98
42
  email: andy.paderin@gmail.com
99
43
  executables: []
@@ -101,7 +45,7 @@ extensions: []
101
45
  extra_rdoc_files:
102
46
  - README.md
103
47
  files:
104
- - ".circleci/config.yml"
48
+ - ".github/workflows/main.yml"
105
49
  - ".gitignore"
106
50
  - ".rspec"
107
51
  - ".rubocop.yml"
@@ -110,19 +54,28 @@ files:
110
54
  - LICENSE.txt
111
55
  - README.md
112
56
  - Rakefile
57
+ - bin/console
58
+ - bin/rake
59
+ - bin/rspec
60
+ - bin/rubocop
61
+ - bin/setup
113
62
  - lib/yookassa.rb
114
- - lib/yookassa/callable.rb
63
+ - lib/yookassa/client.rb
64
+ - lib/yookassa/config.rb
115
65
  - lib/yookassa/entity/amount.rb
66
+ - lib/yookassa/entity/authorization_details.rb
67
+ - lib/yookassa/entity/cancellation_details.rb
116
68
  - lib/yookassa/entity/card.rb
117
69
  - lib/yookassa/entity/confirmation.rb
70
+ - lib/yookassa/entity/error.rb
118
71
  - lib/yookassa/entity/payment.rb
119
- - lib/yookassa/entity/payment_method.rb
72
+ - lib/yookassa/entity/payment_methods.rb
73
+ - lib/yookassa/entity/recipient.rb
120
74
  - lib/yookassa/entity/refund.rb
121
- - lib/yookassa/error.rb
122
- - lib/yookassa/optional.rb
123
- - lib/yookassa/payment.rb
124
- - lib/yookassa/refund.rb
125
- - lib/yookassa/response.rb
75
+ - lib/yookassa/entity/transfer.rb
76
+ - lib/yookassa/entity/types.rb
77
+ - lib/yookassa/payments.rb
78
+ - lib/yookassa/refunds.rb
126
79
  - lib/yookassa/version.rb
127
80
  - spec/fixtures/errors/duplicate_idempotence_key.json
128
81
  - spec/fixtures/errors/invalid_request.json
@@ -131,8 +84,9 @@ files:
131
84
  - spec/fixtures/refund.json
132
85
  - spec/fixtures/refund_response.json
133
86
  - spec/spec_helper.rb
134
- - spec/yookassa/payment_spec.rb
135
- - spec/yookassa/refund_spec.rb
87
+ - spec/yookassa/config_spec.rb
88
+ - spec/yookassa/payments_spec.rb
89
+ - spec/yookassa/refunds_spec.rb
136
90
  - spec/yookassa_spec.rb
137
91
  - yookassa.gemspec
138
92
  homepage: https://github.com/paderinandrey/yookassa
@@ -147,18 +101,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
147
101
  requirements:
148
102
  - - ">="
149
103
  - !ruby/object:Gem::Version
150
- version: '2.5'
104
+ version: '2.6'
151
105
  required_rubygems_version: !ruby/object:Gem::Requirement
152
106
  requirements:
153
107
  - - ">="
154
108
  - !ruby/object:Gem::Version
155
109
  version: '0'
156
110
  requirements: []
157
- rubygems_version: 3.0.6
111
+ rubygems_version: 3.2.22
158
112
  signing_key:
159
113
  specification_version: 4
160
- summary: This product is used for managing payments under The Yookassa API For usage
161
- by those who implemented Yookassa using the API method.
114
+ summary: Yookassa API SDK for Ruby
162
115
  test_files:
163
116
  - spec/fixtures/errors/duplicate_idempotence_key.json
164
117
  - spec/fixtures/errors/invalid_request.json
@@ -167,6 +120,7 @@ test_files:
167
120
  - spec/fixtures/refund.json
168
121
  - spec/fixtures/refund_response.json
169
122
  - spec/spec_helper.rb
170
- - spec/yookassa/payment_spec.rb
171
- - spec/yookassa/refund_spec.rb
123
+ - spec/yookassa/config_spec.rb
124
+ - spec/yookassa/payments_spec.rb
125
+ - spec/yookassa/refunds_spec.rb
172
126
  - spec/yookassa_spec.rb
data/.circleci/config.yml DELETED
@@ -1,28 +0,0 @@
1
- version: 2.1
2
- orbs:
3
- ruby: circleci/ruby@0.1.2
4
-
5
- jobs:
6
- build:
7
- docker:
8
- - image: circleci/ruby:2.6.3-stretch-node
9
- executor: ruby/default
10
- steps:
11
- - checkout
12
- - restore_cache:
13
- keys:
14
- - yookassa-bundle-{{ checksum "Gemfile.lock" }}
15
- - yookassa-bundle-
16
- - run:
17
- name: Install dependencies
18
- command: |
19
- bundle check || bundle install --jobs=4 --retry=3 --path vendor/bundle
20
- - save_cache:
21
- paths:
22
- - ./vendor/bundle
23
- key: yookassa-bundle-{{ checksum "Gemfile.lock" }}
24
-
25
- - run:
26
- name: Run tests
27
- command: |
28
- bundle exec rspec --profile 10 --format progress
@@ -1,10 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Yookassa
4
- module Callable
5
- def call(*args)
6
- new(*args)
7
- end
8
- alias [] call
9
- end
10
- end
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative './card'
4
-
5
- module Yookassa
6
- module Entity
7
- class PaymentMethod
8
- extend Dry::Initializer
9
- extend Yookassa::Callable
10
- include Yookassa::Optional
11
-
12
- option :type, proc(&:to_s)
13
- option :id, proc(&:to_s)
14
- option :saved
15
- option :card, Entity::Card, optional: true
16
- option :title, proc(&:to_s), optional: true
17
- end
18
- end
19
- end
@@ -1,30 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Yookassa
4
- class Error
5
- extend Dry::Initializer
6
- extend Yookassa::Callable
7
- include Yookassa::Optional
8
-
9
- option :type, proc(&:to_s)
10
- option :id, proc(&:to_s), optional: true
11
- option :code, proc(&:to_s), optional: true
12
- option :description, proc(&:to_s), optional: true
13
- option :parameter, proc(&:to_s), optional: true
14
-
15
- def error?
16
- type == 'error'
17
- end
18
-
19
- class << self
20
- def build(*res)
21
- body = res.last
22
- new JSON.parse(body.first)
23
- end
24
-
25
- def new(opts)
26
- super opts.each_with_object({}) { |(key, val), obj| obj[key.to_sym] = val }
27
- end
28
- end
29
- end
30
- end
@@ -1,23 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Yookassa
4
- module Optional
5
- private
6
-
7
- def initialize(opts)
8
- super opts.each_with_object({}) { |(key, val), obj| obj[key.to_sym] = val }
9
- end
10
-
11
- def __options__
12
- @__options__ ||= self.class.dry_initializer.attributes(self)
13
- end
14
-
15
- def respond_to_missing?(name, *)
16
- __options__.respond_to? name
17
- end
18
-
19
- def method_missing(*args, &block)
20
- respond_to_missing?(*args) ? __options__.send(*args, &block) : super
21
- end
22
- end
23
- end
@@ -1,65 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Yookassa
4
- class Payment < Evil::Client
5
- option :shop_id, proc(&:to_s)
6
- option :api_key, proc(&:to_s)
7
-
8
- path { 'https://api.yookassa.ru/v3/payments' }
9
- security { basic_auth shop_id, api_key }
10
-
11
- operation :get_payment_info do
12
- option :payment_id, proc(&:to_s)
13
-
14
- http_method :get
15
- path { "/#{payment_id}" }
16
-
17
- response(200) { |*res| Entity::Payment.build(*res) }
18
- response(400, 404) { |*res| Error.build(*res) }
19
- end
20
-
21
- operation :create do
22
- option :payment
23
- option :idempotency_key, proc(&:to_s)
24
-
25
- http_method :post
26
-
27
- format 'json'
28
- headers { { 'Idempotence-Key' => idempotency_key } }
29
- body { payment }
30
-
31
- response(200) { |*res| Entity::Payment.build(*res) }
32
- response(400) { |*res| Error.build(*res) }
33
- end
34
-
35
- operation :capture do
36
- option :payment_id, proc(&:to_s)
37
- option :idempotency_key, optional: true
38
-
39
- http_method :post
40
-
41
- path { "/#{payment_id}/capture" }
42
-
43
- format 'json'
44
- headers { { 'Idempotence-Key' => idempotency_key } }
45
-
46
- response(200) { |*res| Entity::Payment.build(*res) }
47
- response(400) { |*res| Error.build(*res) }
48
- end
49
-
50
- operation :cancel do
51
- option :payment_id, proc(&:to_s)
52
- option :idempotency_key, optional: true
53
-
54
- http_method :post
55
-
56
- path { "/#{payment_id}/cancel" }
57
-
58
- format 'json'
59
- headers { { 'Idempotence-Key' => idempotency_key } }
60
-
61
- response(200) { |*res| Entity::Payment.build(*res) }
62
- response(400) { |*res| Error.build(*res) }
63
- end
64
- end
65
- end
@@ -1,35 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Yookassa
4
- class Refund < Evil::Client
5
- option :shop_id, proc(&:to_s)
6
- option :api_key, proc(&:to_s)
7
-
8
- path { 'https://api.yookassa.ru/v3/refunds' }
9
- security { basic_auth shop_id, api_key }
10
-
11
- operation :get_refund_info do
12
- option :payment_id, proc(&:to_s)
13
-
14
- http_method :get
15
- path { "/#{payment_id}" }
16
-
17
- response(200) { |*res| Entity::Refund.build(*res) }
18
- response(400, 404) { |*res| Error.build(*res) }
19
- end
20
-
21
- operation :create do
22
- option :payload
23
- option :idempotency_key, proc(&:to_s)
24
-
25
- http_method :post
26
-
27
- format 'json'
28
- headers { { 'Idempotence-Key' => idempotency_key } }
29
- body { payload }
30
-
31
- response(200) { |*res| Entity::Refund.build(*res) }
32
- response(400, 404) { |*res| Error.build(*res) }
33
- end
34
- end
35
- end
@@ -1,20 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Yookassa
4
- class Response
5
- extend Dry::Initializer
6
- option :id, proc(&:to_s)
7
- option :status, proc(&:to_s), default: proc { nil }
8
-
9
- class << self
10
- def build(*res)
11
- body = res.last
12
- new JSON.parse(body.first)
13
- end
14
-
15
- def new(opts)
16
- super opts.each_with_object({}) { |(key, val), obj| obj[key.to_sym] = val }
17
- end
18
- end
19
- end
20
- end