mundipagg_client 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: e5607bdba30cca4c5008d7907ad0383918b8c8d9474a092dd3b62a9a4c4def2f
4
+ data.tar.gz: 160fd5f91ddaf21143f7659a959efce5cb5a166b3505458c60d3310ea9982043
5
+ SHA512:
6
+ metadata.gz: fdb03c4c5e1c9e0046974b39817a984e7223d1f8a225c119363fb559e078c1af901e1ef27a01b399f2fa7fe8dacc47f4eeb3cd475410024f3dcf370d23da554d
7
+ data.tar.gz: ab91fb89f735b96da753251eaeb3694dd8600896bb42a1cf66638313dc49dd61c44f6d268b986d6c6ea3291cb4b61b799674ca7d96edbdac019c7bbc86912152
@@ -0,0 +1,18 @@
1
+ name: Ruby
2
+
3
+ on: [push,pull_request]
4
+
5
+ jobs:
6
+ build:
7
+ runs-on: ubuntu-latest
8
+ steps:
9
+ - uses: actions/checkout@v2
10
+ - name: Set up Ruby
11
+ uses: ruby/setup-ruby@v1
12
+ with:
13
+ ruby-version: 2.6.2
14
+ - name: Run the default task
15
+ run: |
16
+ gem install bundler -v 2.2.8
17
+ bundle install
18
+ bundle exec rake
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,25 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.6
3
+ Exclude:
4
+ - 'spec/**/*.rb'
5
+
6
+ Style/StringLiterals:
7
+ Enabled: true
8
+ EnforcedStyle: double_quotes
9
+
10
+ Style/StringLiteralsInInterpolation:
11
+ Enabled: true
12
+ EnforcedStyle: double_quotes
13
+
14
+ Layout/LineLength:
15
+ Max: 120
16
+
17
+ Documentation:
18
+ Enabled: false
19
+
20
+ Metrics/LineLength:
21
+ Max: 120
22
+ Metrics/MethodLength:
23
+ Max: 20
24
+ Metrics/AbcSize:
25
+ Max: 30
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2021-05-04
4
+
5
+ - Initial release
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in mundipagg_client.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
11
+
12
+ gem "rubocop", "~> 1.7"
data/Gemfile.lock ADDED
@@ -0,0 +1,100 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ mundipagg_client (0.1.0)
5
+ active_interaction (~> 4.0)
6
+ excon (>= 0.73.0)
7
+ faraday
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ active_interaction (4.0.0)
13
+ activemodel (>= 5, < 7)
14
+ activemodel (6.0.3.6)
15
+ activesupport (= 6.0.3.6)
16
+ activesupport (6.0.3.6)
17
+ concurrent-ruby (~> 1.0, >= 1.0.2)
18
+ i18n (>= 0.7, < 2)
19
+ minitest (~> 5.1)
20
+ tzinfo (~> 1.1)
21
+ zeitwerk (~> 2.2, >= 2.2.2)
22
+ addressable (2.7.0)
23
+ public_suffix (>= 2.0.2, < 5.0)
24
+ ast (2.4.2)
25
+ coderay (1.1.3)
26
+ concurrent-ruby (1.1.8)
27
+ crack (0.4.5)
28
+ rexml
29
+ diff-lcs (1.4.4)
30
+ excon (0.79.0)
31
+ faraday (0.17.4)
32
+ multipart-post (>= 1.2, < 3)
33
+ hashdiff (1.0.1)
34
+ i18n (1.8.10)
35
+ concurrent-ruby (~> 1.0)
36
+ method_source (1.0.0)
37
+ minitest (5.14.4)
38
+ multipart-post (2.1.1)
39
+ parallel (1.20.1)
40
+ parser (3.0.1.1)
41
+ ast (~> 2.4.1)
42
+ pry (0.13.1)
43
+ coderay (~> 1.1)
44
+ method_source (~> 1.0)
45
+ public_suffix (4.0.6)
46
+ rainbow (3.0.0)
47
+ rake (13.0.3)
48
+ regexp_parser (2.1.1)
49
+ rexml (3.2.5)
50
+ rspec (3.10.0)
51
+ rspec-core (~> 3.10.0)
52
+ rspec-expectations (~> 3.10.0)
53
+ rspec-mocks (~> 3.10.0)
54
+ rspec-core (3.10.1)
55
+ rspec-support (~> 3.10.0)
56
+ rspec-expectations (3.10.1)
57
+ diff-lcs (>= 1.2.0, < 2.0)
58
+ rspec-support (~> 3.10.0)
59
+ rspec-mocks (3.10.2)
60
+ diff-lcs (>= 1.2.0, < 2.0)
61
+ rspec-support (~> 3.10.0)
62
+ rspec-support (3.10.2)
63
+ rubocop (1.13.0)
64
+ parallel (~> 1.10)
65
+ parser (>= 3.0.0.0)
66
+ rainbow (>= 2.2.2, < 4.0)
67
+ regexp_parser (>= 1.8, < 3.0)
68
+ rexml
69
+ rubocop-ast (>= 1.2.0, < 2.0)
70
+ ruby-progressbar (~> 1.7)
71
+ unicode-display_width (>= 1.4.0, < 3.0)
72
+ rubocop-ast (1.5.0)
73
+ parser (>= 3.0.1.1)
74
+ ruby-progressbar (1.11.0)
75
+ thread_safe (0.3.6)
76
+ tzinfo (1.2.9)
77
+ thread_safe (~> 0.1)
78
+ unicode-display_width (2.0.0)
79
+ vcr (5.1.0)
80
+ webmock (3.12.2)
81
+ addressable (>= 2.3.6)
82
+ crack (>= 0.3.2)
83
+ hashdiff (>= 0.4.0, < 2.0.0)
84
+ zeitwerk (2.4.2)
85
+
86
+ PLATFORMS
87
+ x86_64-darwin-20
88
+
89
+ DEPENDENCIES
90
+ bundler (~> 2.0)
91
+ mundipagg_client!
92
+ pry (~> 0.13.1)
93
+ rake (~> 13.0)
94
+ rspec (~> 3.0)
95
+ rubocop (~> 1.7)
96
+ vcr (~> 5.1)
97
+ webmock (~> 3.8)
98
+
99
+ BUNDLED WITH
100
+ 2.2.8
data/README.md ADDED
@@ -0,0 +1,180 @@
1
+ # MundipaggClient
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/mundipagg_client`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'mundipagg_client'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install mundipagg_client
22
+
23
+ ## Operations
24
+
25
+ Attributes and methods can be accessed like this:
26
+
27
+ ```ruby
28
+ # Valid?
29
+ operation.valid?
30
+
31
+ # Result
32
+ operation.result
33
+ ```
34
+
35
+ ### Customers
36
+
37
+ Create, retrieve or update customers.
38
+
39
+ #### Create
40
+
41
+ ```ruby
42
+ operation = MundipaggClient::Operations::Customers::Create.run(
43
+ params: {
44
+ name: "Anchieta Junior",
45
+ email: "anchieta@junior.com",
46
+ document: "036.899.945-95"
47
+ }
48
+ )
49
+ ```
50
+
51
+ #### Retrieve
52
+
53
+ ```ruby
54
+ operation = MundipaggClient::Operations::Customers::Retrieve.run(
55
+ customer_id: "cus_jahsdjhs"
56
+ )
57
+ ```
58
+
59
+ #### Update
60
+
61
+ ```ruby
62
+ operation = MundipaggClient::Operations::Customers::Update.run(
63
+ customer_id: "cus_jahsdjhs",
64
+ params: {
65
+ name: "Anchieta Junior",
66
+ email: "anchieta@junior.com",
67
+ document: "036.899.945-95"
68
+ }
69
+ )
70
+ ```
71
+
72
+ ### Credit Cards
73
+
74
+ Create, retrieve, update or delete credit cards.
75
+
76
+ #### Create
77
+
78
+ ```ruby
79
+ operation = MundipaggClient::Operations::CreditCards::Create.run(
80
+ params: {
81
+ number: "4000 0000 0000 0010",
82
+ exp_month: "10",
83
+ exp_year: "30",
84
+ cvv: "123",
85
+ holder_name: "Anchieta S Junior",
86
+ holder_document: "355.587.570-19"
87
+ }
88
+ )
89
+ ```
90
+
91
+ #### Retrieve
92
+
93
+ ```ruby
94
+ operation = MundipaggClient::Operations::CreditCards::Retrieve.run(
95
+ customer_id: "card_blRaGElCr5uQzD4N"
96
+ )
97
+ ```
98
+
99
+ #### Update
100
+
101
+ ```ruby
102
+ operation = MundipaggClient::Operations::CreditCards::Update.run(
103
+ customer_id: "card_blRaGElCr5uQzD4N",
104
+ params: {
105
+ exp_month: "10",
106
+ exp_year: "30",
107
+ holder_name: "Anchieta S Junior",
108
+ holder_document: "355.587.570-19"
109
+ }
110
+ )
111
+ ```
112
+
113
+ #### Delete
114
+
115
+ ```ruby
116
+ operation = MundipaggClient::Operations::CreditCards::Delete.run(
117
+ customer_id: "card_blRaGElCr5uQzD4N"
118
+ )
119
+ ```
120
+
121
+ ### Charges
122
+
123
+ Create or delete (refund) charges.
124
+
125
+ #### Create a charge with a new credit card
126
+
127
+ ```ruby
128
+ operation = MundipaggClient::Operations::Charges::Create.run(
129
+ params: {
130
+ amount: 10000,
131
+ customer_id: "cus_rXZgoqjFwtj5GODx",
132
+ statement_descriptor: "Padre Paulo Ricardo",
133
+ card_number: "4000000000000010",
134
+ card_exp_month: "10",
135
+ card_exp_year: "30",
136
+ card_cvv: "123",
137
+ card_holder_name: "Anchieta S Junior",
138
+ card_holder_document: "355.587.570-19"
139
+ }
140
+ )
141
+ ```
142
+
143
+ #### Create a charge with an existing credit card
144
+
145
+ ```ruby
146
+ operation = MundipaggClient::Operations::Charges::Create.run(
147
+ params: {
148
+ amount: 1000,
149
+ customer_id: "card_ZeL9P5mUp1CBPWB1",
150
+ statement_descriptor: "Padre Paulo Ricardo",
151
+ installments: 1,
152
+ card_id: "card_ZeL9P5mUp1CBPWB1"
153
+ }
154
+ )
155
+ ```
156
+
157
+ #### Delete
158
+
159
+ ```ruby
160
+ operation = MundipaggClient::Operations::Charges::Delete.run(
161
+ charge_id: "ch_blRaGElCr5uQzD4N"
162
+ )
163
+ ```
164
+
165
+
166
+
167
+
168
+ ## Development
169
+
170
+ 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.
171
+
172
+ 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).
173
+
174
+ ## Contributing
175
+
176
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/mundipagg_client.
177
+
178
+ ## License
179
+
180
+ 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,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+ RSpec::Core::RakeTask.new(:spec)
6
+ 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 "mundipagg_client"
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,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_interaction"
4
+ require "mundipagg_client/mundipagg_base"
5
+ require "mundipagg_client/configuration"
6
+ require "mundipagg_client/application_formatter"
7
+ require "mundipagg_client/operations/customers/create"
8
+ require_relative "mundipagg_client/version"
9
+
10
+ module MundipaggClient
11
+ class MundipaggClientConfiguration
12
+ def self.configuration
13
+ @configuration ||= Configuration.new
14
+ end
15
+
16
+ def self.configure
17
+ yield(configuration)
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ class ApplicationFormatter
4
+ Result = Struct.new(:success?, :error, :value)
5
+
6
+ def self.call(*args)
7
+ new(*args).call
8
+ end
9
+
10
+ def result(success, error, value)
11
+ Result.new(success, error, value)
12
+ end
13
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MundipaggClient
4
+ class Configuration
5
+ attr_accessor :api_key
6
+ end
7
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MundipaggClient
4
+ class MundipaggBase < ActiveInteraction::Base
5
+ API_VERSION = "1"
6
+ BASE_URL = "https://api.mundipagg.com/core/v#{API_VERSION}"
7
+
8
+ def headers
9
+ {
10
+ "Content-Type" => "application/json",
11
+ "Accept" => "application/json"
12
+ }
13
+ end
14
+
15
+ def build_connection
16
+ connection = Faraday.new(headers: headers)
17
+ connection.basic_auth(MundipaggClient::MundipaggClientConfiguration.configuration.api_key, '')
18
+ connection
19
+ end
20
+
21
+ def connection
22
+ @connection ||= build_connection
23
+ end
24
+
25
+ def sanitize_numbers(number)
26
+ number.gsub(/[^\d]/, "")
27
+ end
28
+
29
+ def sanitize_names(name)
30
+ from = "àáäâãèéëẽêìíïîĩòóöôõùúüûũñçñÁÀÃÂÄÉÈÊËÍÌÎÏÓÒÕÔÖÚÙÛÜÑÇ"
31
+ to = "aaaaaeeeeeiiiiiooooouuuuuncnAAAAAEEEEIIIIOOOOOUUUUNC"
32
+ name.gsub(/[#{from}]/, from.split("").zip(to.split("")).to_h).gsub(/[^A-Z a-z]/, "").upcase
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,74 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "pry"
4
+
5
+ module MundipaggClient
6
+ module Operations
7
+ module Charges
8
+ class Create < MundipaggClient::MundipaggBase
9
+ hash :params do
10
+ integer :amount
11
+ string :customer_id
12
+ string :card_id, default: nil
13
+ string :statement_descriptor
14
+ integer :installments, default: 1
15
+ string :card_number, default: nil
16
+ string :card_holder_name, default: nil
17
+ string :card_exp_month, default: nil
18
+ string :card_exp_year, default: nil
19
+ string :card_cvv, default: nil
20
+ string :card_cvv, default: nil
21
+ end
22
+
23
+ def execute
24
+ raise "Invalid Mundipagg operation" unless request.success?
25
+
26
+ JSON.parse(request.body)
27
+ end
28
+
29
+ private
30
+
31
+ def request
32
+ @request ||= connection.post("#{BASE_URL}/charges") do |req|
33
+ req.body = charge_params.to_json
34
+ end
35
+ end
36
+
37
+ def charge_params
38
+ {}.tap do |hash|
39
+ hash[:amount] = params[:amount]
40
+ hash[:customer_id] = params[:customer_id]
41
+ payment_params(hash)
42
+ credit_card_params(hash)
43
+ end
44
+ end
45
+
46
+ def payment_params(hash)
47
+ hash[:payment] = {
48
+ payment_method: "credit_card",
49
+ credit_card: {
50
+ capture: true,
51
+ recurrence: true,
52
+ installments: params[:installments],
53
+ statement_descriptor: params[:statement_descriptor]
54
+ }
55
+ }
56
+ end
57
+
58
+ def credit_card_params(hash)
59
+ if params[:card_id].present?
60
+ hash[:payment][:credit_card][:card_id] = params[:card_id]
61
+ else
62
+ hash[:payment][:credit_card][:card] = {
63
+ number: params[:card_number],
64
+ holder_name: params[:card_holder_name],
65
+ exp_month: params[:card_exp_month],
66
+ exp_year: params[:card_exp_year],
67
+ cvv: params[:card_cvv]
68
+ }
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "pry"
4
+
5
+ module MundipaggClient
6
+ module Operations
7
+ module Charges
8
+ class Delete < MundipaggClient::MundipaggBase
9
+ string :charge_id
10
+
11
+ def execute
12
+ raise "Invalid Mundipagg operation" unless request.success?
13
+
14
+ JSON.parse(request.body)
15
+ end
16
+
17
+ private
18
+
19
+ def request
20
+ @request ||= connection.delete("#{BASE_URL}/charges/#{charge_id}")
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "pry"
4
+
5
+ module MundipaggClient
6
+ module Operations
7
+ module CreditCards
8
+ class Create < MundipaggClient::MundipaggBase
9
+ string :customer_id
10
+ hash :params do
11
+ string :number
12
+ string :exp_month
13
+ string :exp_year
14
+ string :cvv
15
+ string :holder_name
16
+ string :holder_document
17
+ end
18
+
19
+ def execute
20
+ raise "Invalid Mundipagg operation" unless request.success?
21
+
22
+ JSON.parse(request.body)
23
+ end
24
+
25
+ private
26
+
27
+ def request
28
+ @request ||= connection.post("#{BASE_URL}/customers/#{customer_id}/cards") do |req|
29
+ req.body = credit_card_params.to_json
30
+ end
31
+ end
32
+
33
+ def credit_card_params
34
+ {
35
+ number: sanitize_numbers(params[:number]),
36
+ exp_month: params[:exp_month],
37
+ exp_year: params[:exp_year],
38
+ cvv: params[:cvv],
39
+ holder_name: sanitize_names(params[:holder_document]),
40
+ holder_document: sanitize_numbers(params[:holder_document])
41
+ }
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "pry"
4
+
5
+ module MundipaggClient
6
+ module Operations
7
+ module CreditCards
8
+ class Delete < MundipaggClient::MundipaggBase
9
+ string :customer_id
10
+ string :card_id
11
+
12
+ def execute
13
+ raise "Invalid Mundipagg operation" unless request.success?
14
+
15
+ JSON.parse(request.body)
16
+ end
17
+
18
+ private
19
+
20
+ def request
21
+ @request ||= connection.delete("#{BASE_URL}/customers/#{customer_id}/cards/#{card_id}")
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "pry"
4
+
5
+ module MundipaggClient
6
+ module Operations
7
+ module CreditCards
8
+ class Renew < MundipaggClient::MundipaggBase
9
+ string :customer_id
10
+ string :card_id
11
+
12
+ def execute
13
+ raise "Invalid Mundipagg operation" unless request.success?
14
+
15
+ JSON.parse(request.body)
16
+ end
17
+
18
+ private
19
+
20
+ def request
21
+ @request ||= connection.post("#{BASE_URL}/customers/#{customer_id}/cards/#{card_id}/renew")
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "pry"
4
+
5
+ module MundipaggClient
6
+ module Operations
7
+ module CreditCards
8
+ class Retrieve < MundipaggClient::MundipaggBase
9
+ string :customer_id
10
+ string :card_id
11
+
12
+ def execute
13
+ raise "Invalid Mundipagg operation" unless request.success?
14
+
15
+ JSON.parse(request.body)
16
+ end
17
+
18
+ private
19
+
20
+ def request
21
+ @request ||= connection.get("#{BASE_URL}/customers/#{customer_id}/cards/#{card_id}")
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "pry"
4
+
5
+ module MundipaggClient
6
+ module Operations
7
+ module CreditCards
8
+ class Update < MundipaggClient::MundipaggBase
9
+ string :customer_id
10
+ string :card_id
11
+ hash :params do
12
+ string :exp_month
13
+ string :exp_year
14
+ string :holder_name
15
+ string :holder_document
16
+ end
17
+
18
+ def execute
19
+ # binding.pry
20
+ raise "Invalid Mundipagg operation" unless request.success?
21
+
22
+ JSON.parse(request.body)
23
+ end
24
+
25
+ private
26
+
27
+ def request
28
+ @request ||= connection.put("#{BASE_URL}/customers/#{customer_id}/cards/#{card_id}") do |req|
29
+ req.body = credit_card_params.to_json
30
+ end
31
+ end
32
+
33
+ def credit_card_params
34
+ {
35
+ exp_month: params[:exp_month],
36
+ exp_year: params[:exp_year],
37
+ holder_name: sanitize_names(params[:holder_name]),
38
+ holder_document: sanitize_numbers(params[:holder_document])
39
+ }
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "pry"
4
+
5
+ module MundipaggClient
6
+ module Operations
7
+ module Customers
8
+ class Create < MundipaggClient::MundipaggBase
9
+ hash :params do
10
+ string :name
11
+ string :email
12
+ string :document
13
+ end
14
+
15
+ def execute
16
+ raise "Invalid Mundipagg operation" unless request.success?
17
+
18
+ JSON.parse(request.body)
19
+ end
20
+
21
+ private
22
+
23
+ def request
24
+ @request ||= connection.post("#{BASE_URL}/customers") do |req|
25
+ req.body = customer_params.to_json
26
+ end
27
+ end
28
+
29
+ def customer_params
30
+ {
31
+ name: params[:name],
32
+ email: params[:email],
33
+ type: "individual",
34
+ document: formatted_document
35
+ }
36
+ end
37
+
38
+ def formatted_document
39
+ params[:document].present? ? params[:document].gsub(".", "").gsub("-", "") : nil
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "pry"
4
+
5
+ module MundipaggClient
6
+ module Operations
7
+ module Customers
8
+ class Retrieve < MundipaggClient::MundipaggBase
9
+ string :customer_id
10
+
11
+ def execute
12
+ raise "Invalid Mundipagg operation" unless request.success?
13
+
14
+ JSON.parse(request.body)
15
+ end
16
+
17
+ private
18
+
19
+ def request
20
+ @request ||= connection.get("#{BASE_URL}/customers/#{customer_id}")
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MundipaggClient
4
+ module Operations
5
+ module Customers
6
+ class Update < MundipaggClient::MundipaggBase
7
+ string :customer_id
8
+ hash :params do
9
+ string :name
10
+ string :email
11
+ string :document
12
+ end
13
+
14
+ def execute
15
+ raise "Invalid Mundipagg operation" unless request.success?
16
+
17
+ JSON.parse(request.body)
18
+ end
19
+
20
+ private
21
+
22
+ def request
23
+ @request ||= connection.put("#{BASE_URL}/customers/#{customer_id}") do |req|
24
+ req.body = customer_params.to_json
25
+ end
26
+ end
27
+
28
+ def customer_params
29
+ {
30
+ name: params[:name],
31
+ email: params[:email],
32
+ type: "individual",
33
+ document: formatted_document
34
+ }
35
+ end
36
+
37
+ def formatted_document
38
+ params[:document].present? ? params[:document].gsub(".", "").gsub("-", "") : nil
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MundipaggClient
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/mundipagg_client/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "mundipagg_client"
7
+ spec.version = MundipaggClient::VERSION
8
+ spec.authors = ["Instituto Padre Pio"]
9
+ spec.email = ["santosjr87@gmail.com"]
10
+
11
+ spec.summary = "Wrapper for Mundipagg API."
12
+ spec.description = "Client for Mundipagg Payment Gateway."
13
+ spec.homepage = "http://padrepauloricardo.org"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
16
+
17
+ # Specify which files should be added to the gem when it is released.
18
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
19
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
20
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
21
+ end
22
+ spec.bindir = "exe"
23
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ["lib"]
25
+ spec.add_development_dependency "bundler", "~> 2.0"
26
+ spec.add_development_dependency "rake", "~> 12.3.3"
27
+ spec.add_development_dependency "rspec", "~> 3.7"
28
+ spec.add_runtime_dependency "active_interaction", "~> 4.0"
29
+ spec.add_dependency "excon", ">= 0.73.0"
30
+ spec.add_dependency "faraday"
31
+ spec.add_development_dependency "vcr", "~> 5.1"
32
+ spec.add_development_dependency "webmock", "~> 3.8"
33
+ spec.add_development_dependency "pry", "~> 0.13.1"
34
+ end
metadata ADDED
@@ -0,0 +1,196 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mundipagg_client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Instituto Padre Pio
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-05-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 12.3.3
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 12.3.3
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.7'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.7'
55
+ - !ruby/object:Gem::Dependency
56
+ name: active_interaction
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '4.0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '4.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: excon
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 0.73.0
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 0.73.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: faraday
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: vcr
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '5.1'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '5.1'
111
+ - !ruby/object:Gem::Dependency
112
+ name: webmock
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '3.8'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '3.8'
125
+ - !ruby/object:Gem::Dependency
126
+ name: pry
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: 0.13.1
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: 0.13.1
139
+ description: Client for Mundipagg Payment Gateway.
140
+ email:
141
+ - santosjr87@gmail.com
142
+ executables: []
143
+ extensions: []
144
+ extra_rdoc_files: []
145
+ files:
146
+ - ".github/workflows/main.yml"
147
+ - ".gitignore"
148
+ - ".rspec"
149
+ - ".rubocop.yml"
150
+ - CHANGELOG.md
151
+ - Gemfile
152
+ - Gemfile.lock
153
+ - README.md
154
+ - Rakefile
155
+ - bin/console
156
+ - bin/setup
157
+ - lib/mundipagg_client.rb
158
+ - lib/mundipagg_client/application_formatter.rb
159
+ - lib/mundipagg_client/configuration.rb
160
+ - lib/mundipagg_client/mundipagg_base.rb
161
+ - lib/mundipagg_client/operations/charges/create.rb
162
+ - lib/mundipagg_client/operations/charges/delete.rb
163
+ - lib/mundipagg_client/operations/credit_cards/create.rb
164
+ - lib/mundipagg_client/operations/credit_cards/delete.rb
165
+ - lib/mundipagg_client/operations/credit_cards/renew.rb
166
+ - lib/mundipagg_client/operations/credit_cards/retrieve.rb
167
+ - lib/mundipagg_client/operations/credit_cards/update.rb
168
+ - lib/mundipagg_client/operations/customers/create.rb
169
+ - lib/mundipagg_client/operations/customers/retrieve.rb
170
+ - lib/mundipagg_client/operations/customers/update.rb
171
+ - lib/mundipagg_client/version.rb
172
+ - mundipagg_client.gemspec
173
+ homepage: http://padrepauloricardo.org
174
+ licenses:
175
+ - MIT
176
+ metadata: {}
177
+ post_install_message:
178
+ rdoc_options: []
179
+ require_paths:
180
+ - lib
181
+ required_ruby_version: !ruby/object:Gem::Requirement
182
+ requirements:
183
+ - - ">="
184
+ - !ruby/object:Gem::Version
185
+ version: 2.4.0
186
+ required_rubygems_version: !ruby/object:Gem::Requirement
187
+ requirements:
188
+ - - ">="
189
+ - !ruby/object:Gem::Version
190
+ version: '0'
191
+ requirements: []
192
+ rubygems_version: 3.0.3
193
+ signing_key:
194
+ specification_version: 4
195
+ summary: Wrapper for Mundipagg API.
196
+ test_files: []