remit2 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. data/LICENSE +20 -0
  2. data/README.markdown +26 -0
  3. data/lib/remit2.rb +119 -0
  4. data/lib/remit2/data_types.rb +142 -0
  5. data/lib/remit2/error_codes.rb +118 -0
  6. data/lib/remit2/get_pipeline.rb +195 -0
  7. data/lib/remit2/ipn_request.rb +45 -0
  8. data/lib/remit2/operations/cancel_subscription_and_refund.rb +26 -0
  9. data/lib/remit2/operations/cancel_token.rb +16 -0
  10. data/lib/remit2/operations/discard_results.rb +16 -0
  11. data/lib/remit2/operations/fund_prepaid.rb +29 -0
  12. data/lib/remit2/operations/get_account_activity.rb +58 -0
  13. data/lib/remit2/operations/get_account_balance.rb +27 -0
  14. data/lib/remit2/operations/get_all_credit_instruments.rb +16 -0
  15. data/lib/remit2/operations/get_all_prepaid_instruments.rb +16 -0
  16. data/lib/remit2/operations/get_debt_balance.rb +21 -0
  17. data/lib/remit2/operations/get_outstanding_debt_balance.rb +20 -0
  18. data/lib/remit2/operations/get_payment_instruction.rb +19 -0
  19. data/lib/remit2/operations/get_prepaid_balance.rb +21 -0
  20. data/lib/remit2/operations/get_results.rb +25 -0
  21. data/lib/remit2/operations/get_token_by_caller.rb +23 -0
  22. data/lib/remit2/operations/get_token_usage.rb +16 -0
  23. data/lib/remit2/operations/get_tokens.rb +18 -0
  24. data/lib/remit2/operations/get_total_prepaid_liability.rb +20 -0
  25. data/lib/remit2/operations/get_transaction.rb +40 -0
  26. data/lib/remit2/operations/install_payment_instruction.rb +20 -0
  27. data/lib/remit2/operations/pay.rb +38 -0
  28. data/lib/remit2/operations/refund.rb +28 -0
  29. data/lib/remit2/operations/reserve.rb +28 -0
  30. data/lib/remit2/operations/retry_transaction.rb +16 -0
  31. data/lib/remit2/operations/settle.rb +18 -0
  32. data/lib/remit2/operations/settle_debt.rb +28 -0
  33. data/lib/remit2/operations/write_off_debt.rb +26 -0
  34. data/lib/remit2/pipeline_response.rb +52 -0
  35. data/lib/remit2/request.rb +12 -0
  36. data/lib/remit2/response.rb +54 -0
  37. data/lib/remit2/signature.rb +35 -0
  38. data/spec/spec_helper.rb +32 -0
  39. data/spec/units/cancel_subscription_and_refund_spec.rb +26 -0
  40. data/spec/units/get_pipeline_spec.rb +164 -0
  41. data/spec/units/ipn_request_spec.rb +35 -0
  42. data/spec/units/pay_spec.rb +67 -0
  43. data/spec/units/remit_spec.rb +25 -0
  44. data/spec/units/units_helper.rb +4 -0
  45. metadata +119 -0
