dlocal_go 0.1.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: 8f9e2ff547bf6bc0042c696f0c4815d7601135cb72ec74948faca35073efb458
4
+ data.tar.gz: 072cd8f884e3d1ce4947899a37b9c4e397b2e491d22b8da1ac4fcf6e6133de00
5
+ SHA512:
6
+ metadata.gz: 508e9b4fde2d886f3b4531257e8d3e8b38519303617a0630b395cb802380458d4f5c54673f65d9e77d02d19e234a2237c7ca2b2364b7a3320cd9a4fdd909b3af
7
+ data.tar.gz: 5ac6fe63c35bc31d14ed05cfd3a3200ee902e0dc6526bbae2a9ad3737986b42e162ba2d7aa63f44349c1b7b7306c26254b9392c1bf43c631c6c169fd16886f42
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,22 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.6
3
+
4
+ Style/StringLiterals:
5
+ Enabled: true
6
+ EnforcedStyle: double_quotes
7
+
8
+ Style/StringLiteralsInInterpolation:
9
+ Enabled: true
10
+ EnforcedStyle: double_quotes
11
+
12
+ Layout/LineLength:
13
+ Max: 120
14
+
15
+ Metrics/BlockLength:
16
+ Enabled: true
17
+ Exclude:
18
+ - 'spec/**/*'
19
+
20
+ Metrics/AbcSize:
21
+ Enabled: true
22
+ Max: 30
data/CHANGELOG.md ADDED
@@ -0,0 +1,8 @@
1
+ ## [0.1.0] - 2023-03-03
2
+
3
+ ### Initial release
4
+
5
+ - Config Dlocal Go API credentials
6
+ - Config environment and supported countries
7
+ - Basic client with: create_payment, get_payment, and create_refund
8
+
data/Gemfile ADDED
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in dlocal_go.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
11
+
12
+ gem "rubocop", "~> 1.21"
13
+
14
+ gem "webmock"
15
+
16
+ gem "debug"
data/Gemfile.lock ADDED
@@ -0,0 +1,99 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ dlocal_go (0.1.0)
5
+ http
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ addressable (2.8.1)
11
+ public_suffix (>= 2.0.2, < 6.0)
12
+ ast (2.4.2)
13
+ crack (0.4.5)
14
+ rexml
15
+ debug (1.6.2)
16
+ irb (>= 1.3.6)
17
+ reline (>= 0.3.1)
18
+ diff-lcs (1.5.0)
19
+ domain_name (0.5.20190701)
20
+ unf (>= 0.0.5, < 1.0.0)
21
+ ffi (1.15.5)
22
+ ffi-compiler (1.0.1)
23
+ ffi (>= 1.0.0)
24
+ rake
25
+ hashdiff (1.0.1)
26
+ http (5.1.1)
27
+ addressable (~> 2.8)
28
+ http-cookie (~> 1.0)
29
+ http-form_data (~> 2.2)
30
+ llhttp-ffi (~> 0.4.0)
31
+ http-cookie (1.0.5)
32
+ domain_name (~> 0.5)
33
+ http-form_data (2.3.0)
34
+ io-console (0.5.11)
35
+ irb (1.4.1)
36
+ reline (>= 0.3.0)
37
+ json (2.6.2)
38
+ llhttp-ffi (0.4.0)
39
+ ffi-compiler (~> 1.0)
40
+ rake (~> 13.0)
41
+ parallel (1.22.1)
42
+ parser (3.1.2.1)
43
+ ast (~> 2.4.1)
44
+ public_suffix (5.0.1)
45
+ rainbow (3.1.1)
46
+ rake (13.0.6)
47
+ regexp_parser (2.5.0)
48
+ reline (0.3.1)
49
+ io-console (~> 0.5)
50
+ rexml (3.2.5)
51
+ rspec (3.7.0)
52
+ rspec-core (~> 3.7.0)
53
+ rspec-expectations (~> 3.7.0)
54
+ rspec-mocks (~> 3.7.0)
55
+ rspec-core (3.7.1)
56
+ rspec-support (~> 3.7.0)
57
+ rspec-expectations (3.7.0)
58
+ diff-lcs (>= 1.2.0, < 2.0)
59
+ rspec-support (~> 3.7.0)
60
+ rspec-mocks (3.7.0)
61
+ diff-lcs (>= 1.2.0, < 2.0)
62
+ rspec-support (~> 3.7.0)
63
+ rspec-support (3.7.1)
64
+ rubocop (1.36.0)
65
+ json (~> 2.3)
66
+ parallel (~> 1.10)
67
+ parser (>= 3.1.2.1)
68
+ rainbow (>= 2.2.2, < 4.0)
69
+ regexp_parser (>= 1.8, < 3.0)
70
+ rexml (>= 3.2.5, < 4.0)
71
+ rubocop-ast (>= 1.20.1, < 2.0)
72
+ ruby-progressbar (~> 1.7)
73
+ unicode-display_width (>= 1.4.0, < 3.0)
74
+ rubocop-ast (1.21.0)
75
+ parser (>= 3.1.1.0)
76
+ ruby-progressbar (1.11.0)
77
+ unf (0.1.4)
78
+ unf_ext
79
+ unf_ext (0.0.8.2)
80
+ unicode-display_width (2.2.0)
81
+ webmock (3.18.1)
82
+ addressable (>= 2.8.0)
83
+ crack (>= 0.3.2)
84
+ hashdiff (>= 0.4.0, < 2.0.0)
85
+
86
+ PLATFORMS
87
+ arm64-darwin-21
88
+ x86_64-linux
89
+
90
+ DEPENDENCIES
91
+ debug
92
+ dlocal_go!
93
+ rake (~> 13.0)
94
+ rspec (~> 3.0)
95
+ rubocop (~> 1.21)
96
+ webmock
97
+
98
+ BUNDLED WITH
99
+ 2.3.22
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 matiassalles99
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,72 @@
1
+ # DlocalGo
2
+
3
+ Ruby client for the [dLocal Go](https://dlocalgo.com/) API.
4
+
5
+ ## Installation
6
+
7
+ Add dlocal_go in your Gemfile
8
+
9
+ $ gem 'dlocal_go'
10
+ $ bundle install
11
+
12
+ If bundler is not being used to manage dependencies, install the gem by executing:
13
+
14
+ $ gem install dlocal_go
15
+
16
+ ## Usage
17
+
18
+ 1. Configure DlocalGo in a initializer
19
+
20
+ ```ruby
21
+ DlocalGo.setup do |config|
22
+ config.api_key = 'your_api_key'
23
+ config.api_secret = 'your_api_secret'
24
+ config.environment = 'sandbox' # or 'production'
25
+ config.supported_countries = %w[AR BR CL CO MX PE UY] # Optional, default: %w[UY AR CL BO BR CO CR EC GT ID MX MY PE PY]
26
+ end
27
+ ```
28
+
29
+
30
+ 2. Use the client to create a payment, get a payment, or create a refund.
31
+
32
+ - Create Payment
33
+
34
+ ```ruby
35
+ params = {
36
+ country_code: "UY",
37
+ currency: "USD", # Optional, if not supplied, it uses the default currency for the country
38
+ amount: 100,
39
+ success_url: "https://success.url", # Where the user will be redirected after the payment is approved
40
+ back_url: "https://back.url", # Where the user is redirected if they go back from the checkout page
41
+ notification_url: "https://notification.url" # Optional, where the notification will be sent when payment state changes, (It will send a POST request with a payment_id param in the body, which can be used to retrieve the payment)
42
+ }
43
+ response = DlocalGo::Client.create_payment(params)
44
+ # If request is not successful, it will raise a DlocalGo::Error, otherwise the response will be a DlocalGo::Response::Payment object
45
+ ```
46
+
47
+ - Get Payment
48
+
49
+ ```ruby
50
+ response = DlocalGo::Client.get_payment("payment_id")
51
+ # If request is not successful, it will raise a DlocalGo::Error, otherwise the response will be a DlocalGo::Response::Payment object
52
+ ```
53
+
54
+ - Create Refund
55
+
56
+ ```ruby
57
+ params = {
58
+ payment_id: "payment_id_sample",
59
+ amount: 100,
60
+ reason: "reason_sample"
61
+ }
62
+ response = DlocalGo::Client.create_refund(params)
63
+ # If request is not successful, it will raise a DlocalGo::Error, otherwise the response will be a DlocalGo::Response::Refund object
64
+ ```
65
+
66
+ ## Contributing
67
+
68
+ Bug reports and pull requests are welcome on GitHub at https://github.com/MetaLabs-inc/dlocal_go.
69
+
70
+ ## License
71
+
72
+ 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,12 @@
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
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
data/dlocal_go.gemspec ADDED
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/dlocal_go/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "dlocal_go"
7
+ spec.version = DlocalGo::VERSION
8
+ spec.authors = ["matiassalles99"]
9
+ spec.email = ["matiassalles99@gmail.com"]
10
+
11
+ spec.summary = "Dlocal Go client for ruby"
12
+ spec.description = "Dlocal Go client written in ruby to interact with Dlocal Go's API"
13
+ spec.homepage = "https://github.com/MetaLabs-inc/dlocal_go"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = ">= 2.6.0"
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = "https://github.com/MetaLabs-inc/dlocal_go"
19
+ spec.metadata["changelog_uri"] = "https://github.com/MetaLabs-inc/dlocal_go/blob/main/CHANGELOG.md"
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+ spec.files = Dir.chdir(__dir__) do
24
+ `git ls-files -z`.split("\x0").reject do |f|
25
+ (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
26
+ end
27
+ end
28
+ spec.bindir = "exe"
29
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ spec.add_dependency "http"
33
+
34
+ # For more information and examples about making a new gem, check out our
35
+ # guide at: https://bundler.io/guides/creating_gem.html
36
+ end
@@ -0,0 +1,79 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "responses/payment"
4
+ require_relative "responses/refund"
5
+
6
+ module DlocalGo
7
+ # Client for Dlocal Go API
8
+ class Client
9
+ SANDBOX_URL = "https://api-sbx.dlocalgo.com"
10
+ PRODUCTION_URL = "https://api.dlocalgo.com"
11
+ DEFAULT_SUPPORTED_COUNTRIES = %w[UY AR CL BO BR CO CR EC GT ID MX MY PE PY].freeze
12
+ CURRENCY_FOR_COUNTRY = { UY: "UYU", AR: "ARS", CL: "CLP", BO: "BOB", BR: "BRL",
13
+ CO: "COP", CR: "CRC", EC: "USD", GT: "GTQ", ID: "IDR", MX: "MXN",
14
+ MY: "MYR", PE: "PEN", PY: "PYG" }.freeze
15
+
16
+ def initialize
17
+ @api_key = DlocalGo.api_key
18
+ @api_secret = DlocalGo.api_secret
19
+ @base_url = DlocalGo.environment == "production" ? PRODUCTION_URL : SANDBOX_URL
20
+
21
+ raise DlocalGo::Error, "Dlocal Go api key is not set" if @api_key.nil?
22
+ raise DlocalGo::Error, "Dlocal Go api secret is not set" if @api_secret.nil?
23
+ end
24
+
25
+ def create_payment(params = {})
26
+ raise DlocalGo::Error, "Unsupported country" unless supported_countries.include?(params[:country_code])
27
+
28
+ uri = "/v1/payments"
29
+ body = { amount: params[:amount], country: params[:country_code], notification_url: params[:notification_url],
30
+ currency: params[:currency] || CURRENCY_FOR_COUNTRY[params[:country_code].to_sym],
31
+ success_url: params[:success_url], back_url: params[:back_url] }
32
+
33
+ response = HTTP.auth(auth_header).headers(json_content_type).post(endpoint_url(uri), json: body)
34
+
35
+ raise DlocalGo::Error, "Error creating checkout #{response.parse}" unless response.status.success?
36
+
37
+ DlocalGo::Responses::Payment.new(OpenStruct.new(response.parse))
38
+ end
39
+
40
+ def get_payment(payment_id)
41
+ uri = "/v1/payments/#{payment_id}"
42
+ response = HTTP.auth(auth_header).get(endpoint_url(uri))
43
+
44
+ raise DlocalGo::Error, "Error getting payment: #{response.parse}" unless response.status.success?
45
+
46
+ DlocalGo::Responses::Payment.new(OpenStruct.new(response.parse))
47
+ end
48
+
49
+ def create_refund(params = {})
50
+ uri = "/v1/refunds"
51
+ body = { payment_id: params[:payment_id], currency: params[:currency], amount: params[:amount],
52
+ notification_url: params[:notification_url] }
53
+
54
+ response = HTTP.auth(auth_header).headers(json_content_type).post(endpoint_url(uri), json: body)
55
+
56
+ raise DlocalGo::Error, "Error creating refund: #{response.parse}" unless response.status.success?
57
+
58
+ DlocalGo::Responses::Refund.new(OpenStruct.new(response.parse))
59
+ end
60
+
61
+ private
62
+
63
+ def auth_header
64
+ "Bearer #{@api_key}:#{@api_secret}"
65
+ end
66
+
67
+ def json_content_type
68
+ { 'content-type': "application/json" }
69
+ end
70
+
71
+ def endpoint_url(endpoint_url)
72
+ "#{@base_url}#{endpoint_url}"
73
+ end
74
+
75
+ def supported_countries
76
+ DlocalGo.supported_countries || DEFAULT_SUPPORTED_COUNTRIES
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DlocalGo
4
+ class Error < StandardError; end
5
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DlocalGo
4
+ module Responses
5
+ # Class that represents Dlocal Go payment schema
6
+ class Payment
7
+ RESPONSE_ATTRIBUTES = %i[id amount currency country created_date status order_id success_url back_url
8
+ redirect_url merchant_checkout_token direct].freeze
9
+
10
+ attr_reader(*RESPONSE_ATTRIBUTES)
11
+
12
+ def initialize(response)
13
+ RESPONSE_ATTRIBUTES.each do |attribute|
14
+ instance_variable_set("@#{attribute}", response.send(attribute))
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DlocalGo
4
+ module Responses
5
+ # Class that represents Dlocal Go refund schema
6
+ class Refund
7
+ RESPONSE_ATTRIBUTES = %i[id amount status].freeze
8
+
9
+ attr_reader(*RESPONSE_ATTRIBUTES)
10
+
11
+ def initialize(response)
12
+ RESPONSE_ATTRIBUTES.each do |attribute|
13
+ instance_variable_set("@#{attribute}", response.send(attribute))
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DlocalGo
4
+ VERSION = "0.1.0"
5
+ end
data/lib/dlocal_go.rb ADDED
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "dlocal_go/version"
4
+ require_relative "dlocal_go/errors"
5
+ require_relative "dlocal_go/client"
6
+
7
+ # Main module for Dlocal Go, it provides a way to configure the gem and imports the client
8
+ module DlocalGo
9
+ def self.setup
10
+ yield self
11
+ end
12
+
13
+ def self.clear_setup
14
+ self.api_key = nil
15
+ self.api_secret = nil
16
+ self.environment = nil
17
+ self.supported_countries = nil
18
+ end
19
+
20
+ class << self
21
+ attr_accessor :api_key, :api_secret, :environment, :supported_countries
22
+ end
23
+
24
+ self.api_key = nil
25
+ self.api_secret = nil
26
+ self.environment = nil
27
+ self.supported_countries = nil
28
+ end
@@ -0,0 +1,26 @@
1
+ module DlocalGo
2
+ class Client
3
+ CURRENCY_FOR_COUNTRY: Hash[Symbol, String]
4
+ DEFAULT_SUPPORTED_COUNTRIES: Array[String]
5
+ SANDBOX_URL: String
6
+ PRODUCTION_URL: String
7
+
8
+ @api_key: String
9
+ @api_secret: String
10
+ @base_url: String
11
+
12
+ def create_payment: -> Responses::Payment
13
+ def get_payment: -> Responses::Payment
14
+ def create_refund: -> Responses::Refund
15
+
16
+ private
17
+
18
+ def auth_header: -> untyped
19
+
20
+ def endpoint_url: -> untyped
21
+
22
+ def json_content_type: -> untyped
23
+
24
+ def supported_countries: -> untyped
25
+ end
26
+ end
@@ -0,0 +1,7 @@
1
+ module DlocalGo
2
+ module Responses
3
+ class Payment
4
+ RESPONSE_ATTRIBUTES: Array[Symbol]
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module DlocalGo
2
+ module Responses
3
+ class Refund
4
+ RESPONSE_ATTRIBUTES: Array[Symbol]
5
+ end
6
+ end
7
+ end
data/sig/dlocal_go.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module DlocalGo
2
+ VERSION: String
3
+ def self.setup: -> untyped
4
+ end
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dlocal_go
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - matiassalles99
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-03-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: http
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: Dlocal Go client written in ruby to interact with Dlocal Go's API
28
+ email:
29
+ - matiassalles99@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".rspec"
35
+ - ".rubocop.yml"
36
+ - CHANGELOG.md
37
+ - Gemfile
38
+ - Gemfile.lock
39
+ - LICENSE.txt
40
+ - README.md
41
+ - Rakefile
42
+ - dlocal_go.gemspec
43
+ - lib/dlocal_go.rb
44
+ - lib/dlocal_go/client.rb
45
+ - lib/dlocal_go/errors.rb
46
+ - lib/dlocal_go/responses/payment.rb
47
+ - lib/dlocal_go/responses/refund.rb
48
+ - lib/dlocal_go/version.rb
49
+ - sig/dlocal_go.rbs
50
+ - sig/dlocal_go/client.rbs
51
+ - sig/dlocal_go/responses/payment.rbs
52
+ - sig/dlocal_go/responses/refund.rbs
53
+ homepage: https://github.com/MetaLabs-inc/dlocal_go
54
+ licenses:
55
+ - MIT
56
+ metadata:
57
+ homepage_uri: https://github.com/MetaLabs-inc/dlocal_go
58
+ source_code_uri: https://github.com/MetaLabs-inc/dlocal_go
59
+ changelog_uri: https://github.com/MetaLabs-inc/dlocal_go/blob/main/CHANGELOG.md
60
+ post_install_message:
61
+ rdoc_options: []
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: 2.6.0
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ requirements: []
75
+ rubygems_version: 3.3.7
76
+ signing_key:
77
+ specification_version: 4
78
+ summary: Dlocal Go client for ruby
79
+ test_files: []