1
0
зеркало из https://github.com/glebtv/yookassa.git synced 2026-08-28 15:16:18 +03:00
Этот коммит содержится в:
Ivan Shamatov
2021-10-28 20:15:08 +03:00
родитель 847c90bb6c
Коммит e6a7b5cb7f
23 изменённых файлов: 254 добавлений и 138 удалений

4
.github/workflows/main.yml поставляемый
Просмотреть файл

@@ -24,5 +24,5 @@ jobs:
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
- name: Run the default task
run: bundle exec rspec
- name: Cops & Specs
run: bin/rake

Просмотреть файл

@@ -1,13 +1,20 @@
AllCops:
TargetRubyVersion: 2.5
TargetRubyVersion: 2.6
NewCops: enable
Style/StringLiterals:
Enabled: true
EnforcedStyle: double_quotes
Style/StringLiteralsInInterpolation:
Enabled: true
EnforcedStyle: double_quotes
Style/Documentation:
Enabled: false
Layout/LineLength:
Max: 150
Metrics/BlockLength:
Exclude:
- 'spec/**/*.rb'
Metrics/LineLength:
Max: 100
Naming/FileName:
Exclude:
- 'lib/*.rb'
IgnoredMethods: ['describe', 'context', 'shared_examples']

11
Gemfile
Просмотреть файл

@@ -1,6 +1,6 @@
# frozen_string_literal: true
source 'https://rubygems.org'
source "https://rubygems.org"
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
@@ -8,6 +8,11 @@ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
gemspec
group :development, :test do
gem 'pry', platform: :mri
gem 'pry-byebug', platform: :mri
gem "pry"
gem "pry-byebug"
gem "rake", "~> 13.0"
gem "rspec", "~> 3.0"
gem "rubocop", "~> 1.21"
gem "rubocop-rake", "~> 0.6.0"
gem "rubocop-rspec", "~> 2.5"
end

Просмотреть файл

@@ -9,7 +9,7 @@ GEM
specs:
addressable (2.6.0)
public_suffix (>= 2.0.2, < 4.0)
ast (2.4.0)
ast (2.4.2)
byebug (11.0.1)
coderay (1.1.2)
concurrent-ruby (1.1.7)
@@ -26,15 +26,14 @@ GEM
hashdiff (0.4.0)
i18n (1.8.5)
concurrent-ruby (~> 1.0)
jaro_winkler (1.5.2)
json (2.2.0)
method_source (0.9.2)
mime-types (3.3.1)
mime-types-data (~> 3.2015)
mime-types-data (3.2020.1104)
parallel (1.17.0)
parser (2.6.3.0)
ast (~> 2.4.0)
parallel (1.21.0)
parser (3.0.2.0)
ast (~> 2.4.1)
pry (0.12.2)
coderay (~> 1.1.0)
method_source (~> 0.9.0)
@@ -44,7 +43,9 @@ GEM
public_suffix (3.1.0)
rack (2.2.3)
rainbow (3.0.0)
rake (12.3.2)
rake (13.0.6)
regexp_parser (2.1.1)
rexml (3.2.5)
rspec (3.8.0)
rspec-core (~> 3.8.0)
rspec-expectations (~> 3.8.0)
@@ -58,14 +59,22 @@ GEM
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.8.0)
rspec-support (3.8.0)
rubocop (0.71.0)
jaro_winkler (~> 1.5.1)
rubocop (1.22.3)
parallel (~> 1.10)
parser (>= 2.6)
parser (>= 3.0.0.0)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml
rubocop-ast (>= 1.12.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 1.7)
ruby-progressbar (1.10.1)
unicode-display_width (>= 1.4.0, < 3.0)
rubocop-ast (1.12.0)
parser (>= 3.0.1.1)
rubocop-rake (0.6.0)
rubocop (~> 1.0)
rubocop-rspec (2.5.0)
rubocop (~> 1.19)
ruby-progressbar (1.11.0)
safe_yaml (1.0.5)
simplecov (0.16.1)
docile (~> 1.1)
@@ -75,7 +84,7 @@ GEM
tram-policy (2.0.1)
dry-initializer (> 2, < 4)
i18n (~> 1.0)
unicode-display_width (1.6.0)
unicode-display_width (2.1.0)
webmock (3.5.1)
addressable (>= 2.3.6)
crack (>= 0.3.2)
@@ -87,9 +96,11 @@ PLATFORMS
DEPENDENCIES
pry
pry-byebug
rake (>= 10.0)
rspec (~> 3.5)
rubocop (~> 0.71)
rake (~> 13.0)
rspec (~> 3.0)
rubocop (~> 1.21)
rubocop-rake (~> 0.6.0)
rubocop-rspec (~> 2.5)
simplecov (~> 0.16)
webmock (~> 3.5)
yookassa!

