payments-pl 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. data/.yardoc/checksums +6 -0
  2. data/.yardoc/objects/Payments.dat +0 -0
  3. data/.yardoc/objects/Payments/ENCODINGS.dat +0 -0
  4. data/.yardoc/objects/Payments/ERRORS.dat +0 -0
  5. data/.yardoc/objects/Payments/POS_TYPES.dat +0 -0
  6. data/.yardoc/objects/Payments/Pos.dat +0 -0
  7. data/.yardoc/objects/Payments/Pos/cancel_i.dat +0 -0
  8. data/.yardoc/objects/Payments/Pos/confirm_i.dat +0 -0
  9. data/.yardoc/objects/Payments/Pos/encoding_i.dat +0 -0
  10. data/.yardoc/objects/Payments/Pos/encrypt_i.dat +0 -0
  11. data/.yardoc/objects/Payments/Pos/get_i.dat +0 -0
  12. data/.yardoc/objects/Payments/Pos/initialize_i.dat +0 -0
  13. data/.yardoc/objects/Payments/Pos/key1_i.dat +0 -0
  14. data/.yardoc/objects/Payments/Pos/key2_i.dat +0 -0
  15. data/.yardoc/objects/Payments/Pos/new_transaction_i.dat +0 -0
  16. data/.yardoc/objects/Payments/Pos/new_transaction_url_i.dat +0 -0
  17. data/.yardoc/objects/Payments/Pos/parse_response_body_i.dat +0 -0
  18. data/.yardoc/objects/Payments/Pos/path_for_i.dat +0 -0
  19. data/.yardoc/objects/Payments/Pos/pos_auth_key_i.dat +0 -0
  20. data/.yardoc/objects/Payments/Pos/pos_id_i.dat +0 -0
  21. data/.yardoc/objects/Payments/Pos/prepare_data_i.dat +0 -0
  22. data/.yardoc/objects/Payments/Pos/send_request_i.dat +0 -0
  23. data/.yardoc/objects/Payments/Pos/type_i.dat +0 -0
  24. data/.yardoc/objects/Payments/Pos/verify_i.dat +0 -0
  25. data/.yardoc/objects/Payments/PosInvalid.dat +0 -0
  26. data/.yardoc/objects/Payments/PosNotFound.dat +0 -0
  27. data/.yardoc/objects/Payments/RequestFailed.dat +0 -0
  28. data/.yardoc/objects/Payments/SignatureInvalid.dat +0 -0
  29. data/.yardoc/objects/Payments/Transaction.dat +0 -0
  30. data/.yardoc/objects/Payments/Transaction/column_c.dat +0 -0
  31. data/.yardoc/objects/Payments/Transaction/columns_c.dat +0 -0
  32. data/.yardoc/objects/Payments/Transaction/new_url_i.dat +0 -0
  33. data/.yardoc/objects/Payments/Transaction/pos_i.dat +0 -0
  34. data/.yardoc/objects/Payments/ViewHelpers.dat +0 -0
  35. data/.yardoc/objects/Payments/ViewHelpers/transaction_hidden_fields_i.dat +0 -0
  36. data/.yardoc/objects/Payments/_40_40pos_table.dat +0 -0
  37. data/.yardoc/objects/Payments/_5B_5D_c.dat +0 -0
  38. data/.yardoc/objects/Payments/error_text_c.dat +0 -0
  39. data/.yardoc/objects/Payments/get_pos_by_id_c.dat +0 -0
  40. data/.yardoc/objects/Payments/get_pos_by_name_c.dat +0 -0
  41. data/.yardoc/objects/Payments/init_c.dat +0 -0
  42. data/.yardoc/objects/root.dat +0 -0
  43. data/.yardoc/proxy_types +0 -0
  44. data/VERSION +1 -1
  45. data/doc/Payments.html +288 -46
  46. data/doc/Payments/Pos.html +177 -426
  47. data/doc/Payments/PosInvalid.html +100 -0
  48. data/doc/Payments/PosNotFound.html +1 -1
  49. data/doc/Payments/RequestFailed.html +1 -1
  50. data/doc/Payments/SignatureInvalid.html +1 -1
  51. data/doc/Payments/Transaction.html +81 -15
  52. data/doc/Payments/ViewHelpers.html +1 -1
  53. data/doc/_index.html +10 -3
  54. data/doc/class_list.html +1 -1
  55. data/doc/file.README.html +2 -2
  56. data/doc/frames.html +1 -1
  57. data/doc/index.html +2 -2
  58. data/doc/method_list.html +13 -61
  59. data/doc/top-level-namespace.html +1 -1
  60. data/lib/payments/pos.rb +32 -17
  61. data/lib/payments/transaction.rb +4 -0
  62. data/lib/payments_pl.rb +30 -5
  63. data/payments-pl.gemspec +46 -2
  64. metadata +48 -4
