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
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Micah Wedemeyer
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,26 @@
1
+ Remit2
2
+ ======
3
+
4
+ This API provides access to the Amazon Flexible Payment Service (FPS), using the
5
+ 2008-09-17 version of the API and Signature Version 2.
6
+
7
+ Remit2 is forked from the original Remit library written by Tyler Hunt, which was
8
+ built for the 2007-08-01 FPS API version and Signature Version 1. Due to serious
9
+ incompatibilities between the two API versions, I decided to fork the library
10
+ and give up backward compatibility with the older API version.
11
+
12
+ Working with Remit2 should very closely resemble working with Remit, with the exception
13
+ of the changed API parameter and function names. However, due to these same changes, it's
14
+ almost never the case that Remit2 can be dropped in place of Remit without some changes
15
+ to the client code. For example, the *Amount* parameter in the *Pay* operation has
16
+ changed, and nearly every FPS client application will need to use *Pay*.
17
+
18
+ **WARNING** - This gem should be considered very volatile and incomplete. I (Micah)
19
+ am not looking to write a full wrapper around the FPS API. My only goal is to get it
20
+ working for my needs. Therefore, many of the functions/API calls will be broken.
21
+ Patches are welcome if you want to make additions.
22
+
23
+ I have explicitly marked some files as "# Updated for API Version 2008-09-17". If
24
+ you don't see this near the top of the file, assume that it doesn't work!
25
+
26
+ Copyright (c) 2010 Micah Wedemeyer, released under the MIT license
@@ -0,0 +1,119 @@
1
+ require 'uri'
2
+ require 'openssl'
3
+ require 'openssl/digest'
4
+ require 'net/https'
5
+ require 'date'
6
+ require 'base64'
7
+ require 'erb'
8
+ require 'cgi'
9
+
10
+ require 'rubygems'
11
+
12
+ gem 'relax', '0.0.7'
13
+ require 'relax'
14
+
15
+ require 'remit2/signature'
16
+ require 'remit2/request'
17
+ require 'remit2/response'
18
+ require 'remit2/data_types'
19
+ require 'remit2/error_codes'
20
+ require 'remit2/ipn_request'
21
+ require 'remit2/get_pipeline'
22
+ require 'remit2/pipeline_response'
23
+
24
+ require 'remit2/operations/cancel_subscription_and_refund'
25
+ require 'remit2/operations/cancel_token'
26
+ require 'remit2/operations/discard_results'
27
+ require 'remit2/operations/fund_prepaid'
28
+ require 'remit2/operations/get_account_activity'
29
+ require 'remit2/operations/get_account_balance'
30
+ require 'remit2/operations/get_all_credit_instruments'
31
+ require 'remit2/operations/get_all_prepaid_instruments'
32
+ require 'remit2/operations/get_debt_balance'
33
+ require 'remit2/operations/get_outstanding_debt_balance'
34
+ require 'remit2/operations/get_payment_instruction'
35
+ require 'remit2/operations/get_prepaid_balance'
36
+ require 'remit2/operations/get_results'
37
+ require 'remit2/operations/get_token_by_caller'
38
+ require 'remit2/operations/get_token_usage'
39
+ require 'remit2/operations/get_tokens'
40
+ require 'remit2/operations/get_total_prepaid_liability'
41
+ require 'remit2/operations/get_transaction'
42
+ require 'remit2/operations/install_payment_instruction'
43
+ require 'remit2/operations/pay'
44
+ require 'remit2/operations/refund'
45
+ require 'remit2/operations/reserve'
46
+ require 'remit2/operations/retry_transaction'
47
+ require 'remit2/operations/settle'
48
+ require 'remit2/operations/settle_debt'
49
+ require 'remit2/operations/write_off_debt'
50
+
51
+ module Remit
52
+ class API < Relax::Service
53
+ include Signature
54
+
55
+ include CancelSubscriptionAndRefund
56
+ include CancelToken
57
+ include DiscardResults
58
+ include FundPrepaid
59
+ include GetAccountActivity
60
+ include GetAccountBalance
61
+ include GetAllCreditInstruments
62
+ include GetAllPrepaidInstruments
63
+ include GetDebtBalance
64
+ include GetOutstandingDebtBalance
65
+ include GetPaymentInstruction
66
+ include GetPipeline
67
+ include GetPrepaidBalance
68
+ include GetResults
69
+ include GetTokenUsage
70
+ include GetTokens
71
+ include GetTokenByCaller
72
+ include GetTotalPrepaidLiability
73
+ include GetTransaction
74
+ include InstallPaymentInstruction
75
+ include Pay
76
+ include Refund
77
+ include Reserve
78
+ include RetryTransaction
79
+ include Settle
80
+ include SettleDebt
81
+ include WriteOffDebt
82
+
83
+ API_ENDPOINT = 'https://fps.amazonaws.com/'
84
+ API_SANDBOX_ENDPOINT = 'https://fps.sandbox.amazonaws.com/'
85
+ PIPELINE_URL = 'https://authorize.payments.amazon.com/cobranded-ui/actions/start'
86
+ PIPELINE_SANDBOX_URL = 'https://authorize.payments-sandbox.amazon.com/cobranded-ui/actions/start'
87
+ API_VERSION = "2008-09-17"
88
+ SIGNATURE_VERSION = 2
89
+ SIGNATURE_METHOD = "HmacSHA256"
90
+
91
+ attr_reader :access_key
92
+ attr_reader :secret_key
93
+ attr_reader :pipeline_url
94
+
95
+ def initialize(access_key, secret_key, sandbox=false)
96
+ @access_key = access_key
97
+ @secret_key = secret_key
98
+ @pipeline_url = sandbox ? PIPELINE_SANDBOX_URL : PIPELINE_URL
99
+
100
+ super(sandbox ? API_SANDBOX_ENDPOINT : API_ENDPOINT)
101
+ end
102
+
103
+ def default_query
104
+ Relax::Query.new({
105
+ :AWSAccessKeyId => @access_key,
106
+ :SignatureVersion => SIGNATURE_VERSION,
107
+ :SignatureMethod => SIGNATURE_METHOD,
108
+ :Version => API_VERSION,
109
+ :Timestamp => Time.now.utc.strftime('%Y-%m-%dT%H:%M:%SZ')
110
+ })
111
+ end
112
+
113
+ def query(request)
114
+ query = super
115
+ query[:Signature] = sign(@secret_key, @endpoint, "GET", query)
116
+ query
117
+ end
118
+ end
119
+ end
@@ -0,0 +1,142 @@
1
+ module Remit
2
+ class Amount < BaseResponse
3
+ parameter :currency_code
4
+ parameter :amount, :type => :float
5
+ end
6
+
7
+ class TemporaryDeclinePolicy < BaseResponse
8
+ parameter :temporary_decline_policy_type
9
+ parameter :implicit_retry_timeout_in_mins
10
+ end
11
+
12
+ class DescriptorPolicy < BaseResponse
13
+ parameter :soft_descriptor_type
14
+ parameter :CS_number_of
15
+ end
16
+
17
+ class ChargeFeeTo
18
+ CALLER = 'Caller'
19
+ RECIPIENT = 'Recipient'
20
+ end
21
+
22
+ class Error < BaseResponse
23
+ parameter :code
24
+ parameter :message
25
+ end
26
+
27
+ class InstrumentStatus
28
+ ALL = 'ALL'
29
+ ACTIVE = 'Active'
30
+ INACTIVE = 'Inactive'
31
+ end
32
+
33
+ class PaymentMethods
34
+ BALANCE_TRANSFER = 'abt'
35
+ BANK_ACCOUNT = 'ach'
36
+ CREDIT_CARD = 'credit card'
37
+ PREPAID = 'prepaid'
38
+ DEBT = 'Debt'
39
+ end
40
+
41
+ class Token < BaseResponse
42
+ parameter :token_id
43
+ parameter :friendly_name
44
+ parameter :status
45
+ parameter :date_installed, :type => :time
46
+ parameter :caller_installed
47
+ parameter :caller_reference
48
+ parameter :token_type
49
+ parameter :old_token_id
50
+ parameter :payment_reason
51
+
52
+ class TokenStatus
53
+ ACTIVE = 'Active'
54
+ INACTIVE = 'Inactive'
55
+ end
56
+ end
57
+
58
+ class TokenUsageLimit < BaseResponse
59
+ parameter :count
60
+ parameter :limit
61
+ parameter :last_reset_amount
62
+ parameter :last_reset_count
63
+ parameter :last_reset_time_stamp
64
+ end
65
+
66
+ class TransactionResponse < BaseResponse
67
+ parameter :transaction_id
68
+ parameter :status
69
+ parameter :status_detail
70
+ parameter :new_sender_token_usage, :type => TokenUsageLimit
71
+
72
+ %w(reserved success failure initiated reinitiated temporary_decline).each do |status_name|
73
+ define_method("#{status_name}?") do
74
+ self.status == Remit::TransactionStatus.const_get(status_name.sub('_', '').upcase)
75
+ end
76
+ end
77
+ end
78
+
79
+ class RefundResult < BaseResponse
80
+ parameter :transaction_id
81
+ parameter :transaction_status
82
+ end
83
+
84
+ class TransactionStatus
85
+ RESERVED = 'Reserved'
86
+ SUCCESS = 'Success'
87
+ FAILURE = 'Failure'
88
+ INITIATED = 'Initiated'
89
+ REINITIATED = 'Reinitiated'
90
+ TEMPORARYDECLINE = 'TemporaryDecline'
91
+ end
92
+
93
+ class TokenType
94
+ SINGLE_USE = 'SingleUse'
95
+ MULTI_USE = 'MultiUse'
96
+ RECURRING = 'Recurring'
97
+ UNRESTRICTED = 'Unrestricted'
98
+ end
99
+
100
+ class PipelineName
101
+ SINGLE_USE = 'SingleUse'
102
+ MULTI_USE = 'MultiUse'
103
+ RECURRING = 'Recurring'
104
+ RECIPIENT = 'Recipient'
105
+ SETUP_PREPAID = 'SetupPrepaid'
106
+ SETUP_POSTPAID = 'SetupPostpaid'
107
+ end
108
+
109
+ class PipelineStatusCode
110
+ CALLER_EXCEPTION = 'CE' # problem with your code
111
+ SYSTEM_ERROR = 'SE' # system error, try again
112
+ SUCCESS_ABT = 'SA' # successful payment with Amazon balance
113
+ SUCCESS_ACH = 'SB' # successful payment with bank transfer
114
+ SUCCESS_CC = 'SC' # successful payment with credit card
115
+ ABORTED = 'A' # user aborted payment
116
+ PAYMENT_METHOD_MISMATCH = 'PE' # user does not have payment method requested
117
+ PAYMENT_METHOD_UNSUPPORTED = 'NP' # account doesn't support requested payment method
118
+ INVALID_CALLER = 'NM' # you are not a valid 3rd party caller to the transaction
119
+ SUCCESS_RECIPIENT_TOKEN_INSTALLED = 'SR'
120
+ end
121
+
122
+ module RequestTypes
123
+ class Amount < Remit::Request
124
+ parameter :value
125
+ parameter :currency_code
126
+ end
127
+
128
+ class DescriptorPolicy < Remit::Request
129
+ parameter :soft_descriptor_type
130
+ parameter :CS_number_of
131
+ end
132
+ end
133
+
134
+ class Operation
135
+ PAY = "Pay"
136
+ REFUND = "Refund"
137
+ SETTLE = "Settle"
138
+ SETTLE_DEBT = "SettleDebt"
139
+ WRITE_OFF_DEBT = "WriteOffDebt"
140
+ FUND_PREPAID = "FundPrepaid"
141
+ end
142
+ end
@@ -0,0 +1,118 @@
1
+ # Scraped and categorized from http://docs.amazonwebservices.com/AmazonFPS/\
2
+ # 2007-01-08/FPSDeveloperGuide/index.html?ErrorCodesTable.html. You can use
3
+ # these categories to specify default error handling in your application such
4
+ # as asking users to retry or sending an exception email.
5
+ module Remit::ErrorCodes
6
+ class << self
7
+ def sender_error?(code)
8
+ SENDER.include? code.to_sym
9
+ end
10
+
11
+ def recipient_error?(code)
12
+ RECIPIENT.include? code.to_sym
13
+ end
14
+
15
+ def caller_error?(code)
16
+ CALLER.include?(code.to_sym)
17
+ end
18
+
19
+ def amazon_error?(code)
20
+ AMAZON.include? code.to_sym
21
+ end
22
+
23
+ def api_error?(code)
24
+ API.include? code.to_sym
25
+ end
26
+
27
+ def unknown_error?(code)
28
+ UNKNOWN.include? code.to_sym
29
+ end
30
+ end
31
+
32
+ SENDER = [
33
+ :InactiveAccount_Sender, # The sender's account is in suspended or closed state.
34
+ :InactiveInstrument, # The payment instrument used for this transaction is no longer active.
35
+ :InstrumentExpired, # The prepaid or the postpaid instrument has expired.
36
+ :InstrumentNotActive, # The prepaid or postpaid instrument used in the transaction is not active.
37
+ :InvalidAccountState_Sender, # Sender account cannot participate in the transaction.
38
+ :InvalidInstrumentForAccountType, # The sender account can use only credit cards
39
+ :InvalidInstrumentState, # The prepaid or credit instrument should be active
40
+ :InvalidTokenId_Sender, # The send token specified is either invalid or canceled or the token is not active.
41
+ :PaymentInstrumentNotCC, # The payment method specified in the transaction is not a credit card. You can only use a credit card for this transaction.
42
+ :PaymentInstrumentMissing, # There needs to be a payment instrument defined in the token which defines the payment method.
43
+ :TokenNotActive_Sender, # The sender token is canceled.
44
+ :UnverifiedAccount_Sender, # The sender's account must have a verified U.S. credit card or a verified U.S bank account before this transaction can be initiated
45
+ :UnverifiedBankAccount, # A verified bank account should be used for this transaction
46
+ :UnverifiedEmailAddress_Sender, # The sender account must have a verified e-mail address for this payment
47
+ ]
48
+
49
+ RECIPIENT = [
50
+ :InactiveAccount_Recipient, # The recipient's account is in suspended or closed state.
51
+ :InvalidAccountState_Recipient, # Recipient account cannot participate in the transaction
52
+ :InvalidRecipientRoleForAccountType, # The recipient account is not allowed to receive payments
53
+ :InvalidRecipientForCCTransaction, # This account cannot receive credit card payments.
54
+ :InvalidTokenId_Recipient, # The recipient token specified is either invalid or canceled.
55
+ :TokenNotActive_Recipient, # The recipient token is canceled.
56
+ :UnverifiedAccount_Recipient, # The recipient's account must have a verified bank account or a credit card before this transaction can be initiated.
57
+ :UnverifiedEmailAddress_Recipient, # The recipient account must have a verified e-mail address for receiving payments.
58
+ ]
59
+
60
+ CALLER = [
61
+ :InactiveAccount_Caller, # The caller's account is in suspended or closed state.
62
+ :InvalidAccountState_Caller, # The caller account cannot participate in the transaction
63
+ :InvalidTokenId_Caller, # The caller token specified is either invalid or canceled or the specified token is not active.
64
+ :TokenNotActive_Caller, # The caller token is canceled.
65
+ :UnverifiedEmailAddress_Caller, # The caller account must have a verified e-mail address
66
+ ]
67
+
68
+ AMAZON = [
69
+ :InternalError # A retriable error that happens due to some transient problem in the system.
70
+ ]
71
+
72
+ # bad syntax or logic
73
+ API = [
74
+ :AmountOutOfRange, # The transaction amount is more than the allowed range.
75
+ :BadRule, # One of the GK constructs is not well defined
76
+ :CannotSpecifyUsageForSingleUseToken, # Token usages cannot be specified for a single use token.
77
+ :ConcurrentModification, # A retriable error can happen due to concurrent modification of data by two processes.
78
+ :DuplicateRequest, # A different request associated with this caller reference already exists.
79
+ :IncompatibleTokens, # The transaction could not be completed because the tokens have incompatible payment instructions.
80
+ :InstrumentAccessDenied, # The external calling application is not the recipient for this postpaid or prepaid instrument. The caller should be the liability holder
81
+ :InvalidCallerReference, # The CallerReferece does not have a token associated with it.
82
+ :InvalidDateRange, # The end date specified is before the start date or the start date is in the future.
83
+ :InvalidEvent, # The event specified was not subscribed using the SubscribeForCallerNotification operation.
84
+ :InvalidParams, # One or more parameters in the request is invalid.
85
+ :InvalidPaymentInstrument, # The payment method used in the transaction is invalid.
86
+ :InvalidPaymentMethod, # Payment method specified in the GK construct is invalid.
87
+ :InvalidSenderRoleForAccountType, # This token cannot be used for this operation.
88
+ :InvalidTokenId, # The token that you are trying to cancel was not installed by you.
89
+ :InvalidTokenType, # Invalid operation performed on the token. Example, getting the token usage information on a single use token.
90
+ :InvalidTransactionId, # The specified transaction could not be found or the caller did not execute the transaction or this is not a Pay or Reserve call.
91
+ :InvalidTransactionState, # The transaction is not completed or it has been temporarily failed.
92
+ :InvalidUsageDuration, # The duration cannot be less than one hour.
93
+ :InvalidUsageLimitCount, # The usage count is null or empty.
94
+ :InvalidUsageStartTime, # The start time specified for the token is not valid.
95
+ :InvalidUsageType, # The usage type specified is invalid.
96
+ :OriginalTransactionIncomplete, # The original transaction is still in progress.
97
+ :OriginalTransactionFailed, # The original transaction has failed
98
+ :PaymentMethodNotDefined, # Payment method is not defined in the transaction.
99
+ :RefundAmountExceeded, # The refund amount is more than the refundable amount.
100
+ :SameTokenIdUsedMultipleTimes, # This token is already used in earlier transactions.
101
+ :SenderNotOriginalRecipient, # The sender in the refund transaction is not the recipient of the original transaction.
102
+ :SettleAmountGreaterThanReserveAmount, # The amount being settled is greater than the reserved amount.
103
+ :TransactionDenied, # This transaction is not allowed.
104
+ :TransactionExpired, # Returned when the Caller attempts to explicitly retry a transaction that is temporarily declined and is in queue for implicit retry.
105
+ :TransactionFullyRefundedAlready, # The complete refund for this transaction is already completed
106
+ :TransactionTypeNotRefundable, # You cannot refund this transaction.
107
+ :TokenAccessDenied, # Permission is denied to cancel the token.
108
+ :TokenUsageError, # The token usage limit is exceeded.
109
+ :UsageNotDefined, # For a multi-use token or a recurring token the usage limits are not specified in the GateKeeper text.
110
+ ]
111
+
112
+ # these errors don't specify who is at fault
113
+ UNKNOWN = [
114
+ :InvalidAccountState, # The account is either suspended or closed. Payment instructions cannot be installed on this account.
115
+ :InsufficientBalance, # The sender, caller, or recipient's account balance has insufficient funds to complete the transaction.
116
+ :AccountLimitsExceeded, # The spending or the receiving limit on the account is exceeded
117
+ ]
118
+ end
@@ -0,0 +1,195 @@
1
+ # Updated for API Version 2008-09-17
2
+ module Remit
3
+ module GetPipeline
4
+ class Pipeline
5
+ include Signature
6
+
7
+ @parameters = []
8
+ attr_reader :parameters
9
+
10
+ class << self
11
+ # Create the parameters hash for the subclass.
12
+ def inherited(subclass) #:nodoc:
13
+ subclass.instance_variable_set('@parameters', [])
14
+ end
15
+
16
+ def parameter(name)
17
+ attr_accessor name
18
+ @parameters << name
19
+ end
20
+
21
+ def convert_key(key)
22
+ key.to_s.gsub(/_(.)/) { $1.upcase }.to_sym
23
+ end
24
+
25
+ # Returns a hash of all of the parameters for this request, including
26
+ # those that are inherited.
27
+ def parameters #:nodoc:
28
+ (superclass.respond_to?(:parameters) ? superclass.parameters : []) + @parameters
29
+ end
30
+ end
31
+
32
+ attr_reader :api
33
+
34
+ parameter :pipeline_name
35
+ parameter :return_url
36
+ parameter :caller_key
37
+ parameter :version
38
+ parameter :address_name
39
+ parameter :address_line_1
40
+ parameter :address_line_2
41
+ parameter :city
42
+ parameter :state
43
+ parameter :zip
44
+ parameter :country
45
+ parameter :phone_number
46
+
47
+ def initialize(api, options)
48
+ @api = api
49
+
50
+ options.each do |k,v|
51
+ self.send("#{k}=", v)
52
+ end
53
+ end
54
+
55
+ def url
56
+ uri = URI.parse(@api.pipeline_url)
57
+
58
+ query = {
59
+ "signatureVersion" => "2",
60
+ "signatureMethod" => "HmacSHA256",
61
+ "version" => "2009-01-09"
62
+ }
63
+
64
+ self.class.parameters.each do |p|
65
+ val = self.send(p)
66
+
67
+ # Convert Time values to seconds from Epoch
68
+ val = val.to_i if val.is_a?(Time)
69
+
70
+ query[self.class.convert_key(p.to_s)] = val
71
+ end
72
+
73
+ # Remove any unused optional parameters
74
+ query.reject! { |key, value| value.nil? || (value.is_a?(String) && value.empty?) }
75
+
76
+ signature = sign(@api.secret_key, @api.pipeline_url, "GET", query)
77
+ uri.query = query.merge('signature' => signature).collect {|k,v| "#{CGI::escape(k.to_s)}=#{CGI::escape(v.to_s)}"}.join("&")
78
+
79
+ uri.to_s
80
+ end
81
+ end
82
+
83
+ class SingleUsePipeline < Pipeline
84
+ parameter :caller_reference
85
+ parameter :payment_reason
86
+ parameter :payment_method
87
+ parameter :transaction_amount
88
+ parameter :recipient_token
89
+
90
+ def pipeline_name
91
+ Remit::PipelineName::SINGLE_USE
92
+ end
93
+ end
94
+
95
+ class MultiUsePipeline < Pipeline
96
+ parameter :caller_reference
97
+ parameter :payment_reason
98
+ parameter :recipient_token_list
99
+ parameter :amount_type
100
+ parameter :transaction_amount
101
+ parameter :validity_start
102
+ parameter :validity_expiry
103
+ parameter :payment_method
104
+ parameter :global_amount_limit
105
+ parameter :usage_limit_type_1
106
+ parameter :usage_limit_period_1
107
+ parameter :usage_limit_value_1
108
+ parameter :usage_limit_type_2
109
+ parameter :usage_limit_period_2
110
+ parameter :usage_limit_value_2
111
+ parameter :is_recipient_cobranding
112
+
113
+ def pipeline_name
114
+ Remit::PipelineName::MULTI_USE
115
+ end
116
+ end
117
+
118
+ class RecipientPipeline < Pipeline
119
+ parameter :caller_reference
120
+ parameter :validity_start # Time or seconds from Epoch
121
+ parameter :validity_expiry # Time or seconds from Epoch
122
+ parameter :payment_method
123
+ parameter :recipient_pays_fee
124
+ parameter :caller_reference_refund
125
+ parameter :max_variable_fee
126
+ parameter :max_fixed_fee
127
+
128
+ def pipeline_name
129
+ Remit::PipelineName::RECIPIENT
130
+ end
131
+ end
132
+
133
+ class RecurringUsePipeline < Pipeline
134
+ parameter :caller_reference
135
+ parameter :payment_reason
136
+ parameter :recipient_token
137
+ parameter :transaction_amount
138
+ parameter :validity_start # Time or seconds from Epoch
139
+ parameter :validity_expiry # Time or seconds from Epoch
140
+ parameter :payment_method
141
+ parameter :recurring_period
142
+
143
+ def pipeline_name
144
+ Remit::PipelineName::RECURRING
145
+ end
146
+ end
147
+
148
+ class PostpaidPipeline < Pipeline
149
+ parameter :caller_reference_sender
150
+ parameter :caller_reference_settlement
151
+ parameter :payment_reason
152
+ parameter :payment_method
153
+ parameter :validity_start # Time or seconds from Epoch
154
+ parameter :validity_expiry # Time or seconds from Epoch
155
+ parameter :credit_limit
156
+ parameter :global_amount_limit
157
+ parameter :usage_limit_type1
158
+ parameter :usage_limit_period1
159
+ parameter :usage_limit_value1
160
+ parameter :usage_limit_type2
161
+ parameter :usage_limit_period2
162
+ parameter :usage_limit_value2
163
+
164
+ def pipeline_name
165
+ Remit::PipelineName::SETUP_POSTPAID
166
+ end
167
+ end
168
+
169
+ def get_single_use_pipeline(options)
170
+ self.get_pipeline(SingleUsePipeline, options)
171
+ end
172
+
173
+ def get_multi_use_pipeline(options)
174
+ self.get_pipeline(MultiUsePipeline, options)
175
+ end
176
+
177
+ def get_recipient_pipeline(options)
178
+ self.get_pipeline(RecipientPipeline, options)
179
+ end
180
+
181
+ def get_recurring_use_pipeline(options)
182
+ self.get_pipeline(RecurringUsePipeline, options)
183
+ end
184
+
185
+ def get_postpaid_pipeline(options)
186
+ self.get_pipeline(PostpaidPipeline, options)
187
+ end
188
+
189
+ def get_pipeline(pipeline_subclass, options)
190
+ pipeline = pipeline_subclass.new(self, {
191
+ :caller_key => @access_key
192
+ }.merge(options))
193
+ end
194
+ end
195
+ end