epaybg 0.2.0 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 45239c656f82ff2132ca9fe16e741f8e32dc2e64
4
- data.tar.gz: 2b0e1aff8b514c1d5c36a0b0a39634b08c8c0295
3
+ metadata.gz: 710d9ff6dbbfe8ff3daab192b62f75ef67b1a2c9
4
+ data.tar.gz: 86253a6b8fd37208140b98c572662734fc789f82
5
5
  SHA512:
6
- metadata.gz: 3e000ddb03b5b5c862afe7ce69560a5ee816f8b35db4dab0896514943ded9d63d656ed520f72a336368f749e4026193cbc9ed4908386186a164586e726238d1e
7
- data.tar.gz: 89595e590c3f5bc75cce1a803d705325e07ef798404bf54d4cfe51a5076bfc1028cea91702168f4761e20d11850c1846d68f4568eaf18d829c97c1f2fdba4d36
6
+ metadata.gz: d294f6db3df01afff33c59686f7e378c43b7fee59b79dc427ac6259c415897a378ec07069dccb5bbcae2477e4079e4b19fff00ca42fb9ba8a9126743be934fc4
7
+ data.tar.gz: 8d67b601ea920480d12d7ef56414c740cbe4234bcbe69b2c4a23c11cf9261aab054b6682a79296ce566b1639393c4effb36fae0dea60aab18025eabebb552735
data/Rakefile CHANGED
@@ -5,3 +5,7 @@ RSpec::Core::RakeTask.new
5
5
 
6
6
  task default: :spec
7
7
  task test: :spec
8
+
9
+ task :console do
10
+ exec "irb -r epaybg -I ./lib"
11
+ end
@@ -19,4 +19,5 @@ Gem::Specification.new do |gem|
19
19
 
20
20
  gem.add_development_dependency 'rake'
21
21
  gem.add_development_dependency 'rspec'
22
+ gem.add_development_dependency 'activesupport'
22
23
  end
@@ -1,12 +1,12 @@
1
- require 'epaybg/railtie'
1
+ require 'epaybg/railtie' if defined?(Rails)
2
2
  require 'epaybg/transaction'
3
3
  require 'epaybg/response'
4
4
  require 'epaybg/version'
5
5
 
6
6
  module Epaybg
7
7
  class << self
8
- def hmac(data)
9
- OpenSSL::HMAC.hexdigest('sha1', config['secret'], data)
8
+ def hmac(data, secret)
9
+ OpenSSL::HMAC.hexdigest('sha1', secret, data)
10
10
  end
11
11
 
12
12
  # Configuration is loaded based on this property.
@@ -16,8 +16,8 @@ module Epaybg
16
16
  Hash[*i]
17
17
  end
18
18
 
19
- def valid?
20
- Epaybg.hmac(@encoded) == @checksum
19
+ def valid? secret
20
+ Epaybg.hmac(@encoded, secret) == @checksum
21
21
  end
22
22
 
23
23
  def status
@@ -3,7 +3,7 @@ require 'net/http'
3
3
  module Epaybg
4
4
  class Transaction
5
5
  attr_accessor :url, :url_idn, :invoice, :amount, :expires_on,
6
- :description, :encoding, :url_ok, :url_cancel
6
+ :description, :encoding, :url_ok, :url_cancel, :min, :secret
7
7
 
8
8
  def initialize(args = {})
9
9
  set_defaults!
@@ -18,7 +18,7 @@ module Epaybg
18
18
  exp_time = expires_on.strftime('%d.%m.%Y')
19
19
 
20
20
  data = <<-DATA
21
- MIN=#{Epaybg.config['min']}
21
+ MIN=#{min}
22
22
  LANG=bg
23
23
  INVOICE=#{invoice}
24
24
  AMOUNT=#{amount}
@@ -29,7 +29,7 @@ EXP_TIME=#{exp_time}
29
29
  end
30
30
 
31
31
  def checksum
32
- Epaybg.hmac(encoded)
32
+ Epaybg.hmac(encoded, secret)
33
33
  end
34
34
 
35
35
  def register_payment
@@ -66,6 +66,8 @@ EXP_TIME=#{exp_time}
66
66
  @url ||= Epaybg.config['url']
67
67
  @url_idn ||= Epaybg.config['url_idn']
68
68
  @encoding ||= 'utf-8'
69
+ @min ||= Epaybg.config['min']
70
+ @secret ||= Epaybg.config['secret']
69
71
  end