Просмотреть файл

@@ -1,6 +1,12 @@
# frozen_string_literal: true
require "bundler/gem_tasks"
require "rspec/core/rake_task"
RSpec::Core::RakeTask.new(:spec)
task :default => :spec
require "rubocop/rake_task"
RuboCop::RakeTask.new
task default: %i[rubocop spec]

29
bin/rake Исполняемый файл
Просмотреть файл

@@ -0,0 +1,29 @@
#!/usr/bin/env ruby
# frozen_string_literal: true
#
# This file was generated by Bundler.
#
# The application 'rake' is installed as part of a gem, and
# this file is here to facilitate running it.
#
require "pathname"
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
Pathname.new(__FILE__).realpath)
bundle_binstub = File.expand_path("bundle", __dir__)
if File.file?(bundle_binstub)
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
load(bundle_binstub)
else
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
end
end
require "rubygems"
require "bundler/setup"
load Gem.bin_path("rake", "rake")

29
bin/rspec Исполняемый файл
Просмотреть файл

@@ -0,0 +1,29 @@
#!/usr/bin/env ruby
# frozen_string_literal: true
#
# This file was generated by Bundler.
#
# The application 'rspec' is installed as part of a gem, and
# this file is here to facilitate running it.
#
require "pathname"
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
Pathname.new(__FILE__).realpath)
bundle_binstub = File.expand_path("bundle", __dir__)
if File.file?(bundle_binstub)
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
load(bundle_binstub)
else
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
end
end
require "rubygems"
require "bundler/setup"
load Gem.bin_path("rspec-core", "rspec")

29
bin/rubocop Исполняемый файл
Просмотреть файл

@@ -0,0 +1,29 @@
#!/usr/bin/env ruby
# frozen_string_literal: true
#
# This file was generated by Bundler.
#
# The application 'rubocop' is installed as part of a gem, and
# this file is here to facilitate running it.
#
require "pathname"
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
Pathname.new(__FILE__).realpath)
bundle_binstub = File.expand_path("bundle", __dir__)
if File.file?(bundle_binstub)
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
load(bundle_binstub)
else
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
end
end
require "rubygems"
require "bundler/setup"
load Gem.bin_path("rubocop", "rubocop")

Просмотреть файл

@@ -1,13 +1,13 @@
# frozen_string_literal: true
require 'evil/client'
require "evil/client"
require 'yookassa/version'
require 'yookassa/payment'
require 'yookassa/refund'
require 'yookassa/response'
require 'yookassa/callable'
require 'yookassa/optional'
require 'yookassa/entity/payment'
require 'yookassa/entity/refund'
require 'yookassa/error'
require "yookassa/version"
require "yookassa/payment"
require "yookassa/refund"
require "yookassa/response"
require "yookassa/callable"
require "yookassa/optional"
require "yookassa/entity/payment"
require "yookassa/entity/refund"
require "yookassa/error"

Просмотреть файл

@@ -1,8 +1,8 @@
# frozen_string_literal: true
require_relative './amount'
require_relative './payment_method'
require_relative './confirmation'
require_relative "./amount"
require_relative "./payment_method"
require_relative "./confirmation"
module Yookassa
module Entity

Просмотреть файл

