ya_kassa 0.1.5 → 0.1.6

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: c573c67e1fa9662e57df83658ea91e067b45fc5abe4d2a3d305ebf74aeba1d03
4
- data.tar.gz: 49f7f418f8eedf3048b62ade69b9578e6539d9d38127f7edd67d51ae176632e4
3
+ metadata.gz: e0e97f8e125bc23105025a162a54854727fe7f9ccc4492443841bfc3248fed4e
4
+ data.tar.gz: 175eaf01abd5e1262fe7c5abb73bff64992f91c35213354e91d3aaeac19150f0
5
5
  SHA512:
6
- metadata.gz: 0a517effe1da33514ad80e8eb87cb4f3d3d73d7a4ee4a0d37469485552f5fe8421ba017dcd8f24556f30a87a17391a6256ff1bcda88f2382e7f35661116ced13
7
- data.tar.gz: 0a9b4c5e7430282e2203352de0c99f9d2f8a2d8c212f344c8d91bd765376f6b37601518c14c6b8d3c400660a71029fd508c933bf93dd1226fd25b2d5e9062f8f
6
+ metadata.gz: a8353d23560f4bf3239822ede9ae860d729730d76a580179b60cd8d9a10f7f87b6f7fafa76b9bc98b3db8a5d87571406d8f2648404c0162ae7b48ef9bbe4a4be
7
+ data.tar.gz: 90177a8a0ddebc037d54939f31a0483a741ee6ac621f604d60ee7758b5b1f3fb201de4950d6dd15032c7cce3757c82ab2d2992d084ac8809d97892b0329d3c51
data/README.md CHANGED
@@ -1,8 +1,6 @@
1
1
  # YaKassa
