better-mundipagg 0.0.1

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
+ SHA1:
3
+ metadata.gz: bf6c2fa6efbdc60ab99a7fd6cd7e1366ada9a353
4
+ data.tar.gz: cd36a9dade4a75ec020155d19d2d78c3fdd3bcad
5
+ SHA512:
6
+ metadata.gz: 4ea9480b10ef21375e1f1869785751e8d7efda76d44ecca1f98e0a0125b9efa903b65f3d2d0ecbb3d7aab0974da39bdad0102bfeae0e4f67cba3b1f4e43a91d2
7
+ data.tar.gz: 90e43a293df2f3964b51056e57fa2a47e8225d594577b57122ac1736b51d50c1adb5c00d7bc7da628d14b3d9602bf8d7e8d331e27016dc9025706a9f25ec54d5
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ coverage
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/Dockerfile ADDED
@@ -0,0 +1,19 @@
1
+ FROM azisaka/ruby:2.1.4
2
+
3
+ USER root
4
+ RUN apt-get update
5
+ RUN apt-get install -y git-core
6
+
7
+ USER dev
8
+ ENV GEM_HOME /home/dev/.gems
9
+ ENV PATH /home/dev/.gems/bin:$PATH
10
+
11
+ COPY . /tmp
12
+ WORKDIR /tmp
13
+
14
+ RUN bundle install
15
+
16
+ VOLUME /app
17
+ WORKDIR /app
18
+
19
+ ENTRYPOINT bundle exec rspec
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,85 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ mundipagg (0.0.1)
5
+ activemodel
6
+ savon
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activemodel (4.1.8)
12
+ activesupport (= 4.1.8)
13
+ builder (~> 3.1)
14
+ activesupport (4.1.8)
15
+ i18n (~> 0.6, >= 0.6.9)
16
+ json (~> 1.7, >= 1.7.7)
17
+ minitest (~> 5.1)
18
+ thread_safe (~> 0.1)
19
+ tzinfo (~> 1.1)
20
+ akami (1.2.2)
21
+ gyoku (>= 0.4.0)
22
+ nokogiri
23
+ builder (3.2.2)
24
+ diff-lcs (1.2.5)
25
+ docile (1.1.5)
26
+ gyoku (1.2.2)
27
+ builder (>= 2.1.2)
28
+ httpi (2.3.0)
29
+ rack
30
+ i18n (0.6.11)
31
+ json (1.8.1)
32
+ macaddr (1.7.1)
33
+ systemu (~> 2.6.2)
34
+ mime-types (1.25.1)
35
+ mini_portile (0.6.1)
36
+ minitest (5.4.3)
37
+ multi_json (1.10.1)
38
+ nokogiri (1.6.5)
39
+ mini_portile (~> 0.6.0)
40
+ nori (2.4.0)
41
+ rack (1.5.2)
42
+ rspec (3.1.0)
43
+ rspec-core (~> 3.1.0)
44
+ rspec-expectations (~> 3.1.0)
45
+ rspec-mocks (~> 3.1.0)
46
+ rspec-core (3.1.7)
47
+ rspec-support (~> 3.1.0)
48
+ rspec-expectations (3.1.2)
49
+ diff-lcs (>= 1.2.0, < 2.0)
50
+ rspec-support (~> 3.1.0)
51
+ rspec-mocks (3.1.3)
52
+ rspec-support (~> 3.1.0)
53
+ rspec-support (3.1.2)
54
+ savon (2.8.0)
55
+ akami (~> 1.2)
56
+ builder (>= 2.1.2)
57
+ gyoku (~> 1.2)
58
+ httpi (~> 2.3)
59
+ nokogiri (>= 1.4.0)
60
+ nori (~> 2.4)
61
+ uuid (~> 2.3.7)
62
+ wasabi (= 3.3.0)
63
+ simplecov (0.9.1)
64
+ docile (~> 1.1.0)
65
+ multi_json (~> 1.0)
66
+ simplecov-html (~> 0.8.0)
67
+ simplecov-html (0.8.0)
68
+ systemu (2.6.4)
69
+ thread_safe (0.3.4)
70
+ tzinfo (1.2.2)
71
+ thread_safe (~> 0.1)
72
+ uuid (2.3.7)
73
+ macaddr (~> 1.0)
74
+ wasabi (3.3.0)
75
+ httpi (~> 2.0)
76
+ mime-types (< 2.0.0)
77
+ nokogiri (>= 1.4.0)
78
+
79
+ PLATFORMS
80
+ ruby
81
+
82
+ DEPENDENCIES
83
+ mundipagg!
84
+ rspec (~> 3.1.0)
85
+ simplecov (~> 0.9.0)
data/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # Mundipagg
2
+
3
+ Library to integrate with Mundipagg's webservice
@@ -0,0 +1,4 @@
1
+ module Mundipagg
2
+ class Buyer
3
+ end
4
+ end
@@ -0,0 +1,28 @@
1
+ require "savon"
2
+ require "mundipagg/gateway/message"
3
+ require "mundipagg/gateway/key"
4
+
5
+ module Mundipagg
6
+ module Gateway
7
+ class Client
8
+ attr_reader :adapter
9
+
10
+ def initialize
11
+ @adapter ||= Savon.client do
12
+ wsdl "https://transaction.mundipaggone.com/MundiPaggService.svc?wsdl"
13
+ namespaces "xmlns:mun" => "http://schemas.datacontract.org/2004/07/MundiPagg.One.Service.DataContracts"
14
+ log_level :debug
15
+ log true
16
+ end
17
+ end
18
+
19
+ def call(operation, command, message)
20
+ root = Mundipagg::Gateway::Key.new("tns", command).to_s
21
+
22
+ adapter.call(operation, message: {
23
+ root => Mundipagg::Gateway::Message.new(message).translate
24
+ })
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,23 @@
1
+ require "active_support/core_ext/string/conversions"
2
+
3
+ module Mundipagg
4
+ module Gateway
5
+ class Key
6
+ def initialize(prefix, value)
7
+ @prefix, @value = prefix, value.to_s
8
+ end
9
+
10
+ def to_s
11
+ "#{@prefix}:#{camelize}"
12
+ end
13
+
14
+ def camelize
15
+ @value.camelize(format)
16
+ end
17
+
18
+ def format
19
+ @prefix == "tns" ? :lower : :upper
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,20 @@
1
+ require "mundipagg/gateway/key"
2
+
3
+ module Mundipagg
4
+ module Gateway
5
+ class Message
6
+ def initialize(hash)
7
+ @hash = hash
8
+ end
9
+
10
+ def translate
11
+ @hash.inject(Hash.new) do |hash, (key, value)|
12
+ key = Mundipagg::Gateway::Key.new("mun", key).to_s
13
+
14
+ hash[key] = value.is_a?(Hash) ? Message.new(value).translate : value
15
+ hash
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,26 @@
1
+ module Mundipagg
2
+ class Order
3
+ include ActiveModel::Model
4
+
5
+ attr_accessor :id, :transaction
6
+ validates :id, :transaction, presence: true
7
+
8
+ def transaction=(transaction)
9
+ transaction.order_id = id
10
+ @transaction = transaction
11
+ end
12
+
13
+ def create
14
+ client = Mundipagg::Gateway::Client.new
15
+ client.call(:create_order, :create_order_request, to_message)
16
+ end
17
+
18
+ def to_message
19
+ {
20
+ amount_in_cents: transaction.amount,
21
+ currency_iso_enum: "BRL",
22
+ merchant_key: Mundipagg.merchant_key
23
+ }.merge(transaction.to_message)
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,23 @@
1
+ module Mundipagg
2
+ module Transaction
3
+ class Boleto
4
+ include ActiveModel::Model
5
+
6
+ attr_accessor :amount, :order_id
7
+
8
+ def to_message
9
+ {
10
+ boleto_transaction_collection: {
11
+ boleto_transaction: {
12
+ amount_in_cents: amount,
13
+ bank_number: Mundipagg.bank_number,
14
+ days_to_add_in_boleto_expiration_date: Mundipagg.days_to_expire,
15
+ nosso_numero: Mundipagg.bank_code,
16
+ transaction_reference: order_id
17
+ }
18
+ }
19
+ }
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,3 @@
1
+ module Mundipagg
2
+ VERSION = "0.0.1"
3
+ end
data/lib/mundipagg.rb ADDED
@@ -0,0 +1,23 @@
1
+ require "active_support"
2
+ require "active_model"
3
+ require "mundipagg/gateway/client"
4
+ require "mundipagg/buyer"
5
+ require "mundipagg/order"
6
+ require "mundipagg/transaction/boleto"
7
+
8
+ module Mundipagg
9
+ mattr_accessor :merchant_key, :bank_number, :bank_code, :days_to_expire, :env
10
+ @@env = :test
11
+ @@days_to_expire = 5
12
+ @@bank_number = 341
13
+
14
+ class << self
15
+ def setup
16
+ yield self
17
+ end
18
+
19
+ def test?
20
+ env == :test
21
+ end
22
+ end
23
+ end
data/mundipagg.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ $:.push File.expand_path("../lib", __FILE__)
4
+ require "mundipagg/version"
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "better-mundipagg"
8
+ s.version = Mundipagg::VERSION
9
+ s.platform = Gem::Platform::RUBY
10
+ s.authors = ["Bruno Azisaka"]
11
+ s.email = ["bruno@azisaka.com.br"]
12
+ s.homepage = ""
13
+ s.summary = %q{Mundipagg Integration}
14
+ s.description = %q{Gem to integrate with Mundipagg's webservice.}
15
+
16
+ s.add_development_dependency "rspec", "~> 3.1.0"
17
+ s.add_development_dependency "simplecov", "~> 0.9.0"
18
+ s.add_dependency "activemodel"
19
+ s.add_dependency "savon"
20
+
21
+ s.files = `git ls-files`.split("\n")
22
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
23
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
24
+ s.require_paths = ["lib"]
25
+ end
26
+
@@ -0,0 +1,23 @@
1
+ RSpec.describe Mundipagg::Gateway::Client do
2
+ describe "#adapter" do
3
+ subject { described_class.new.adapter }
4
+
5
+ it { expect(subject.globals[:wsdl]).to eq("https://transaction.mundipaggone.com/MundiPaggService.svc?wsdl") }
6
+ it { expect(subject.globals[:namespaces]).to eq("xmlns:mun" => "http://schemas.datacontract.org/2004/07/MundiPagg.One.Service.DataContracts") }
7
+ end
8
+
9
+ describe "#call" do
10
+ let(:gateway) { described_class.new }
11
+
12
+ it "sends a message" do
13
+ expect(gateway.adapter).to receive(:call) do |operation, options|
14
+ expect(operation).to eq("create_order")
15
+ expect(options).to include(message: {
16
+ "tns:createOrderRequest" => { "mun:Test" => "works" }
17
+ })
18
+ end
19
+
20
+ gateway.call("create_order", "create_order_request", { test: "works" })
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,8 @@
1
+ RSpec.describe Mundipagg::Gateway::Message do
2
+ describe "#translate" do
3
+ let(:message) { described_class.new({ that_test: { works: "fine" } }) }
4
+ subject { message.translate }
5
+
6
+ it { is_expected.to include("mun:ThatTest" => { "mun:Works" => "fine" }) }
7
+ end
8
+ end
@@ -0,0 +1,54 @@
1
+ RSpec.describe Mundipagg::Order do
2
+ describe "validation" do
3
+ it "validates presence of id" do
4
+ subject.valid?
5
+ expect(subject.errors[:id]).to include("can't be blank")
6
+ end
7
+
8
+ it "validates presence of transaction" do
9
+ subject.valid?
10
+ expect(subject.errors[:transaction]).to include("can't be blank")
11
+ end
12
+ end
13
+
14
+ describe "#to_message" do
15
+ before do
16
+ Mundipagg.setup do |config|
17
+ config.merchant_key = "MERCHANT_KEY"
18
+ config.bank_code = "BANK_NUMBER"
19
+ end
20
+ end
21
+
22
+ let(:transaction) { Mundipagg::Transaction::Boleto.new(amount: 100) }
23
+ let(:order) { described_class.new id: "ORDER_ID", transaction: transaction }
24
+
25
+ subject { order.to_message }
26
+
27
+ it { is_expected.to include(amount_in_cents: 100) }
28
+ it { is_expected.to include(currency_iso_enum: "BRL") }
29
+ it { is_expected.to include(merchant_key: "MERCHANT_KEY") }
30
+ it { is_expected.to have_key(:boleto_transaction_collection) }
31
+
32
+ context "boleto_transaction_collection" do
33
+ subject { order.to_message[:boleto_transaction_collection][:boleto_transaction] }
34
+ it { is_expected.to include(amount_in_cents: 100) }
35
+ it { is_expected.to include(bank_number: 341) }
36
+ it { is_expected.to include(days_to_add_in_boleto_expiration_date: 5) }
37
+ it { is_expected.to include(nosso_numero: "BANK_NUMBER") }
38
+ it { is_expected.to include(transaction_reference: "ORDER_ID") }
39
+ end
40
+ end
41
+
42
+ describe "#create" do
43
+ let(:client) { double "client" }
44
+ let(:order) { described_class.new }
45
+
46
+ it "sends a message through the gateway client" do
47
+ expect(order).to receive(:to_message).and_return({ "mun:Message" => "ok" })
48
+ expect(Mundipagg::Gateway::Client).to receive(:new).and_return(client)
49
+ expect(client).to receive(:call).with(:create_order, :create_order_request, { "mun:Message" => "ok" })
50
+
51
+ order.create
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,18 @@
1
+ RSpec.describe Mundipagg::Transaction::Boleto do
2
+ describe "#to_message" do
3
+ let(:transaction) { described_class.new(order_id: "ORDER_ID", amount: 100) }
4
+ subject { transaction.to_message[:boleto_transaction_collection][:boleto_transaction] }
5
+
6
+ before do
7
+ Mundipagg.setup do |config|
8
+ config.bank_code = "BANK_CODE"
9
+ end
10
+ end
11
+
12
+ it { is_expected.to include amount_in_cents: 100 }
13
+ it { is_expected.to include bank_number: 341 }
14
+ it { is_expected.to include days_to_add_in_boleto_expiration_date: 5 }
15
+ it { is_expected.to include nosso_numero: "BANK_CODE" }
16
+ it { is_expected.to include transaction_reference: "ORDER_ID" }
17
+ end
18
+ end
@@ -0,0 +1,28 @@
1
+ require "mundipagg"
2
+ require 'simplecov'
3
+ SimpleCov.start
4
+
5
+ I18n.enforce_available_locales = true
6
+
7
+ RSpec.configure do |config|
8
+ config.expect_with :rspec do |expectations|
9
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
10
+ end
11
+
12
+ config.mock_with :rspec do |mocks|
13
+ mocks.verify_partial_doubles = true
14
+ end
15
+
16
+ config.filter_run :focus
17
+ config.run_all_when_everything_filtered = true
18
+
19
+ config.disable_monkey_patching!
20
+
21
+ config.warnings = true
22
+
23
+ if config.files_to_run.one?
24
+ config.default_formatter = 'doc'
25
+ end
26
+
27
+ config.order = :random
28
+ end
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: better-mundipagg
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Bruno Azisaka
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 3.1.0
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 3.1.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: simplecov
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.9.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.9.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: activemodel
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: savon
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Gem to integrate with Mundipagg's webservice.
70
+ email:
71
+ - bruno@azisaka.com.br
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - Dockerfile
79
+ - Gemfile
80
+ - Gemfile.lock
81
+ - README.md
82
+ - lib/mundipagg.rb
83
+ - lib/mundipagg/buyer.rb
84
+ - lib/mundipagg/gateway/client.rb
85
+ - lib/mundipagg/gateway/key.rb
86
+ - lib/mundipagg/gateway/message.rb
87
+ - lib/mundipagg/order.rb
88
+ - lib/mundipagg/transaction/boleto.rb
89
+ - lib/mundipagg/version.rb
90
+ - mundipagg.gemspec
91
+ - spec/lib/mundipagg/gateway/client_spec.rb
92
+ - spec/lib/mundipagg/gateway/message_spec.rb
93
+ - spec/lib/mundipagg/order_spec.rb
94
+ - spec/lib/mundipagg/transaction/boleto_spec.rb
95
+ - spec/spec_helper.rb
96
+ homepage: ''
97
+ licenses: []
98
+ metadata: {}
99
+ post_install_message:
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ requirements: []
114
+ rubyforge_project:
115
+ rubygems_version: 2.2.2
116
+ signing_key:
117
+ specification_version: 4
118
+ summary: Mundipagg Integration
119
+ test_files: []