70
72
  end
71
73
  end
@@ -1,3 +1,3 @@
1
1
  module Epaybg
2
- VERSION = '0.2.0'
2
+ VERSION = '0.3.0'
3
3
  end
@@ -0,0 +1,58 @@
1
+ require 'spec_helper'
2
+ require 'yaml'
3
+
4
+ describe 'Transaction' do
5
+ before {
6
+ Epaybg.config = YAML.load_file('spec/test_config.yml')
7
+ }
8
+
9
+ it 'can generate an epay_link for a transaction without using the config' do
10
+ transaction_params_without_config = {
11
+ invoice: 12345,
12
+ amount: 1,
13
+ expires_on: Date.today + 1,
14
+ min: "YOUR-MIN",
15
+ secret: "YOUR-SECRET-KEY",
16
+ url_ok: 'http://www.google.com',
17
+ url_cancel: 'http://www.yahoo.com',
18
+ }
19
+
20
+ transaction_params_with_config = {
21
+ invoice: 12345,
22
+ amount: 1,
23
+ expires_on: Date.today + 1,
24
+ url_ok: 'http://www.google.com',
25
+ url_cancel: 'http://www.yahoo.com',
26
+ }
27
+
28
+ config_transaction = ::Epaybg::Transaction.new(transaction_params_with_config)
29
+ no_config_transaction = ::Epaybg::Transaction.new(transaction_params_without_config)
30
+
31
+ expect(config_transaction.epay_link).to eq(no_config_transaction.epay_link)
32
+ end
33
+
34
+ it 'can generate a credit_card_link for a transaction without using the config' do
35
+ transaction_params_without_config = {
36
+ invoice: 12345,
37
+ amount: 1,
38
+ expires_on: Date.today + 1,
39
+ min: "YOUR-MIN",
40
+ secret: "YOUR-SECRET-KEY",
41
+ url_ok: 'http://www.google.com',
42
+ url_cancel: 'http://www.yahoo.com',
43
+ }
44
+
45
+ transaction_params_with_config = {
46
+ invoice: 12345,
47
+ amount: 1,
48
+ expires_on: Date.today + 1,
49
+ url_ok: 'http://www.google.com',
50
+ url_cancel: 'http://www.yahoo.com',
51
+ }
52
+
53
+ config_transaction = ::Epaybg::Transaction.new(transaction_params_with_config)
54
+ no_config_transaction = ::Epaybg::Transaction.new(transaction_params_without_config)
55
+
56
+ expect(config_transaction.credit_card_link).to eq(no_config_transaction.credit_card_link)
57
+ end
58
+ end
@@ -0,0 +1,4 @@
1
+ require 'bundler/setup'
2
+ Bundler.setup
3
+ require 'active_support/all'
4
+ require 'epaybg'
@@ -0,0 +1,11 @@
1
+ production:
2
+ secret: YOUR-SECRET-KEY
3
+ min: YOUR-MIN
4
+ url: "https://epay.bg"
5
+ url_idn: "https://epay.bg/ezp/reg_bill.cgi"
6
+
7
+ test:
8
+ secret: YOUR-SECRET-KEY
9
+ min: YOUR-MIN
10
+ url: "https://demo.epay.bg"
11
+ url_idn: "https://demo.epay.bg/ezp/reg_bill.cgi"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: epaybg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - gmitrev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-03 00:00:00.000000000 Z
11
+ date: 2015-09-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: activesupport
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  description: Gem for dealing with epay.bg payments.
42
56
  email:
43
57
  - gvmitrev@gmail.com
@@ -60,6 +74,9 @@ files:
60
74
  - lib/epaybg/version.rb
61
75
  - lib/epaybg/view_helpers.rb
62
76
  - log/test.log
77
+ - spec/epaybg/transaction_spec.rb
78
+ - spec/spec_helper.rb
79
+ - spec/test_config.yml
63
80
  homepage: http://github.com/gmitrev/epaybg
64
81
  licenses: []
65
82
  metadata: {}
@@ -84,4 +101,7 @@ signing_key:
84
101
  specification_version: 4
85
102
  summary: Epaybg provides integration with the epay.bg payment services. It supports
86
103
  payments through epay.bg, credit cards and in EasyPay offices.
87
- test_files: []
104
+ test_files:
105
+ - spec/epaybg/transaction_spec.rb
106
+ - spec/spec_helper.rb
107
+ - spec/test_config.yml