mondido 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 38e6de19a52348345f2dbf4bd5d70c87e22a0c91
4
- data.tar.gz: b1b872b2642b5e20137dee77339701658e03440a
3
+ metadata.gz: 2844bcc3718fa1e1e93c9b3fc35f62c9430c2251
4
+ data.tar.gz: 40c734aff3acc4c0375551efe1663d501a33ff35
5
5
  SHA512:
6
- metadata.gz: cce179185b1a6636409286aa925daea01baa98ca5086b9bad3e0074337f63100f017fdfe1c703eab76a2a0503c3ddacd083eef07848f5756c7cfe5a130d67852
7
- data.tar.gz: d70be22746fe80499c75767eaecee37b7437844dbb4ec814a3e0e3bb417d7cde4db629093b8b8288aa1ea843af3db95b26f572e4190b1019960e7836439ca354
6
+ metadata.gz: f6b82c440260a10b0912c904865bf3ed64ca13431428458db56379c1d4dddd0d688b66695e307e37298f2122429ee46621d679e9e6f7b8c5d5c4f4eaa7946d6d
7
+ data.tar.gz: ef7263f2b40e9c32162c87b1eb7960c7185e2400564d40e58fa9e1cfa6219b14d71f1f1dd061a1a9fad2b9fb03be8f9405d6f0bde442101d28fa375a8ddfc87e
data/lib/mondido.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  module Mondido
2
2
  require 'active_support'
3
3
  require 'active_model'
4
+ require 'mondido/credentials'
4
5
  require 'mondido/config'
5
6
  require 'mondido/exceptions/exceptions'
6
7
  require 'mondido/rest_client'
@@ -8,12 +9,6 @@ module Mondido
8
9
  require 'mondido/credit_card/transaction'
9
10
  require 'mondido/credit_card/refund'
10
11
  require 'mondido/credit_card/stored_card'
11
-
12
- class Railtie < Rails::Railtie
13
- initializer 'require credentials after rails is initialized' do
14
- require 'mondido/credentials'
15
- end
16
- end
17
12
  end
18
13
 
19
14
 
@@ -1,5 +1,5 @@
1
1
  module Mondido
2
2
  class Config
3
- URI = 'http://api.localmondido.com:3000/v1'
3
+ URI = 'http://api.mondido.com/v1'
4
4
  end
5
5
  end
@@ -1,16 +1,37 @@
1
1
  module Mondido
2
2
  class Credentials
3
- unless Rails.root.nil?
3
+ @@merchant_id = nil
4
+ @@secret = nil
5
+ @@password = nil
6
+
7
+ def self.merchant_id
8
+ setup if @@merchant_id.nil?
9
+ @@merchant_id
10
+ end
11
+
12
+ def self.secret
13
+ setup if @@secret.nil?
14
+ @@secret
15
+ end
16
+
17
+ def self.password
18
+ setup if @@password.nil?
19
+ @@password
20
+ end
21
+
22
+ private
23
+
24
+ def self.setup
4
25
  config_file = File.join(Rails.root, 'config', 'mondido.yml')
5
26
  if File.exist?(config_file)
6
27
  yaml = YAML.load(File.read(config_file))
28
+ @@merchant_id = yaml['merchant_id']
29
+ @@secret = yaml['secret']
30
+ @@password = yaml['password']
7
31
  else
8
- raise 'Could not find app/mondido.yml'
32
+ raise Mondido::Exceptions::MissingFile.new 'Could not locate config/mondido.yml'
9
33
  end
10
-
11
- MERCHANT_ID ||= yaml['merchant_id'] or raise 'Mondido merchant ID not set in config/mondido.yml'
12
- SECRET ||= yaml['secret'] or raise 'Mondido secret not set in config/mondido.yml'
13
- PASSWORD ||= yaml['password'] or raise 'Mondido password not set in config/mondido.yml'
14
34
  end
35
+
15
36
  end
16
37
  end
@@ -63,7 +63,7 @@ module Mondido
63
63
  end