@@ -79,7 +79,7 @@
79
79
  </div>
80
80
 
81
81
  <div id="footer">
82
- Generated on Tue Aug 17 16:13:28 2010 by
82
+ Generated on Wed Aug 18 22:12:45 2010 by
83
83
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool">yard</a>
84
84
  0.5.8 (ruby-1.8.7).
85
85
  </div>
data/lib/payments/pos.rb CHANGED
@@ -4,6 +4,9 @@ module Payments
4
4
  class Pos
5
5
  attr_reader :pos_id, :pos_auth_key, :key1, :key2, :type, :encoding
6
6
 
7
+ # Creates new Pos instance
8
+ # @param [Hash] options options hash
9
+ # @return [Object] Pos object
7
10
  def initialize(options)
8
11
  options.symbolize_keys!
9
12
 
@@ -11,10 +14,20 @@ module Payments
11
14
  @pos_auth_key = options[:pos_auth_key]
12
15
  @key1 = options[:key1]
13
16
  @key2 = options[:key2]
14
- @type = options[:type] || 'express_gateway'
17
+ @type = options[:type] || 'default'
15
18
  @encoding = options[:encoding] || 'UTF'
19
+
20
+ raise PosInvalid.new('Missing pos_id parameter') if @pos_id.blank?
21
+ raise PosInvalid.new('Missing pos_auth_key parameter') if @pos_auth_key.blank?
22
+ raise PosInvalid.new('Missing key1 parameter') if @key1.blank?
23
+ raise PosInvalid.new('Missing key2 parameter') if @key2.blank?
24
+ raise PosInvalid.new("Invalid type parameter, expected one of these: #{Payments::POS_TYPES.join(', ')}") unless Payments::POS_TYPES.include?(@type)
25
+ raise PosInvalid.new("Invalid encoding parameter, expected one of these: #{Payments::ENCODINGS.join(', ')}") unless Payments::ENCODINGS.include?(@encoding)
16
26
  end
17
27
 
28
+ # Creates new transaction
29
+ # @param [Hash] options options hash for new transaction
30
+ # @return [Object] Transaction object
18
31
  def new_transaction(options = {})
19
32
  options.stringify_keys!
20
33
 
@@ -25,16 +38,30 @@ module Payments
25
38
  Transaction.new(options)
26
39
  end
27
40
 
41
+ # Returns new transaction url, depending on Pos type
42
+ # @return [String] new transaction url
28
43
  def new_transaction_url
29
- if @type == 'express_gateway'
30
- return "https://www.platnosci.pl/paygw/#{@encoding}/NewPayment"
31
- elsif @type == 'sms_premium'
44
+ if @type == 'sms_premium'
32
45
  return "https://www.platnosci.pl/paygw/#{@encoding}/NewSMS"
33
46
  else
34
- return nil
47
+ return "https://www.platnosci.pl/paygw/#{@encoding}/NewPayment"
35
48
  end
36
49
  end
37
50
 
51
+ def get(session_id)
52
+ send_request(:get, session_id)
53
+ end
54
+
55
+ def confirm(session_id)
56
+ send_request(:confirm, session_id)
57
+ end
58
+
59
+ def cancel(session_id)
60
+ send_request(:cancel, session_id)
61
+ end
62
+
63
+ protected
64
+
38
65
  def path_for(method)
39
66
  case method
40
67
  when :get then "/paygw/#{@encoding}/Payment/get/txt"