@@ -1,6 +1,6 @@
# frozen_string_literal: true
require_relative './card'
require_relative "./card"
module Yookassa
module Entity

Просмотреть файл

@@ -1,6 +1,6 @@
# frozen_string_literal: true
require_relative './amount'
require_relative "./amount"
module Yookassa
module Entity

Просмотреть файл

@@ -13,7 +13,7 @@ module Yookassa
option :parameter, proc(&:to_s), optional: true
def error?
type == 'error'
type == "error"
end
class << self
@@ -23,7 +23,7 @@ module Yookassa
end
def new(opts)
super opts.each_with_object({}) { |(key, val), obj| obj[key.to_sym] = val }
super opts.transform_keys(&:to_sym)
end
end
end

Просмотреть файл

@@ -5,7 +5,7 @@ module Yookassa
private
def initialize(opts)
super opts.each_with_object({}) { |(key, val), obj| obj[key.to_sym] = val }
super opts.transform_keys(&:to_sym)
end
def __options__

Просмотреть файл

@@ -5,7 +5,7 @@ module Yookassa
option :shop_id, proc(&:to_s)
option :api_key, proc(&:to_s)
path { 'https://api.yookassa.ru/v3/payments' }
path { "https://api.yookassa.ru/v3/payments" }
security { basic_auth shop_id, api_key }
operation :get_payment_info do
@@ -24,8 +24,8 @@ module Yookassa
http_method :post
format 'json'
headers { { 'Idempotence-Key' => idempotency_key } }
format "json"
headers { { "Idempotence-Key" => idempotency_key } }
body { payment }
response(200) { |*res| Entity::Payment.build(*res) }
@@ -40,8 +40,8 @@ module Yookassa
path { "/#{payment_id}/capture" }
format 'json'
headers { { 'Idempotence-Key' => idempotency_key } }
format "json"
headers { { "Idempotence-Key" => idempotency_key } }
response(200) { |*res| Entity::Payment.build(*res) }
response(400) { |*res| Error.build(*res) }
@@ -55,8 +55,8 @@ module Yookassa
path { "/#{payment_id}/cancel" }
format 'json'
headers { { 'Idempotence-Key' => idempotency_key } }
format "json"
headers { { "Idempotence-Key" => idempotency_key } }
response(200) { |*res| Entity::Payment.build(*res) }
response(400) { |*res| Error.build(*res) }

Просмотреть файл

@@ -5,7 +5,7 @@ module Yookassa
option :shop_id, proc(&:to_s)
option :api_key, proc(&:to_s)
path { 'https://api.yookassa.ru/v3/refunds' }
path { "https://api.yookassa.ru/v3/refunds" }
security { basic_auth shop_id, api_key }
operation :get_refund_info do
@@ -24,8 +24,8 @@ module Yookassa
http_method :post
format 'json'
headers { { 'Idempotence-Key' => idempotency_key } }
format "json"
headers { { "Idempotence-Key" => idempotency_key } }
body { payload }
response(200) { |*res| Entity::Refund.build(*res) }

Просмотреть файл

@@ -4,7 +4,7 @@ module Yookassa
class Response
extend Dry::Initializer
option :id, proc(&:to_s)
option :status, proc(&:to_s), default: proc { nil }
option :status, proc(&:to_s), default: proc {}
class << self
def build(*res)
@@ -13,7 +13,7 @@ module Yookassa
end
def new(opts)
super opts.each_with_object({}) { |(key, val), obj| obj[key.to_sym] = val }
super opts.transform_keys(&:to_sym)
end
end
end

Просмотреть файл

@@ -1,5 +1,5 @@
# frozen_string_literal: true
module Yookassa
VERSION = '0.1.0'
VERSION = "0.1.0"
end

Просмотреть файл

@@ -1,13 +1,13 @@
# frozen_string_literal: true
begin
require 'pry'
require "pry"
rescue LoadError
nil
end
require 'yookassa'
require 'webmock/rspec'
require "yookassa"
require "webmock/rspec"
RSpec.configure do |config|
config.order = :random