2
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/ya_kassa`. 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
3
+ Обёртка для работы с API V3 сервиса ЯндексКасса(YandexKassa)
6
4
 
7
5
  ## Installation
8
6
 
@@ -20,9 +18,94 @@ Or install it yourself as:
20
18
 
21
19
  $ gem install ya_kassa
22
20
 
23
- ## Usage
21
+ Create initializer file like this
22
+ ```ruby
23
+ # /config/initializers/ya_kassa.rb
24
+
25
+ YaKassa::V3::Settings.shop_id = Rails.application.credentials[:ya_kassa][:shop_id]
26
+ YaKassa::V3::Settings.secret_key = Rails.application.credentials[:ya_kassa][:secret_key]
27
+
28
+ ```
29
+
30
+ ## Example of Usage
31
+ #### Payment
32
+ default_values:
33
+ - amount_currency - `"RUB"`
34
+ - confirmation_type - `"redirect"`
35
+ - capture - `true`
36
+ ```ruby
37
+ idempotence_key = '123456'
38
+
39
+ payment_params = {
40
+ amount_value: 10.0,
41
+ payment_id: '123',
42
+ return_url: 'http://example.com'
43
+ }
44
+
45
+ YaKassa::V3::PaymentRequest.new(idempotence_key, payment_params).create
46
+ # => {"id"=>"2534fac6-000f-5000-a000-105ab7c0ab90", "status"=>"pending", "paid"=>false, "amount"=>{"value"=>"10.00", "currency"=>"RUB"}, "confirmation"=>{"type"=>"redirect", "confirmation_url"=>"https://money.yandex.ru/api-pages/v2/payment-confirm/epl?orderId=2534fac6-000f-50....."}, "created_at"=>"2019-10-13T08:57:42.987Z", "metadata"=>{}, "recipient"=>{"account_id"=>"123123", "gateway_id"=>"123123"}, "refundable"=>false, "test"=>true}
47
+ ```
48
+
49
+ #### Payment status
50
+ ```ruby
51
+ YaKassa::V3::PaymentStatusRequest.new('2534fac6-000f-5000-a000-105ab7c0ab90').create
52
+ # => {"id"=>"2534fac6-000f-5000-a000-105ab7c0ab90", "status"=>"pending", "paid"=>false, "amount"=>{"value"=>"10.00", "currency"=>"RUB"}, "confirmation"=>{"type"=>"redirect", "confirmation_url"=>"https://money.yandex.ru/api-pages/v2/payment-confirm/epl?orderId=2534fac6-000f..."}, "created_at"=>"2019-10-13T08:57:42.987Z", "metadata"=>{}, "recipient"=>{"account_id"=>"123123", "gateway_id"=>"123123"}, "refundable"=>false, "test"=>true}
53
+ ```
54
+
55
+ #### Payment capture
56
+ Works just for payments with `capture: false`
57
+ ```ruby
58
+ idempotence_key = '123456'
59
+
60
+ capture_params = {
61
+ amount_value: 10.0,
62
+ payment_id: '2534fac6-000f-5000-a000-105ab7c0ab90'
63
+ }
64
+ YaKassa::V3::PaymentCaptureRequest.new(idempotence_key, capture_params).create
65
+ # => {"id"=>"253503ee-000f-5000-a000-1c5fb44eaf40", "status"=>"succeeded", "paid"=>true, "amount"=>{"value"=>"10.00", "currency"=>"RUB"}, "authorization_details"=>{"rrn"=>"123123272641", "auth_code"=>"21231"}, "captured_at"=>"2019-10-13T09:38:14.133Z", "created_at"=>"2019-10-13T09:37:58.019Z", "metadata"=>{}, "payment_method"=>{"type"=>"bank_card", "id"=>"253503ee-000f-5000-a000-1c5fb44eaf40", "saved"=>false, "card"=>{"first6"=>"555555", "last4"=>"4444", "expiry_month"=>"01", "expiry_year"=>"2022", "card_type"=>"MasterCard"}, "title"=>"Bank card *4444"}, "recipient"=>{"account_id"=>"45358", "gateway_id"=>"16234542"}, "refundable"=>true, "refunded_amount"=>{"value"=>"0.00", "currency"=>"RUB"}, "test"=>true}
66
+ ```
24
67
 
25
- TODO: Write usage instructions here
68
+ #### Refund
69
+ ```ruby
70
+ idempotence_key = '123456'
71
+
72
+ refund_params = {
73
+ amount_value: 10.0,
74
+ payment_id: '2534fac6-000f-5000-a000-105ab7c0ab90'
75
+ }
76
+ YaKassa::V3::RefundRequest.new(idempotence_key, payment_params).create
77
+ # => {"id"=>"253505ba-0015-5000-a000-1f19dc0", "status"=>"succeeded", "amount"=>{"value"=>"10.0", "currency"=>"RUB"}, "created_at"=>"2019-10-13T09:44:26.548Z", "payment_id"=>"253503ee-000f-5000-a000-1c5fb4"
78
+ ```
79
+
80
+ #### Receipt
81
+ ```ruby
82
+ idempotence_key = '123456'
83
+
84
+ receipt_params = {
85
+ full_name: 'Ivan Ivanov',
86
+ email: 'example@exaple.com',
87
+ phone: '+7 777777',
88
+ payment_id: "253503ee-000f-5000-a000-1c5fb44eaf40",
89
+ items: [
90
+ { description: 'product1', quantity: 1, amount_value: 10.0 }
91
+ ]
92
+ }
93
+
94
+ YaKassa::V3::ReceiptRequest.new(idempotence_key, receipt_params).create
95
+ ```
96
+
97
+ ### Validation
98
+ ```ruby
99
+ idempotence_key = '123456'
100
+
101
+ payment_params = {
102
+ payment_id: '123',
103
+ return_url: 'http://example.com'
104
+ }
105
+
106
+ YaKassa::V3::PaymentRequest.new(idempotence_key, payment_params).create
107
+ # => {:amount_value=>["Should be Float"]}
108
+ ```
26
109
 
27
110
  ## Development
28
111
 
@@ -5,7 +5,11 @@ module YaKassa
5
5
  protected
6
6
 
7
7
  def response_body(response)
8
- JSON.parse(response.body)
8
+ begin
9
+ JSON.parse(response.body)
10
+ rescue JSON::ParserError
11
+ response.body
12
+ end
9
13
  end
10
14
 
11
15
  def send
@@ -1,7 +1,7 @@
1
1
  module YaKassa
2
2
  module V3
3
3
  class ReceiptRequest < BaseRequest
4
- attributable :customer
4
+ attributable :customer
5
5
  attributable :payment_id
6
6
  attributable :type, default: "payment"
7
7
  attributable :send, default: "true"
@@ -22,7 +22,6 @@ module YaKassa
22
22
  validatable :full_name, :is_a, class: "String"
23
23
  validatable :email, :is_a, class: "String"
24
24
  validatable :phone, :present
25
- validatable :inn, :present
26
25
 
27
26
  def body
28
27
  {
@@ -1,3 +1,3 @@
1
1
  module YaKassa
2
- VERSION = "0.1.5"
2
+ VERSION = "0.1.6"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ya_kassa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - nikulinaleksandr