ianlevesque-remit 0.0.6
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.
- data/LICENSE +20 -0
- data/README.markdown +91 -0
- data/lib/remit/common.rb +88 -0
- data/lib/remit/data_types.rb +166 -0
- data/lib/remit/error_codes.rb +118 -0
- data/lib/remit/get_pipeline.rb +195 -0
- data/lib/remit/ipn_request.rb +49 -0
- data/lib/remit/operations/cancel_token.rb +18 -0
- data/lib/remit/operations/discard_results.rb +18 -0
- data/lib/remit/operations/fund_prepaid.rb +31 -0
- data/lib/remit/operations/get_account_activity.rb +60 -0
- data/lib/remit/operations/get_account_balance.rb +29 -0
- data/lib/remit/operations/get_all_credit_instruments.rb +18 -0
- data/lib/remit/operations/get_all_prepaid_instruments.rb +18 -0
- data/lib/remit/operations/get_debt_balance.rb +23 -0
- data/lib/remit/operations/get_outstanding_debt_balance.rb +22 -0
- data/lib/remit/operations/get_payment_instruction.rb +21 -0
- data/lib/remit/operations/get_prepaid_balance.rb +23 -0
- data/lib/remit/operations/get_results.rb +27 -0
- data/lib/remit/operations/get_token_by_caller.rb +19 -0
- data/lib/remit/operations/get_token_usage.rb +18 -0
- data/lib/remit/operations/get_tokens.rb +20 -0
- data/lib/remit/operations/get_total_prepaid_liability.rb +22 -0
- data/lib/remit/operations/get_transaction.rb +42 -0
- data/lib/remit/operations/install_payment_instruction.rb +22 -0
- data/lib/remit/operations/pay.rb +35 -0
- data/lib/remit/operations/refund.rb +36 -0
- data/lib/remit/operations/reserve.rb +30 -0
- data/lib/remit/operations/retry_transaction.rb +18 -0
- data/lib/remit/operations/settle.rb +20 -0
- data/lib/remit/operations/settle_debt.rb +30 -0
- data/lib/remit/operations/subscribe_for_caller_notification.rb +18 -0
- data/lib/remit/operations/unsubscribe_for_caller_notification.rb +17 -0
- data/lib/remit/operations/write_off_debt.rb +28 -0
- data/lib/remit/pipeline_response.rb +53 -0
- data/lib/remit.rb +133 -0
- data/spec/integrations/get_account_activity_spec.rb +36 -0
- data/spec/integrations/get_tokens_spec.rb +38 -0
- data/spec/integrations/integrations_helper.rb +8 -0
- data/spec/spec_helper.rb +36 -0
- data/spec/units/get_pipeline_spec.rb +165 -0
- data/spec/units/get_results_spec.rb +49 -0
- data/spec/units/ipn_request_spec.rb +32 -0
- data/spec/units/pay_spec.rb +133 -0
- data/spec/units/units_helper.rb +4 -0
- metadata +106 -0
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'remit/common'
|
2
|
+
|
3
|
+
module Remit
|
4
|
+
module SettleDebt
|
5
|
+
class Request < Remit::Request
|
6
|
+
action :SettleDebt
|
7
|
+
parameter :caller_description
|
8
|
+
parameter :caller_reference, :required => true
|
9
|
+
parameter :caller_token_id, :required => true
|
10
|
+
parameter :charge_fee_to, :required => true
|
11
|
+
parameter :credit_instrument_id, :required => true
|
12
|
+
parameter :meta_data
|
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 :settlement_amount, :type => Remit::RequestTypes::Amount, :required => true
|
19
|
+
parameter :transaction_date
|
20
|
+
end
|
21
|
+
|
22
|
+
class Response < Remit::Response
|
23
|
+
parameter :transaction_response, :type => TransactionResponse
|
24
|
+
end
|
25
|
+
|
26
|
+
def settle_debt(request = Request.new)
|
27
|
+
call(request, Response)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'remit/common'
|
2
|
+
|
3
|
+
module Remit
|
4
|
+
module SubscribeForCallerNotification
|
5
|
+
class Request < Remit::Request
|
6
|
+
action :SubscribeForCallerNotification
|
7
|
+
parameter :notification_operation_name, :required => true
|
8
|
+
parameter :web_service_api_url, :required => true
|
9
|
+
end
|
10
|
+
|
11
|
+
class Response < Remit::Response
|
12
|
+
end
|
13
|
+
|
14
|
+
def subscribe_for_caller_notification(request = Request.new)
|
15
|
+
call(request, Response)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'remit/common'
|
2
|
+
|
3
|
+
module Remit
|
4
|
+
module UnsubscribeForCallerNotification
|
5
|
+
class Request < Remit::Request
|
6
|
+
action :UnSubscribeForCallerNotification
|
7
|
+
parameter :notification_operation_name, :required => true
|
8
|
+
end
|
9
|
+
|
10
|
+
class Response < Remit::Response
|
11
|
+
end
|
12
|
+
|
13
|
+
def unsubscribe_for_caller_notification(request = Request.new)
|
14
|
+
call(request, Response)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'remit/common'
|
2
|
+
|
3
|
+
module Remit
|
4
|
+
module WriteOffDebt
|
5
|
+
class Request < Remit::Request
|
6
|
+
action :WriteOffDebt
|
7
|
+
parameter :caller_token_id, :required => true
|
8
|
+
parameter :credit_instrument_id, :required => true
|
9
|
+
parameter :adjustment_amount, :required => true
|
10
|
+
parameter :transaction_date
|
11
|
+
parameter :sender_reference
|
12
|
+
parameter :caller_reference, :required => true
|
13
|
+
parameter :recipient_reference
|
14
|
+
parameter :sender_description
|
15
|
+
parameter :recipient_description
|
16
|
+
parameter :caller_description
|
17
|
+
parameter :meta_data
|
18
|
+
end
|
19
|
+
|
20
|
+
class Response < Remit::Response
|
21
|
+
parameter :transaction_response, :type => TransactionResponse
|
22
|
+
end
|
23
|
+
|
24
|
+
def write_off_debt(request = Request.new)
|
25
|
+
call(request, Response)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module Remit
|
2
|
+
class PipelineResponse
|
3
|
+
def initialize(uri, secret_key)
|
4
|
+
@uri = URI.parse(uri)
|
5
|
+
@secret_key = secret_key
|
6
|
+
end
|
7
|
+
|
8
|
+
# Returns +true+ if the response is correctly signed (awsSignature).
|
9
|
+
#
|
10
|
+
#--
|
11
|
+
# The unescape_value method is used here because the awsSignature value
|
12
|
+
# pulled from the request is filtered through the same method.
|
13
|
+
#++
|
14
|
+
def valid?
|
15
|
+
return false unless given_signature
|
16
|
+
Relax::Query.unescape_value(correct_signature) == given_signature
|
17
|
+
end
|
18
|
+
|
19
|
+
# Returns +true+ if the response returns a successful state.
|
20
|
+
def successful?
|
21
|
+
[
|
22
|
+
Remit::PipelineStatusCode::SUCCESS_ABT,
|
23
|
+
Remit::PipelineStatusCode::SUCCESS_ACH,
|
24
|
+
Remit::PipelineStatusCode::SUCCESS_CC,
|
25
|
+
Remit::PipelineStatusCode::SUCCESS_NO_CHANGE,
|
26
|
+
Remit::PipelineStatusCode::SUCCESS_RECIPIENT_TOKEN_INSTALLED
|
27
|
+
].include?(request_query[:status])
|
28
|
+
end
|
29
|
+
|
30
|
+
def method_missing(method, *args) #:nodoc:
|
31
|
+
if request_query.has_key?(method.to_sym)
|
32
|
+
request_query[method.to_sym]
|
33
|
+
else
|
34
|
+
super
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def request_query(reload = false)
|
39
|
+
@query ||= Remit::SignedQuery.parse(@uri, @secret_key, @uri.query || '')
|
40
|
+
end
|
41
|
+
private :request_query
|
42
|
+
|
43
|
+
def given_signature
|
44
|
+
request_query[:awsSignature]
|
45
|
+
end
|
46
|
+
private :given_signature
|
47
|
+
|
48
|
+
def correct_signature
|
49
|
+
Remit::SignedQuery.new(@uri.path, @secret_key, request_query).sign
|
50
|
+
end
|
51
|
+
private :correct_signature
|
52
|
+
end
|
53
|
+
end
|
data/lib/remit.rb
ADDED
@@ -0,0 +1,133 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__)) unless $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
2
|
+
|
3
|
+
require 'openssl'
|
4
|
+
require 'net/https'
|
5
|
+
require 'uri'
|
6
|
+
require 'date'
|
7
|
+
require 'base64'
|
8
|
+
require 'erb'
|
9
|
+
|
10
|
+
require 'rubygems'
|
11
|
+
|
12
|
+
gem 'relax', '0.0.7'
|
13
|
+
require 'relax'
|
14
|
+
|
15
|
+
require 'remit/common'
|
16
|
+
require 'remit/data_types'
|
17
|
+
require 'remit/error_codes'
|
18
|
+
require 'remit/ipn_request'
|
19
|
+
require 'remit/get_pipeline'
|
20
|
+
require 'remit/pipeline_response'
|
21
|
+
|
22
|
+
require 'remit/operations/cancel_token'
|
23
|
+
require 'remit/operations/discard_results'
|
24
|
+
require 'remit/operations/fund_prepaid'
|
25
|
+
require 'remit/operations/get_account_activity'
|
26
|
+
require 'remit/operations/get_account_balance'
|
27
|
+
require 'remit/operations/get_all_credit_instruments'
|
28
|
+
require 'remit/operations/get_all_prepaid_instruments'
|
29
|
+
require 'remit/operations/get_debt_balance'
|
30
|
+
require 'remit/operations/get_outstanding_debt_balance'
|
31
|
+
require 'remit/operations/get_payment_instruction'
|
32
|
+
require 'remit/operations/get_prepaid_balance'
|
33
|
+
require 'remit/operations/get_results'
|
34
|
+
require 'remit/operations/get_token_by_caller'
|
35
|
+
require 'remit/operations/get_token_usage'
|
36
|
+
require 'remit/operations/get_tokens'
|
37
|
+
require 'remit/operations/get_total_prepaid_liability'
|
38
|
+
require 'remit/operations/get_transaction'
|
39
|
+
require 'remit/operations/install_payment_instruction'
|
40
|
+
require 'remit/operations/pay'
|
41
|
+
require 'remit/operations/refund'
|
42
|
+
require 'remit/operations/reserve'
|
43
|
+
require 'remit/operations/retry_transaction'
|
44
|
+
require 'remit/operations/settle'
|
45
|
+
require 'remit/operations/settle_debt'
|
46
|
+
require 'remit/operations/subscribe_for_caller_notification'
|
47
|
+
require 'remit/operations/unsubscribe_for_caller_notification'
|
48
|
+
require 'remit/operations/write_off_debt'
|
49
|
+
|
50
|
+
module Remit
|
51
|
+
class API < Relax::Service
|
52
|
+
include CancelToken
|
53
|
+
include DiscardResults
|
54
|
+
include FundPrepaid
|
55
|
+
include GetAccountActivity
|
56
|
+
include GetAccountBalance
|
57
|
+
include GetAllCreditInstruments
|
58
|
+
include GetAllPrepaidInstruments
|
59
|
+
include GetDebtBalance
|
60
|
+
include GetOutstandingDebtBalance
|
61
|
+
include GetPaymentInstruction
|
62
|
+
include GetPipeline
|
63
|
+
include GetPrepaidBalance
|
64
|
+
include GetResults
|
65
|
+
include GetTokenUsage
|
66
|
+
include GetTokens
|
67
|
+
include GetTokenByCaller
|
68
|
+
include GetTotalPrepaidLiability
|
69
|
+
include GetTransaction
|
70
|
+
include InstallPaymentInstruction
|
71
|
+
include Pay
|
72
|
+
include Refund
|
73
|
+
include Reserve
|
74
|
+
include RetryTransaction
|
75
|
+
include Settle
|
76
|
+
include SettleDebt
|
77
|
+
include SubscribeForCallerNotification
|
78
|
+
include UnsubscribeForCallerNotification
|
79
|
+
include WriteOffDebt
|
80
|
+
|
81
|
+
API_ENDPOINT = 'https://fps.amazonaws.com/'.freeze
|
82
|
+
API_SANDBOX_ENDPOINT = 'https://fps.sandbox.amazonaws.com/'.freeze
|
83
|
+
PIPELINE_URL = 'https://authorize.payments.amazon.com/cobranded-ui/actions/start'.freeze
|
84
|
+
PIPELINE_SANDBOX_URL = 'https://authorize.payments-sandbox.amazon.com/cobranded-ui/actions/start'.freeze
|
85
|
+
API_VERSION = Date.new(2007, 1, 8).to_s.freeze
|
86
|
+
SIGNATURE_VERSION = 1.freeze
|
87
|
+
|
88
|
+
attr_reader :access_key
|
89
|
+
attr_reader :secret_key
|
90
|
+
attr_reader :pipeline_url
|
91
|
+
|
92
|
+
def initialize(access_key, secret_key, sandbox=false)
|
93
|
+
@access_key = access_key
|
94
|
+
@secret_key = secret_key
|
95
|
+
@pipeline_url = sandbox ? PIPELINE_SANDBOX_URL : PIPELINE_URL
|
96
|
+
|
97
|
+
super(sandbox ? API_SANDBOX_ENDPOINT : API_ENDPOINT)
|
98
|
+
end
|
99
|
+
|
100
|
+
def new_query(query={})
|
101
|
+
SignedQuery.new(@endpoint, @secret_key, query)
|
102
|
+
end
|
103
|
+
private :new_query
|
104
|
+
|
105
|
+
def default_query
|
106
|
+
new_query({
|
107
|
+
:AWSAccessKeyId => @access_key,
|
108
|
+
:SignatureVersion => SIGNATURE_VERSION,
|
109
|
+
:Version => API_VERSION,
|
110
|
+
:Timestamp => Time.now.utc.strftime('%Y-%m-%dT%H:%M:%SZ')
|
111
|
+
})
|
112
|
+
end
|
113
|
+
private :default_query
|
114
|
+
|
115
|
+
def query(request)
|
116
|
+
query = super
|
117
|
+
query[:Signature] = sign(query)
|
118
|
+
query
|
119
|
+
end
|
120
|
+
private :query
|
121
|
+
|
122
|
+
def sign(values)
|
123
|
+
keys = values.keys.sort { |a, b| a.to_s.downcase <=> b.to_s.downcase }
|
124
|
+
|
125
|
+
signature = keys.inject('') do |signature, key|
|
126
|
+
signature += key.to_s + values[key].to_s
|
127
|
+
end
|
128
|
+
|
129
|
+
Base64.encode64(OpenSSL::HMAC.digest(OpenSSL::Digest::SHA1.new, @secret_key, signature)).strip
|
130
|
+
end
|
131
|
+
private :sign
|
132
|
+
end
|
133
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/integrations_helper'
|
2
|
+
|
3
|
+
describe 'a GetAccountActivity call' do
|
4
|
+
it_should_behave_like 'a successful response'
|
5
|
+
|
6
|
+
before(:all) do
|
7
|
+
request = Remit::GetAccountActivity::Request.new
|
8
|
+
request.start_date = Date.today - 7
|
9
|
+
@response = remit.get_account_activity(request)
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should have a collection of transactions' do
|
13
|
+
@response.should have_at_least(1).transactions
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should have a transaction with all of its values set' do
|
17
|
+
transaction = @response.transactions.first
|
18
|
+
transaction.caller_name.should_not be_empty
|
19
|
+
transaction.caller_token_id.should_not be_empty
|
20
|
+
transaction.caller_transaction_date.should_not be_nil
|
21
|
+
transaction.date_completed.should_not be_nil
|
22
|
+
transaction.date_received.should_not be_nil
|
23
|
+
transaction.error_code.should be_empty
|
24
|
+
transaction.error_detail.should be_nil
|
25
|
+
transaction.error_message.should be_nil
|
26
|
+
transaction.fees.should_not be_nil
|
27
|
+
transaction.operation.should_not be_empty
|
28
|
+
transaction.recipient_name.should_not be_empty
|
29
|
+
transaction.sender_name.should_not be_empty
|
30
|
+
transaction.sender_token_id.should_not be_empty
|
31
|
+
transaction.status.should_not be_empty
|
32
|
+
transaction.transaction_amount.should_not be_nil
|
33
|
+
transaction.transaction_id.should_not be_empty
|
34
|
+
transaction.transaction_parts.should_not be_empty
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/integrations_helper'
|
2
|
+
|
3
|
+
describe 'a GetTokens call' do
|
4
|
+
it_should_behave_like 'a successful response'
|
5
|
+
|
6
|
+
before(:all) do
|
7
|
+
@response = remit.get_tokens
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'should have a collection of tokens' do
|
11
|
+
@response.should have_at_least(1).tokens
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should have a token with all of its values set' do
|
15
|
+
token = @response.tokens.first
|
16
|
+
token.token_id.should_not be_empty
|
17
|
+
token.friendly_name.should_not be_empty
|
18
|
+
token.status.should_not be_empty
|
19
|
+
token.date_installed.should_not be_nil
|
20
|
+
token.caller_installed.should_not be_empty
|
21
|
+
token.caller_reference.should_not be_empty
|
22
|
+
token.token_type.should_not be_empty
|
23
|
+
token.old_token_id.should_not be_empty
|
24
|
+
token.payment_reason.should_not be_empty
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should have a token with a token ID' do
|
28
|
+
@response.tokens.first.token_id.should_not be_empty
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should have a token with a valid token status' do
|
32
|
+
@response.tokens.first.status.should match(/^(IN)?ACTIVE$/i)
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'should have a token with a valid installation date' do
|
36
|
+
@response.tokens.first.date_installed.should be_a_kind_of(Time)
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
ACCESS_KEY = ENV['AWS_ACCESS_KEY'] || ENV['AMAZON_ACCESS_KEY_ID']
|
2
|
+
SECRET_KEY = ENV['AWS_SECRET_KEY'] || ENV['AMAZON_SECRET_ACCESS_KEY']
|
3
|
+
|
4
|
+
unless ACCESS_KEY and SECRET_KEY
|
5
|
+
raise RuntimeError, "You must set your AWS_ACCESS_KEY and AWS_SECRET_KEY environment variables to run integration tests"
|
6
|
+
end
|
7
|
+
|
8
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'spec'
|
3
|
+
|
4
|
+
require File.dirname(__FILE__) + '/../lib/remit'
|
5
|
+
|
6
|
+
def remit
|
7
|
+
@remit ||= Remit::API.new(ACCESS_KEY, SECRET_KEY, true)
|
8
|
+
end
|
9
|
+
|
10
|
+
describe 'a successful response', :shared => true do
|
11
|
+
it 'should return success' do
|
12
|
+
@response.status.should == 'Success'
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should not have any errors' do
|
16
|
+
@response.errors.should be_nil
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should have a request ID' do
|
20
|
+
@response.request_id.should_not be_nil
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe 'a failed response', :shared => true do
|
25
|
+
it "is not successful" do
|
26
|
+
@response.should_not be_successful
|
27
|
+
end
|
28
|
+
|
29
|
+
it "has a request id" do
|
30
|
+
@response.request_id.should_not be_empty
|
31
|
+
end
|
32
|
+
|
33
|
+
it "has errors" do
|
34
|
+
@response.errors.should_not be_empty
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,165 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/units_helper'
|
2
|
+
|
3
|
+
describe 'A pipeline', :shared => true do
|
4
|
+
before do
|
5
|
+
@pipeline_options = {
|
6
|
+
:return_url => 'http://example.com/'
|
7
|
+
}
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'should sign its URL' do
|
11
|
+
uri = URI.parse(@pipeline.url)
|
12
|
+
pipeline = Remit::SignedQuery.parse(uri, remit.secret_key, uri.query)
|
13
|
+
query = Relax::Query.parse(uri)
|
14
|
+
|
15
|
+
pipeline[:awsSignature].should == query[:awsSignature]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe 'A single-use pipeline' do
|
20
|
+
it_should_behave_like 'A pipeline'
|
21
|
+
|
22
|
+
before do
|
23
|
+
@pipeline_options.merge!({
|
24
|
+
:transaction_amount => 10,
|
25
|
+
:caller_reference => 'N2PCBEIA5864E27EL7C86PJL1FGUGPBL61QTJJM5GQK265SPEN8ZKIJPMQARDVJK',
|
26
|
+
:recipient_token => 'N5PCME5A5Q6FE2QEB7CD64JLGFTUGXBE61HTCJMGGAK2R5IPEQ8EKIVP3QAVD7JP'
|
27
|
+
})
|
28
|
+
|
29
|
+
@pipeline = remit.get_single_use_pipeline(@pipeline_options)
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should ignore unused parameters' do
|
33
|
+
uri = URI.parse(@pipeline.url)
|
34
|
+
query = Relax::Query.parse(uri)
|
35
|
+
|
36
|
+
query[:paymentReason].should be_nil
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'should have the right name' do
|
40
|
+
@pipeline.pipeline_name.should == Remit::PipelineName::SINGLE_USE
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe 'A multi-use pipeline' do
|
45
|
+
it_should_behave_like 'A pipeline'
|
46
|
+
|
47
|
+
before do
|
48
|
+
@pipeline_options.merge!({
|
49
|
+
:transaction_amount => 10,
|
50
|
+
:caller_reference => 'N2PCBEIA5864E27EL7C86PJL1FGUGPBL61QTJJM5GQK265SPEN8ZKIJPMQARDVJK',
|
51
|
+
:recipient_token_list => 'N5PCME5A5Q6FE2QEB7CD64JLGFTUGXBE61HTCJMGGAK2R5IPEQ8EKIVP3QAVD7JP'
|
52
|
+
})
|
53
|
+
|
54
|
+
@pipeline = remit.get_multi_use_pipeline(@pipeline_options)
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'should ignore unused parameters' do
|
58
|
+
uri = URI.parse(@pipeline.url)
|
59
|
+
query = Relax::Query.parse(uri)
|
60
|
+
|
61
|
+
query[:paymentReason].should be_nil
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'should have the right name' do
|
65
|
+
@pipeline.pipeline_name.should == Remit::PipelineName::MULTI_USE
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
describe 'A recipient pipeline' do
|
70
|
+
it_should_behave_like 'A pipeline'
|
71
|
+
|
72
|
+
before do
|
73
|
+
@validity_start = Time.now + (3600 * 24) # 1 day from now
|
74
|
+
@validity_expiry = Time.now + (2600 * 24 * 180) # ~6 months from now
|
75
|
+
|
76
|
+
@pipeline_options.merge!({
|
77
|
+
:validity_start => @validity_start,
|
78
|
+
:validity_expiry => @validity_expiry,
|
79
|
+
:caller_reference => 'N2PCBEIA5864E27EL7C86PJL1FGUGPBL61QTJJM5GQK265SPEN8ZKIJPMQARDVJK',
|
80
|
+
:max_variable_fee => '0.25',
|
81
|
+
:recipient_pays_fee => true
|
82
|
+
})
|
83
|
+
|
84
|
+
@pipeline = remit.get_recipient_pipeline(@pipeline_options)
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'should have the recipient pay marketplace fees' do
|
88
|
+
@pipeline.url.should match(/recipientPaysFee=true/)
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'should have the right name' do
|
92
|
+
@pipeline.pipeline_name.should == Remit::PipelineName::RECIPIENT
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
describe 'A recurring-use pipeline' do
|
97
|
+
it_should_behave_like 'A pipeline'
|
98
|
+
|
99
|
+
before do
|
100
|
+
@validity_start = Time.now + (3600 * 24) # 1 day from now
|
101
|
+
@validity_expiry = Time.now + (3600 * 24 * 180) # ~6 months from now
|
102
|
+
@recurring_period = '1 Month'
|
103
|
+
|
104
|
+
@pipeline_options.merge!({
|
105
|
+
:validity_start => @validity_start,
|
106
|
+
:validity_expiry => @validity_expiry,
|
107
|
+
:recurring_period => @recurring_period,
|
108
|
+
:transaction_amount => 10,
|
109
|
+
:caller_reference => 'N2PCBEIA5864E27EL7C86PJL1FGUGPBL61QTJJM5GQK265SPEN8ZKIJPMQARDVJK',
|
110
|
+
:recipient_token => 'N5PCME5A5Q6FE2QEB7CD64JLGFTUGXBE61HTCJMGGAK2R5IPEQ8EKIVP3QAVD7JP'
|
111
|
+
})
|
112
|
+
|
113
|
+
@pipeline = remit.get_recurring_use_pipeline(@pipeline_options)
|
114
|
+
end
|
115
|
+
|
116
|
+
it 'should convert times to seconds from epoch' do
|
117
|
+
uri = URI.parse(@pipeline.url)
|
118
|
+
query = Relax::Query.parse(uri)
|
119
|
+
|
120
|
+
@validity_start.to_i.to_s.should == query[:validityStart]
|
121
|
+
@validity_expiry.to_i.to_s.should == query[:validityExpiry]
|
122
|
+
end
|
123
|
+
|
124
|
+
it 'should allow time in seconds' do
|
125
|
+
options = @pipeline_options.merge({
|
126
|
+
:validity_start => @validity_start.to_i,
|
127
|
+
:validity_expiry => @validity_expiry.to_i
|
128
|
+
})
|
129
|
+
@pipeline = remit.get_recurring_use_pipeline(options)
|
130
|
+
|
131
|
+
uri = URI.parse(@pipeline.url)
|
132
|
+
query = Relax::Query.parse(uri)
|
133
|
+
|
134
|
+
@validity_start.to_i.to_s.should == query[:validityStart]
|
135
|
+
@validity_expiry.to_i.to_s.should == query[:validityExpiry]
|
136
|
+
end
|
137
|
+
|
138
|
+
it 'should have the right name' do
|
139
|
+
@pipeline.pipeline_name.should == Remit::PipelineName::RECURRING
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
describe 'A postpaid pipeline' do
|
144
|
+
it_should_behave_like 'A pipeline'
|
145
|
+
|
146
|
+
before do
|
147
|
+
@credit_limit = 100
|
148
|
+
@global_amount_limit = 100
|
149
|
+
|
150
|
+
@pipeline_options.merge!({
|
151
|
+
:credit_limit => @credit_limit,
|
152
|
+
:global_amount_limit => @global_amount_limit
|
153
|
+
})
|
154
|
+
|
155
|
+
@pipeline = remit.get_postpaid_pipeline(@pipeline_options)
|
156
|
+
end
|
157
|
+
|
158
|
+
it 'should create a PostpaidPipeline' do
|
159
|
+
@pipeline.class.should == Remit::GetPipeline::PostpaidPipeline
|
160
|
+
end
|
161
|
+
|
162
|
+
it 'should have the right name' do
|
163
|
+
@pipeline.pipeline_name.should == Remit::PipelineName::SETUP_POSTPAID
|
164
|
+
end
|
165
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/units_helper'
|
2
|
+
|
3
|
+
describe "the GetResults API" do
|
4
|
+
describe "a successful response" do
|
5
|
+
it_should_behave_like 'a successful response'
|
6
|
+
|
7
|
+
before do
|
8
|
+
doc = <<-XML
|
9
|
+
<?xml version=\"1.0\"?>
|
10
|
+
<ns3:GetResultsResponse xmlns:ns3=\"http://fps.amazonaws.com/doc/2007-01-08/\">
|
11
|
+
<TransactionResults>
|
12
|
+
<TransactionId>abc123</TransactionId>
|
13
|
+
<Operation>Pay</Operation>
|
14
|
+
<CallerReference>1827</CallerReference>
|
15
|
+
<Status>Success</Status>
|
16
|
+
</TransactionResults>
|
17
|
+
<NumberPending>1</NumberPending>
|
18
|
+
<Status>Success</Status>
|
19
|
+
<RequestId>f89727ba-9ff6-4ca8-87a3-0fd6c9de6b95:0</RequestId>
|
20
|
+
</ns3:GetResultsResponse>
|
21
|
+
XML
|
22
|
+
|
23
|
+
@response = Remit::GetResults::Response.new(doc)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "has one result" do
|
27
|
+
@response.number_pending.should == 1
|
28
|
+
@response.transaction_results.size == "1"
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "the result" do
|
32
|
+
before do
|
33
|
+
@result = @response.transaction_results.first
|
34
|
+
end
|
35
|
+
|
36
|
+
it "references a previous transaction" do
|
37
|
+
@result.transaction_id.should == "abc123"
|
38
|
+
end
|
39
|
+
|
40
|
+
it "references a pay transaction" do
|
41
|
+
@result.operation_type.should == 'Pay'
|
42
|
+
end
|
43
|
+
|
44
|
+
it "reports the transaction's new status" do
|
45
|
+
@result.transaction_status.should == 'Success'
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/units_helper'
|
2
|
+
|
3
|
+
describe 'an IPN request' do
|
4
|
+
before(:each) do
|
5
|
+
@request_params = {
|
6
|
+
"action" => "notice",
|
7
|
+
"buyerName" => "Fps Buyer",
|
8
|
+
"callerReference" => "4-8-1-3.5",
|
9
|
+
"controller" => "amazon_fps/ipn",
|
10
|
+
"operation" => "PAY",
|
11
|
+
"paymentMethod" => "CC",
|
12
|
+
"recipientEmail" => "recipient@email.url",
|
13
|
+
"recipientName" => "Fps Business",
|
14
|
+
"signature" => "DA7ZbuQaBDt2/+Mty9XweJyqI1E=",
|
15
|
+
"status" => "SUCCESS",
|
16
|
+
"transactionAmount" => "USD 3.50",
|
17
|
+
"transactionDate" => "1224687134",
|
18
|
+
"transactionId" => "13KIGL9RC25853BGPPOS2VSKBKF2JERR3HO"
|
19
|
+
}
|
20
|
+
@request = Remit::IpnRequest.new(@request_params, 'THISISMYTESTKEY')
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should be a valid request' do
|
24
|
+
@request.should be_valid
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should pass through access to given parameters' do
|
28
|
+
@request.status.should == 'SUCCESS'
|
29
|
+
@request.operation.should == 'PAY'
|
30
|
+
@request.transactionId.should == '13KIGL9RC25853BGPPOS2VSKBKF2JERR3HO'
|
31
|
+
end
|
32
|
+
end
|