dbalatero-remit 0.0.2.5

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.
Files changed (44) hide show
  1. data/lib/remit.rb +133 -0
  2. data/lib/remit/common.rb +88 -0
  3. data/lib/remit/data_types.rb +181 -0
  4. data/lib/remit/error_codes.rb +118 -0
  5. data/lib/remit/get_pipeline.rb +181 -0
  6. data/lib/remit/ipn_request.rb +46 -0
  7. data/lib/remit/operations/cancel_token.rb +18 -0
  8. data/lib/remit/operations/discard_results.rb +18 -0
  9. data/lib/remit/operations/fund_prepaid.rb +31 -0
  10. data/lib/remit/operations/get_account_activity.rb +60 -0
  11. data/lib/remit/operations/get_account_balance.rb +29 -0
  12. data/lib/remit/operations/get_all_credit_instruments.rb +18 -0
  13. data/lib/remit/operations/get_all_prepaid_instruments.rb +18 -0
  14. data/lib/remit/operations/get_debt_balance.rb +23 -0
  15. data/lib/remit/operations/get_outstanding_debt_balance.rb +22 -0
  16. data/lib/remit/operations/get_payment_instruction.rb +21 -0
  17. data/lib/remit/operations/get_prepaid_balance.rb +23 -0
  18. data/lib/remit/operations/get_results.rb +27 -0
  19. data/lib/remit/operations/get_token_by_caller.rb +19 -0
  20. data/lib/remit/operations/get_token_usage.rb +18 -0
  21. data/lib/remit/operations/get_tokens.rb +20 -0
  22. data/lib/remit/operations/get_total_prepaid_liability.rb +22 -0
  23. data/lib/remit/operations/get_transaction.rb +42 -0
  24. data/lib/remit/operations/install_payment_instruction.rb +22 -0
  25. data/lib/remit/operations/pay.rb +35 -0
  26. data/lib/remit/operations/refund.rb +43 -0
  27. data/lib/remit/operations/reserve.rb +30 -0
  28. data/lib/remit/operations/retry_transaction.rb +18 -0
  29. data/lib/remit/operations/settle.rb +20 -0
  30. data/lib/remit/operations/settle_debt.rb +30 -0
  31. data/lib/remit/operations/subscribe_for_caller_notification.rb +18 -0
  32. data/lib/remit/operations/unsubscribe_for_caller_notification.rb +17 -0
  33. data/lib/remit/operations/write_off_debt.rb +28 -0
  34. data/lib/remit/pipeline_response.rb +52 -0
  35. data/spec/integrations/get_account_activity_spec.rb +36 -0
  36. data/spec/integrations/get_tokens_spec.rb +38 -0
  37. data/spec/integrations/integrations_helper.rb +8 -0
  38. data/spec/spec_helper.rb +36 -0
  39. data/spec/units/get_pipeline_spec.rb +165 -0
  40. data/spec/units/get_results_spec.rb +49 -0
  41. data/spec/units/ipn_request_spec.rb +32 -0
  42. data/spec/units/pay_spec.rb +133 -0
  43. data/spec/units/units_helper.rb +4 -0
  44. metadata +104 -0