@@ -0,0 +1,45 @@
1
+ module Remit
2
+ # Encapsulates the logic for IPN request validation and attribute retrieval.
3
+ #
4
+ # This should probably be updated to support the VerifySignature function now provided.
5
+ class IpnRequest
6
+ # Signature key name used by AmazonFPS IPNs
7
+ SIGNATURE_KEY = 'signature'
8
+
9
+ # +params+ should be your controllers request parameters.
10
+ def initialize(params, secret_key)
11
+ raise ArgumentError, "Expected the request params hash, received: #{params.inspect}" unless params.kind_of?(Hash)
12
+ @params = strip_keys_from(params, 'action', 'controller')
13
+ @supplied_signature = @params.delete(SIGNATURE_KEY)
14
+ @secret_key = secret_key
15
+ end
16
+
17
+ def valid?
18
+ return false unless @supplied_signature
19
+ generate_signature_for(@params) == @supplied_signature
20
+ end
21
+
22
+ def method_missing(method, *args) #:nodoc:
23
+ if @params.has_key?(method.to_s)
24
+ @params[method.to_s]
25
+ else
26
+ super(method, *args)
27
+ end
28
+ end
29
+
30
+ def generate_signature_for(params)
31
+ query = params.sort_by { |k,v| k.downcase }
32
+ digest = OpenSSL::Digest::Digest.new('sha1')
33
+ hmac = OpenSSL::HMAC.digest(digest, @secret_key, query.to_s)
34
+ encoded = Base64.encode64(hmac).chomp
35
+ end
36
+ private :generate_signature_for
37
+
38
+ def strip_keys_from(params, *ignore_keys)
39
+ parsed = params.dup
40
+ ignore_keys.each { |key| parsed.delete(key) }
41
+ parsed
42
+ end
43
+ private :strip_keys_from
44
+ end
45
+ end
@@ -0,0 +1,26 @@
1
+ # Updated for API Version 2008-09-17
2
+ # This operation is used by Amazon Simple Pay.
3
+ module Remit
4
+ module CancelSubscriptionAndRefund
5
+ class Request < Remit::Request
6
+ action :CancelSubscriptionAndRefund
7
+ parameter :caller_reference
8
+ parameter :cancel_reason
9
+ parameter :refund_amount, :type => Remit::RequestTypes::Amount
10
+ parameter :subscription_id, :required => true
11
+ end
12
+
13
+ class InnerResponse < Remit::BaseResponse
14
+ parameter :refund_transaction_id
15
+ end
16
+
17
+ class Response < Remit::Response
18
+ parameter :inner, :element => "CancelSubscriptionAndRefundResult", :type => InnerResponse
19
+ inner_parameters :refund_transaction_id
20
+ end
21
+
22
+ def cancel_subscription_and_refund(request = Request.new)
23
+ call(request, Response)
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,16 @@
1
+ module Remit
2
+ module CancelToken
3
+ class Request < Remit::Request
4
+ action :CancelToken
5
+ parameter :token_id, :required => true
6
+ parameter :reason_text
7
+ end
8
+
9
+ class Response < Remit::Response
10
+ end
11
+
12
+ def cancel_token(request = Request.new)
13
+ call(request, Response)
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ module Remit
2
+ module DiscardResults
3
+ class Request < Remit::Request
4
+ action :DiscardResults
5
+ parameter :transaction_ids, :required => true
6
+ end
7
+
8
+ class Response < Remit::Response
9
+ parameter :discard_errors
10
+ end
11
+
12
+ def discard_results(request = Request.new)
13
+ call(request, Response)
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,29 @@
1
+ module Remit
2
+ module FundPrepaid
3
+ class Request < Remit::Request
4
+ action :FundPrepaid
5
+ parameter :transaction_ids
6
+ parameter :caller_description
7
+ parameter :caller_reference, :required => true
8
+ parameter :caller_token_id, :required => true
9
+ parameter :charge_fee_to, :required => true
10
+ parameter :funding_amount, :type => Remit::RequestTypes::Amount, :required => true
11
+ parameter :meta_data
12
+ parameter :prepaid_instrument_id, :required => true
13
+ parameter :recipient_description
14
+ parameter :recipient_reference
15
+ parameter :sender_description
16
+ parameter :sender_reference
17
+ parameter :sender_token_id, :required => true
18
+ parameter :transaction_date
19
+ end
20
+
21
+ class Response < Remit::Response
22
+ parameter :transaction_response, :type => TransactionResponse
23
+ end
24
+
25
+ def fund_prepaid(request = Request.new)
26
+ call(request, Response)
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,58 @@
1
+ module Remit
2
+ module GetAccountActivity
3
+ class Request < Remit::Request
4
+ action :GetAccountActivity
5
+ parameter :start_date, :required => true
6
+ parameter :end_date
7
+ parameter :max_batch_size
8
+ parameter :sort_order_by_date
9
+ parameter :response_group
10
+ parameter :operation
11
+ parameter :payment_method
12
+ parameter :role
13
+ parameter :status
14
+ end
15
+
16
+ class Response < Remit::Response
17
+ class Transaction < Remit::BaseResponse
18
+ class TransactionPart < Remit::BaseResponse
19
+ parameter :account_id
20
+ parameter :role
21
+ parameter :name
22
+ parameter :reference
23
+ parameter :description
24
+ parameter :fee_paid, :type => Amount
25
+ end
26
+
27
+ parameter :caller_name
28
+ parameter :caller_token_id
29
+ parameter :caller_transaction_date, :type => :time
30
+ parameter :date_completed, :type => :time
31
+ parameter :date_received, :type => :time
32
+ parameter :error_code
33
+ parameter :error_detail
34
+ parameter :error_message
35
+ parameter :fees, :type => Amount
36
+ parameter :meta_data
37
+ parameter :operation
38
+ parameter :original_transaction_id
39
+ parameter :payment_method
40
+ parameter :recipient_name
41
+ parameter :sender_name
42
+ parameter :sender_token_id
43
+ parameter :status
44
+ parameter :transaction_amount, :type => Amount
45
+ parameter :transaction_id
46
+ parameter :transaction_parts, :collection => TransactionPart
47
+ end
48
+
49
+ parameter :response_batch_size
50
+ parameter :transactions, :collection => Transaction
51
+ parameter :start_time_for_next_transaction, :type => :time
52
+ end
53
+
54
+ def get_account_activity(request = Request.new)
55
+ call(request, Response)
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,27 @@
1
+ module Remit
2
+ module GetAccountBalance
3
+ class Request < Remit::Request
4
+ action :GetAccountBalance
5
+ end
6
+
7
+ class Response < Remit::Response
8
+ class AccountBalance < Remit::BaseResponse
9
+ class AvailableBalances < Remit::BaseResponse
10
+ parameter :disburse_balance, :type => Amount
11
+ parameter :refund_balance, :type => Amount
12
+ end
13
+
14
+ parameter :total_balance, :type => Amount
15
+ parameter :pending_in_balance, :type => Amount
16
+ parameter :pending_out_balance, :type => Amount
17
+ parameter :available_balances, :type => AvailableBalances
18
+ end
19
+
20
+ parameter :account_balance, :type => AccountBalance
21
+ end
22
+
23
+ def get_account_balance(request = Request.new)
24
+ call(request, Response)
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,16 @@
1
+ module Remit
2
+ module GetAllCreditInstruments
3
+ class Request < Remit::Request
4
+ action :GetAllCreditInstruments
5
+ parameter :instrument_status
6
+ end
7
+
8
+ class Response < Remit::Response
9
+ parameter :credit_instrument_ids
10
+ end
11
+
12
+ def get_all_credit_instruments(request = Request.new)
13
+ call(request, Response)
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ module Remit
2
+ module GetAllPrepaidInstruments
3
+ class Request < Remit::Request
4
+ action :GetAllPrepaidInstruments
5
+ parameter :instrument_status
6
+ end
7
+
8
+ class Response < Remit::Response
9
+ parameter :prepaid_instrument_ids
10
+ end
11
+
12
+ def get_all_prepaid_instruments(request = Request.new)
13
+ call(request, Response)
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,21 @@
1
+ module Remit
2
+ module GetDebtBalance
3
+ class Request < Remit::Request
4
+ action :GetDebtBalance
5
+ parameter :credit_instrument_id, :required => true
6
+ end
7
+
8
+ class Response < Remit::Response
9
+ class DebtBalance < Remit::BaseResponse
10
+ parameter :available_balance, :type => Amount
11
+ parameter :pending_out_balance, :type => Amount
12
+ end
13
+
14
+ parameter :debt_balance, :type => DebtBalance
15
+ end
16
+
17
+ def get_debt_balance(request = Request.new)
18
+ call(request, Response)
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,20 @@
1
+ module Remit
2
+ module GetOutstandingDebtBalance
3
+ class Request < Remit::Request
4
+ action :GetOutStandingDebtBalance
5
+ end
6
+
7
+ class Response < Remit::Response
8
+ class OutstandingDebtBalance < Remit::BaseResponse
9
+ parameter :outstanding_balance, :type => Amount
10
+ parameter :pending_out_balance, :type => Amount
11
+ end
12
+
13
+ parameter :outstanding_debt, :type => OutstandingDebtBalance
14
+ end
15
+
16
+ def get_outstanding_debt_balance(request = Request.new)
17
+ call(request, Response)
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,19 @@
1
+ module Remit
2
+ module GetPaymentInstruction
3
+ class Request < Remit::Request
4
+ action :GetPaymentInstruction
5
+ parameter :token_id, :required => true
6
+ end
7
+
8
+ class Response < Remit::Response
9
+ parameter :token, :type => Token
10
+ parameter :payment_instruction
11
+ parameter :account_id
12
+ parameter :token_friendly_name
13
+ end
14
+
15
+ def get_payment_instruction(request = Request.new)
16
+ call(request, Response)
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,21 @@
1
+ module Remit
2
+ module GetPrepaidBalance
3
+ class Request < Remit::Request
4
+ action :GetPrepaidBalance
5
+ parameter :prepaid_instrument_id, :required => true
6
+ end
7
+
8
+ class Response < Remit::Response
9
+ class PrepaidBalance < Remit::BaseResponse
10
+ parameter :available_balance, :type => Amount
11
+ parameter :pending_in_balance, :type => Amount
12
+ end
13
+
14
+ parameter :prepaid_balance, :type => PrepaidBalance
15
+ end
16
+
17
+ def get_prepaid_balance(request = Request.new)
18
+ call(request, Response)
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,25 @@
1
+ module Remit
2
+ module GetResults
3
+ class Request < Remit::Request
4
+ action :GetResults
5
+ parameter :operation
6
+ parameter :max_results_count
7
+ end
8
+
9
+ class Response < Remit::Response
10
+ class TransactionResults < Remit::BaseResponse
11
+ parameter :transaction_id
12
+ parameter :operation_type, :element => :operation
13
+ parameter :caller_reference
14
+ parameter :transaction_status, :element => :status
15
+ end
16
+
17
+ parameter :transaction_results, :collection => TransactionResults
18
+ parameter :number_pending, :type => :integer
19
+ end
20
+
21
+ def get_results(request = Request.new)
22
+ call(request, Response)
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,23 @@
1
+ # Updated for API Version 2008-09-17
2
+ module Remit
3
+ module GetTokenByCaller
4
+ class Request < Remit::Request
5
+ action :GetTokenByCaller
6
+ parameter :caller_reference
7
+ parameter :token_id
8
+ end
9
+
10
+ class InnerResponse < Remit::BaseResponse
11
+ parameter :token, :type => Token
12
+ end
13
+
14
+ class Response < Remit::Response
15
+ parameter :inner, :element => "GetTokenByCallerResult", :type => InnerResponse
16
+ inner_parameters :token
17
+ end
18
+
19
+ def get_token_by_caller(request = Request.new)
20
+ call(request, Response)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,16 @@
1
+ module Remit
2
+ module GetTokenUsage
3
+ class Request < Remit::Request
4
+ action :GetTokenUsage
5
+ parameter :token_id, :required => true
6
+ end
7
+
8
+ class Response < Remit::Response
9
+ parameter :token_usage_limits, :type => TokenUsageLimit
10
+ end
11
+
12
+ def get_token_usage(request = Request.new)
13
+ call(request, Response)
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,18 @@
1
+ module Remit
2
+ module GetTokens
3
+ class Request < Remit::Request
4
+ action :GetTokens
5
+ parameter :caller_reference
6
+ parameter :token_friendly_name
7
+ parameter :token_status
8
+ end
9
+
10
+ class Response < Remit::Response
11
+ parameter :tokens, :collection => Token
12
+ end
13
+
14
+ def get_tokens(request = Request.new)
15
+ call(request, Response)
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,20 @@
1
+ module Remit
2
+ module GetTotalPrepaidLiability
3
+ class Request < Remit::Request
4
+ action :GetTotalPrepaidLiability
5
+ end
6
+
7
+ class Response < Remit::Response
8
+ class OutstandingPrepaidLiability < Remit::BaseResponse
9
+ parameter :outstanding_balance, :type => Amount
10
+ parameter :panding_in_balance, :type => Amount
11
+ end
12
+
13
+ parameter :outstanding_prepaid_liability, :type => OutstandingPrepaidLiability
14
+ end
15
+
16
+ def get_total_prepaid_liability(request = Request.new)
17
+ call(request, Response)
18
+ end
19
+ end
20
+ end