1
0
зеркало из https://github.com/glebtv/yookassa.git synced 2026-09-03 17:55:51 +03:00
Этот коммит содержится в:
Andrey
2020-12-07 23:10:23 +03:00
родитель 55dbde6397
Коммит b40b9a32b3
29 изменённых файлов: 133 добавлений и 184 удалений

28
.circleci/config.yml Обычный файл
Просмотреть файл

@@ -0,0 +1,28 @@
version: 2.1
orbs:
ruby: circleci/ruby@0.1.2
jobs:
build:
docker:
- image: circleci/ruby:2.6.3-stretch-node
executor: ruby/default
steps:
- checkout
- restore_cache:
keys:
- yookassa-bundle-{{ checksum "Gemfile.lock" }}
- yookassa-bundle-
- run:
name: Install dependencies
command: |
bundle check || bundle install --jobs=4 --retry=3 --path vendor/bundle
- save_cache:
paths:
- ./vendor/bundle
key: yookassa-bundle-{{ checksum "Gemfile.lock" }}
- run:
name: Run tests
command: |
bundle exec rspec --profile 10 --format progress

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

@@ -1,7 +0,0 @@
---
sudo: false
language: ruby
cache: bundler
rvm:
- 2.5.3
before_install: gem install bundler -v 1.17.3

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