@@ -58,18 +85,6 @@ module Payments
58
85
  return sig == t.trans_sig
59
86
  end
60
87
 
61
- def get(session_id)
62
- send_request(:get, session_id)
63
- end
64
-
65
- def confirm(session_id)
66
- send_request(:confirm, session_id)
67
- end
68
-
69
- def cancel(session_id)
70
- send_request(:cancel, session_id)
71
- end
72
-
73
88
  def send_request(method, session_id)
74
89
  url = path_for(method)
75
90
  data = prepare_data(session_id)
@@ -34,10 +34,14 @@ module Payments
34
34
  column :sig, :string
35
35
  column :ts, :string
36
36
 
37
+ # Returns Pos object for current transaction
38
+ # @return [Object] Pos object
37
39
  def pos
38
40
  Payments[pos_id]
39
41
  end
40
42
 
43
+ # Returns url for new payment, used in payment form
44
+ # @return [String] new payment url
41
45
  def new_url
42
46
  pos.new_transaction_url
43
47
  end
data/lib/payments_pl.rb CHANGED
@@ -43,29 +43,50 @@ module Payments
43
43
  999 => 'Inny błąd krytyczny - prosimy o kontakt'
44
44
  }
45
45
 
46
+ POS_TYPES = ['default', 'sms_premium']
47
+ ENCODINGS = ['ISO', 'WIN', 'UTF']
48
+
46
49
  @@pos_table = {}
47
50
 
48
51
  class SignatureInvalid < StandardError; end
49
52
  class PosNotFound < StandardError; end
50
53
  class RequestFailed < StandardError; end
54
+ class PosInvalid < StandardError; end
51
55
 
52
56
  class << self
57
+
58
+ # Loads payments.yml file and creates specified Pos objects
53
59
  def init
54
- config = YAML.load_file(File.join(RAILS_ROOT, 'config', 'payments.yml'))
55
- config.each do |k, v|
56
- pos = Pos.new(v)
57
- @@pos_table[k] = pos
60
+ filename = File.join(Rails.root, 'config', 'payments.yml')
61
+ if File.exist?(filename)
62
+ config = YAML.load_file(filename)
63
+ config.each do |k, v|
64
+ pos = Pos.new(v)
65
+ @@pos_table[k] = pos
66
+ end
58
67
  end
59
68
  end
60
69
 
70
+ # Combined accessor, returns Pos object with given pos_id or name
71
+ #
72
+ # @param [String, Integer] name_or_id name or pos_id of Pos
73
+ # @return [Object] the Pos object
61
74
  def [](name_or_id)
62
75
  get_pos_by_name(name_or_id) || get_pos_by_id(name_or_id) || raise(PosNotFound)
63
76
  end
64
77
 
78
+ # Returns Pos object with given name, the same as in payments.yml file
79
+ #
80
+ # @param [String] name name of Pos
81
+ # @return [Object] the Pos object
65
82
  def get_pos_by_name(name)
66
83
  @@pos_table[name]
67
84
  end
68
85
 
86
+ # Returns Pos object with given pos_id, the same as in payments.yml file
87
+ #
88
+ # @param [Integer] id pos_id of Pos
89
+ # @return [Object] the Pos object
69
90
  def get_pos_by_id(id)
70
91
  id = id.to_i
71
92
  @@pos_table.each do |k, v|
@@ -74,6 +95,10 @@ module Payments
74
95
  nil
75
96
  end
76
97
 
98
+ # Returns error explanation for given error code
99
+ #
100
+ # @param [Integer] error_code
101
+ # @return [String] string with error message
77
102
  def error_text(error_code)
78
103
  ERRORS[error_code.to_i]
79
104
  end
@@ -81,4 +106,4 @@ module Payments
81
106
  end
82
107
 
83
108
  Payments.init
84
- ActionView::Base.send(:include, Payments::ViewHelpers)
109
+ ActionView::Base.send(:include, Payments::ViewHelpers)
data/payments-pl.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{payments-pl}
8
- s.version = "0.4.1"
8
+ s.version = "0.4.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Micha\305\202 M\305\202o\305\272niak"]
12
- s.date = %q{2010-08-17}
12
+ s.date = %q{2010-08-18}
13
13
  s.description = %q{Simple library for payments via platnosci.pl}
