cloud_payments 0.0.3 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.travis.yml +12 -15
- data/Gemfile +2 -2
- data/README.md +74 -5
- data/Rakefile +1 -0
- data/cloud_payments.gemspec +7 -6
- data/config.ru +1 -0
- data/lib/cloud_payments.rb +1 -1
- data/lib/cloud_payments/client.rb +3 -2
- data/lib/cloud_payments/client/errors.rb +1 -0
- data/lib/cloud_payments/client/gateway_errors.rb +3 -1
- data/lib/cloud_payments/client/response.rb +2 -1
- data/lib/cloud_payments/client/serializer.rb +1 -0
- data/lib/cloud_payments/client/serializer/base.rb +9 -1
- data/lib/cloud_payments/client/serializer/multi_json.rb +1 -0
- data/lib/cloud_payments/config.rb +4 -0
- data/lib/cloud_payments/models.rb +2 -0
- data/lib/cloud_payments/models/like_subscription.rb +1 -0
- data/lib/cloud_payments/models/model.rb +1 -0
- data/lib/cloud_payments/models/on_fail.rb +2 -0
- data/lib/cloud_payments/models/on_kassa_receipt.rb +23 -0
- data/lib/cloud_payments/models/on_pay.rb +2 -0
- data/lib/cloud_payments/models/on_recurrent.rb +1 -0
- data/lib/cloud_payments/models/order.rb +1 -0
- data/lib/cloud_payments/models/secure3d.rb +1 -0
- data/lib/cloud_payments/models/subscription.rb +2 -1
- data/lib/cloud_payments/models/transaction.rb +9 -0
- data/lib/cloud_payments/namespaces.rb +12 -1
- data/lib/cloud_payments/namespaces/apple_pay.rb +18 -0
- data/lib/cloud_payments/namespaces/base.rb +2 -1
- data/lib/cloud_payments/namespaces/cards.rb +6 -0
- data/lib/cloud_payments/namespaces/kassa.rb +22 -0
- data/lib/cloud_payments/namespaces/orders.rb +5 -0
- data/lib/cloud_payments/namespaces/payments.rb +11 -0
- data/lib/cloud_payments/namespaces/subscriptions.rb +6 -0
- data/lib/cloud_payments/namespaces/tokens.rb +1 -0
- data/lib/cloud_payments/version.rb +2 -1
- data/lib/cloud_payments/webhooks.rb +7 -2
- data/spec/cloud_payments/client/response_spec.rb +3 -1
- data/spec/cloud_payments/client/serializer/multi_json_spec.rb +1 -0
- data/spec/cloud_payments/models/order_spec.rb +1 -0
- data/spec/cloud_payments/models/secure3d_spec.rb +1 -0
- data/spec/cloud_payments/models/subscription_spec.rb +1 -1
- data/spec/cloud_payments/models/transaction_spec.rb +25 -1
- data/spec/cloud_payments/namespaces/apple_pay_spec.rb +21 -0
- data/spec/cloud_payments/namespaces/base_spec.rb +10 -3
- data/spec/cloud_payments/namespaces/cards_spec.rb +42 -2
- data/spec/cloud_payments/namespaces/kassa_spec.rb +43 -0
- data/spec/cloud_payments/namespaces/orders_spec.rb +13 -0
- data/spec/cloud_payments/namespaces/payments_spec.rb +119 -0
- data/spec/cloud_payments/namespaces/subscriptions_spec.rb +21 -1
- data/spec/cloud_payments/namespaces/tokens_spec.rb +1 -0
- data/spec/cloud_payments/namespaces_spec.rb +2 -1
- data/spec/cloud_payments/webhooks_spec.rb +43 -0
- data/spec/cloud_payments_spec.rb +27 -4
- data/spec/fixtures/apis/cards/post3ds/failed.yml +45 -0
- data/spec/fixtures/apis/cards/post3ds/successful.yml +48 -0
- data/spec/fixtures/apis/orders/cancel/failed.yml +6 -0
- data/spec/fixtures/apis/orders/cancel/successful.yml +6 -0
- data/spec/fixtures/apis/payments/find/failed.yml +45 -0
- data/spec/fixtures/apis/payments/find/failed_with_message.yml +6 -0
- data/spec/fixtures/apis/payments/find/successful.yml +48 -0
- data/spec/fixtures/apis/payments/get/failed.yml +46 -0
- data/spec/fixtures/apis/payments/get/failed_with_message.yml +6 -0
- data/spec/fixtures/apis/payments/get/refunded.yml +49 -0
- data/spec/fixtures/apis/payments/get/successful.yml +49 -0
- data/spec/fixtures/apis/subscriptions/find/successful.yml +4 -4
- data/spec/fixtures/apis/subscriptions/get/successful.yml +31 -0
- data/spec/spec_helper.rb +13 -24
- data/spec/support/examples.rb +1 -0
- data/spec/support/helpers.rb +3 -2
- metadata +45 -15
- data/spec/cloud_payments/client_spec.rb +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 04fb941f12526716bc4134db20ccbde6b973f1f0cbd4cbdedb16f61a0a832907
|
4
|
+
data.tar.gz: 195b80061bb94786f2520491a72d7ae3e01310309fcc2ff23ef656d82de494ee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 84362d280a6c6f40e2929f88a2b2d0a30b24f1e544538fb9de349bc57fc4a9dde44fc3228d937063e3a991e0bd73f378eecb1da1dccfe18013f0d8b01cd6217b
|
7
|
+
data.tar.gz: ebe23ab42b51850c0eb6836dc8edd52f79c94fa63da8396f91cf440e05c1a6941b79145946609294f2f92519761e11f43dcd7f68727600f0eee0137e234ff3fa
|
data/.travis.yml
CHANGED
@@ -1,17 +1,14 @@
|
|
1
1
|
language: ruby
|
2
|
-
|
3
|
-
cache: bundler
|
4
|
-
script: bundle exec rspec
|
5
|
-
env:
|
6
|
-
- CODECLIMATE_REPO_TOKEN=8e9b89269d9aafc2dec2706a43825201de496b743505d7a7666068f7b22b07d
|
2
|
+
|
7
3
|
rvm:
|
8
|
-
-
|
9
|
-
-
|
10
|
-
-
|
11
|
-
-
|
12
|
-
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
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'
|
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 (
|
3
|
+
CloudPayments ruby client (https://developers.cloudpayments.ru/en/)
|
4
4
|
|
5
|
-
[](https://codeclimate.com/github/undr/cloud_payments)
|
7
|
-
[](https://codeclimate.com/github/undr/cloud_payments)
|
5
|
+
[](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/
|
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
data/cloud_payments.gemspec
CHANGED
@@ -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'
|
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', '~>
|
26
|
-
spec.add_development_dependency 'rspec', '~> 3.
|
26
|
+
spec.add_development_dependency 'rake', '~> 13.0'
|
27
|
+
spec.add_development_dependency 'rspec', '~> 3.9'
|
27
28
|
end
|
data/config.ru
CHANGED
data/lib/cloud_payments.rb
CHANGED
@@ -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,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(
|
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
|
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 =
|
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 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
|
# @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,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
|
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
|