yandex-checkout 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ca784413805b540143cc6fc3b342ae90a73261052e72571eece6446998c08b42
4
+ data.tar.gz: ed5cbf82c50834ed1ea26cf33e3b4c64a9aeadb520a640e1cdf7a480cd49cf67
5
+ SHA512:
6
+ metadata.gz: c8f724ef05c43223d8485bc9e41454eb421045b8fd8039a803fadfa7e7bf1af82ee3b0a23fc3feca8196fd3b481b8e7036294393725a7b1bb5c95b63ebbd87b0
7
+ data.tar.gz: '099856a2cd575808e7c9504a326810f8e3d3b03235f31539baa4a86a6c152bb7930f222f506b354aaa295f60ca521d31206cf5879edd8cd8670571518345373d'
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ .ruby-version
10
+ .ruby-gemset
11
+
12
+ # rspec failure tracking
13
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
@@ -0,0 +1,13 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.5
3
+
4
+ Metrics/BlockLength:
5
+ Exclude:
6
+ - 'spec/**/*.rb'
7
+
8
+ Metrics/LineLength:
9
+ Max: 100
10
+
11
+ Naming/FileName:
12
+ Exclude:
13
+ - 'lib/*.rb'
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.5.3
7
+ before_install: gem install bundler -v 1.17.3
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at andy.paderin@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in yandex-checkout.gemspec
6
+ gemspec
7
+
8
+ group :development, :test do
9
+ gem 'pry', platform: :mri
10
+ gem 'pry-byebug', platform: :mri
11
+ end
@@ -0,0 +1,98 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ yandex-checkout (0.1.1)
5
+ evil-client (~> 3.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ 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.5)
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.1)
21
+ evil-client (3.0.3)
22
+ dry-initializer (>= 2.1, < 4)
23
+ mime-types (~> 3.1)
24
+ rack (~> 2)
25
+ tram-policy (>= 0.3.1, < 2)
26
+ hashdiff (0.4.0)
27
+ i18n (1.6.0)
28
+ 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.2.2)
33
+ mime-types-data (~> 3.2015)
34
+ mime-types-data (3.2019.0331)
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)
42
+ byebug (~> 11.0)
43
+ pry (~> 0.10)
44
+ public_suffix (3.1.0)
45
+ rack (2.0.7)
46
+ 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)
55
+ diff-lcs (>= 1.2.0, < 2.0)
56
+ rspec-support (~> 3.8.0)
57
+ rspec-mocks (3.8.0)
58
+ 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)
63
+ parallel (~> 1.10)
64
+ parser (>= 2.6)
65
+ rainbow (>= 2.2.2, < 4.0)
66
+ 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)
71
+ docile (~> 1.1)
72
+ json (>= 1.8, < 3)
73
+ simplecov-html (~> 0.10.0)
74
+ simplecov-html (0.10.2)
75
+ tram-policy (1.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)
81
+ crack (>= 0.3.2)
82
+ hashdiff
83
+
84
+ PLATFORMS
85
+ ruby
86
+
87
+ DEPENDENCIES
88
+ pry
89
+ pry-byebug
90
+ rake (>= 10.0)
91
+ rspec (~> 3.5)
92
+ rubocop (~> 0.71)
93
+ simplecov (~> 0.16)
94
+ webmock (~> 3.5)
95
+ yandex-checkout!
96
+
97
+ BUNDLED WITH
98
+ 1.17.3
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Andrey Paderin
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,43 @@
1
+ # Yandex::Checkout
2
+
3
+ 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.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'yandex-checkout'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install yandex-checkout
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ 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.
30
+
31
+ 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).
32
+
33
+ ## Contributing
34
+
35
+ 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.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
40
+
41
+ ## Code of Conduct
42
+
43
+ Everyone interacting in the Yandex::Checkout project’s 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).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'evil/client'
4
+
5
+ require 'yandex-checkout/version'
6
+ require 'yandex-checkout/payment'
7
+ require 'yandex-checkout/refund'
8
+ require 'yandex-checkout/response'
9
+ require 'yandex-checkout/callable'
10
+ require 'yandex-checkout/optional'
11
+ require 'yandex-checkout/entity/payment'
12
+ require 'yandex-checkout/entity/refund'
13
+ require 'yandex-checkout/error'
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module YandexCheckout
4
+ module Callable
5
+ def call(*args)
6
+ new(*args)
7
+ end
8
+ alias [] call
9
+ end
10
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module YandexCheckout
4
+ module Entity
5
+ class Amount
6
+ extend Dry::Initializer
7
+ extend YandexCheckout::Callable
8
+ include YandexCheckout::Optional
9
+
10
+ option :value, proc(&:to_f), optional: true
11
+ option :currency, proc(&:to_s), optional: true
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module YandexCheckout
4
+ module Entity
5
+ class Card
6
+ extend Dry::Initializer
7
+ extend YandexCheckout::Callable
8
+ include YandexCheckout::Optional
9
+
10
+ option :first6
11
+ option :last4
12
+ option :expiry_month
13
+ option :expiry_year
14
+ option :card_type, proc(&:to_s)
15
+ option :source, proc(&:to_s), optional: true
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module YandexCheckout
4
+ module Entity
5
+ class Confirmation
6
+ extend Dry::Initializer
7
+ extend YandexCheckout::Callable
8
+ include YandexCheckout::Optional
9
+
10
+ option :type, proc(&:to_s), optional: true
11
+ option :confirmation_url, proc(&:to_s), optional: true
12
+ option :enforce, optional: true
13
+ option :return_url, proc(&:to_s), optional: true
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './amount'
4
+ require_relative './payment_method'
5
+ require_relative './confirmation'
6
+
7
+ module YandexCheckout
8
+ module Entity
9
+ class Payment < YandexCheckout::Response
10
+ option :paid
11
+ option :amount, Entity::Amount
12
+ option :created_at
13
+ option :captured_at, proc(&:to_s), optional: true
14
+ option :expires_at, optional: true
15
+ option :description, proc(&:to_s), optional: true
16
+ option :metadata, optional: true
17
+ option :payment_method, Entity::PaymentMethod, optional: true
18
+ option :confirmation, Entity::Confirmation, optional: true
19
+ option :test
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './card'
4
+
5
+ module YandexCheckout
6
+ module Entity
7
+ class PaymentMethod
8
+ extend Dry::Initializer
9
+ extend YandexCheckout::Callable
10
+ include YandexCheckout::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
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './amount'
4
+
5
+ module YandexCheckout
6
+ module Entity
7
+ class Refund < YandexCheckout::Response
8
+ option :payment_id
9
+ option :created_at, proc(&:to_s)
10
+ option :amount, Entity::Amount
11
+ option :receipt_registration, proc(&:to_s), optional: true
12
+ option :description, proc(&:to_s), optional: true
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module YandexCheckout
4
+ class Error
5
+ extend Dry::Initializer
6
+ extend YandexCheckout::Callable
7
+ include YandexCheckout::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
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module YandexCheckout
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
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+
3
+ module YandexCheckout
4
+ class Payment < Evil::Client
5
+ option :shop_id, proc(&:to_s)
6
+ option :api_key, proc(&:to_s)
7
+
8
+ path { 'https://payment.yandex.net/api/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
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module YandexCheckout
4
+ class Refund < Evil::Client
5
+ option :shop_id, proc(&:to_s)
6
+ option :api_key, proc(&:to_s)
7
+
8
+ path { 'https://payment.yandex.net/api/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
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module YandexCheckout
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
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module YandexCheckout
4
+ VERSION = '0.1.1'
5
+ end
@@ -0,0 +1,7 @@
1
+ {
2
+ "type": "error",
3
+ "id": "afd4a246-ba97-4412-aa19-f5def9322f8b",
4
+ "code": "invalid_request",
5
+ "description": "Idempotence key duplicated",
6
+ "parameter": "Idempotence-Key"
7
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "type": "error",
3
+ "id": "85e254dd-e1e5-40c9-82c0-9f59f4130828",
4
+ "code": "invalid_request",
5
+ "description": "Payment not found or forbidden",
6
+ "parameter": "payment_id"
7
+ }
@@ -0,0 +1,14 @@
1
+ {
2
+ "amount": {
3
+ "value": "10.00",
4
+ "currency": "RUB"
5
+ },
6
+ "payment_method_data": {
7
+ "type": "bank_card"
8
+ },
9
+ "confirmation": {
10
+ "type": "redirect",
11
+ "return_url": "https://www.merchant-website.com/return_url"
12
+ },
13
+ "description": "Заказ №72"
14
+ }
@@ -0,0 +1,28 @@
1
+ {
2
+ "id": "2490ded1-000f-5000-8000-1f64111bc63e",
3
+ "status": "pending",
4
+ "paid": false,
5
+ "amount": {
6
+ "value": "10.00",
7
+ "currency": "RUB"
8
+ },
9
+ "confirmation": {
10
+ "type": "redirect",
11
+ "return_url": "https://url.test",
12
+ "confirmation_url": "https://money.yandex.ru/payments/external/confirmation?orderId=2490ded1-000f-5000-8000-1f64111bc63e"
13
+ },
14
+ "created_at": "2019-06-10T21:26:41.395Z",
15
+ "metadata": {
16
+ },
17
+ "payment_method": {
18
+ "type": "bank_card",
19
+ "id": "2490ded1-000f-5000-8000-1f64111bc63e",
20
+ "saved": false
21
+ },
22
+ "recipient": {
23
+ "account_id": "54401",
24
+ "gateway_id": "289250"
25
+ },
26
+ "refundable": false,
27
+ "test": true
28
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "amount": {
3
+ "value": "8.00",
4
+ "currency": "RUB"
5
+ },
6
+ "payment_id": "40484c25-1095-4d36-8b17-92672d1e127d",
7
+ "description": "test refund, idem-key 40484c25-1095-4d36-8b17-92672d1e127d"
8
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "id": "2491ab0c-0015-5000-9000-1640c7f1a6f0",
3
+ "status": "succeeded",
4
+ "amount": {
5
+ "value": "8.00",
6
+ "currency": "RUB"
7
+ },
8
+ "created_at": "2019-06-11T11:58:04.502Z",
9
+ "description": "test refund, idem-key 78c95366-ec4b-4284-a0fd-41e694bcdf11",
10
+ "payment_id": "2491a6e2-000f-5000-9000-1480e820ae17"
11
+ }
@@ -0,0 +1,19 @@
1
+ begin
2
+ require 'pry'
3
+ rescue LoadError
4
+ nil
5
+ end
6
+
7
+ require 'yandex-checkout'
8
+ require 'webmock/rspec'
9
+
10
+ RSpec.configure do |config|
11
+ config.order = :random
12
+ config.filter_run focus: true
13
+ config.run_all_when_everything_filtered = true
14
+
15
+ config.around(:each) do |example|
16
+ stub_request(:any, //)
17
+ example.run
18
+ end
19
+ end
@@ -0,0 +1,104 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe YandexCheckout::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 YandexCheckout::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 YandexCheckout::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 YandexCheckout::Entity::Confirmation
26
+ expect(subject.confirmation.confirmation_url).to eq 'https://money.yandex.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 YandexCheckout::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://payment.yandex.net/api/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://payment.yandex.net/api/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://payment.yandex.net/api/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://payment.yandex.net/api/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
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe YandexCheckout::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 YandexCheckout::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 YandexCheckout::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://payment.yandex.net/api/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://payment.yandex.net/api/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
@@ -0,0 +1,5 @@
1
+ RSpec.describe YandexCheckout do
2
+ it 'has a version number' do
3
+ expect(YandexCheckout::VERSION).not_to be nil
4
+ end
5
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'yandex-checkout/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'yandex-checkout'
9
+ spec.version = YandexCheckout::VERSION
10
+ spec.authors = 'Andrey Paderin'
11
+ spec.email = 'andy.paderin@gmail.com'
12
+
13
+ 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.'
14
+ spec.homepage = 'https://github.com/paderinandrey/yandex-checkout'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
18
+ spec.test_files = spec.files.grep(/^spec/)
19
+ spec.extra_rdoc_files = Dir['README.md', 'LICENSE', 'CHANGELOG.md']
20
+
21
+ spec.require_paths = ['lib']
22
+
23
+ spec.required_ruby_version = '>= 2.5'
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'
32
+ end
metadata ADDED
@@ -0,0 +1,174 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yandex-checkout
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Andrey Paderin
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-07-04 00:00:00.000000000 Z
12
+ dependencies:
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
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !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'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !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
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.5'
97
+ description:
98
+ email: andy.paderin@gmail.com
99
+ executables: []
100
+ extensions: []
101
+ extra_rdoc_files:
102
+ - README.md
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - ".rubocop.yml"
107
+ - ".travis.yml"
108
+ - CODE_OF_CONDUCT.md
109
+ - Gemfile
110
+ - Gemfile.lock
111
+ - LICENSE.txt
112
+ - README.md
113
+ - Rakefile
114
+ - lib/yandex-checkout.rb
115
+ - lib/yandex-checkout/callable.rb
116
+ - lib/yandex-checkout/entity/amount.rb
117
+ - lib/yandex-checkout/entity/card.rb
118
+ - lib/yandex-checkout/entity/confirmation.rb
119
+ - lib/yandex-checkout/entity/payment.rb
120
+ - lib/yandex-checkout/entity/payment_method.rb
121
+ - lib/yandex-checkout/entity/refund.rb
122
+ - lib/yandex-checkout/error.rb
123
+ - lib/yandex-checkout/optional.rb
124
+ - lib/yandex-checkout/payment.rb
125
+ - lib/yandex-checkout/refund.rb
126
+ - lib/yandex-checkout/response.rb
127
+ - lib/yandex-checkout/version.rb
128
+ - spec/fixtures/errors/duplicate_idempotence_key.json
129
+ - spec/fixtures/errors/invalid_request.json
130
+ - spec/fixtures/payment.json
131
+ - spec/fixtures/payment_response.json
132
+ - spec/fixtures/refund.json
133
+ - spec/fixtures/refund_response.json
134
+ - spec/spec_helper.rb
135
+ - spec/yandex-checkout/payment_spec.rb
136
+ - spec/yandex-checkout/refund_spec.rb
137
+ - spec/yandex-checkout_spec.rb
138
+ - yandex-checkout.gemspec
139
+ homepage: https://github.com/paderinandrey/yandex-checkout
140
+ licenses:
141
+ - MIT
142
+ metadata: {}
143
+ post_install_message:
144
+ rdoc_options: []
145
+ require_paths:
146
+ - lib
147
+ required_ruby_version: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ version: '2.5'
152
+ required_rubygems_version: !ruby/object:Gem::Requirement
153
+ requirements:
154
+ - - ">="
155
+ - !ruby/object:Gem::Version
156
+ version: '0'
157
+ requirements: []
158
+ rubyforge_project:
159
+ rubygems_version: 2.7.8
160
+ signing_key:
161
+ specification_version: 4
162
+ summary: This product is used for managing payments under The Yandex.Checkout API
163
+ For usage by those who implemented Yandex.Checkout using the API method.
164
+ test_files:
165
+ - spec/fixtures/errors/duplicate_idempotence_key.json
166
+ - spec/fixtures/errors/invalid_request.json
167
+ - spec/fixtures/payment.json
168
+ - spec/fixtures/payment_response.json
169
+ - spec/fixtures/refund.json
170
+ - spec/fixtures/refund_response.json
171
+ - spec/spec_helper.rb
172
+ - spec/yandex-checkout/payment_spec.rb
173
+ - spec/yandex-checkout/refund_spec.rb
174
+ - spec/yandex-checkout_spec.rb