multisafepay-ruby-wrapper 0.2.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 9940155336a4cbf2c000893eff941266a112520c59bd5036b340ada9128dc0f4
4
+ data.tar.gz: 98453a0727f386ea277400992422e9f0ed6b3d184740d8cfe2eb66b122114941
5
+ SHA512:
6
+ metadata.gz: d5641b717f15ab4b519a435facec46e1c24170903cc40333e6ce40e37799b0254c0c3c5cc903e1e276d40e968de8c288ecaf42f08cb40766b6808b0fff6804dd
7
+ data.tar.gz: fd9996ad99b79d06d5874db4f9354267ecf33a30d4f8bc585d158f6734c603b6704afad2abe12a0c45938bac8d06f5d9d31edb6280573370e229db3df9e5b97e
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.idea
2
+ /.bundle/
3
+ /.yardoc
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ gem "rake"
6
+ gem "rspec", "~> 3.0"
7
+ gem "standard"
data/Gemfile.lock ADDED
@@ -0,0 +1,86 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ multisafepay-ruby-wrapper (0.2.0)
5
+ faraday (~> 1.7)
6
+ faraday_middleware (~> 1.1)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ ast (2.4.2)
12
+ diff-lcs (1.4.4)
13
+ faraday (1.7.1)
14
+ faraday-em_http (~> 1.0)
15
+ faraday-em_synchrony (~> 1.0)
16
+ faraday-excon (~> 1.1)
17
+ faraday-httpclient (~> 1.0.1)
18
+ faraday-net_http (~> 1.0)
19
+ faraday-net_http_persistent (~> 1.1)
20
+ faraday-patron (~> 1.0)
21
+ faraday-rack (~> 1.0)
22
+ multipart-post (>= 1.2, < 3)
23
+ ruby2_keywords (>= 0.0.4)
24
+ faraday-em_http (1.0.0)
25
+ faraday-em_synchrony (1.0.0)
26
+ faraday-excon (1.1.0)
27
+ faraday-httpclient (1.0.1)
28
+ faraday-net_http (1.0.1)
29
+ faraday-net_http_persistent (1.2.0)
30
+ faraday-patron (1.0.0)
31
+ faraday-rack (1.0.0)
32
+ faraday_middleware (1.1.0)
33
+ faraday (~> 1.0)
34
+ multipart-post (2.1.1)
35
+ parallel (1.20.1)
36
+ parser (3.0.2.0)
37
+ ast (~> 2.4.1)
38
+ rainbow (3.0.0)
39
+ rake (13.0.6)
40
+ regexp_parser (2.1.1)
41
+ rexml (3.2.5)
42
+ rspec (3.10.0)
43
+ rspec-core (~> 3.10.0)
44
+ rspec-expectations (~> 3.10.0)
45
+ rspec-mocks (~> 3.10.0)
46
+ rspec-core (3.10.1)
47
+ rspec-support (~> 3.10.0)
48
+ rspec-expectations (3.10.1)
49
+ diff-lcs (>= 1.2.0, < 2.0)
50
+ rspec-support (~> 3.10.0)
51
+ rspec-mocks (3.10.2)
52
+ diff-lcs (>= 1.2.0, < 2.0)
53
+ rspec-support (~> 3.10.0)
54
+ rspec-support (3.10.2)
55
+ rubocop (1.20.0)
56
+ parallel (~> 1.10)
57
+ parser (>= 3.0.0.0)
58
+ rainbow (>= 2.2.2, < 4.0)
59
+ regexp_parser (>= 1.8, < 3.0)
60
+ rexml
61
+ rubocop-ast (>= 1.9.1, < 2.0)
62
+ ruby-progressbar (~> 1.7)
63
+ unicode-display_width (>= 1.4.0, < 3.0)
64
+ rubocop-ast (1.11.0)
65
+ parser (>= 3.0.1.1)
66
+ rubocop-performance (1.11.5)
67
+ rubocop (>= 1.7.0, < 2.0)
68
+ rubocop-ast (>= 0.4.0)
69
+ ruby-progressbar (1.11.0)
70
+ ruby2_keywords (0.0.5)
71
+ standard (1.3.0)
72
+ rubocop (= 1.20.0)
73
+ rubocop-performance (= 1.11.5)
74
+ unicode-display_width (2.0.0)
75
+
76
+ PLATFORMS
77
+ x64-mingw32
78
+
79
+ DEPENDENCIES
80
+ multisafepay-ruby-wrapper!
81
+ rake
82
+ rspec (~> 3.0)
83
+ standard
84
+
85
+ BUNDLED WITH
86
+ 2.2.5
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Diego
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,66 @@
1
+ <p align="center">
2
+ <img src="https://www.multisafepay.com/img/multisafepaylogo.svg" width="400px" position="center">
3
+ </p>
4
+
5
+ # Unofficial Ruby wrapper for the MultiSafepay API
6
+
7
+ This wrapper simplifies working with the MultiSafepay API and allows you to integrate MultiSafepay within your Ruby application.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'multisafepay-ruby-multisafepay'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle install
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install multisafepay-ruby-wrapper
24
+
25
+ ## Usage
26
+ Setup the client for testing
27
+ ```ruby
28
+ client = Multisafepay::Client.new(api_key: 'REPLACE WITH API KEY', env: :test)
29
+ ```
30
+ Creating a test order
31
+ ```ruby
32
+ # The following code will create a iDEAL order
33
+ client.orders.create({
34
+ type: "redirect",
35
+ order_id: "my-order-id-1",
36
+ gateway: "IDEAL",
37
+ currency: "EUR",
38
+ amount: "1000",
39
+ description: "Test Order Description",
40
+ payment_options: {
41
+ notification_url: "https://www.example.com/client/notification?type=notification",
42
+ redirect_url: "https://www.example.com/client/notification?type=redirect",
43
+ cancel_url: "https://www.example.com/client/notification?type=cancel"
44
+ },
45
+ customer: {
46
+ locale: "en_US"
47
+ }
48
+ })
49
+ ```
50
+ Click [here](#) for more examples.
51
+ ## Development
52
+
53
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
54
+
55
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
56
+
57
+ ## Contributing
58
+
59
+ Bug reports and pull requests are welcome on GitHub at https://github.com/denjamio/multisafepay-ruby-wrapper.
60
+
61
+ ## API Documentation
62
+ [Click here](https://docs.multisafepay.com/api/) for the MultiSafepay API documentation.
63
+
64
+ ## License
65
+
66
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "multisafepay-ruby-wrapper"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,54 @@
1
+ module Multisafepay
2
+ class Client
3
+ attr_reader :api_key, :env, :adapter
4
+
5
+ def initialize(api_key: nil, env: :live, adapter: Faraday.default_adapter)
6
+ @api_key = api_key
7
+ @env = env
8
+ @adapter = adapter
9
+ end
10
+
11
+ def account
12
+ AccountResource.new(self)
13
+ end
14
+
15
+ def gateways
16
+ GatewaysResource.new(self)
17
+ end
18
+
19
+ def orders
20
+ OrdersResource.new(self)
21
+ end
22
+
23
+ def tokens
24
+ TokensResource.new(self)
25
+ end
26
+
27
+ def transactions
28
+ TransactionsResource.new(self)
29
+ end
30
+
31
+ def connection
32
+ @connection ||= Faraday.new do |conn|
33
+ conn.url_prefix = base_url
34
+ conn.headers["api_key"] = api_key
35
+ conn.request :json
36
+
37
+ conn.response :json, content_type: "application/json"
38
+
39
+ conn.adapter adapter
40
+ end
41
+ end
42
+
43
+ private
44
+
45
+ def base_url
46
+ case env
47
+ when :live
48
+ "https://api.multisafepay.com/v1/json"
49
+ when :test
50
+ "https://testapi.multisafepay.com/v1/json"
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,4 @@
1
+ module Multisafepay
2
+ class Error < StandardError
3
+ end
4
+ end
@@ -0,0 +1,22 @@
1
+ require "ostruct"
2
+
3
+ module Multisafepay
4
+ class Object
5
+ def initialize(attributes)
6
+ @attributes = OpenStruct.new(attributes)
7
+ end
8
+
9
+ def success?
10
+ @attributes.success
11
+ end
12
+
13
+ def method_missing(method, *args, &block)
14
+ attribute = @attributes.send(method, *args, &block)
15
+ attribute.is_a?(Hash) ? Object.new(attribute) : attribute
16
+ end
17
+
18
+ def respond_to_missing?(method, include_private = false)
19
+ true
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,4 @@
1
+ module Multisafepay
2
+ class Account < Object
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Multisafepay
2
+ class Gateway < Object
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Multisafepay
2
+ class Order < Object
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Multisafepay
2
+ class Token < Object
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Multisafepay
2
+ class Transaction < Object
3
+ end
4
+ end
@@ -0,0 +1,48 @@
1
+ module Multisafepay
2
+ class Resource
3
+ attr_reader :client
4
+
5
+ def initialize(client)
6
+ @client = client
7
+ end
8
+
9
+ private
10
+
11
+ def get_request(url, params: {}, headers: {})
12
+ handle_response client.connection.get(url, params, headers)
13
+ end
14
+
15
+ def post_request(url, body:, headers: {})
16
+ handle_response client.connection.post(url, body, headers)
17
+ end
18
+
19
+ def patch_request(url, body:, headers: {})
20
+ handle_response client.connection.patch(url, body, headers)
21
+ end
22
+
23
+ def put_request(url, body:, headers: {})
24
+ handle_response client.connection.put(url, body, headers)
25
+ end
26
+
27
+ def delete_request(url, params: {}, headers: {})
28
+ handle_response client.connection.delete(url, params, headers)
29
+ end
30
+
31
+ def handle_response(response)
32
+ case response.status
33
+ when 400
34
+ raise Error, "Request malformed. #{response.body["error"]}"
35
+ when 401
36
+ raise Error, "Invalid api_key. #{response.body["error"]}"
37
+ when 403
38
+ raise Error, "Action not allowed. #{response.body}"
39
+ when 404
40
+ raise Error, "No results. #{response.body["error"]}"
41
+ when 500
42
+ raise Error, "Unable to perform the request due to server-side problems. #{response.body["error"]}"
43
+ end
44
+
45
+ response.body
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,15 @@
1
+ module Multisafepay
2
+ class AccountResource < Resource
3
+ def balances(affiliated_id:)
4
+ Account.new get_request("accounts/#{affiliated_id}/balances")
5
+ end
6
+
7
+ def charges(affiliated_id:, **attributes)
8
+ Account.new post_request("accounts/#{affiliated_id}/charges", body: attributes)
9
+ end
10
+
11
+ def payouts(affiliated_id:, **attributes)
12
+ Account.new post_request("accounts/#{affiliated_id}/payouts", body: attributes)
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,11 @@
1
+ module Multisafepay
2
+ class GatewaysResource < Resource
3
+ def list
4
+ Gateway.new get_request("gateways")
5
+ end
6
+
7
+ def retrieve(id)
8
+ Gateway.new get_request("gateways/#{id}")
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,19 @@
1
+ module Multisafepay
2
+ class OrdersResource < Resource
3
+ def retrieve(id)
4
+ Order.new get_request("orders/#{id}")
5
+ end
6
+
7
+ def create(**attributes)
8
+ Order.new post_request("orders", body: attributes)
9
+ end
10
+
11
+ def update(id:, **attributes)
12
+ Order.new patch_request("orders/#{id}", body: attributes)
13
+ end
14
+
15
+ def delete(id:, **attributes)
16
+ Order.new patch_request("orders/#{id}", body: attributes)
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,20 @@
1
+ module Multisafepay
2
+ class TokensResource < Resource
3
+ def create
4
+ Token.new get_request("auth/api_token")
5
+ end
6
+
7
+ def retrieve(your_customer_reference:, your_token: nil)
8
+ url = your_token.nil? ? "recurring/#{your_customer_reference}" : "recurring/#{your_customer_reference}/token/#{your_token}"
9
+ Token.new get_request(url)
10
+ end
11
+
12
+ def update(your_customer_reference:, your_token:, **attributes)
13
+ Token.new patch_request("recurring/#{your_customer_reference}/update/#{your_token}", body: attributes)
14
+ end
15
+
16
+ def delete(your_customer_reference:, your_token:)
17
+ Token.new delete_request("recurring/#{your_customer_reference}/token/#{your_token}")
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,7 @@
1
+ module Multisafepay
2
+ class TransactionsResource < Resource
3
+ def list
4
+ Transaction.new get_request("transactions")
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ module Multisafepay
2
+ VERSION = "0.2.0".freeze
3
+ end
@@ -0,0 +1,22 @@
1
+ require "faraday"
2
+ require "faraday_middleware"
3
+ require "multisafepay/version"
4
+
5
+ module Multisafepay
6
+ autoload :Client, "multisafepay/client"
7
+ autoload :Error, "multisafepay/error"
8
+ autoload :Object, "multisafepay/object"
9
+ autoload :Resource, "multisafepay/resource"
10
+
11
+ autoload :AccountResource, "multisafepay/resources/account"
12
+ autoload :GatewaysResource, "multisafepay/resources/gateways"
13
+ autoload :OrdersResource, "multisafepay/resources/orders"
14
+ autoload :TokensResource, "multisafepay/resources/tokens"
15
+ autoload :TransactionsResource, "multisafepay/resources/transactions"
16
+
17
+ autoload :Account, "multisafepay/objects/account"
18
+ autoload :Gateway, "multisafepay/objects/gateway"
19
+ autoload :Order, "multisafepay/objects/order"
20
+ autoload :Token, "multisafepay/objects/token"
21
+ autoload :Transaction, "multisafepay/objects/transaction"
22
+ end
@@ -0,0 +1,25 @@
1
+ require_relative "lib/multisafepay/version"
2
+
3
+ Gem::Specification.new do |gem|
4
+ gem.name = "multisafepay-ruby-wrapper"
5
+ gem.version = Multisafepay::VERSION
6
+ gem.authors = ["Diego"]
7
+ gem.email = ["denjamio@gmail.com"]
8
+
9
+ gem.summary = "Unofficial MultiSafePay API Library for Ruby"
10
+ gem.description = "Unofficial MultiSafePay API Library for Ruby. Simplifies integrating with the MultiSafePay API."
11
+ gem.homepage = "https://github.com/denjamio/multisafepay-ruby-wrapper"
12
+ gem.license = "MIT"
13
+
14
+ gem.required_ruby_version = ">= 2.3"
15
+
16
+ gem.files = Dir.chdir(File.expand_path(__dir__)) do
17
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
18
+ end
19
+
20
+ gem.executables = gem.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
21
+ gem.require_paths = ["lib"]
22
+
23
+ gem.add_dependency "faraday", "~> 1.7"
24
+ gem.add_dependency "faraday_middleware", "~> 1.1"
25
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: multisafepay-ruby-wrapper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Diego
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-09-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday_middleware
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.1'
41
+ description: Unofficial MultiSafePay API Library for Ruby. Simplifies integrating
42
+ with the MultiSafePay API.
43
+ email:
44
+ - denjamio@gmail.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".gitignore"
50
+ - ".rspec"
51
+ - Gemfile
52
+ - Gemfile.lock
53
+ - LICENSE.txt
54
+ - README.md
55
+ - Rakefile
56
+ - bin/console
57
+ - bin/setup
58
+ - lib/multisafepay-ruby-wrapper.rb
59
+ - lib/multisafepay/client.rb
60
+ - lib/multisafepay/error.rb
61
+ - lib/multisafepay/object.rb
62
+ - lib/multisafepay/objects/account.rb
63
+ - lib/multisafepay/objects/gateway.rb
64
+ - lib/multisafepay/objects/order.rb
65
+ - lib/multisafepay/objects/token.rb
66
+ - lib/multisafepay/objects/transaction.rb
67
+ - lib/multisafepay/resource.rb
68
+ - lib/multisafepay/resources/account.rb
69
+ - lib/multisafepay/resources/gateways.rb
70
+ - lib/multisafepay/resources/orders.rb
71
+ - lib/multisafepay/resources/tokens.rb
72
+ - lib/multisafepay/resources/transactions.rb
73
+ - lib/multisafepay/version.rb
74
+ - multisafepay-ruby-wrapper.gemspec
75
+ homepage: https://github.com/denjamio/multisafepay-ruby-wrapper
76
+ licenses:
77
+ - MIT
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '2.3'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubygems_version: 3.1.6
95
+ signing_key:
96
+ specification_version: 4
97
+ summary: Unofficial MultiSafePay API Library for Ruby
98
+ test_files: []