cloud_payments 0.0.3 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. checksums.yaml +5 -5
  2. data/.travis.yml +12 -15
  3. data/Gemfile +2 -2
  4. data/README.md +74 -5
  5. data/Rakefile +1 -0
  6. data/cloud_payments.gemspec +7 -6
  7. data/config.ru +1 -0
  8. data/lib/cloud_payments.rb +1 -1
  9. data/lib/cloud_payments/client.rb +3 -2
  10. data/lib/cloud_payments/client/errors.rb +1 -0
  11. data/lib/cloud_payments/client/gateway_errors.rb +3 -1
  12. data/lib/cloud_payments/client/response.rb +2 -1
  13. data/lib/cloud_payments/client/serializer.rb +1 -0
  14. data/lib/cloud_payments/client/serializer/base.rb +9 -1
  15. data/lib/cloud_payments/client/serializer/multi_json.rb +1 -0
  16. data/lib/cloud_payments/config.rb +4 -0
  17. data/lib/cloud_payments/models.rb +2 -0
  18. data/lib/cloud_payments/models/like_subscription.rb +1 -0
  19. data/lib/cloud_payments/models/model.rb +1 -0
  20. data/lib/cloud_payments/models/on_fail.rb +2 -0
  21. data/lib/cloud_payments/models/on_kassa_receipt.rb +23 -0
  22. data/lib/cloud_payments/models/on_pay.rb +2 -0
  23. data/lib/cloud_payments/models/on_recurrent.rb +1 -0
  24. data/lib/cloud_payments/models/order.rb +1 -0
  25. data/lib/cloud_payments/models/secure3d.rb +1 -0
  26. data/lib/cloud_payments/models/subscription.rb +2 -1
  27. data/lib/cloud_payments/models/transaction.rb +9 -0
  28. data/lib/cloud_payments/namespaces.rb +12 -1
  29. data/lib/cloud_payments/namespaces/apple_pay.rb +18 -0
  30. data/lib/cloud_payments/namespaces/base.rb +2 -1
  31. data/lib/cloud_payments/namespaces/cards.rb +6 -0
  32. data/lib/cloud_payments/namespaces/kassa.rb +22 -0
  33. data/lib/cloud_payments/namespaces/orders.rb +5 -0
  34. data/lib/cloud_payments/namespaces/payments.rb +11 -0
  35. data/lib/cloud_payments/namespaces/subscriptions.rb +6 -0
  36. data/lib/cloud_payments/namespaces/tokens.rb +1 -0
  37. data/lib/cloud_payments/version.rb +2 -1
  38. data/lib/cloud_payments/webhooks.rb +7 -2
  39. data/spec/cloud_payments/client/response_spec.rb +3 -1
  40. data/spec/cloud_payments/client/serializer/multi_json_spec.rb +1 -0
  41. data/spec/cloud_payments/models/order_spec.rb +1 -0
  42. data/spec/cloud_payments/models/secure3d_spec.rb +1 -0
  43. data/spec/cloud_payments/models/subscription_spec.rb +1 -1
  44. data/spec/cloud_payments/models/transaction_spec.rb +25 -1
  45. data/spec/cloud_payments/namespaces/apple_pay_spec.rb +21 -0
  46. data/spec/cloud_payments/namespaces/base_spec.rb +10 -3
  47. data/spec/cloud_payments/namespaces/cards_spec.rb +42 -2
  48. data/spec/cloud_payments/namespaces/kassa_spec.rb +43 -0
  49. data/spec/cloud_payments/namespaces/orders_spec.rb +13 -0
  50. data/spec/cloud_payments/namespaces/payments_spec.rb +119 -0
  51. data/spec/cloud_payments/namespaces/subscriptions_spec.rb +21 -1
  52. data/spec/cloud_payments/namespaces/tokens_spec.rb +1 -0
  53. data/spec/cloud_payments/namespaces_spec.rb +2 -1
  54. data/spec/cloud_payments/webhooks_spec.rb +43 -0
  55. data/spec/cloud_payments_spec.rb +27 -4
  56. data/spec/fixtures/apis/cards/post3ds/failed.yml +45 -0
  57. data/spec/fixtures/apis/cards/post3ds/successful.yml +48 -0
  58. data/spec/fixtures/apis/orders/cancel/failed.yml +6 -0
  59. data/spec/fixtures/apis/orders/cancel/successful.yml +6 -0
  60. data/spec/fixtures/apis/payments/find/failed.yml +45 -0
  61. data/spec/fixtures/apis/payments/find/failed_with_message.yml +6 -0
  62. data/spec/fixtures/apis/payments/find/successful.yml +48 -0
  63. data/spec/fixtures/apis/payments/get/failed.yml +46 -0
  64. data/spec/fixtures/apis/payments/get/failed_with_message.yml +6 -0
  65. data/spec/fixtures/apis/payments/get/refunded.yml +49 -0
  66. data/spec/fixtures/apis/payments/get/successful.yml +49 -0
  67. data/spec/fixtures/apis/subscriptions/find/successful.yml +4 -4
  68. data/spec/fixtures/apis/subscriptions/get/successful.yml +31 -0
  69. data/spec/spec_helper.rb +13 -24
  70. data/spec/support/examples.rb +1 -0
  71. data/spec/support/helpers.rb +3 -2
  72. metadata +45 -15
  73. data/spec/cloud_payments/client_spec.rb +0 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 9e65806150df505158679b9614835f31235eb91d