64
64
 
65
65
  def set_hash!
66
- unhashed = [Mondido::Credentials::MERCHANT_ID, payment_ref, amount, currency, Mondido::Credentials::SECRET]
66
+ unhashed = [Mondido::Credentials.merchant_id, payment_ref, amount, currency, Mondido::Credentials.secret]
67
67
  self.hash = Digest::MD5.hexdigest(unhashed.join)
68
68
  end
69
69
 
@@ -2,5 +2,6 @@ module Mondido
2
2
  module Exceptions
3
3
  require 'mondido/exceptions/validation_exception'
4
4
  require 'mondido/exceptions/api_exception'
5
+ require 'mondido/exceptions/missing_file'
5
6
  end
6
7
  end
@@ -0,0 +1,7 @@
1
+
2
+ module Mondido
3
+ module Exceptions
4
+ class MissingFile < StandardError
5
+ end
6
+ end
7
+ end
@@ -23,7 +23,7 @@ module Mondido
23
23
  when :get
24
24
  request = Net::HTTP::Get.new(uri.path)
25
25
  end
26
- request.basic_auth(Mondido::Credentials::MERCHANT_ID, Mondido::Credentials::PASSWORD)
26
+ request.basic_auth(Mondido::Credentials.merchant_id, Mondido::Credentials.password)
27
27
  request.set_form_data(args[:data]) if args.has_key?(:data)
28
28
  response = http.start { |http| http.request(request) }
29
29
  unless (200..299).include?(response.code.to_i)
@@ -1,3 +1,3 @@
1
1
  module Mondido
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
@@ -5,8 +5,8 @@ describe Mondido::CreditCard::Refund do
5
5
  context 'valid' do
6
6
  before(:all) do
7
7
  uri = URI.parse(Mondido::Config::URI + '/refunds')
8
- uri.user = Mondido::Credentials::MERCHANT_ID.to_s
9
- uri.password = Mondido::Credentials::PASSWORD.to_s
8
+ uri.user = Mondido::Credentials.merchant_id.to_s
9
+ uri.password = Mondido::Credentials.password.to_s
10
10
  json_refund = File.read('spec/stubs/refund.json')
11
11
  @refund_hash = JSON.parse(json_refund)
12
12
 
@@ -5,8 +5,8 @@ describe Mondido::CreditCard::StoredCard do
5
5
  context 'valid call' do
6
6
  before(:all) do
7
7
  uri = URI.parse(Mondido::Config::URI + '/stored_cards/300')
8
- uri.user = Mondido::Credentials::MERCHANT_ID.to_s
9
- uri.password = Mondido::Credentials::PASSWORD.to_s
8
+ uri.user = Mondido::Credentials.merchant_id.to_s
9
+ uri.password = Mondido::Credentials.password.to_s
10
10
  json_stored_card = File.read('spec/stubs/stored_card.json')
11
11
  @stored_card_hash = JSON.parse(json_stored_card)
12
12
  stub_request(:get, uri.to_s)
@@ -37,8 +37,8 @@ describe Mondido::CreditCard::StoredCard do
37
37
  context '#create' do
38
38
  before(:all) do
39
39
  uri = URI.parse(Mondido::Config::URI + '/stored_cards')
40
- uri.user = Mondido::Credentials::MERCHANT_ID.to_s
41
- uri.password = Mondido::Credentials::PASSWORD.to_s
40
+ uri.user = Mondido::Credentials.merchant_id.to_s
41
+ uri.password = Mondido::Credentials.password.to_s
42
42
  json_transaction = File.read('spec/stubs/stored_card.json')
43
43
  @transaction_hash = JSON.parse(json_transaction)
44
44
 
@@ -5,8 +5,8 @@ describe Mondido::CreditCard::Transaction do
5
5
  context 'list transactions' do
6
6
  before(:all) do
7
7
  uri = URI.parse(Mondido::Config::URI + '/transactions')
