cloud_payments 0.0.6 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +5 -5
  2. data/.travis.yml +11 -8
  3. data/README.md +53 -3
  4. data/cloud_payments.gemspec +6 -6
  5. data/lib/cloud_payments.rb +0 -1
  6. data/lib/cloud_payments/client.rb +2 -2
  7. data/lib/cloud_payments/config.rb +3 -0
  8. data/lib/cloud_payments/models.rb +1 -0
  9. data/lib/cloud_payments/models/on_fail.rb +1 -0
  10. data/lib/cloud_payments/models/on_kassa_receipt.rb +23 -0
  11. data/lib/cloud_payments/models/on_pay.rb +1 -0
  12. data/lib/cloud_payments/models/subscription.rb +1 -1
  13. data/lib/cloud_payments/models/transaction.rb +8 -0
  14. data/lib/cloud_payments/namespaces.rb +6 -1
  15. data/lib/cloud_payments/namespaces/base.rb +1 -1
  16. data/lib/cloud_payments/namespaces/cards.rb +5 -0
  17. data/lib/cloud_payments/namespaces/kassa.rb +22 -0
  18. data/lib/cloud_payments/namespaces/orders.rb +4 -0
  19. data/lib/cloud_payments/version.rb +1 -1
  20. data/lib/cloud_payments/webhooks.rb +6 -2
  21. data/spec/cloud_payments/models/subscription_spec.rb +0 -1
  22. data/spec/cloud_payments/models/transaction_spec.rb +23 -0
  23. data/spec/cloud_payments/namespaces/cards_spec.rb +41 -2
  24. data/spec/cloud_payments/namespaces/orders_spec.rb +12 -0
  25. data/spec/cloud_payments/namespaces/payments_spec.rb +6 -0
  26. data/spec/cloud_payments/namespaces_spec.rb +1 -1
  27. data/spec/cloud_payments/webhooks_spec.rb +42 -0
  28. data/spec/cloud_payments_spec.rb +26 -4
  29. data/spec/fixtures/apis/cards/post3ds/failed.yml +45 -0
  30. data/spec/fixtures/apis/cards/post3ds/successful.yml +48 -0
  31. data/spec/fixtures/apis/orders/cancel/failed.yml +6 -0
  32. data/spec/fixtures/apis/orders/cancel/successful.yml +6 -0
  33. data/spec/fixtures/apis/payments/get/failed.yml +1 -0
  34. data/spec/fixtures/apis/payments/get/refunded.yml +49 -0
  35. data/spec/fixtures/apis/payments/get/successful.yml +1 -0
  36. data/spec/spec_helper.rb +10 -8
  37. metadata +26 -15
  38. data/spec/cloud_payments/client_spec.rb +0 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: ed4e88a861a6e0f61c9758ae8db253faf5479e74
4
- data.tar.gz: 26b8c758021f249079c5b00d88e62cdf7bc80327
2
+ SHA256:
3
+ metadata.gz: e31ba1babda3743559e6106299ac4f94a7ed045cee632366e3cf9392b193fd2e
4
+ data.tar.gz: 658ef8a73850a5a9b61c704a30157856fdb38d2821d41d38cf6a0386bbea629b
5
5
  SHA512:
6
- metadata.gz: 1556658db7e02a39c840876f9017218182a853b92fe590fb7ed0ca793a20784b81c917ca959e72b565d8df616ed1354cd91e21f921ac5a82b4cd32be64f76dc2
7
- data.tar.gz: 4a1c1a70e208bc95d3c3bfaf07219309c8e0171912ca0267a18e47667112c8cadf67ae4809ab723348fb1351029d3fd9a8c9bca53e7271b3eb5eaa1cf862abe1
6
+ metadata.gz: ea82b5a807c04599cc39d878b1e9150e5c4173183386e5549c9d9e37062528857bed984f60838fb797e992f2759a86a92f09a629aea2edc795822858e9f0aa87
7
+ data.tar.gz: 52c31c9c3872ddc39d8174ae0b49d60626466a468d90a760e7c7adf92bfafd54179d476e9b46cfcb36be80f57fc42b2c8d775be620c87d12e27f4401a328aaa1
@@ -1,11 +1,14 @@
1
1
  language: ruby
2
+
3
+ rvm:
4
+ - 2.3
5
+ - 2.4
6
+ - 2.5
7
+ - 2.6
8
+ - 2.7
9
+
2
10
  cache: bundler
3
- script: bundle exec rspec
11
+
4
12
  before_install: gem install bundler
5
- rvm:
6
- - '2.2'
7
- - '2.3'
8
- - ruby-head
9
- matrix:
10
- allow_failures:
11
- - rvm: ruby-head
13
+
14
+ script: bundle exec rspec
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # CloudPayments
2
2
 
