yookassa 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -1,104 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe Yookassa::Payment do
|
4
|
-
let(:settings) { { shop_id: 'SHOP_ID', api_key: 'API_KEY' } }
|
5
|
-
let(:idempotency_key) { 12_345 }
|
6
|
-
let(:payment) { described_class.new(settings) }
|
7
|
-
|
8
|
-
shared_examples 'returns_payment_object' do
|
9
|
-
it 'returns success' do
|
10
|
-
expect(subject).to be_kind_of Yookassa::Response
|
11
|
-
expect(subject.id).to eq '2490ded1-000f-5000-8000-1f64111bc63e'
|
12
|
-
expect(subject.test).to eq true
|
13
|
-
expect(subject.paid).to eq false
|
14
|
-
expect(subject.status).to eq 'pending'
|
15
|
-
expect(subject.captured_at).to eq nil
|
16
|
-
expect(subject.created_at).to eq '2019-06-10T21:26:41.395Z'
|
17
|
-
expect(subject.description).to eq nil
|
18
|
-
expect(subject.expires_at).to eq nil
|
19
|
-
expect(subject.metadata).to eq Hash[]
|
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 10.0
|
24
|
-
|
25
|
-
expect(subject.confirmation).to be_kind_of Yookassa::Entity::Confirmation
|
26
|
-
expect(subject.confirmation.confirmation_url).to eq 'https://money.yookassa.ru/payments/external/confirmation?orderId=2490ded1-000f-5000-8000-1f64111bc63e'
|
27
|
-
expect(subject.confirmation.type).to eq 'redirect'
|
28
|
-
expect(subject.confirmation.return_url).to eq 'https://url.test'
|
29
|
-
expect(subject.confirmation.enforce).to eq nil
|
30
|
-
|
31
|
-
expect(subject.payment_method).to be_kind_of Yookassa::Entity::PaymentMethod
|
32
|
-
expect(subject.payment_method.card).to eq nil
|
33
|
-
expect(subject.payment_method.id).to eq '2490ded1-000f-5000-8000-1f64111bc63e'
|
34
|
-
expect(subject.payment_method.saved).to eq false
|
35
|
-
expect(subject.payment_method.type).to eq 'bank_card'
|
36
|
-
expect(subject.payment_method.title).to eq nil
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
describe '#create' do
|
41
|
-
let(:params) { { payment: File.read('spec/fixtures/payment.json') } }
|
42
|
-
let(:url) { 'https://api.yookassa.ru/v3/payments' }
|
43
|
-
let(:body) { File.read('spec/fixtures/payment_response.json') }
|
44
|
-
|
45
|
-
before { stub_request(:any, //).to_return(body: body) }
|
46
|
-
subject { payment.create(payment: params, idempotency_key: idempotency_key) }
|
47
|
-
|
48
|
-
it 'sends a request' do
|
49
|
-
subject
|
50
|
-
expect(a_request(:post, url)).to have_been_made
|
51
|
-
end
|
52
|
-
|
53
|
-
it_behaves_like 'returns_payment_object'
|
54
|
-
end
|
55
|
-
|
56
|
-
describe '#get_payment_info' do
|
57
|
-
let(:payment_id) { '2490ded1-000f-5000-8000-1f64111bc63e' }
|
58
|
-
let(:url) { "https://api.yookassa.ru/v3/payments/#{payment_id}" }
|
59
|
-
let(:body) { File.read('spec/fixtures/payment_response.json') }
|
60
|
-
|
61
|
-
before { stub_request(:any, //).to_return(body: body) }
|
62
|
-
subject { payment.get_payment_info(payment_id: payment_id) }
|
63
|
-
|
64
|
-
it 'sends a request' do
|
65
|
-
subject
|
66
|
-
expect(a_request(:get, url)).to have_been_made
|
67
|
-
end
|
68
|
-
|
69
|
-
it_behaves_like 'returns_payment_object'
|
70
|
-
end
|
71
|
-
|
72
|
-
describe '#capture' do
|
73
|
-
let(:payment_id) { '2490ded1-000f-5000-8000-1f64111bc63e' }
|
74
|
-
let(:params) { { payment: File.read('spec/fixtures/payment.json') } }
|
75
|
-
let(:url) { "https://api.yookassa.ru/v3/payments/#{payment_id}/capture" }
|
76
|
-
let(:body) { File.read('spec/fixtures/payment_response.json') }
|
77
|
-
|
78
|
-
before { stub_request(:any, //).to_return(body: body) }
|
79
|
-
subject { payment.capture(payment_id: payment_id, idempotency_key: idempotency_key) }
|
80
|
-
|
81
|
-
it 'sends a request' do
|
82
|
-
subject
|
83
|
-
expect(a_request(:post, url)).to have_been_made
|
84
|
-
end
|
85
|
-
|
86
|
-
it_behaves_like 'returns_payment_object'
|
87
|
-
end
|
88
|
-
|
89
|
-
describe '#cancel' do
|
90
|
-
let(:payment_id) { '2490ded1-000f-5000-8000-1f64111bc63e' }
|
91
|
-
let(:url) { "https://api.yookassa.ru/v3/payments/#{payment_id}/cancel" }
|
92
|
-
let(:body) { File.read('spec/fixtures/payment_response.json') }
|
93
|
-
|
94
|
-
before { stub_request(:any, //).to_return(body: body) }
|
95
|
-
subject { payment.cancel(payment_id: payment_id, idempotency_key: idempotency_key) }
|
96
|
-
|
97
|
-
it 'sends a request' do
|
98
|
-
subject
|
99
|
-
expect(a_request(:post, url)).to have_been_made
|
100
|
-
end
|
101
|
-
|
102
|
-
it_behaves_like 'returns_payment_object'
|
103
|
-
end
|
104
|
-
end
|
@@ -1,54 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe Yookassa::Refund do
|
4
|
-
let(:settings) { { shop_id: 'SHOP_ID', api_key: 'API_KEY' } }
|
5
|
-
let(:idempotency_key) { 12_345 }
|
6
|
-
let(:payment) { described_class.new(settings) }
|
7
|
-
|
8
|
-
shared_examples 'returns_refund_object' do
|
9
|
-
it 'returns success' do
|
10
|
-
expect(subject).to be_kind_of Yookassa::Response
|
11
|
-
expect(subject.id).to eq '2491ab0c-0015-5000-9000-1640c7f1a6f0'
|
12
|
-
expect(subject.payment_id).to eq '2491a6e2-000f-5000-9000-1480e820ae17'
|
13
|
-
expect(subject.status).to eq 'succeeded'
|
14
|
-
expect(subject.created_at).to eq '2019-06-11T11:58:04.502Z'
|
15
|
-
expect(subject.description).to eq 'test refund, idem-key 78c95366-ec4b-4284-a0fd-41e694bcdf11'
|
16
|
-
|
17
|
-
expect(subject.amount).to be_kind_of Yookassa::Entity::Amount
|
18
|
-
expect(subject.amount.currency).to eq 'RUB'
|
19
|
-
expect(subject.amount.value).to eq 8.0
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
describe '#create' do
|
24
|
-
let(:payload) { File.read('spec/fixtures/refund.json') }
|
25
|
-
let(:url) { 'https://api.yookassa.ru/v3/refunds' }
|
26
|
-
let(:body) { File.read('spec/fixtures/refund_response.json') }
|
27
|
-
|
28
|
-
before { stub_request(:any, //).to_return(body: body) }
|
29
|
-
subject { payment.create(payload: payload, idempotency_key: idempotency_key) }
|
30
|
-
|
31
|
-
it 'sends a request' do
|
32
|
-
subject
|
33
|
-
expect(a_request(:post, url)).to have_been_made
|
34
|
-
end
|
35
|
-
|
36
|
-
it_behaves_like 'returns_refund_object'
|
37
|
-
end
|
38
|
-
|
39
|
-
describe '#get_refund_info' do
|
40
|
-
let(:payment_id) { '2490ded1-000f-5000-8000-1f64111bc63e' }
|
41
|
-
let(:url) { "https://api.yookassa.ru/v3/refunds/#{payment_id}" }
|
42
|
-
let(:body) { File.read('spec/fixtures/refund_response.json') }
|
43
|
-
|
44
|
-
before { stub_request(:any, //).to_return(body: body) }
|
45
|
-
subject { payment.get_refund_info(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
|