14
14
  s.email = %q{m.mlozniak@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -19,12 +19,56 @@ Gem::Specification.new do |s|
19
19
  s.files = [
20
20
  ".document",
21
21
  ".gitignore",
22
+ ".yardoc/checksums",
23
+ ".yardoc/objects/Payments.dat",
24
+ ".yardoc/objects/Payments/ENCODINGS.dat",
25
+ ".yardoc/objects/Payments/ERRORS.dat",
26
+ ".yardoc/objects/Payments/POS_TYPES.dat",
27
+ ".yardoc/objects/Payments/Pos.dat",
28
+ ".yardoc/objects/Payments/Pos/cancel_i.dat",
29
+ ".yardoc/objects/Payments/Pos/confirm_i.dat",
30
+ ".yardoc/objects/Payments/Pos/encoding_i.dat",
31
+ ".yardoc/objects/Payments/Pos/encrypt_i.dat",
32
+ ".yardoc/objects/Payments/Pos/get_i.dat",
33
+ ".yardoc/objects/Payments/Pos/initialize_i.dat",
34
+ ".yardoc/objects/Payments/Pos/key1_i.dat",
35
+ ".yardoc/objects/Payments/Pos/key2_i.dat",
36
+ ".yardoc/objects/Payments/Pos/new_transaction_i.dat",
37
+ ".yardoc/objects/Payments/Pos/new_transaction_url_i.dat",
38
+ ".yardoc/objects/Payments/Pos/parse_response_body_i.dat",
39
+ ".yardoc/objects/Payments/Pos/path_for_i.dat",
40
+ ".yardoc/objects/Payments/Pos/pos_auth_key_i.dat",
41
+ ".yardoc/objects/Payments/Pos/pos_id_i.dat",
42
+ ".yardoc/objects/Payments/Pos/prepare_data_i.dat",
43
+ ".yardoc/objects/Payments/Pos/send_request_i.dat",
44
+ ".yardoc/objects/Payments/Pos/type_i.dat",
45
+ ".yardoc/objects/Payments/Pos/verify_i.dat",
46
+ ".yardoc/objects/Payments/PosInvalid.dat",
47
+ ".yardoc/objects/Payments/PosNotFound.dat",
48
+ ".yardoc/objects/Payments/RequestFailed.dat",
49
+ ".yardoc/objects/Payments/SignatureInvalid.dat",
50
+ ".yardoc/objects/Payments/Transaction.dat",
51
+ ".yardoc/objects/Payments/Transaction/column_c.dat",
52
+ ".yardoc/objects/Payments/Transaction/columns_c.dat",
53
+ ".yardoc/objects/Payments/Transaction/new_url_i.dat",
54
+ ".yardoc/objects/Payments/Transaction/pos_i.dat",
55
+ ".yardoc/objects/Payments/ViewHelpers.dat",
56
+ ".yardoc/objects/Payments/ViewHelpers/transaction_hidden_fields_i.dat",
57
+ ".yardoc/objects/Payments/_40_40pos_table.dat",
58
+ ".yardoc/objects/Payments/_5B_5D_c.dat",
59
+ ".yardoc/objects/Payments/error_text_c.dat",
60
+ ".yardoc/objects/Payments/get_pos_by_id_c.dat",
61
+ ".yardoc/objects/Payments/get_pos_by_name_c.dat",
62
+ ".yardoc/objects/Payments/init_c.dat",
63
+ ".yardoc/objects/root.dat",
64
+ ".yardoc/proxy_types",
22
65
  "LICENSE",
23
66
  "README.rdoc",
24
67
  "Rakefile",
25
68
  "VERSION",
26
69
  "doc/Payments.html",
27
70
  "doc/Payments/Pos.html",
71
+ "doc/Payments/PosInvalid.html",
28
72
  "doc/Payments/PosNotFound.html",
29
73
  "doc/Payments/RequestFailed.html",
30
74
  "doc/Payments/SignatureInvalid.html",
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: payments-pl
3
3
  version: !ruby/object:Gem::Version
4
- hash: 13
4
+ hash: 11
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 4
9
- - 1
10
- version: 0.4.1
9
+ - 2
10
+ version: 0.4.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - !binary |
@@ -17,7 +17,7 @@ autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
19
 
20
- date: 2010-08-17 00:00:00 +02:00
20
+ date: 2010-08-18 00:00:00 +02:00
21
21
  default_executable:
22
22
  dependencies: []
23
23
 
@@ -33,12 +33,56 @@ extra_rdoc_files:
33
33
  files:
34
34
  - .document
35
35
  - .gitignore
36
+ - .yardoc/checksums
37
+ - .yardoc/objects/Payments.dat
38
+ - .yardoc/objects/Payments/ENCODINGS.dat
39
+ - .yardoc/objects/Payments/ERRORS.dat
40
+ - .yardoc/objects/Payments/POS_TYPES.dat
41
+ - .yardoc/objects/Payments/Pos.dat
42
+ - .yardoc/objects/Payments/Pos/cancel_i.dat
43
+ - .yardoc/objects/Payments/Pos/confirm_i.dat
44
+ - .yardoc/objects/Payments/Pos/encoding_i.dat
45
+ - .yardoc/objects/Payments/Pos/encrypt_i.dat
46
+ - .yardoc/objects/Payments/Pos/get_i.dat
47
+ - .yardoc/objects/Payments/Pos/initialize_i.dat
48
+ - .yardoc/objects/Payments/Pos/key1_i.dat
49
+ - .yardoc/objects/Payments/Pos/key2_i.dat
50
+ - .yardoc/objects/Payments/Pos/new_transaction_i.dat
51
+ - .yardoc/objects/Payments/Pos/new_transaction_url_i.dat
52
+ - .yardoc/objects/Payments/Pos/parse_response_body_i.dat
53
+ - .yardoc/objects/Payments/Pos/path_for_i.dat
54
+ - .yardoc/objects/Payments/Pos/pos_auth_key_i.dat
55
+ - .yardoc/objects/Payments/Pos/pos_id_i.dat
56
+ - .yardoc/objects/Payments/Pos/prepare_data_i.dat
57
+ - .yardoc/objects/Payments/Pos/send_request_i.dat
58
+ - .yardoc/objects/Payments/Pos/type_i.dat
59
+ - .yardoc/objects/Payments/Pos/verify_i.dat
60
+ - .yardoc/objects/Payments/PosInvalid.dat
61
+ - .yardoc/objects/Payments/PosNotFound.dat
62
+ - .yardoc/objects/Payments/RequestFailed.dat
63
+ - .yardoc/objects/Payments/SignatureInvalid.dat
64
+ - .yardoc/objects/Payments/Transaction.dat
65
+ - .yardoc/objects/Payments/Transaction/column_c.dat
66
+ - .yardoc/objects/Payments/Transaction/columns_c.dat
67
+ - .yardoc/objects/Payments/Transaction/new_url_i.dat
68
+ - .yardoc/objects/Payments/Transaction/pos_i.dat
69
+ - .yardoc/objects/Payments/ViewHelpers.dat
70
+ - .yardoc/objects/Payments/ViewHelpers/transaction_hidden_fields_i.dat
71
+ - .yardoc/objects/Payments/_40_40pos_table.dat
72
+ - .yardoc/objects/Payments/_5B_5D_c.dat
73
+ - .yardoc/objects/Payments/error_text_c.dat
74
+ - .yardoc/objects/Payments/get_pos_by_id_c.dat
75
+ - .yardoc/objects/Payments/get_pos_by_name_c.dat
76
+ - .yardoc/objects/Payments/init_c.dat
77
+ - .yardoc/objects/root.dat
78
+ - .yardoc/proxy_types
36
79
  - LICENSE
37
80
  - README.rdoc
38
81
  - Rakefile
39
82
  - VERSION
40
83
  - doc/Payments.html
41
84
  - doc/Payments/Pos.html
85
+ - doc/Payments/PosInvalid.html
42
86
  - doc/Payments/PosNotFound.html
43
87
  - doc/Payments/RequestFailed.html
44
88
  - doc/Payments/SignatureInvalid.html