@@ -1,74 +0,0 @@
# Contributor Covenant Code of Conduct
## Our Pledge
In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, gender identity and expression, level of experience,
nationality, personal appearance, race, religion, or sexual identity and
orientation.
## Our Standards
Examples of behavior that contributes to creating a positive environment
include:
* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members
Examples of unacceptable behavior by participants include:
* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting
## Our Responsibilities
Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.
Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.
## Scope
This Code of Conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community. Examples of
representing a project or community include using an official project e-mail
address, posting via an official social media account, or acting as an appointed
representative at an online or offline event. Representation of a project may be
further defined and clarified by project maintainers.
## Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at andy.paderin@gmail.com. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Further details of specific enforcement policies may be posted separately.
Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.
## Attribution
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at [http://contributor-covenant.org/version/1/4][version]
[homepage]: http://contributor-covenant.org
[version]: http://contributor-covenant.org/version/1/4/

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

@@ -1,8 +1,10 @@
source "https://rubygems.org"
# frozen_string_literal: true
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
source 'https://rubygems.org'
# Specify your gem's dependencies in yandex-checkout.gemspec
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
# Specify your gem's dependencies in yookassa.gemspec
gemspec
group :development, :test do

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

@@ -1,7 +1,7 @@
PATH
remote: .
specs:
yandex-checkout (0.1.1)
yookassa (0.1.0)
evil-client (~> 3.0)
GEM
@@ -12,26 +12,26 @@ GEM
ast (2.4.0)
byebug (11.0.1)
coderay (1.1.2)
concurrent-ruby (1.1.5)
concurrent-ruby (1.1.7)
crack (0.4.3)
safe_yaml (~> 1.0.0)
diff-lcs (1.3)
docile (1.3.1)
dry-initializer (3.0.1)
evil-client (3.0.3)
dry-initializer (3.0.4)
evil-client (3.0.4)
dry-initializer (>= 2.1, < 4)
mime-types (~> 3.1)
rack (~> 2)
tram-policy (>= 0.3.1, < 2)
tram-policy (>= 0.3.1, < 3)
hashdiff (0.4.0)
i18n (1.6.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.2.2)
mime-types (3.3.1)
mime-types-data (~> 3.2015)
mime-types-data (3.2019.0331)
mime-types-data (3.2020.1104)
parallel (1.17.0)
parser (2.6.3.0)
ast (~> 2.4.0)
@@ -42,7 +42,7 @@ GEM
byebug (~> 11.0)
pry (~> 0.10)
public_suffix (3.1.0)
rack (2.0.7)
rack (2.2.3)
rainbow (3.0.0)
rake (12.3.2)
rspec (3.8.0)
@@ -72,7 +72,7 @@ GEM
json (>= 1.8, < 3)
simplecov-html (~> 0.10.0)
simplecov-html (0.10.2)
tram-policy (1.0.1)
tram-policy (2.0.1)
dry-initializer (> 2, < 4)
i18n (~> 1.0)
unicode-display_width (1.6.0)
@@ -92,7 +92,7 @@ DEPENDENCIES
rubocop (~> 0.71)
simplecov (~> 0.16)
webmock (~> 3.5)
yandex-checkout!
yookassa!
BUNDLED WITH
1.17.3

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

@@ -1,15 +1,17 @@
# Yandex::Checkout
# YooKassa API Ruby Client
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/yandex/checkout`. To experiment with that code, run `bin/console` for an interactive prompt.
[![Gem Version][gem-badger]][gem]
[![Yookassa](https://circleci.com/gh/paderinandrey/yookassa.svg?style=svg)](https://circleci.com/gh/paderinandrey/yookassa)
TODO: Delete this and the text above, and describe your gem
[gem-badger]: https://img.shields.io/gem/v/yookassa.svg?style=flat&color=blue
[gem]: https://rubygems.org/gems/yookassa
## Installation
Add this line to your application's Gemfile:
```ruby
gem 'yandex-checkout'
gem 'yookassa'
```
And then execute:
@@ -18,26 +20,21 @@ And then execute:
Or install it yourself as:
$ gem install yandex-checkout
$ gem install yookassa
## Usage
TODO: Write usage instructions here
## Development
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
## Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/yandex-checkout. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
Everyone is encouraged to help improve this project. Here are a few ways you can help:
- [Report bugs](https://github.com/paderinandrey/yookassa/issues)
- Fix bugs and [submit pull requests](https://github.com/paderinandrey/yookassa/pulls)
- Write, clarify, or fix documentation
- Suggest or add new features
## License
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
## Code of Conduct
Everyone interacting in the Yandex::Checkout projects codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/yandex-checkout/blob/master/CODE_OF_CONDUCT.md).

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

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

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

@@ -1,5 +0,0 @@
# frozen_string_literal: true
module YandexCheckout
VERSION = '0.1.1'
end

13
lib/yookassa.rb Обычный файл
Просмотреть файл

@@ -0,0 +1,13 @@
# frozen_string_literal: true
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'

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

@@ -1,6 +1,6 @@
# frozen_string_literal: true
module YandexCheckout
module Yookassa
module Callable
def call(*args)
new(*args)

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

@@ -1,11 +1,11 @@
# frozen_string_literal: true
module YandexCheckout
module Yookassa
module Entity
class Amount
extend Dry::Initializer
extend YandexCheckout::Callable
include YandexCheckout::Optional
extend Yookassa::Callable
include Yookassa::Optional
option :value, proc(&:to_f), optional: true
option :currency, proc(&:to_s), optional: true

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

@@ -1,11 +1,11 @@
# frozen_string_literal: true
module YandexCheckout
module Yookassa
module Entity
class Card
extend Dry::Initializer
extend YandexCheckout::Callable
include YandexCheckout::Optional
extend Yookassa::Callable
include Yookassa::Optional
option :first6
option :last4

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

@@ -1,11 +1,11 @@
# frozen_string_literal: true
module YandexCheckout
module Yookassa
module Entity
class Confirmation
extend Dry::Initializer
extend YandexCheckout::Callable
include YandexCheckout::Optional
extend Yookassa::Callable
include Yookassa::Optional
option :type, proc(&:to_s), optional: true
option :confirmation_url, proc(&:to_s), optional: true

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

@@ -4,9 +4,9 @@ require_relative './amount'
require_relative './payment_method'
require_relative './confirmation'
module YandexCheckout
module Yookassa
module Entity
class Payment < YandexCheckout::Response
class Payment < Yookassa::Response
option :paid
option :amount, Entity::Amount
option :created_at

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

@@ -2,12 +2,12 @@
require_relative './card'
module YandexCheckout
module Yookassa
module Entity
class PaymentMethod
extend Dry::Initializer
extend YandexCheckout::Callable
include YandexCheckout::Optional
extend Yookassa::Callable
include Yookassa::Optional
option :type, proc(&:to_s)
option :id, proc(&:to_s)

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

@@ -2,9 +2,9 @@
require_relative './amount'
module YandexCheckout
module Yookassa
module Entity
class Refund < YandexCheckout::Response
class Refund < Yookassa::Response
option :payment_id
option :created_at, proc(&:to_s)
option :amount, Entity::Amount

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

@@ -1,10 +1,10 @@
# frozen_string_literal: true
module YandexCheckout
module Yookassa
class Error
extend Dry::Initializer
extend YandexCheckout::Callable
include YandexCheckout::Optional
extend Yookassa::Callable
include Yookassa::Optional
option :type, proc(&:to_s)
option :id, proc(&:to_s), optional: true

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

@@ -1,6 +1,6 @@
# frozen_string_literal: true
module YandexCheckout
module Yookassa
module Optional
private

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

@@ -1,11 +1,11 @@
# frozen_string_literal: true
module YandexCheckout
module Yookassa
class Payment < Evil::Client
option :shop_id, proc(&:to_s)
option :api_key, proc(&:to_s)
path { 'https://payment.yandex.net/api/v3/payments' }
path { 'https://api.yookassa.ru/v3/payments' }
security { basic_auth shop_id, api_key }
operation :get_payment_info do

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

@@ -1,11 +1,11 @@
# frozen_string_literal: true
module YandexCheckout
module Yookassa
class Refund < Evil::Client
option :shop_id, proc(&:to_s)
option :api_key, proc(&:to_s)
path { 'https://payment.yandex.net/api/v3/refunds' }
path { 'https://api.yookassa.ru/v3/refunds' }
security { basic_auth shop_id, api_key }
operation :get_refund_info do

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

@@ -1,6 +1,6 @@
# frozen_string_literal: true
module YandexCheckout
module Yookassa
class Response
extend Dry::Initializer
option :id, proc(&:to_s)

5
lib/yookassa/version.rb Обычный файл
Просмотреть файл

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

5
spec/fixtures/payment_response.json поставляемый
Просмотреть файл

@@ -9,11 +9,10 @@
"confirmation": {
"type": "redirect",
"return_url": "https://url.test",
"confirmation_url": "https://money.yandex.ru/payments/external/confirmation?orderId=2490ded1-000f-5000-8000-1f64111bc63e"
"confirmation_url": "https://money.yookassa.ru/payments/external/confirmation?orderId=2490ded1-000f-5000-8000-1f64111bc63e"
},
"created_at": "2019-06-10T21:26:41.395Z",
"metadata": {
},
"metadata": {},
"payment_method": {
"type": "bank_card",
"id": "2490ded1-000f-5000-8000-1f64111bc63e",

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

@@ -1,10 +1,12 @@
# frozen_string_literal: true
begin
require 'pry'
rescue LoadError
nil
end
require 'yandex-checkout'
require 'yookassa'
require 'webmock/rspec'
RSpec.configure do |config|

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

@@ -1,5 +0,0 @@
RSpec.describe YandexCheckout do
it 'has a version number' do
expect(YandexCheckout::VERSION).not_to be nil
end
end

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

@@ -1,13 +1,13 @@
# frozen_string_literal: true
RSpec.describe YandexCheckout::Payment do
RSpec.describe Yookassa::Payment do
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
expect(subject).to be_kind_of YandexCheckout::Response
expect(subject).to be_kind_of Yookassa::Response
expect(subject.id).to eq '2490ded1-000f-5000-8000-1f64111bc63e'
expect(subject.test).to eq true
expect(subject.paid).to eq false
@@ -18,17 +18,17 @@ RSpec.describe YandexCheckout::Payment do
expect(subject.expires_at).to eq nil
expect(subject.metadata).to eq Hash[]
expect(subject.amount).to be_kind_of YandexCheckout::Entity::Amount
expect(subject.amount).to be_kind_of Yookassa::Entity::Amount
expect(subject.amount.currency).to eq 'RUB'
expect(subject.amount.value).to eq 10.0
expect(subject.confirmation).to be_kind_of YandexCheckout::Entity::Confirmation
expect(subject.confirmation.confirmation_url).to eq 'https://money.yandex.ru/payments/external/confirmation?orderId=2490ded1-000f-5000-8000-1f64111bc63e'
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.enforce).to eq nil
expect(subject.payment_method).to be_kind_of YandexCheckout::Entity::PaymentMethod
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.saved).to eq false
@@ -39,7 +39,7 @@ RSpec.describe YandexCheckout::Payment do
describe '#create' do
let(:params) { { payment: File.read('spec/fixtures/payment.json') } }
let(:url) { 'https://payment.yandex.net/api/v3/payments' }
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) }
@@ -55,7 +55,7 @@ RSpec.describe YandexCheckout::Payment do
describe '#get_payment_info' do
let(:payment_id) { '2490ded1-000f-5000-8000-1f64111bc63e' }
let(:url) { "https://payment.yandex.net/api/v3/payments/#{payment_id}" }
let(:url) { "https://api.yookassa.ru/v3/payments/#{payment_id}" }
let(:body) { File.read('spec/fixtures/payment_response.json') }
before { stub_request(:any, //).to_return(body: body) }
@@ -72,7 +72,7 @@ RSpec.describe YandexCheckout::Payment do
describe '#capture' do
let(:payment_id) { '2490ded1-000f-5000-8000-1f64111bc63e' }
let(:params) { { payment: File.read('spec/fixtures/payment.json') } }
let(:url) { "https://payment.yandex.net/api/v3/payments/#{payment_id}/capture" }
let(:url) { "https://api.yookassa.ru/v3/payments/#{payment_id}/capture" }
let(:body) { File.read('spec/fixtures/payment_response.json') }
before { stub_request(:any, //).to_return(body: body) }
@@ -88,7 +88,7 @@ RSpec.describe YandexCheckout::Payment do
describe '#cancel' do
let(:payment_id) { '2490ded1-000f-5000-8000-1f64111bc63e' }
let(:url) { "https://payment.yandex.net/api/v3/payments/#{payment_id}/cancel" }
let(:url) { "https://api.yookassa.ru/v3/payments/#{payment_id}/cancel" }
let(:body) { File.read('spec/fixtures/payment_response.json') }
before { stub_request(:any, //).to_return(body: body) }

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

@@ -1,20 +1,20 @@
# frozen_string_literal: true
RSpec.describe YandexCheckout::Refund do
RSpec.describe Yookassa::Refund do
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
expect(subject).to be_kind_of YandexCheckout::Response
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.amount).to be_kind_of YandexCheckout::Entity::Amount
expect(subject.amount).to be_kind_of Yookassa::Entity::Amount
expect(subject.amount.currency).to eq 'RUB'
expect(subject.amount.value).to eq 8.0
end
@@ -22,7 +22,7 @@ RSpec.describe YandexCheckout::Refund do
describe '#create' do
let(:payload) { File.read('spec/fixtures/refund.json') }
let(:url) { 'https://payment.yandex.net/api/v3/refunds' }
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) }
@@ -38,7 +38,7 @@ RSpec.describe YandexCheckout::Refund do
describe '#get_refund_info' do
let(:payment_id) { '2490ded1-000f-5000-8000-1f64111bc63e' }
let(:url) { "https://payment.yandex.net/api/v3/refunds/#{payment_id}" }
let(:url) { "https://api.yookassa.ru/v3/refunds/#{payment_id}" }
let(:body) { File.read('spec/fixtures/refund_response.json') }
before { stub_request(:any, //).to_return(body: body) }

7
spec/yookassa_spec.rb Обычный файл
Просмотреть файл

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

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

@@ -2,16 +2,16 @@
lib = File.expand_path('lib', __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'yandex-checkout/version'
require 'yookassa/version'
Gem::Specification.new do |spec|
spec.name = 'yandex-checkout'
spec.version = YandexCheckout::VERSION
spec.name = 'yookassa'
spec.version = Yookassa::VERSION
spec.authors = 'Andrey Paderin'
spec.email = 'andy.paderin@gmail.com'
spec.summary = 'This product is used for managing payments under The Yandex.Checkout API For usage by those who implemented Yandex.Checkout using the API method.'
spec.homepage = 'https://github.com/paderinandrey/yandex-checkout'
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.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)