yaka 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 974f7ba0a3bdd56aaddef4625ee7e57be4235fd09cb310b489b19c21bb59dd20
4
- data.tar.gz: 2be2cf7054857aac7575a794ec8b99e4eb822f31362beca6c6e629775d5d38e7
3
+ metadata.gz: adbc706650cd04b94a1537131ddac857130956ab301f53202c75257089225550
4
+ data.tar.gz: f775b38a8ed44a1ccf60845948560c86699e55b822ee49eb8b0aa89837e7160a
5
5
  SHA512:
6
- metadata.gz: 861fd5d7f14efb25be050277d31a03c6b268f3cf66b79cf18a079bfb2eb56481b2b0497b71148a1cca5a928680730c0010ee7cba227483c50965d73bf367184a
7
- data.tar.gz: b9f0ec56e9d7ff01168043f8301984a923ca5bf5e84fcedb10660fa571b1a9097ac77458eb6ec13388dc8ff3f2b78254849b38fbb4c6ce9091ee8a273bfbb7d5
6
+ metadata.gz: e99179ad75402a594290e058d00779520ecaf7f4fa21a24916d5fef18ca3357e89cb47c68add3fc2c72ac39786b4423f12af3905dc6440d7255cad571a37bb6f
7
+ data.tar.gz: 60fa4d2e27900ab425011c39c7628a35f48ec392edd8492c08fb5817319e8df5354f4aabe88f5a9bf43406d4c58a07f1a059523ba9f0dd8780a31d4b74835e63
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- yaka (1.0.0)
4
+ yaka (1.0.1)
5
5
  dry-configurable
6
6
  dry-struct
7
7
  faraday
@@ -37,7 +37,7 @@ GEM
37
37
  dry-equalizer (~> 0.2)
38
38
  dry-types (~> 1.0)
39
39
  ice_nine (~> 0.11)
40
- dry-types (1.0.0)
40
+ dry-types (1.0.1)
41
41
  concurrent-ruby (~> 1.0)
42
42
  dry-container (~> 0.3)
43
43
  dry-core (~> 0.4, >= 0.4.4)
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Yaka
4
4
  module Types
5
- include Dry::Types.module
5
+ include Dry::Types()
6
6
  end
7
7
 
8
8
  class BasicStruct < Dry::Struct
@@ -3,10 +3,6 @@
3
3
  module Yaka
4
4
  module ClassMethods
5
5
  def publish_payment(data, token = nil)
6
- payment = data.is_a?(Yaka::Payment) ? data : Yaka::Payment.new(data)
7
-
8
- data = payment.to_json
9
-
10
6
  conn = Faraday.new(url: Yaka::HOST_URL) # create a new Connection with base URL
11
7
  conn.basic_auth(Yaka.config.shop_id, Yaka.config.private_key) # set the Authentication header
12
8
 
@@ -14,10 +10,13 @@ module Yaka
14
10
  req.url Yaka::PAYMENTS_URL
15
11
  req.headers['Content-Type'] = 'application/json'
16
12
  req.headers['Idempotence-Key'] = token
17
- req.body = data
13
+ req.body = data.to_json
18
14
  end
19
15
 
20
- Yaka::PaymentResponse.new(JSON.parse(@result.body))
16
+ body = JSON.parse(@result.body)
17
+ raise Yaka::Error, body['description'] if body.dig('code').to_s.include?('error')
18
+
19
+ body
21
20
  end
22
21
 
23
22
  def yandex_ip?(ip)
data/lib/yaka/payment.rb CHANGED
@@ -3,34 +3,67 @@
3
3
  module Yaka
4
4
  class Payment < BasicStruct
5
5
  # This class is used for sending payments to Yandex Kassa.
6
+
7
+ # https://kassa.yandex.ru/developers/payments/54fz#54fz-payment-subject
8
+ # commodity Товар
9
+ # excise Подакцизный товар
10
+ # job Работа
11
+ # service Услуга
12
+ # gambling_bet Ставка в азартной игре
13
+ # gambling_prize Выигрыш в азартной игре
14
+ # lottery Лотерейный билет
15
+ # lottery_prize Выигрыш в лотерею
16
+ # intellectual_activity Результаты интеллектуальной деятельности
17
+ # payment Платеж
18
+ # agent_commission Агентское вознаграждение
19
+ # property_right Имущественные права
20
+ # non_operating_gain Внереализационный доход
21
+ # insurance_premium Страховой сбор
22
+ # sales_tax Торговый сбор
23
+ # resort_fee Курортный сбор
24
+ # composite Несколько вариантов
25
+ # another Другое
26
+ PAYMENT_SUBJECTS = Types::Strict::String.enum(
27
+ 'commodity', 'excise', 'job', 'service', 'gambling_bet',
28
+ 'gambling_prize', 'lottery', 'lottery_prize', 'intellectual_activity',
29
+ 'payment', 'agent_commission', 'property_right', 'non_operating_gain',
30
+ 'insurance_premium', 'sales_tax', 'resort_fee', 'composite', 'another'
31
+ )
32
+
33
+
6
34
  attribute :amount, BasicStruct do