8
- uri.user = Mondido::Credentials::MERCHANT_ID.to_s
9
- uri.password = Mondido::Credentials::PASSWORD.to_s
8
+ uri.user = Mondido::Credentials.merchant_id.to_s
9
+ uri.password = Mondido::Credentials.password.to_s
10
10
  json_transactions = File.read('spec/stubs/transactions.json')
11
11
  @transactions_array = JSON.parse(json_transactions)
12
12
 
@@ -25,8 +25,8 @@ describe Mondido::CreditCard::Transaction do
25
25
  context 'get transaction' do
26
26
  before(:all) do
27
27
  uri = URI.parse(Mondido::Config::URI + '/transactions/200')
28
- uri.user = Mondido::Credentials::MERCHANT_ID.to_s
29
- uri.password = Mondido::Credentials::PASSWORD.to_s
28
+ uri.user = Mondido::Credentials.merchant_id.to_s
29
+ uri.password = Mondido::Credentials.password.to_s
30
30
  json_transaction = File.read('spec/stubs/transaction.json')
31
31
  @transaction_hash = JSON.parse(json_transaction)
32
32
 
@@ -65,8 +65,8 @@ describe Mondido::CreditCard::Transaction do
65
65
  before(:all) do
66
66
 
67
67
  uri = URI.parse(Mondido::Config::URI + '/transactions/201')
68
- uri.user = Mondido::Credentials::MERCHANT_ID.to_s
69
- uri.password = Mondido::Credentials::PASSWORD.to_s
68
+ uri.user = Mondido::Credentials.merchant_id.to_s
69
+ uri.password = Mondido::Credentials.password.to_s
70
70
 
71
71
  json_error = {
72
72
  code: 128,
@@ -147,8 +147,8 @@ describe Mondido::CreditCard::Transaction do
147
147
 
148
148
  it 'raises ApiException errors.payment.declined' do
149
149
  uri = URI.parse(Mondido::Config::URI + '/transactions')
150
- uri.user = Mondido::Credentials::MERCHANT_ID.to_s
151
- uri.password = Mondido::Credentials::PASSWORD.to_s
150
+ uri.user = Mondido::Credentials.merchant_id.to_s
151
+ uri.password = Mondido::Credentials.password.to_s
152
152
  json_transaction = File.read('spec/stubs/transaction.json')
153
153
  stub_request(:post, uri.to_s)
154
154
  .with(body: hash_including({card_cvv: '201'}))
@@ -168,8 +168,8 @@ describe Mondido::CreditCard::Transaction do
168
168
 
169
169
  before(:all) do
170
170
  uri = URI.parse(Mondido::Config::URI + '/transactions')
171
- uri.user = Mondido::Credentials::MERCHANT_ID.to_s
172
- uri.password = Mondido::Credentials::PASSWORD.to_s
171
+ uri.user = Mondido::Credentials.merchant_id.to_s
172
+ uri.password = Mondido::Credentials.password.to_s
173
173
  json_transaction = File.read('spec/stubs/transaction.json')
174
174
 
175
175
  stub_request(:post, uri.to_s)
data/spec/spec_helper.rb CHANGED
@@ -12,8 +12,8 @@ end
12
12
  # Monkeymock the config class
13
13
  module Mondido
14
14
  class Credentials
15
- MERCHANT_ID = 1
16
- SECRET = 'secret'
17
- PASSWORD = 'password'
15
+ def self.merchant_id; 1; end
16
+ def self.secret; 'secret'; end
17
+ def self.password; 'password'; end
18
18
  end
19
19
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mondido
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Falkén
@@ -68,6 +68,7 @@ files:
68
68
  - lib/mondido/credit_card/transaction.rb
69
69
  - lib/mondido/exceptions/api_exception.rb
70
70
  - lib/mondido/exceptions/exceptions.rb
71
+ - lib/mondido/exceptions/missing_file.rb
71
72
  - lib/mondido/exceptions/validation_exception.rb
72
73
  - lib/mondido/rest_client.rb
73
74
  - lib/mondido/version.rb