@@ -0,0 +1,181 @@
1
+ require 'erb'
2
+
3
+ require 'remit/common'
4
+
5
+ module Remit
6
+ module GetPipeline
7
+ class Pipeline
8
+ @parameters = []
9
+ attr_reader :parameters
10
+
11
+ class << self
12
+ # Create the parameters hash for the subclass.
13
+ def inherited(subclass) #:nodoc:
14
+ subclass.instance_variable_set('@parameters', [])
15
+ end
16
+
17
+ def parameter(name)
18
+ attr_accessor name
19
+ @parameters << name
20
+ end
21
+
22
+ def convert_key(key)
23
+ key.to_s.gsub(/_(.)/) { $1.upcase }.to_sym
24
+ end
25
+
26
+ # Returns a hash of all of the parameters for this request, including
27
+ # those that are inherited.
28
+ def parameters #:nodoc:
29
+ (superclass.respond_to?(:parameters) ? superclass.parameters : []) + @parameters
30
+ end
31
+ end
32
+
33
+ attr_reader :api
34
+
35
+ parameter :pipeline_name
36
+ parameter :return_url
37
+ parameter :caller_key
38
+ parameter :version
39
+
40
+ def initialize(api, options)
41
+ @api = api
42
+
43
+ options.each do |k,v|
44
+ self.send("#{k}=", v)
45
+ end
46
+ end
47
+
48
+ def url
49
+ uri = URI.parse(@api.pipeline_url)
50
+
51
+ query = {}
52
+ self.class.parameters.each do |p|
53
+ val = self.send(p)
54
+
55
+ # Convert Time values to seconds from Epoch
56
+ val = val.to_i if val.class == Time
57
+
58
+ query[self.class.convert_key(p.to_s)] = val
59
+ end
60
+
61
+ # Remove any unused optional parameters
62
+ query.reject! { |key, value| value.nil? }
63
+
64
+ uri.query = SignedQuery.new(@api.pipeline_url, @api.secret_key, query).to_s
65
+ uri.to_s
66
+ end
67
+ end
68
+
69
+ class SingleUsePipeline < Pipeline
70
+ parameter :caller_reference
71
+ parameter :payment_reason
72
+ parameter :payment_method
73
+ parameter :transaction_amount
74
+ parameter :recipient_token
75
+
76
+ def pipeline_name
77
+ Remit::PipelineName::SINGLE_USE
78
+ end
79
+ end
80
+
81
+ class MultiUsePipeline < Pipeline
82
+ parameter :caller_reference
83
+ parameter :payment_reason
84
+ parameter :recipient_token_list
85
+ parameter :amount_type
86
+ parameter :transaction_amount
87
+ parameter :validity_start
88
+ parameter :validity_expiry
89
+ parameter :payment_method
90
+ parameter :global_amount_limit
91
+ parameter :usage_limit_type_1
92
+ parameter :usage_limit_period_1
93
+ parameter :usage_limit_value_1
94
+ parameter :usage_limit_type_2
95
+ parameter :usage_limit_period_2
96
+ parameter :usage_limit_value_2
97
+ parameter :is_recipient_cobranding
98
+
99
+ def pipeline_name
100
+ Remit::PipelineName::MULTI_USE
101
+ end
102
+ end
103
+
104
+ class RecipientPipeline < Pipeline
105
+ parameter :caller_reference
106
+ parameter :validity_start # Time or seconds from Epoch
107
+ parameter :validity_expiry # Time or seconds from Epoch
108
+ parameter :payment_method
109
+ parameter :recipient_pays_fee
110
+ parameter :caller_reference_refund
111
+ parameter :max_variable_fee
112
+ parameter :max_fixed_fee
113
+
114
+ def pipeline_name
115
+ Remit::PipelineName::RECIPIENT
116
+ end
117
+ end
118
+
119
+ class RecurringUsePipeline < Pipeline
120
+ parameter :caller_reference
121
+ parameter :payment_reason
122
+ parameter :recipient_token
123
+ parameter :transaction_amount
124
+ parameter :validity_start # Time or seconds from Epoch
125
+ parameter :validity_expiry # Time or seconds from Epoch
126
+ parameter :payment_method
127
+ parameter :recurring_period
128
+
129
+ def pipeline_name
130
+ Remit::PipelineName::RECURRING
131
+ end
132
+ end
133
+
134
+ class PostpaidPipeline < Pipeline
135
+ parameter :caller_reference_sender
136
+ parameter :caller_reference_settlement
137
+ parameter :payment_reason
138
+ parameter :payment_method
139
+ parameter :validity_start # Time or seconds from Epoch
140
+ parameter :validity_expiry # Time or seconds from Epoch
141
+ parameter :credit_limit
142
+ parameter :global_amount_limit
143
+ parameter :usage_limit_type1
144
+ parameter :usage_limit_period1
145
+ parameter :usage_limit_value1
146
+ parameter :usage_limit_type2
147
+ parameter :usage_limit_period2
148
+ parameter :usage_limit_value2
149
+
150
+ def pipeline_name
151
+ Remit::PipelineName::SETUP_POSTPAID
152
+ end
153
+ end
154
+
155
+ def get_single_use_pipeline(options)
156
+ self.get_pipeline(SingleUsePipeline, options)
157
+ end
158
+
159
+ def get_multi_use_pipeline(options)
160
+ self.get_pipeline(MultiUsePipeline, options)
161
+ end
162
+
163
+ def get_recipient_pipeline(options)
164
+ self.get_pipeline(RecipientPipeline, options)
165
+ end
166
+
167
+ def get_recurring_use_pipeline(options)
168
+ self.get_pipeline(RecurringUsePipeline, options)
169
+ end
170
+
171
+ def get_postpaid_pipeline(options)
172
+ self.get_pipeline(PostpaidPipeline, options)
173
+ end
174
+
175
+ def get_pipeline(pipeline_subclass, options)
176
+ pipeline = pipeline_subclass.new(self, {
177
+ :caller_key => @access_key
178
+ }.merge(options))
179
+ end
180
+ end
181
+ end
@@ -0,0 +1,46 @@
1
+ require 'base64'
2
+ require 'openssl/digest'
3
+
4
+ module Remit
5
+ # Encapsulates the logic for IPN request validation and attribute retrieval.
6
+ class IpnRequest
7
+ # Signature key name used by AmazonFPS IPNs
8
+ SIGNATURE_KEY = 'awsSignature'
9
+
10
+ # +params+ should be your controllers request parameters.
11
+ def initialize(params, secret_key)
12
+ raise ArgumentError, "Expected the request params hash, received: #{params.inspect}" unless params.kind_of?(Hash)
13
+ @params = strip_keys_from(params, 'action', 'controller')
14
+ @supplied_signature = @params.delete(SIGNATURE_KEY)
15
+ @secret_key = secret_key
16
+ end
17
+
18
+ def valid?
19
+ return false unless @supplied_signature
20
+ generate_signature_for(@params) == @supplied_signature
21
+ end
22
+
23
+ def method_missing(method, *args) #:nodoc:
24
+ if @params.has_key?(method.to_s)
25
+ @params[method.to_s]
26
+ else
27
+ super(method, *args)
28
+ end
29
+ end
30
+
31
+ def generate_signature_for(params)
32
+ query = params.sort_by { |k,v| k.downcase }
33
+ digest = OpenSSL::Digest::Digest.new('sha1')
34
+ hmac = OpenSSL::HMAC.digest(digest, @secret_key, query.to_s)
35
+ encoded = Base64.encode64(hmac).chomp
36
+ end
37
+ private :generate_signature_for
38
+
39
+ def strip_keys_from(params, *ignore_keys)
40
+ parsed = params.dup
41
+ ignore_keys.each { |key| parsed.delete(key) }
42
+ parsed
43
+ end
44
+ private :strip_keys_from
45
+ end
46
+ end
@@ -0,0 +1,18 @@
1
+ require 'remit/common'
2
+
3
+ module Remit
4
+ module CancelToken
5
+ class Request < Remit::Request
6
+ action :CancelToken
7
+ parameter :token_id, :required => true
8
+ parameter :reason_text
9
+ end
10
+
11
+ class Response < Remit::Response
12
+ end
13
+
14
+ def cancel_token(request = Request.new)
15
+ call(request, Response)
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ require 'remit/common'
2
+
3
+ module Remit
4
+ module DiscardResults
5
+ class Request < Remit::Request
6
+ action :DiscardResults
7
+ parameter :transaction_ids, :required => true
8
+ end
9
+
10
+ class Response < Remit::Response
11
+ parameter :discard_errors
12
+ end
13
+
14
+ def discard_results(request = Request.new)
15
+ call(request, Response)
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,31 @@
1
+ require 'remit/common'
2
+
3
+ module Remit
4
+ module FundPrepaid
5
+ class Request < Remit::Request
6
+ action :FundPrepaid
7
+ parameter :transaction_ids
8
+ parameter :caller_description
9
+ parameter :caller_reference, :required => true
10
+ parameter :caller_token_id, :required => true
11
+ parameter :charge_fee_to, :required => true
12
+ parameter :funding_amount, :type => Remit::RequestTypes::Amount, :required => true
13
+ parameter :meta_data
14
+ parameter :prepaid_instrument_id, :required => true
15
+ parameter :recipient_description
16
+ parameter :recipient_reference
17
+ parameter :sender_description
18
+ parameter :sender_reference
19
+ parameter :sender_token_id, :required => true
20
+ parameter :transaction_date
21
+ end
22
+
23
+ class Response < Remit::Response
24
+ parameter :transaction_response, :type => TransactionResponse
25
+ end
26
+
27
+ def fund_prepaid(request = Request.new)
28
+ call(request, Response)
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,60 @@
1
+ require 'remit/common'
2
+
3
+ module Remit
4
+ module GetAccountActivity
5
+ class Request < Remit::Request
6
+ action :GetAccountActivity
7
+ parameter :start_date, :required => true
8
+ parameter :end_date
9
+ parameter :max_batch_size
10
+ parameter :sort_order_by_date
11
+ parameter :response_group
12
+ parameter :operation
13
+ parameter :payment_method
14
+ parameter :role
15
+ parameter :status
16
+ end
17
+
18
+ class Response < Remit::Response
19
+ class Transaction < Remit::BaseResponse
20
+ class TransactionPart < Remit::BaseResponse
21
+ parameter :account_id
22
+ parameter :role
23
+ parameter :name
24
+ parameter :reference
25
+ parameter :description
26
+ parameter :fee_paid, :type => Amount
27
+ end
28
+
29
+ parameter :caller_name
30
+ parameter :caller_token_id
31
+ parameter :caller_transaction_date, :type => :time
32
+ parameter :date_completed, :type => :time
33
+ parameter :date_received, :type => :time
34
+ parameter :error_code
35
+ parameter :error_detail
36
+ parameter :error_message
37
+ parameter :fees, :type => Amount
38
+ parameter :meta_data
39
+ parameter :operation
40
+ parameter :original_transaction_id
41
+ parameter :payment_method
42
+ parameter :recipient_name
43
+ parameter :sender_name
44
+ parameter :sender_token_id
45
+ parameter :status
46
+ parameter :transaction_amount, :type => Amount
47
+ parameter :transaction_id
48
+ parameter :transaction_parts, :collection => TransactionPart
49
+ end
50
+
51
+ parameter :response_batch_size
52
+ parameter :transactions, :collection => Transaction
53
+ parameter :start_time_for_next_transaction, :type => :time
54
+ end
55
+
56
+ def get_account_activity(request = Request.new)
57
+ call(request, Response)
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,29 @@
1
+ require 'remit/common'
2
+
3
+ module Remit
4
+ module GetAccountBalance
5
+ class Request < Remit::Request
6
+ action :GetAccountBalance
7
+ end
8
+
9
+ class Response < Remit::Response
10
+ class AccountBalance < Remit::BaseResponse
11
+ class AvailableBalances < Remit::BaseResponse
12
+ parameter :disburse_balance, :type => Amount
13
+ parameter :refund_balance, :type => Amount
14
+ end
15
+
16
+ parameter :total_balance, :type => Amount
17
+ parameter :pending_in_balance, :type => Amount
18
+ parameter :pending_out_balance, :type => Amount
19
+ parameter :available_balances, :type => AvailableBalances
20
+ end
21
+
22
+ parameter :account_balance, :type => AccountBalance
23
+ end
24
+
25
+ def get_account_balance(request = Request.new)
26
+ call(request, Response)
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,18 @@
1
+ require 'remit/common'
2
+
3
+ module Remit
4
+ module GetAllCreditInstruments
5
+ class Request < Remit::Request
6
+ action :GetAllCreditInstruments
7
+ parameter :instrument_status
8
+ end
9
+
10
+ class Response < Remit::Response
11
+ parameter :credit_instrument_ids
12
+ end
13
+
14
+ def get_all_credit_instruments(request = Request.new)
15
+ call(request, Response)
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ require 'remit/common'
2
+
3
+ module Remit
4
+ module GetAllPrepaidInstruments
5
+ class Request < Remit::Request
6
+ action :GetAllPrepaidInstruments
7
+ parameter :instrument_status
8
+ end
9
+
10
+ class Response < Remit::Response
11
+ parameter :prepaid_instrument_ids
12
+ end
13
+
14
+ def get_all_prepaid_instruments(request = Request.new)
15
+ call(request, Response)
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,23 @@
1
+ require 'remit/common'
2
+
3
+ module Remit
4
+ module GetDebtBalance
5
+ class Request < Remit::Request
6
+ action :GetDebtBalance
7
+ parameter :credit_instrument_id, :required => true
8
+ end
9
+
10
+ class Response < Remit::Response
11
+ class DebtBalance < Remit::BaseResponse
12
+ parameter :available_balance, :type => Amount
13
+ parameter :pending_out_balance, :type => Amount
14
+ end
15
+
16
+ parameter :debt_balance, :type => DebtBalance
17
+ end
18
+
19
+ def get_debt_balance(request = Request.new)
20
+ call(request, Response)
21
+ end
22
+ end
23
+ end