4
- data.tar.gz: fb0bbe75f1d804547b4eef7fa4f6e3ec72f65a94
2
+ SHA256:
3
+ metadata.gz: 04fb941f12526716bc4134db20ccbde6b973f1f0cbd4cbdedb16f61a0a832907
4
+ data.tar.gz: 195b80061bb94786f2520491a72d7ae3e01310309fcc2ff23ef656d82de494ee
5
5
  SHA512:
6
- metadata.gz: ebc7f7442b275344048f833e615f889abfb38a1253a06e10199a328835447cf3d076d7a2af3263174461963cbcef1ae8549a9d499d606ccf09652b1486d2bd6b
7
- data.tar.gz: 8bb8fe1362062a6ba1cb73cdfc43a845ff80519380b2be392cc19a0dd738e5d7af529d190bbbfe9fdfc766e8a7555707741695d185a29784d55b5c949b842621
6
+ metadata.gz: 84362d280a6c6f40e2929f88a2b2d0a30b24f1e544538fb9de349bc57fc4a9dde44fc3228d937063e3a991e0bd73f378eecb1da1dccfe18013f0d8b01cd6217b
7
+ data.tar.gz: ebe23ab42b51850c0eb6836dc8edd52f79c94fa63da8396f91cf440e05c1a6941b79145946609294f2f92519761e11f43dcd7f68727600f0eee0137e234ff3fa
@@ -1,17 +1,14 @@
1
1
  language: ruby
2
- sudo: false
3
- cache: bundler
4
- script: bundle exec rspec
5
- env:
6
- - CODECLIMATE_REPO_TOKEN=8e9b89269d9aafc2dec2706a43825201de496b743505d7a7666068f7b22b07d
2
+
7
3
  rvm:
8
- - '1.9.3'
9
- - '2.0'
10
- - '2.1'
11
- - '2.2'
12
- - '2.3.0'
13
- - rbx-2
14
- - ruby-head
15
- matrix:
16
- allow_failures:
17
- - rvm: ruby-head
4
+ - 2.3
5
+ - 2.4
6
+ - 2.5
7
+ - 2.6
8
+ - 2.7
9
+
10
+ cache: bundler
11
+
12
+ before_install: gem install bundler
13
+
14
+ script: bundle exec rspec
data/Gemfile CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  source 'https://rubygems.org'
2
3
 
3
4
  # Specify your gem's dependencies in cloud_payments.gemspec
@@ -6,5 +7,4 @@ gemspec
6
7
  gem 'oj'
7
8
  gem 'pry'
8
9
  gem 'rack'