Просмотреть файл

@@ -1,104 +1,104 @@
# frozen_string_literal: true
RSpec.describe Yookassa::Payment do
let(:settings) { { shop_id: 'SHOP_ID', api_key: 'API_KEY' } }
let(:settings) { { shop_id: "SHOP_ID", api_key: "API_KEY" } }
let(:idempotency_key) { 12_345 }
let(:payment) { described_class.new(settings) }
shared_examples 'returns_payment_object' do
it 'returns success' do
shared_examples "returns_payment_object" do
it "returns success" do
expect(subject).to be_kind_of Yookassa::Response
expect(subject.id).to eq '2490ded1-000f-5000-8000-1f64111bc63e'
expect(subject.id).to eq "2490ded1-000f-5000-8000-1f64111bc63e"
expect(subject.test).to eq true
expect(subject.paid).to eq false
expect(subject.status).to eq 'pending'
expect(subject.status).to eq "pending"
expect(subject.captured_at).to eq nil
expect(subject.created_at).to eq '2019-06-10T21:26:41.395Z'
expect(subject.created_at).to eq "2019-06-10T21:26:41.395Z"
expect(subject.description).to eq nil
expect(subject.expires_at).to eq nil
expect(subject.metadata).to eq Hash[]
expect(subject.metadata).to eq({})
expect(subject.amount).to be_kind_of Yookassa::Entity::Amount
expect(subject.amount.currency).to eq 'RUB'
expect(subject.amount.currency).to eq "RUB"
expect(subject.amount.value).to eq 10.0
expect(subject.confirmation).to be_kind_of Yookassa::Entity::Confirmation
expect(subject.confirmation.confirmation_url).to eq 'https://money.yookassa.ru/payments/external/confirmation?orderId=2490ded1-000f-5000-8000-1f64111bc63e'
expect(subject.confirmation.type).to eq 'redirect'
expect(subject.confirmation.return_url).to eq 'https://url.test'
expect(subject.confirmation.confirmation_url).to eq "https://money.yookassa.ru/payments/external/confirmation?orderId=2490ded1-000f-5000-8000-1f64111bc63e"
expect(subject.confirmation.type).to eq "redirect"
expect(subject.confirmation.return_url).to eq "https://url.test"
expect(subject.confirmation.enforce).to eq nil
expect(subject.payment_method).to be_kind_of Yookassa::Entity::PaymentMethod
expect(subject.payment_method.card).to eq nil
expect(subject.payment_method.id).to eq '2490ded1-000f-5000-8000-1f64111bc63e'
expect(subject.payment_method.id).to eq "2490ded1-000f-5000-8000-1f64111bc63e"
expect(subject.payment_method.saved).to eq false
expect(subject.payment_method.type).to eq 'bank_card'
expect(subject.payment_method.type).to eq "bank_card"
expect(subject.payment_method.title).to eq nil
end
end
describe '#create' do
let(:params) { { payment: File.read('spec/fixtures/payment.json') } }
let(:url) { 'https://api.yookassa.ru/v3/payments' }
let(:body) { File.read('spec/fixtures/payment_response.json') }
describe "#create" do
let(:params) { { payment: File.read("spec/fixtures/payment.json") } }
let(:url) { "https://api.yookassa.ru/v3/payments" }
let(:body) { File.read("spec/fixtures/payment_response.json") }
before { stub_request(:any, //).to_return(body: body) }
subject { payment.create(payment: params, idempotency_key: idempotency_key) }
it 'sends a request' do
it "sends a request" do
subject
expect(a_request(:post, url)).to have_been_made
end
it_behaves_like 'returns_payment_object'
it_behaves_like "returns_payment_object"
end
describe '#get_payment_info' do
let(:payment_id) { '2490ded1-000f-5000-8000-1f64111bc63e' }
describe "#get_payment_info" do
let(:payment_id) { "2490ded1-000f-5000-8000-1f64111bc63e" }
let(:url) { "https://api.yookassa.ru/v3/payments/#{payment_id}" }
let(:body) { File.read('spec/fixtures/payment_response.json') }
let(:body) { File.read("spec/fixtures/payment_response.json") }
before { stub_request(:any, //).to_return(body: body) }
subject { payment.get_payment_info(payment_id: payment_id) }
it 'sends a request' do
it "sends a request" do
subject
expect(a_request(:get, url)).to have_been_made
end
it_behaves_like 'returns_payment_object'
it_behaves_like "returns_payment_object"
end
describe '#capture' do
let(:payment_id) { '2490ded1-000f-5000-8000-1f64111bc63e' }
let(:params) { { payment: File.read('spec/fixtures/payment.json') } }
describe "#capture" do
let(:payment_id) { "2490ded1-000f-5000-8000-1f64111bc63e" }
let(:params) { { payment: File.read("spec/fixtures/payment.json") } }
let(:url) { "https://api.yookassa.ru/v3/payments/#{payment_id}/capture" }
let(:body) { File.read('spec/fixtures/payment_response.json') }
let(:body) { File.read("spec/fixtures/payment_response.json") }
before { stub_request(:any, //).to_return(body: body) }
subject { payment.capture(payment_id: payment_id, idempotency_key: idempotency_key) }
it 'sends a request' do
it "sends a request" do
subject
expect(a_request(:post, url)).to have_been_made
end
it_behaves_like 'returns_payment_object'
it_behaves_like "returns_payment_object"
end
describe '#cancel' do
let(:payment_id) { '2490ded1-000f-5000-8000-1f64111bc63e' }
describe "#cancel" do
let(:payment_id) { "2490ded1-000f-5000-8000-1f64111bc63e" }
let(:url) { "https://api.yookassa.ru/v3/payments/#{payment_id}/cancel" }
let(:body) { File.read('spec/fixtures/payment_response.json') }
let(:body) { File.read("spec/fixtures/payment_response.json") }
before { stub_request(:any, //).to_return(body: body) }
subject { payment.cancel(payment_id: payment_id, idempotency_key: idempotency_key) }
it 'sends a request' do
it "sends a request" do
subject
expect(a_request(:post, url)).to have_been_made
end
it_behaves_like 'returns_payment_object'
it_behaves_like "returns_payment_object"
end
end

Просмотреть файл

@@ -1,54 +1,54 @@
# frozen_string_literal: true
RSpec.describe Yookassa::Refund do
let(:settings) { { shop_id: 'SHOP_ID', api_key: 'API_KEY' } }
let(:settings) { { shop_id: "SHOP_ID", api_key: "API_KEY" } }
let(:idempotency_key) { 12_345 }
let(:payment) { described_class.new(settings) }
shared_examples 'returns_refund_object' do
it 'returns success' do
shared_examples "returns_refund_object" do
it "returns success" do
expect(subject).to be_kind_of Yookassa::Response
expect(subject.id).to eq '2491ab0c-0015-5000-9000-1640c7f1a6f0'
expect(subject.payment_id).to eq '2491a6e2-000f-5000-9000-1480e820ae17'
expect(subject.status).to eq 'succeeded'
expect(subject.created_at).to eq '2019-06-11T11:58:04.502Z'
expect(subject.description).to eq 'test refund, idem-key 78c95366-ec4b-4284-a0fd-41e694bcdf11'
expect(subject.id).to eq "2491ab0c-0015-5000-9000-1640c7f1a6f0"
expect(subject.payment_id).to eq "2491a6e2-000f-5000-9000-1480e820ae17"
expect(subject.status).to eq "succeeded"
expect(subject.created_at).to eq "2019-06-11T11:58:04.502Z"
expect(subject.description).to eq "test refund, idem-key 78c95366-ec4b-4284-a0fd-41e694bcdf11"
expect(subject.amount).to be_kind_of Yookassa::Entity::Amount
expect(subject.amount.currency).to eq 'RUB'
expect(subject.amount.currency).to eq "RUB"
expect(subject.amount.value).to eq 8.0
end
end
describe '#create' do
let(:payload) { File.read('spec/fixtures/refund.json') }
let(:url) { 'https://api.yookassa.ru/v3/refunds' }
let(:body) { File.read('spec/fixtures/refund_response.json') }
describe "#create" do
let(:payload) { File.read("spec/fixtures/refund.json") }
let(:url) { "https://api.yookassa.ru/v3/refunds" }
let(:body) { File.read("spec/fixtures/refund_response.json") }
before { stub_request(:any, //).to_return(body: body) }
subject { payment.create(payload: payload, idempotency_key: idempotency_key) }
it 'sends a request' do
it "sends a request" do
subject
expect(a_request(:post, url)).to have_been_made
end
it_behaves_like 'returns_refund_object'
it_behaves_like "returns_refund_object"
end
describe '#get_refund_info' do
let(:payment_id) { '2490ded1-000f-5000-8000-1f64111bc63e' }
describe "#get_refund_info" do
let(:payment_id) { "2490ded1-000f-5000-8000-1f64111bc63e" }
let(:url) { "https://api.yookassa.ru/v3/refunds/#{payment_id}" }
let(:body) { File.read('spec/fixtures/refund_response.json') }
let(:body) { File.read("spec/fixtures/refund_response.json") }
before { stub_request(:any, //).to_return(body: body) }
subject { payment.get_refund_info(payment_id: payment_id) }
it 'sends a request' do
it "sends a request" do
subject
expect(a_request(:get, url)).to have_been_made
end
it_behaves_like 'returns_refund_object'
it_behaves_like "returns_refund_object"
end
end

Просмотреть файл

@@ -1,7 +1,7 @@
# frozen_string_literal: true
RSpec.describe Yookassa do
it 'has a version number' do
it "has a version number" do
expect(Yookassa::VERSION).not_to be nil
end
end

Просмотреть файл

@@ -1,32 +1,32 @@
# frozen_string_literal: true
lib = File.expand_path('lib', __dir__)
lib = File.expand_path("lib", __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'yookassa/version'
require "yookassa/version"
Gem::Specification.new do |spec|
spec.name = 'yookassa'
spec.name = "yookassa"
spec.version = Yookassa::VERSION
spec.authors = 'Andrey Paderin'
spec.email = 'andy.paderin@gmail.com'
spec.authors = "Andrey Paderin"
spec.email = "andy.paderin@gmail.com"
spec.summary = 'This product is used for managing payments under The Yookassa API For usage by those who implemented Yookassa using the API method.'
spec.homepage = 'https://github.com/paderinandrey/yookassa'
spec.license = 'MIT'
spec.summary = "Yookassa API SDK for Ruby"
spec.homepage = "https://github.com/paderinandrey/yookassa"
spec.license = "MIT"
spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
spec.test_files = spec.files.grep(/^spec/)
spec.extra_rdoc_files = Dir['README.md', 'LICENSE', 'CHANGELOG.md']
spec.extra_rdoc_files = Dir["README.md", "LICENSE", "CHANGELOG.md"]
spec.require_paths = ['lib']
spec.require_paths = ["lib"]
spec.required_ruby_version = '>= 2.5'
spec.required_ruby_version = ">= 2.6"
spec.add_runtime_dependency 'evil-client', '~> 3.0'
spec.add_runtime_dependency "evil-client", "~> 3.0"
spec.add_development_dependency 'rake', '>= 10.0'
spec.add_development_dependency 'rspec', '~> 3.5'
spec.add_development_dependency 'rubocop', '~> 0.71'
spec.add_development_dependency 'simplecov', '~> 0.16'
spec.add_development_dependency 'webmock', '~> 3.5'
spec.add_development_dependency "rake", ">= 10.0"
spec.add_development_dependency "rspec", "~> 3.5"
spec.add_development_dependency "rubocop", "~> 0.71"
spec.add_development_dependency "simplecov", "~> 0.16"
spec.add_development_dependency "webmock", "~> 3.5"
end