3
- CloudPayments ruby client (http://cloudpayments.eu/Docs/Integration)
3
+ CloudPayments ruby client (https://developers.cloudpayments.ru/en/)
4
4
 
5
- [![Build Status](https://travis-ci.org/undr/cloud_payments.svg)](https://travis-ci.org/undr/cloud_payments)
5
+ [![Build Status](https://travis-ci.org/platmart/cloud_payments.svg)](https://travis-ci.org/platmart/cloud_payments)
6
6
 
7
7
  ## Installation
8
8
 
@@ -28,6 +28,8 @@ $ gem install cloud_payments
28
28
 
29
29
  ### Configuration
30
30
 
31
+ #### Global configuration
32
+
31
33
  ```ruby
32
34
  CloudPayments.configure do |c|
33
35
  c.host = 'http://localhost:3000' # By default, it is https://api.cloudpayments.ru
@@ -37,6 +39,28 @@ CloudPayments.configure do |c|
37
39
  c.logger = Logger.new('/dev/null') # By default, it writes logs to stdout
38
40
  c.raise_banking_errors = true # By default, it is not raising banking errors
39
41
  end
42
+
43
+ # API client
44
+ CloudPayments.client.payments.cards.charge(...)
45
+
46
+ # Webhooks
47
+ CloudPayments.webhooks.on_pay(...)
48
+ ```
49
+
50
+ #### Local configuration
51
+
52
+ ```ruby
53
+ config = CloudPayments::Config.new do |c|
54
+ # ...
55
+ end
56
+
57
+ # API client
58
+ client = CloudPayments::Client.new(config)
59
+ client.payments.cards.charge(...)
60
+
61
+ # Webhooks
62
+ webhooks = CloudPayments::Webhooks.new(config)
63
+ webhooks.on_pay(...)
40
64
  ```
41
65
 
42
66
  ### Test method
@@ -81,6 +105,7 @@ transaction = CloudPayments.client.payments.cards.charge(
81
105
  # :card_last_four=>"1111",
82
106
  # :card_type=>"Visa",
83
107
  # :card_type_code=>0,
108
+ # :issuer=>"Sberbank of Russia",
84
109
  # :issuer_bank_country=>"RU",
85
110
  # :status=>"Completed",
86
111
  # :status_code=>3,
@@ -95,6 +120,31 @@ transaction.token
95
120
  # => "a4e67841-abb0-42de-a364-d1d8f9f4b3c0"
96
121
  ```
97
122
 
123
+ ## Kassa Receipt
124
+
125
+ CloudPayments Kassa API (https://cloudpayments.ru/docs/api/kassa)
126
+
127
+ ```ruby
128
+ CloudPayments.client.kassa.receipt({
129
+ account_id: "user@example.com",
130
+ customer_receipt: {
131
+ items: [
132
+ {
133
+ amount: "13350.00",
134
+ ean13: nil,
135
+ label: "Good Description",
136
+ price: "13350.00",
137
+ quantity: 1.0,
138
+ vat: nil
139
+ }
140
+ ]
141
+ },
142
+ inn: "7708806666",
143
+ invoice_id: "231312312",
144
+ type: "Income"
145
+ })
146
+ ```
147
+
98
148
  ## Webhooks
99
149
 
100
150
  ```ruby
@@ -132,7 +182,7 @@ end
132
182
 
133
183
  ## Contributing
134
184
 
135
- 1. Fork it ( https://github.com/undr/cloud_payments/fork )
185
+ 1. Fork it ( https://github.com/platmart/cloud_payments/fork )
136
186
  2. Create your feature branch (`git checkout -b my-new-feature`)
137
187
  3. Commit your changes (`git commit -am 'Add some feature'`)
138
188
  4. Push to the branch (`git push origin my-new-feature`)
@@ -7,11 +7,11 @@ require 'cloud_payments/version'
7
7
  Gem::Specification.new do |spec|
8
8
  spec.name = 'cloud_payments'
9
9
  spec.version = CloudPayments::VERSION
10
- spec.authors = ['undr']
11
- spec.email = ['undr@yandex.ru']
10
+ spec.authors = ['undr', 'kirillplatonov']
11
+ spec.email = ['undr@yandex.ru', 'mail@kirillplatonov.com']
12
12
  spec.summary = %q{CloudPayments ruby client}
13
13
  spec.description = %q{CloudPayments ruby client}
14
- spec.homepage = ''
14
+ spec.homepage = 'https://github.com/platmart/cloud_payments'
15
15
  spec.license = 'MIT'
16
16
 
17
17
  spec.files = `git ls-files -z`.split("\x0")
@@ -19,10 +19,10 @@ Gem::Specification.new do |spec|
19
19
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
20
  spec.require_paths = ['lib']
21
21
 
22
- spec.add_dependency 'faraday', '~> 0.9.2'
22
+ spec.add_dependency 'faraday'
23
23
  spec.add_dependency 'multi_json', '~> 1.11'
24
24
  spec.add_dependency 'hashie', '~> 3.4'
25
25
 
26
- spec.add_development_dependency 'rake', '~> 10.0'
27
- spec.add_development_dependency 'rspec', '~> 3.4'
26
+ spec.add_development_dependency 'rake', '~> 13.0'
27
+ spec.add_development_dependency 'rspec', '~> 3.9'
28
28
  end
@@ -3,7 +3,6 @@ require 'date'
3
3
  require 'hashie'
4
4
  require 'faraday'
5
5
  require 'multi_json'
6
- require 'pp'
7
6
  require 'cloud_payments/version'
8
7
  require 'cloud_payments/config'
9
8
  require 'cloud_payments/namespaces'
@@ -10,8 +10,8 @@ module CloudPayments
10
10
 
11
11
  attr_reader :config, :connection
12
12
 
13
- def initialize
14
- @config = CloudPayments.config
13
+ def initialize(config = nil)
14
+ @config = config || CloudPayments.config
15
15
  @connection = build_connection
16
16
  end
17
17
 
@@ -18,6 +18,9 @@ module CloudPayments
18
18
  @connection_options = {}
19
19
  @connection_block = nil
20
20
  @host = 'https://api.cloudpayments.ru'
21
+ if block_given?
22
+ yield self
23
+ end
21
24
  end
22
25
 
23
26
  def logger
@@ -9,3 +9,4 @@ require 'cloud_payments/models/order'
9
9
  require 'cloud_payments/models/on_recurrent'
10
10
  require 'cloud_payments/models/on_pay'
11
11
  require 'cloud_payments/models/on_fail'
12
+ require 'cloud_payments/models/on_kassa_receipt'
@@ -23,6 +23,7 @@ module CloudPayments
23
23
  property :ip_city
24
24
  property :ip_region
25
25
  property :ip_district
26
+ property :issuer
26
27
  property :issuer_bank_country
27
28
  property :description
28
29
  property :metadata, from: :data, default: {}
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+ module CloudPayments
3
+ # @see https://cloudpayments.ru/Docs/Notifications#receipt CloudPayments API
4
+ class OnKassaReceipt < Model
5
+ property :id, required: true
6
+ property :document_number, required: true
7
+ property :session_number, required: true
8
+ property :fiscal_sign, required: true
9
+ property :device_number, required: true
10
+ property :reg_number, required: true
11
+ property :inn, required: true
12
+ property :type, required: true
13
+ property :ofd, required: true
14
+ property :url, required: true
15
+ property :qr_code_url, required: true
16
+ property :amount, transform_with: DecimalTransform, required: true
17
+ property :date_time, transform_with: DateTimeTransform
18
+ property :receipt
19
+ property :invoice_id
20
+ property :transaction_id
21
+ property :account_id
22
+ end
23
+ end
@@ -26,6 +26,7 @@ module CloudPayments
26
26
  property :card_type_code
27
27
  property :card_exp_date
28
28
  property :name
29
+ property :issuer
29
30
  property :issuer_bank_country
30
31
  property :status, required: true
31
32
  property :status_code
@@ -5,7 +5,7 @@ module CloudPayments
5
5
 
6
6
  property :id, required: true
7
7
  property :account_id, required: true
8
- property :description, required: true
8
+ property :description
9
9
  property :email, required: true
10
10
  property :amount, transform_with: DecimalTransform, required: true
11
11
  property :currency, required: true
@@ -36,13 +36,17 @@ module CloudPayments
36
36
  property :card_type_code
37
37
  property :card_exp_date
38
38
  property :name
39
+ property :issuer
39
40
  property :issuer_bank_country
40
41
  property :status, required: true
41
42
  property :status_code
42
43
  property :reason
43
44
  property :reason_code
45
+ property :refunded
44
46
  property :card_holder_message
45
47
  property :token
48
+ property :apple_pay
49
+ property :android_pay
46
50
 
47
51
  def required_secure3d?
48
52
  false
@@ -79,5 +83,9 @@ module CloudPayments
79
83
  def declined?
80
84
  status == DECLINED
81
85
  end
86
+
87
+ def refunded?
88
+ refunded
89
+ end
82
90
  end
83
91
  end
@@ -5,6 +5,7 @@ require 'cloud_payments/namespaces/tokens'
5
5
  require 'cloud_payments/namespaces/payments'
6
6
  require 'cloud_payments/namespaces/subscriptions'
7
7
  require 'cloud_payments/namespaces/orders'
8
+ require 'cloud_payments/namespaces/kassa'
8
9
 
9
10
  module CloudPayments
10
11
  module Namespaces
@@ -12,6 +13,10 @@ module CloudPayments
12
13
  Payments.new(self)
13
14
  end
14
15
 
16
+ def kassa
17
+ Kassa.new(self)
18
+ end
19
+
15
20
  def subscriptions
16
21
  Subscriptions.new(self)
17
22
  end
@@ -22,7 +27,7 @@ module CloudPayments
22
27
 
23
28
  def ping
24
29
  !!(perform_request('/test').body || {})[:success]
25
- rescue ::Faraday::Error::ConnectionFailed, ::Faraday::Error::TimeoutError, CloudPayments::Client::ServerError => e
30
+ rescue ::Faraday::ConnectionFailed, ::Faraday::TimeoutError, CloudPayments::Client::ServerError => e
26
31
  false
27
32
  end
28
33
  end
@@ -24,7 +24,7 @@ module CloudPayments
24
24
  protected
25
25
 
26
26
  def api_exceptions
27
- [::Faraday::Error::ConnectionFailed, ::Faraday::Error::TimeoutError, Client::ServerError, Client::GatewayError]
27
+ [::Faraday::ConnectionFailed, ::Faraday::TimeoutError, Client::ServerError, Client::GatewayError]
28
28
  end
29
29
 
30
30
  def resource_path(path = nil)
@@ -12,6 +12,11 @@ module CloudPayments
12
12
  instantiate(response[:model])
13
13
  end
14
14
 
15
+ def post3ds(attributes)
16
+ response = request(:post3ds, attributes)
17
+ instantiate(response[:model])
18
+ end
19
+
15
20
  private
16
21
 
17
22
  def instantiate(model)
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+ module CloudPayments
3
+ module Namespaces
4
+ class Kassa < Base
5
+ InnNotProvided = Class.new(StandardError)
6
+ TypeNotProvided = Class.new(StandardError)
7
+ CustomerReceiptNotProvided = Class.new(StandardError)
8
+
9
+ def self.resource_name
10
+ 'kkt'
11
+ end
12
+
13
+ def receipt(attributes)
14
+ attributes.fetch(:inn) { raise InnNotProvided.new('inn attribute is required') }
15
+ attributes.fetch(:type) { raise TypeNotProvided.new('type attribute is required') }
16
+ attributes.fetch(:inn) { raise CustomerReceiptNotProvided.new('customer_receipt is required') }
17
+
18
+ request(:receipt, attributes)
19
+ end
20
+ end
21
+ end
22
+ end
@@ -6,6 +6,10 @@ module CloudPayments
6
6
  response = request(:create, attributes)
7
7
  Order.new(response[:model])
8
8
  end
9
+
10
+ def cancel(order_id)
11
+ request(:cancel, id: order_id)[:success]
12
+ end
9
13
  end
10
14
  end
11
15
  end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module CloudPayments
3
- VERSION = '0.0.6'
3
+ VERSION = '1.0.0'
4
4
  end
@@ -8,8 +8,8 @@ module CloudPayments
8
8
 
9
9
  attr_reader :config
10
10
 
11
- def initialize
12
- @config = CloudPayments.config
11
+ def initialize(config = nil)
12
+ @config = config || CloudPayments.config
13
13
  @digest = OpenSSL::Digest.new('sha256')
14
14
  @serializer = Client::Serializer::Base.new(config)
15
15
  end
@@ -23,6 +23,10 @@ module CloudPayments
23
23
  true
24
24
  end
25
25
 
26
+ def kassa_receipt(data)
27
+ OnKassaReceipt.new(@serializer.load(data))
28
+ end
29
+
26
30
  def on_recurrent(data)
27
31
  OnRecurrent.new(@serializer.load(data))
28
32
  end
@@ -54,7 +54,6 @@ describe CloudPayments::Subscription do
54
54
 
55
55
  it_behaves_like :raise_without_attribute, :id
56
56
  it_behaves_like :raise_without_attribute, :account_id
57
- it_behaves_like :raise_without_attribute, :description
58
57
  it_behaves_like :raise_without_attribute, :email
59
58
  it_behaves_like :raise_without_attribute, :amount
60
59
  it_behaves_like :raise_without_attribute, :currency_code
@@ -34,11 +34,13 @@ describe CloudPayments::Transaction do
34
34
  card_type: 'Visa',
35
35
  card_type_code: 0,
36
36
  card_exp_date: '10/17',
37
+ issuer: 'Sberbank of Russia',
37
38
  issuer_bank_country: 'RU',
38
39
  status: 'Completed',
39
40
  status_code: 3,
40
41
  reason: 'Approved',
41
42
  reason_code: 0,
43
+ refunded: false,
42
44
  card_holder_message: 'Payment successful',
43
45
  name: 'CARDHOLDER NAME',
44
46
  token: 'a4e67841-abb0-42de-a364-d1d8f9f4b3c0'
@@ -72,12 +74,14 @@ describe CloudPayments::Transaction do
72
74
  specify{ expect(subject.card_type).to eq('Visa') }
73
75
  specify{ expect(subject.card_type_code).to eq(0) }
74
76
  specify{ expect(subject.card_exp_date).to eq('10/17') }
77
+ specify{ expect(subject.issuer).to eq('Sberbank of Russia') }
75
78
  specify{ expect(subject.issuer_bank_country).to eq('RU') }
76
79
  specify{ expect(subject.reason).to eq('Approved') }
77
80
  specify{ expect(subject.reason_code).to eq(0) }
78
81
  specify{ expect(subject.card_holder_message).to eq('Payment successful') }
79
82
  specify{ expect(subject.name).to eq('CARDHOLDER NAME') }
80
83
  specify{ expect(subject.token).to eq('a4e67841-abb0-42de-a364-d1d8f9f4b3c0') }
84
+ specify{ expect(subject.refunded).to eq(false) }
81
85
 
82
86
  context 'without any attributes' do
83
87
  let(:attributes){ {} }
@@ -111,9 +115,11 @@ describe CloudPayments::Transaction do
111
115
  it_behaves_like :not_raise_without_attribute, :ip_longitude, :ip_lng
112
116
  it_behaves_like :not_raise_without_attribute, :card_type_code
113
117
  it_behaves_like :not_raise_without_attribute, :card_exp_date
118
+ it_behaves_like :not_raise_without_attribute, :issuer
114
119
  it_behaves_like :not_raise_without_attribute, :issuer_bank_country
115
120
  it_behaves_like :not_raise_without_attribute, :reason
116
121
  it_behaves_like :not_raise_without_attribute, :reason_code
122
+ it_behaves_like :not_raise_without_attribute, :refunded
117
123
  it_behaves_like :not_raise_without_attribute, :card_holder_message
118
124
  it_behaves_like :not_raise_without_attribute, :name
119
125
  it_behaves_like :not_raise_without_attribute, :token
@@ -251,5 +257,22 @@ describe CloudPayments::Transaction do
251
257
  specify{ expect(subject.ip_location).to be_nil }
252
258
  end
253
259
  end
260
+
261
+ describe '#refunded?' do
262
+ context do
263
+ let(:attributes) { { refunded: false } }
264
+ specify { expect(subject.refunded?).to be_falsey }
265
+ end
266
+
267
+ context do
268
+ let(:attributes) { { refunded: true } }
269
+ specify { expect(subject.refunded?).to be_truthy }
270
+ end
271
+
272
+ context do
273
+ let(:attributes) { { refunded: nil } }
274
+ specify { expect(subject.refunded?).to be_falsey }
275
+ end
276
+ end
254
277
  end
255
278
  end
@@ -14,11 +14,11 @@ describe CloudPayments::Namespaces::Cards do
14
14
  card_cryptogram_packet: '01492500008719030128SM'
15
15
  } }
16
16
 
17
- context do
17
+ describe '#charge' do
18
18
  context 'config.raise_banking_errors = false' do
19
19
  before { CloudPayments.config.raise_banking_errors = false }
20
20
 
21
- describe '#charge' do
21
+ context do
22
22
  before{ stub_api_request('cards/charge/successful').perform }
23
23
  specify{ expect(subject.charge(attributes)).to be_instance_of(CloudPayments::Transaction) }
24
24
  specify{ expect(subject.charge(attributes)).not_to be_required_secure3d }
@@ -117,4 +117,43 @@ describe CloudPayments::Namespaces::Cards do
117
117
  end
118
118
  end
119
119
  end
120
+
121
+ describe '#post3ds' do
122
+ let(:attributes){ { transaction_id: 12345, pa_res: 'AQ==' } }
123
+
124
+ context 'config.raise_banking_errors = false' do
125
+ before { CloudPayments.config.raise_banking_errors = false }
126
+
127
+ context do
128
+ before{ stub_api_request('cards/post3ds/successful').perform }
129
+ specify{ expect(subject.post3ds(attributes)).to be_instance_of(CloudPayments::Transaction) }
130
+ specify{ expect(subject.post3ds(attributes)).not_to be_required_secure3d }
131
+ specify{ expect(subject.post3ds(attributes)).to be_completed }
132
+ specify{ expect(subject.post3ds(attributes).id).to eq(12345) }
133
+ end
134
+
135
+ context do
136
+ before{ stub_api_request('cards/post3ds/failed').perform }
137
+ specify{ expect(subject.post3ds(attributes)).to be_instance_of(CloudPayments::Transaction) }
138
+ specify{ expect(subject.post3ds(attributes)).not_to be_required_secure3d }
139
+ specify{ expect(subject.post3ds(attributes)).to be_declined }
140
+ specify{ expect(subject.post3ds(attributes).id).to eq(12345) }
141
+ specify{ expect(subject.post3ds(attributes).reason).to eq('InsufficientFunds') }
142
+ end
143
+ end
144
+
145
+ context 'config.raise_banking_errors = true' do
146
+ before { CloudPayments.config.raise_banking_errors = true }
147
+
148
+ context do
149
+ before{ stub_api_request('cards/post3ds/successful').perform }
150
+ specify{ expect{ subject.post3ds(attributes) }.not_to raise_error }
151
+ end
152
+
153
+ context do
154
+ before{ stub_api_request('cards/post3ds/failed').perform }
155
+ specify{ expect{ subject.post3ds(attributes) }.to raise_error(CloudPayments::Client::GatewayErrors::InsufficientFunds) }
156
+ end
157
+ end
158
+ end
120
159
  end
@@ -42,4 +42,16 @@ describe CloudPayments::Namespaces::Orders do
42
42
  end
43
43
  end
44
44
  end
45
+
46
+ describe '#cancel' do
47
+ context do
48
+ before{ stub_api_request('orders/cancel/successful').perform }
49
+ specify{ expect(subject.cancel('12345')).to be_truthy }
50
+ end
51
+
52
+ context do
53
+ before{ stub_api_request('orders/cancel/failed').perform }
54
+ specify{ expect{ subject.cancel('12345') }.to raise_error(CloudPayments::Client::GatewayError, 'Error message') }
55
+ end
56
+ end
45
57
  end
@@ -123,6 +123,12 @@ describe CloudPayments::Namespaces::Payments do
123
123
  specify{ expect(subject.get(transaction_id).id).to eq(transaction_id) }
124
124
  specify{ expect(subject.get(transaction_id).reason).to eq('Approved') }
125
125
  end
126
+
127
+ context 'transaction is refunded' do
128
+ before{ stub_api_request('payments/get/refunded').perform }
129
+ specify{ expect(subject.get(transaction_id)).to be_completed }
130
+ specify{ expect(subject.get(transaction_id)).to be_refunded }
131
+ end
126
132
  end
127
133
 
128
134
  context 'config.raise_banking_errors = true' do
@@ -34,7 +34,7 @@ describe CloudPayments::Namespaces do
34
34
  end
35
35
 
36
36
  context 'when exception occurs while request' do
37
- before{ stub_api_request('ping/failed').to_raise(::Faraday::Error::ConnectionFailed) }
37
+ before{ stub_api_request('ping/failed').to_raise(::Faraday::ConnectionFailed) }
38
38
  specify{ expect(subject.ping).to be_falsy }
39
39
  end
40
40
 
@@ -227,4 +227,46 @@ describe CloudPayments::Webhooks do
227
227
  specify { expect(subject.failed_transactions).to eq 22 }
228
228
  specify { expect(subject.next_transaction_at).to eq DateTime.parse('2015-11-18 20:29:05') }
229
229
  end
230
+
231
+ describe 'on_kassa_receipt' do
232
+ let(:raw_data) do
233
+ {"Id"=>"sc_a38ca02005d40db7d32b36a0097b0",
234
+ "DocumentNumber"=>"1234",
235
+ "SessionNumber"=>"12345",
236
+ "FiscalSign"=>"signsgin",
237
+ "DeviceNumber"=>"123465",
238
+ "RegNumber"=>"12345",
239
+ "Inn"=>"0",
240
+ "Type"=>"Type",
241
+ "Ofd"=>"Ofd",
242
+ "Url"=>"http://example.com/url/",
243
+ "QrCodeUrl"=>"http://example.com/url",
244
+ "Amount"=>"11.11",
245
+ "DateTime"=>"2015-11-18 20:29:05",
246
+ "Receipt"=>"{}",
247
+ "TransactionId" => "12321123",
248
+ "InvoiceId" => "123123",
249
+ "AccountId" => "3213213"}
250
+ end
251
+
252
+ subject { CloudPayments.webhooks.kassa_receipt(raw_data) }
253
+
254
+ specify { expect(subject.id).to eq "sc_a38ca02005d40db7d32b36a0097b0" }
255
+ specify { expect(subject.document_number).to eq '1234' }
256
+ specify { expect(subject.session_number).to eq '12345' }
257
+ specify { expect(subject.fiscal_sign).to eq 'signsgin' }
258
+ specify { expect(subject.device_number).to eq '123465' }
259
+ specify { expect(subject.reg_number).to eq '12345' }
260
+ specify { expect(subject.inn).to eq '0' }
261
+ specify { expect(subject.type).to eq 'Type' }
262
+ specify { expect(subject.ofd).to eq 'Ofd' }
263
+ specify { expect(subject.url).to eq 'http://example.com/url/' }
264
+ specify { expect(subject.qr_code_url).to eq 'http://example.com/url' }
265
+ specify { expect(subject.amount).to eq 11.11 }
266
+ specify { expect(subject.date_time).to eq DateTime.parse('2015-11-18 20:29:05') }
267
+ specify { expect(subject.receipt).to eq '{}' }
268
+ specify { expect(subject.transaction_id).to eq '12321123' }
269
+ specify { expect(subject.invoice_id).to eq '123123' }
270
+ specify { expect(subject.account_id).to eq '3213213' }
271
+ end
230
272
  end
@@ -3,13 +3,35 @@ require 'spec_helper'
3
3
 
4
4
  describe CloudPayments do
5
5
  describe '#config=' do
6
- before{ @old_config = CloudPayments.config }
7
- after{ CloudPayments.config = @old_config }
6
+ before { @old_config = CloudPayments.config }
7
+ after { CloudPayments.config = @old_config }
8
8
 
9
9
  specify{ expect{ CloudPayments.config = 'config' }.to change{ CloudPayments.config }.to('config') }
10
10
  end
11
11
 
12
- describe '#config' do
13
- specify{ expect(CloudPayments.config).to be_instance_of(CloudPayments::Config) }
12
+ it 'supports global configuration' do
13
+ CloudPayments.config.secret_key = "OLD_KEY"
14
+
15
+ CloudPayments.configure do |c|
16
+ c.secret_key = "NEW_KEY"
17
+ end
18
+
19
+ expect(CloudPayments.config.secret_key).to eq "NEW_KEY"
20
+ expect(CloudPayments.client.config.secret_key).to eq "NEW_KEY"
21
+ end
22
+
23
+ it 'supports local configuration' do
24
+ CloudPayments.config.secret_key = "OLD_KEY"
25
+
26
+ config = CloudPayments::Config.new do |c|
27
+ c.secret_key = "NEW_KEY"
28
+ end
29
+ client = CloudPayments::Client.new(config)
30
+ webhooks = CloudPayments::Webhooks.new(config)
31
+
32
+ expect(CloudPayments.config.secret_key).to eq "OLD_KEY"
33
+ expect(config.secret_key).to eq "NEW_KEY"
34
+ expect(client.config.secret_key).to eq "NEW_KEY"
35
+ expect(webhooks.config.secret_key).to eq "NEW_KEY"
14
36
  end
15
37
  end
@@ -0,0 +1,45 @@
1
+ ---
2
+ :request:
3
+ :url: '/payments/cards/post3ds'
4
+ :body: '{"TransactionId":12345,"PaRes":"AQ=="}'
5
+ :response:
6
+ :body: >
7
+ {
8
+ "Model": {
9
+ "TransactionId": 12345,
10
+ "Amount": 10.0,
11
+ "Currency": "RUB",
12
+ "CurrencyCode": 0,
13
+ "PaymentAmount": 10.0,
14
+ "PaymentCurrency": "RUB",
15
+ "PaymentCurrencyCode": 0,
16
+ "InvoiceId": "1234567",
17
+ "AccountId": "user_x",
18
+ "Email": null,
19
+ "Description": "Payment for goods on example.com",
20
+ "JsonData": null,
21
+ "CreatedDate": "\/Date(1401718880000)\/",
22
+ "CreatedDateIso":"2014-08-09T11:49:41",
23
+ "TestMode": true,
24
+ "IpAddress": "195.91.194.13",
25
+ "IpCountry": "RU",
26
+ "IpCity": "Ufa",
27
+ "IpRegion": "Bashkortostan Republic",
28
+ "IpDistrict": "Volga Federal District",
29
+ "IpLatitude": 54.7355,
30
+ "IpLongitude": 55.991982,
31
+ "CardFirstSix": "411111",
32
+ "CardLastFour": "1111",
33
+ "CardType": "Visa",
34
+ "CardTypeCode": 0,
35
+ "IssuerBankCountry": "RU",
36
+ "Status": "Declined",
37
+ "StatusCode": 5,
38
+ "Reason": "InsufficientFunds",
39
+ "ReasonCode": 5051,
40
+ "CardHolderMessage": "Insufficient funds on account",
41
+ "Name": "CARDHOLDER NAME"
42
+ },
43
+ "Success": false,
44
+ "Message": null
45
+ }
@@ -0,0 +1,48 @@
1
+ ---
2
+ :request:
3
+ :url: '/payments/cards/post3ds'
4
+ :body: '{"TransactionId":12345,"PaRes":"AQ=="}'
5
+ :response:
6
+ :body: >
7
+ {
8
+ "Model":{
9
+ "TransactionId":12345,
10
+ "Amount":10.0,
11
+ "Currency":"RUB",
12
+ "CurrencyCode":0,
13
+ "InvoiceId":"1234567",
14
+ "AccountId":"user_x",
15
+ "Email":null,
16
+ "Description":"Payment for goods on example.com",
17
+ "JsonData":null,
18
+ "CreatedDate":"\/Date(1401718880000)\/",
19
+ "CreatedDateIso":"2014-08-09T11:49:41",
20
+ "AuthDate":"\/Date(1401733880523)\/",
21
+ "AuthDateIso":"2014-08-09T11:49:42",
22
+ "ConfirmDate":"\/Date(1401733880523)\/",
23
+ "ConfirmDateIso":"2014-08-09T11:49:42",
24
+ "AuthCode":"123456",
25
+ "TestMode":true,
26
+ "IpAddress":"195.91.194.13",
27
+ "IpCountry":"RU",
28
+ "IpCity":"Ufa",
29
+ "IpRegion":"Bashkortostan Republic",
30
+ "IpDistrict":"Volga Federal District",
31
+ "IpLatitude":54.7355,
32
+ "IpLongitude":55.991982,
33
+ "CardFirstSix":"411111",
34
+ "CardLastFour":"1111",
35
+ "CardType":"Visa",
36
+ "CardTypeCode":0,
37
+ "IssuerBankCountry":"RU",
38
+ "Status":"Completed",
39
+ "StatusCode":3,
40
+ "Reason":"Approved",
41
+ "ReasonCode":0,
42
+ "CardHolderMessage":"Payment successful",
43
+ "Name":"CARDHOLDER NAME",
44
+ "Token":"a4e67841-abb0-42de-a364-d1d8f9f4b3c0"
45
+ },
46
+ "Success":true,
47
+ "Message": null
48
+ }
@@ -0,0 +1,6 @@
1
+ ---
2
+ :request:
3
+ :url: '/orders/cancel'
4
+ :body: '{"Id":"12345"}'
5
+ :response:
6
+ :body: '{"Success":false,"Message":"Error message"}'
@@ -0,0 +1,6 @@
1
+ ---
2
+ :request:
3
+ :url: '/orders/cancel'
4
+ :body: '{"Id":"12345"}'
5
+ :response:
6
+ :body: '{"Success":true,"Message":null}'
@@ -37,6 +37,7 @@
37
37
  "StatusCode": 5,
38
38
  "Reason": "InsufficientFunds",
39
39
  "ReasonCode": 5051,
40
+ "Refunded": false,
40
41
  "CardHolderMessage": "Insufficient funds on account",
41
42
  "Name": "CARDHOLDER NAME"
42
43
  },
@@ -0,0 +1,49 @@
1
+ ---
2
+ :request:
3
+ :url: '/payments/get'
4
+ :body: '{"TransactionId":12345}'
5
+ :response:
6
+ :body: >
7
+ {
8
+ "Model":{
9
+ "TransactionId":12345,
10
+ "Amount":10.0,
11
+ "Currency":"RUB",
12
+ "CurrencyCode":0,
13
+ "InvoiceId":"1234567",
14
+ "AccountId":"user_x",
15
+ "Email":null,
16
+ "Description":"Payment for goods on example.com",
17
+ "JsonData":null,
18
+ "CreatedDate":"\/Date(1401718880000)\/",
19
+ "CreatedDateIso":"2014-08-09T11:49:41",
20
+ "AuthDate":"\/Date(1401733880523)\/",
21
+ "AuthDateIso":"2014-08-09T11:49:42",
22
+ "ConfirmDate":"\/Date(1401733880523)\/",
23
+ "ConfirmDateIso":"2014-08-09T11:49:42",
24
+ "AuthCode":"123456",
25
+ "TestMode":true,
26
+ "IpAddress":"195.91.194.13",
27
+ "IpCountry":"RU",
28
+ "IpCity":"Ufa",
29
+ "IpRegion":"Bashkortostan Republic",
30
+ "IpDistrict":"Volga Federal District",
31
+ "IpLatitude":54.7355,
32
+ "IpLongitude":55.991982,
33
+ "CardFirstSix":"411111",
34
+ "CardLastFour":"1111",
35
+ "CardType":"Visa",
36
+ "CardTypeCode":0,
37
+ "IssuerBankCountry":"RU",
38
+ "Status":"Completed",
39
+ "StatusCode":3,
40
+ "Reason":"Approved",
41
+ "ReasonCode":0,
42
+ "Refunded": true,
43
+ "CardHolderMessage":"Payment successful",
44
+ "Name":"CARDHOLDER NAME",
45
+ "Token":"a4e67841-abb0-42de-a364-d1d8f9f4b3c0"
46
+ },
47
+ "Success":true,
48
+ "Message": null
49
+ }
@@ -39,6 +39,7 @@
39
39
  "StatusCode":3,
40
40
  "Reason":"Approved",
41
41
  "ReasonCode":0,
42
+ "Refunded": false,
42
43
  "CardHolderMessage":"Payment successful",
43
44
  "Name":"CARDHOLDER NAME",
44
45
  "Token":"a4e67841-abb0-42de-a364-d1d8f9f4b3c0"
@@ -11,15 +11,17 @@ WebMock.disable_net_connect!
11
11
 
12
12
  Dir["./spec/support/**/*.rb"].each { |f| require f }
13
13
 
14
- CloudPayments.configure do |c|
15
- c.public_key = 'user'
16
- c.secret_key = 'pass'
17
- c.host = 'http://localhost:9292'
18
- c.log = false
19
- # c.raise_banking_errors = true
20
- end
21
-
22
14
  RSpec.configure do |config|
23
15
  config.mock_with :rspec
24
16
  config.include CloudPayments::RSpec::Helpers
17
+
18
+ config.before :each do
19
+ CloudPayments.configure do |c|
20
+ c.public_key = 'user'
21
+ c.secret_key = 'pass'
22
+ c.host = 'http://localhost:9292'
23
+ c.log = false
24
+ # c.raise_banking_errors = true
25
+ end
26
+ end
25
27
  end
metadata CHANGED
@@ -1,29 +1,30 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloud_payments
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - undr
8
+ - kirillplatonov
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2017-08-09 00:00:00.000000000 Z
12
+ date: 2020-04-23 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: faraday
15
16
  requirement: !ruby/object:Gem::Requirement
16
17
  requirements:
17
- - - "~>"
18
+ - - ">="
18
19
  - !ruby/object:Gem::Version
19
- version: 0.9.2
20
+ version: '0'
20
21
  type: :runtime
21
22
  prerelease: false
22
23
  version_requirements: !ruby/object:Gem::Requirement
23
24
  requirements:
24
- - - "~>"
25
+ - - ">="
25
26
  - !ruby/object:Gem::Version
26
- version: 0.9.2
27
+ version: '0'
27
28
  - !ruby/object:Gem::Dependency
28
29
  name: multi_json
29
30
  requirement: !ruby/object:Gem::Requirement
@@ -58,31 +59,32 @@ dependencies:
58
59
  requirements:
59
60
  - - "~>"
60
61
  - !ruby/object:Gem::Version
61
- version: '10.0'
62
+ version: '13.0'
62
63
  type: :development
63
64
  prerelease: false
64
65
  version_requirements: !ruby/object:Gem::Requirement
65
66
  requirements:
66
67
  - - "~>"
67
68
  - !ruby/object:Gem::Version
68
- version: '10.0'
69
+ version: '13.0'
69
70
  - !ruby/object:Gem::Dependency
70
71
  name: rspec
71
72
  requirement: !ruby/object:Gem::Requirement
72
73
  requirements:
73
74
  - - "~>"
74
75
  - !ruby/object:Gem::Version
75
- version: '3.4'
76
+ version: '3.9'
76
77
  type: :development
77
78
  prerelease: false
78
79
  version_requirements: !ruby/object:Gem::Requirement
79
80
  requirements:
80
81
  - - "~>"
81
82
  - !ruby/object:Gem::Version
82
- version: '3.4'
83
+ version: '3.9'
83
84
  description: CloudPayments ruby client
84
85
  email:
85
86
  - undr@yandex.ru
87
+ - mail@kirillplatonov.com
86
88
  executables: []
87
89
  extensions: []
88
90
  extra_rdoc_files: []
@@ -109,6 +111,7 @@ files:
109
111
  - lib/cloud_payments/models/like_subscription.rb
110
112
  - lib/cloud_payments/models/model.rb
111
113
  - lib/cloud_payments/models/on_fail.rb
114
+ - lib/cloud_payments/models/on_kassa_receipt.rb
112
115
  - lib/cloud_payments/models/on_pay.rb
113
116
  - lib/cloud_payments/models/on_recurrent.rb
114
117
  - lib/cloud_payments/models/order.rb
@@ -118,6 +121,7 @@ files:
118
121
  - lib/cloud_payments/namespaces.rb
119
122
  - lib/cloud_payments/namespaces/base.rb
120
123
  - lib/cloud_payments/namespaces/cards.rb
124
+ - lib/cloud_payments/namespaces/kassa.rb
121
125
  - lib/cloud_payments/namespaces/orders.rb
122
126
  - lib/cloud_payments/namespaces/payments.rb
123
127
  - lib/cloud_payments/namespaces/subscriptions.rb
@@ -126,7 +130,6 @@ files:
126
130
  - lib/cloud_payments/webhooks.rb
127
131
  - spec/cloud_payments/client/response_spec.rb
128
132
  - spec/cloud_payments/client/serializer/multi_json_spec.rb
129
- - spec/cloud_payments/client_spec.rb
130
133
  - spec/cloud_payments/models/order_spec.rb
131
134
  - spec/cloud_payments/models/secure3d_spec.rb
132
135
  - spec/cloud_payments/models/subscription_spec.rb
@@ -146,6 +149,10 @@ files:
146
149
  - spec/fixtures/apis/cards/charge/failed.yml
147
150
  - spec/fixtures/apis/cards/charge/secure3d.yml
148
151
  - spec/fixtures/apis/cards/charge/successful.yml
152
+ - spec/fixtures/apis/cards/post3ds/failed.yml
153
+ - spec/fixtures/apis/cards/post3ds/successful.yml
154
+ - spec/fixtures/apis/orders/cancel/failed.yml
155
+ - spec/fixtures/apis/orders/cancel/successful.yml
149
156
  - spec/fixtures/apis/orders/create/successful.yml
150
157
  - spec/fixtures/apis/payments/confirm/failed.yml
151
158
  - spec/fixtures/apis/payments/confirm/failed_with_message.yml
@@ -155,6 +162,7 @@ files:
155
162
  - spec/fixtures/apis/payments/find/successful.yml
156
163
  - spec/fixtures/apis/payments/get/failed.yml
157
164
  - spec/fixtures/apis/payments/get/failed_with_message.yml
165
+ - spec/fixtures/apis/payments/get/refunded.yml
158
166
  - spec/fixtures/apis/payments/get/successful.yml
159
167
  - spec/fixtures/apis/payments/post3ds/failed.yml
160
168
  - spec/fixtures/apis/payments/post3ds/successful.yml
@@ -178,7 +186,7 @@ files:
178
186
  - spec/spec_helper.rb
179
187
  - spec/support/examples.rb
180
188
  - spec/support/helpers.rb
181
- homepage: ''
189
+ homepage: https://github.com/platmart/cloud_payments
182
190
  licenses:
183
191
  - MIT
184
192
  metadata: {}
@@ -197,15 +205,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
197
205
  - !ruby/object:Gem::Version
198
206
  version: '0'
199
207
  requirements: []
200
- rubyforge_project:
201
- rubygems_version: 2.6.11
208
+ rubygems_version: 3.1.2
202
209
  signing_key:
203
210
  specification_version: 4
204
211
  summary: CloudPayments ruby client
205
212
  test_files:
206
213
  - spec/cloud_payments/client/response_spec.rb
207
214
  - spec/cloud_payments/client/serializer/multi_json_spec.rb
208
- - spec/cloud_payments/client_spec.rb
209
215
  - spec/cloud_payments/models/order_spec.rb
210
216
  - spec/cloud_payments/models/secure3d_spec.rb
211
217
  - spec/cloud_payments/models/subscription_spec.rb
@@ -225,6 +231,10 @@ test_files:
225
231
  - spec/fixtures/apis/cards/charge/failed.yml
226
232
  - spec/fixtures/apis/cards/charge/secure3d.yml
227
233
  - spec/fixtures/apis/cards/charge/successful.yml
234
+ - spec/fixtures/apis/cards/post3ds/failed.yml
235
+ - spec/fixtures/apis/cards/post3ds/successful.yml
236
+ - spec/fixtures/apis/orders/cancel/failed.yml
237
+ - spec/fixtures/apis/orders/cancel/successful.yml
228
238
  - spec/fixtures/apis/orders/create/successful.yml
229
239
  - spec/fixtures/apis/payments/confirm/failed.yml
230
240
  - spec/fixtures/apis/payments/confirm/failed_with_message.yml
@@ -234,6 +244,7 @@ test_files:
234
244
  - spec/fixtures/apis/payments/find/successful.yml
235
245
  - spec/fixtures/apis/payments/get/failed.yml
236
246
  - spec/fixtures/apis/payments/get/failed_with_message.yml
247
+ - spec/fixtures/apis/payments/get/refunded.yml
237
248
  - spec/fixtures/apis/payments/get/successful.yml
238
249
  - spec/fixtures/apis/payments/post3ds/failed.yml
239
250
  - spec/fixtures/apis/payments/post3ds/successful.yml
@@ -1,6 +0,0 @@
1
- # frozen_string_literal: true
2
- require 'spec_helper'
3
-
4
- describe CloudPayments::Client do
5
-
6
- end