7
35
  attribute :value, Types::String
8
36
  attribute :currency, Types::String
9
37
  end
10
38
  attribute :confirmation, BasicStruct do
11
39
  attribute :type, Types::String.default('redirect')
12
- attribute :return_url, Types::Strict::String
40
+ attribute :return_url, Types::Strict::String.meta(omittable: true)
13
41
  end
14
42
  attribute :capture, Types::Bool.default(true)
43
+ attribute :save_payment_method, Types::Bool.meta(omittable: true)
15
44
  attribute :description, Types::Strict::String
16
45
  attribute :receipt, BasicStruct.meta(omittable: true) do
17
- attribute :items, Types::Array.of(BasicStruct).default([]) do
46
+ attribute :items, Types::Array.of(BasicStruct).default([].freeze) do
18
47
  attribute :description, Types::String
19
48
  attribute :amount, BasicStruct.meta(omittable: true) do
20
49
  attribute :value, Types::String.meta(omittable: true)
21
50
  attribute :currency, Types::String.meta(omittable: true)
22
51
  end
23
52
  attribute :quantity, Types::Integer
24
- attribute :vat_code, Types::String
25
- attribute :payment_mode, Types::Strict::String.meta(omittable: true)
26
- attribute :payment_subject, Types::String.meta(omittable: true)
53
+ attribute :vat_code, Types::Integer # https://kassa.yandex.ru/docs/guides/#54fz-vat-codes
54
+ attribute :payment_mode, Types::Strict::String.meta(omittable: true) # https://kassa.yandex.ru/developers/payments/54fz#54fz-payment-mode
55
+ attribute :payment_subject, PAYMENT_SUBJECTS.meta(omittable: true)
27
56
  end
28
57
  attribute :phone, Types::String.meta(omittable: true)
29
58
  attribute :email, Types::String.meta(omittable: true)
30
- attribute :tax_system_code, Types::String.meta(omittable: true)
59
+ attribute :tax_system_code, Types::String.meta(omittable: true) # https://kassa.yandex.ru/developers/payments/54fz#54fz-tax-systems
31
60
  end
32
- attribute :payment_token, Types::String
61
+ attribute :payment_token, Types::String.meta(omittable: true)
33
62
  attribute :metadata, Types::Hash
34
63
  attribute :client_ip, Types::String
64
+ attribute :payment_method_data, BasicStruct.meta(omittable: true) do
65
+ attribute :type, Types::String
66
+ attribute :phone, Types::String.meta(omittable: true)
67
+ end
35
68
  end
36
69
  end
@@ -11,20 +11,20 @@ module Yaka
11
11
  attribute :value, Types::String
12
12
  attribute :currency, Types::String
13
13
  end
14
- attribute :authorization_details, BasicStruct do
14
+ attribute :authorization_details, BasicStruct.meta(omittable: true) do
15
15
  attribute :rrn, Types::String
16
16
  attribute :auth_code, Types::String
17
17
  end
18
- attribute :captured_at, Types::DateTime
18
+ attribute :captured_at, Types::DateTime.meta(omittable: true)
19
19
  attribute :created_at, Types::DateTime
20
20
  attribute :description, Types::String
21
21
  attribute :metadata, Types::Hash
22
22
  attribute :payment_method, BasicStruct do
23
23
  attribute :id, Types::String
24
24
  attribute :type, Types::String
25
- attribute :saved, Types::String
26
- attribute :title, Types::String
27
- attribute :card, BasicStruct do
25
+ attribute :saved, Types::String.meta(omittable: true)
26
+ attribute :title, Types::String.meta(omittable: true)
27
+ attribute :card, BasicStruct.meta(omittable: true) do
28
28
  attribute :first6, Types::String
29
29
  attribute :last4, Types::String
30
30
  attribute :expiry_month, Types::String
@@ -37,7 +37,7 @@ module Yaka
37
37
  attribute :gateway_id, Types::String
38
38
  end
39
39
  attribute :refundable, Types::Bool
40
- attribute :refunded_amount, BasicStruct do
40
+ attribute :refunded_amount, BasicStruct.meta(omittable: true) do
41
41
  attribute :value, Types::String
42
42
  attribute :currency, Types::String
43
43
  end
data/lib/yaka/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Yaka
4
- VERSION = '1.0.0'
4
+ VERSION = '1.0.1'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yaka
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Igor Pavlov