9
- gem 'webmock', require: 'webmock/rspec'
10
- gem "codeclimate-test-reporter", group: :test, require: nil
10
+ gem 'webmock'
data/README.md CHANGED
@@ -1,10 +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)
6
- [![Code Climate](https://codeclimate.com/github/undr/cloud_payments/badges/gpa.svg)](https://codeclimate.com/github/undr/cloud_payments)
7
- [![Test Coverage](https://codeclimate.com/github/undr/cloud_payments/badges/coverage.svg)](https://codeclimate.com/github/undr/cloud_payments)
5
+ [![Build Status](https://travis-ci.org/platmart/cloud_payments.svg)](https://travis-ci.org/platmart/cloud_payments)
8
6
 
9
7
  ## Installation
10
8
 
@@ -30,6 +28,8 @@ $ gem install cloud_payments
30
28
 
31
29
  ### Configuration
32
30
 
31
+ #### Global configuration
32
+
33
33
  ```ruby
34
34
  CloudPayments.configure do |c|
35
35
  c.host = 'http://localhost:3000' # By default, it is https://api.cloudpayments.ru
@@ -39,6 +39,28 @@ CloudPayments.configure do |c|
39
39
  c.logger = Logger.new('/dev/null') # By default, it writes logs to stdout
40
40
  c.raise_banking_errors = true # By default, it is not raising banking errors
41
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(...)
42
64
  ```
43
65
 
44
66
  ### Test method
@@ -83,6 +105,7 @@ transaction = CloudPayments.client.payments.cards.charge(
83
105
  # :card_last_four=>"1111",
84
106
  # :card_type=>"Visa",
85
107
  # :card_type_code=>0,
108
+ # :issuer=>"Sberbank of Russia",
86
109
  # :issuer_bank_country=>"RU",
87
110
  # :status=>"Completed",
88
111
  # :status_code=>3,
@@ -97,6 +120,52 @@ transaction.token
97
120
  # => "a4e67841-abb0-42de-a364-d1d8f9f4b3c0"
98
121
  ```
99
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
+
148
+ ## Apple Pay Start Session
149
+ [Start Apple Pay session](https://developers.cloudpayments.ru/#zapusk-sessii-dlya-oplaty-cherez-apple-pay)
150
+ ```ruby
151
+ CloudPayments.client.apple_pay.start_session({validation_url: "https://apple-pay-gateway-pr-pod2.apple.com/paymentservices/startSession"})
152
+ # => {
153
+ # :message => nil,
154
+ # :model => {
155
+ # :display_name => "example.com,
156
+ # :domain_name => "example.com",
157
+ # :epoch_timestamp => 1594072416294,
158
+ # :expires_at => 1594076016294,
159
+ # :merchant_identifier => "5DCCE3A52CFC3FAF9F4EA8421472E47BC503E03051B04D2ED67A3834386B52F2",
160
+ # :merchant_session_identifier => "SSHDA3C703BD69B45EDB8934E6BFCC159B2B83AAFC02DB625F1F1E3997CCC2FE2CFD11F636558",
161
+ # :nonce => "51c77142",
162
+ # :signature => "30800.....0"
163
+ # },
164
+ # :success => true
165
+ # }
166
+
167
+ ```
168
+
100
169
  ## Webhooks
101
170
 
102
171
  ```ruby
@@ -134,7 +203,7 @@ end
134
203
 
135
204
  ## Contributing
136
205
 
137
- 1. Fork it ( https://github.com/undr/cloud_payments/fork )
206
+ 1. Fork it ( https://github.com/platmart/cloud_payments/fork )
138
207
  2. Create your feature branch (`git checkout -b my-new-feature`)
139
208
  3. Commit your changes (`git commit -am 'Add some feature'`)
140
209
  4. Push to the branch (`git push origin my-new-feature`)
data/Rakefile CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'bundler/gem_tasks'
2
3
  require 'rspec/core/rake_task'
3
4
 
@@ -1,4 +1,5 @@
1
1
  # coding: utf-8
2
+ # frozen_string_literal: true
2
3
  lib = File.expand_path('../lib', __FILE__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
  require 'cloud_payments/version'
@@ -6,11 +7,11 @@ require 'cloud_payments/version'
6
7
  Gem::Specification.new do |spec|
7
8
  spec.name = 'cloud_payments'
8
9
  spec.version = CloudPayments::VERSION
9
- spec.authors = ['undr']
10
- spec.email = ['undr@yandex.ru']
10
+ spec.authors = ['undr', 'kirillplatonov']
11
+ spec.email = ['undr@yandex.ru', 'mail@kirillplatonov.com']
11
12
  spec.summary = %q{CloudPayments ruby client}
12
13
  spec.description = %q{CloudPayments ruby client}
13
- spec.homepage = ''
14
+ spec.homepage = 'https://github.com/platmart/cloud_payments'
14
15
  spec.license = 'MIT'
15
16
 
16
17
  spec.files = `git ls-files -z`.split("\x0")
@@ -18,10 +19,10 @@ Gem::Specification.new do |spec|
18
19
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
20
  spec.require_paths = ['lib']
20
21
 
21
- spec.add_dependency 'faraday', '~> 0.9.2'
22
+ spec.add_dependency 'faraday'
22
23
  spec.add_dependency 'multi_json', '~> 1.11'
23
24
  spec.add_dependency 'hashie', '~> 3.4'
24
25
 
25
- spec.add_development_dependency 'rake', '~> 10.0'
26
- spec.add_development_dependency 'rspec', '~> 3.4'
26
+ spec.add_development_dependency 'rake', '~> 13.0'
27
+ spec.add_development_dependency 'rspec', '~> 3.9'
27
28
  end
data/config.ru CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
3
  require 'cloud_payments'
3
4
  require 'rack'
@@ -1,8 +1,8 @@
1
+ # frozen_string_literal: true
1
2
  require 'date'
2
3
  require 'hashie'
3
4
  require 'faraday'
4
5
  require 'multi_json'
5
- require 'pp'
6
6
  require 'cloud_payments/version'
7
7
  require 'cloud_payments/config'
8
8
  require 'cloud_payments/namespaces'
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'cloud_payments/client/errors'
2
3
  require 'cloud_payments/client/gateway_errors'
3
4
  require 'cloud_payments/client/response'
@@ -9,8 +10,8 @@ module CloudPayments
9
10
 
10
11
  attr_reader :config, :connection
11
12
 
12
- def initialize
13
- @config = CloudPayments.config
13
+ def initialize(config = nil)
14
+ @config = config || CloudPayments.config
14
15
  @connection = build_connection
15
16
  end
16
17
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module CloudPayments
2
3
  class Client
3
4
  class Error < StandardError; end
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
1
2
  module CloudPayments
2
3
  class Client
4
+ class ReasonedGatewayError < StandardError; end
3
5
  module GatewayErrors; end
4
6
 
5
7
  REASON_CODES = {
@@ -29,7 +31,7 @@ module CloudPayments
29
31
 
30
32
  GATEWAY_ERRORS = REASON_CODES.inject({}) do |result, error|
31
33
  status, name = error
32
- result[status] = GatewayErrors.const_set(name, Class.new(StandardError))
34
+ result[status] = GatewayErrors.const_set(name, Class.new(ReasonedGatewayError))
33
35
  result
34
36
  end
35
37
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module CloudPayments
2
3
  class Client
3
4
  class Response
@@ -5,7 +6,7 @@ module CloudPayments
5
6
 
6
7
  def initialize(status, body, headers = {})
7
8
  @status, @origin_body, @headers = status, body, headers
8
- @origin_body = body.force_encoding('UTF-8') if body.respond_to?(:force_encoding)
9
+ @origin_body = body.dup.force_encoding('UTF-8') if body.respond_to?(:force_encoding)
9
10
  end
10
11
 
11
12
  def body
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'cloud_payments/client/serializer/base'
2
3
  require 'cloud_payments/client/serializer/multi_json'
3
4
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module CloudPayments
2
3
  class Client
3
4
  module Serializer
@@ -20,7 +21,14 @@ module CloudPayments
20
21
 
21
22
  def convert_keys_from_api(attributes)
22
23
  attributes.each_with_object({}) do |(key, value), result|
23
- value = convert_keys_from_api(value) if value.is_a?(Hash)
24
+ value = case value
25
+ when Hash
26
+ convert_keys_from_api(value)
27
+ when Array
28
+ value.map { |item| convert_keys_from_api(item) }
29
+ else
30
+ value
31
+ end
24
32
 
25
33
  key = key.to_s.gsub(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2')
26
34
  key.gsub!(/([a-z\d])([A-Z])/, '\1_\2')
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module CloudPayments
2
3
  class Client
3
4
  module Serializer
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module CloudPayments
2
3
  class Config
3
4
  attr_accessor :connection_options, :serializer, :log, :public_key, :secret_key, :host, :raise_banking_errors
@@ -17,6 +18,9 @@ module CloudPayments
17
18
  @connection_options = {}
18
19
  @connection_block = nil
19
20
  @host = 'https://api.cloudpayments.ru'
21
+ if block_given?
22
+ yield self
23
+ end
20
24
  end
21
25
 
22
26
  def logger
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'cloud_payments/models/model'
2
3
  require 'cloud_payments/models/like_subscription'
3
4
  require 'cloud_payments/models/secure3d'
@@ -8,3 +9,4 @@ require 'cloud_payments/models/order'
8
9
  require 'cloud_payments/models/on_recurrent'
9
10
  require 'cloud_payments/models/on_pay'
10
11
  require 'cloud_payments/models/on_fail'
12
+ require 'cloud_payments/models/on_kassa_receipt'
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module CloudPayments
2
3
  module LikeSubscription
3
4
  ACTIVE = 'Active'
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'bigdecimal'
2
3
  require 'bigdecimal/util'
3
4
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module CloudPayments
2
3
  # @see https://cloudpayments.ru/Docs/Notifications#fail CloudPayments API
3
4
  class OnFail < Model
@@ -22,6 +23,7 @@ module CloudPayments
22
23
  property :ip_city
23
24
  property :ip_region
24
25
  property :ip_district
26
+ property :issuer
25
27
  property :issuer_bank_country
26
28
  property :description
27
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
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module CloudPayments
2
3
  class OnPay < Model
3
4
  property :id, from: :transaction_id, required: true
@@ -25,6 +26,7 @@ module CloudPayments
25
26
  property :card_type_code
26
27
  property :card_exp_date
27
28
  property :name
29
+ property :issuer
28
30
  property :issuer_bank_country
29
31
  property :status, required: true
30
32
  property :status_code
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module CloudPayments
2
3
  class OnRecurrent < Model
3
4
  property :id, required: true
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module CloudPayments
2
3
  class Order < Model
3
4
  property :id, required: true
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module CloudPayments
2
3
  class Secure3D < Model
3
4
  property :transaction_id, required: true
@@ -1,10 +1,11 @@
1
+ # frozen_string_literal: true
1
2
  module CloudPayments
2
3
  class Subscription < Model
3
4
  include LikeSubscription
4
5
 
5
6
  property :id, required: true
6
7
  property :account_id, required: true
7
- property :description, required: true
8
+ property :description
8
9
  property :email, required: true
9
10
  property :amount, transform_with: DecimalTransform, required: true
10
11
  property :currency, required: true
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module CloudPayments
2
3
  class Transaction < Model
3
4
  AWAITING_AUTHENTICATION = 'AwaitingAuthentication'
@@ -35,13 +36,17 @@ module CloudPayments
35
36
  property :card_type_code
36
37
  property :card_exp_date
37
38
  property :name
39
+ property :issuer
38
40
  property :issuer_bank_country
39
41
  property :status, required: true
40
42
  property :status_code
41
43
  property :reason
42
44
  property :reason_code
45
+ property :refunded
43
46
  property :card_holder_message
44
47
  property :token
48
+ property :apple_pay
49
+ property :android_pay
45
50
 
46
51
  def required_secure3d?
47
52
  false
@@ -78,5 +83,9 @@ module CloudPayments
78
83
  def declined?
79
84
  status == DECLINED
80
85
  end
86
+
87
+ def refunded?
88
+ refunded
89
+ end
81
90
  end
82
91
  end