remit 0.0.6 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. data/README.markdown +36 -5
  2. data/lib/remit.rb +35 -39
  3. data/lib/remit/common.rb +79 -24
  4. data/lib/remit/data_types.rb +118 -17
  5. data/lib/remit/get_pipeline.rb +160 -80
  6. data/lib/remit/inbound_request.rb +85 -0
  7. data/lib/remit/ipn_request.rb +4 -39
  8. data/lib/remit/operations/cancel.rb +20 -0
  9. data/lib/remit/operations/cancel_subscription_and_refund.rb +5 -1
  10. data/lib/remit/operations/cancel_token.rb +1 -0
  11. data/lib/remit/operations/fund_prepaid.rb +6 -4
  12. data/lib/remit/operations/get_account_activity.rb +5 -34
  13. data/lib/remit/operations/get_account_balance.rb +14 -11
  14. data/lib/remit/operations/get_all_credit_instruments.rb +2 -0
  15. data/lib/remit/operations/get_all_prepaid_instruments.rb +2 -0
  16. data/lib/remit/operations/get_debt_balance.rb +9 -4
  17. data/lib/remit/operations/get_outstanding_debt_balance.rb +8 -5
  18. data/lib/remit/operations/get_payment_instruction.rb +2 -0
  19. data/lib/remit/operations/get_prepaid_balance.rb +9 -5
  20. data/lib/remit/operations/get_recipient_verification_status.rb +25 -0
  21. data/lib/remit/operations/get_token_by_caller.rb +5 -1
  22. data/lib/remit/operations/get_token_usage.rb +5 -1
  23. data/lib/remit/operations/get_tokens.rb +5 -1
  24. data/lib/remit/operations/get_total_prepaid_liability.rb +9 -5
  25. data/lib/remit/operations/get_transaction.rb +1 -25
  26. data/lib/remit/operations/get_transaction_status.rb +28 -0
  27. data/lib/remit/operations/install_payment_instruction.rb +8 -1
  28. data/lib/remit/operations/pay.rb +5 -9
  29. data/lib/remit/operations/refund.rb +20 -11
  30. data/lib/remit/operations/reserve.rb +2 -4
  31. data/lib/remit/operations/settle.rb +2 -1
  32. data/lib/remit/operations/settle_debt.rb +2 -4
  33. data/lib/remit/operations/subscribe_for_caller_notification.rb +2 -0
  34. data/lib/remit/operations/unsubscribe_for_caller_notification.rb +2 -0
  35. data/lib/remit/operations/write_off_debt.rb +2 -4
  36. data/lib/remit/pipeline_response.rb +8 -41
  37. data/lib/remit/signature_utils_for_outbound.rb +74 -0
  38. data/lib/remit/verify_signature.rb +21 -0
  39. data/spec/integrations/get_account_activity_spec.rb +25 -19
  40. data/spec/integrations/get_tokens_spec.rb +9 -7
  41. data/spec/integrations/integrations_helper.rb +7 -0
  42. data/spec/integrations/ipn_request_spec.rb +28 -20
  43. data/spec/integrations/pipeline_response_spec.rb +27 -0
  44. data/spec/integrations/verify_signature_spec.rb +140 -0
  45. data/spec/mocks/CancelResponse.xml +13 -0
  46. data/spec/mocks/CancelSubscriptionAndRefundResponse.xml +10 -0
  47. data/spec/mocks/CancelTokenResponse.xml +6 -0
  48. data/spec/mocks/ErrorResponse.xml +15 -0
  49. data/spec/mocks/FundPrepaidResponse.xml +11 -0
  50. data/spec/mocks/GetAccountActivityResponse.xml +68 -0
  51. data/spec/mocks/GetAccountBalanceResponse.xml +34 -0
  52. data/spec/mocks/GetDebtBalanceResponse.xml +21 -0
  53. data/spec/mocks/GetOutstandingDebtBalanceResponse.xml +21 -0
  54. data/spec/mocks/GetPaymentInstructionResponse.xml +25 -0
  55. data/spec/mocks/GetPrepaidBalanceResponse.xml +21 -0
  56. data/spec/mocks/GetRecipientVerificationStatusResponse.xml +9 -0
  57. data/spec/mocks/GetTokenByCallerResponse.xml +22 -0
  58. data/spec/mocks/GetTokenUsageResponse.xml +28 -0
  59. data/spec/mocks/GetTokensResponse.xml +22 -0
  60. data/spec/mocks/GetTotalPrepaidLiabilityResponse.xml +21 -0
  61. data/spec/mocks/GetTransactionResponse.xml +76 -0
  62. data/spec/mocks/GetTransactionStatusResponse.xml +16 -0
  63. data/spec/mocks/InstallPaymentInstructionResponse.xml +10 -0
  64. data/spec/mocks/PayResponse.xml +11 -0
  65. data/spec/mocks/RefundResponse.xml +11 -0
  66. data/spec/mocks/ReserveResponse.xml +11 -0
  67. data/spec/mocks/SettleDebtResponse.xml +11 -0
  68. data/spec/mocks/SettleResponse.xml +11 -0
  69. data/spec/mocks/VerifySignatureResponse.xml +11 -0
  70. data/spec/mocks/WriteOffDebtResponse.xml +11 -0
  71. data/spec/mocks/errors/InvalidParameterValue.xml +10 -0
  72. data/spec/mocks/errors/InvalidParams_certificateUrl.xml +2 -0
  73. data/spec/mocks/errors/RequestExpired.xml +10 -0
  74. data/spec/spec_helper.rb +59 -10
  75. data/spec/units/cancel_subscription_and_refund_spec.rb +29 -0
  76. data/spec/units/cancel_token_spec.rb +24 -0
  77. data/spec/units/fund_prepaid_spec.rb +28 -0
  78. data/spec/units/get_account_activity_spec.rb +58 -0
  79. data/spec/units/get_account_balance_spec.rb +28 -0
  80. data/spec/units/get_debt_balance_spec.rb +29 -0
  81. data/spec/units/get_outstanding_debt_balance_spec.rb +29 -0
  82. data/spec/units/get_pipeline_spec.rb +16 -0
  83. data/spec/units/get_prepaid_balance_spec.rb +29 -0
  84. data/spec/units/get_recipient_verification_status_spec.rb +26 -0
  85. data/spec/units/get_token_by_caller_spec.rb +56 -0
  86. data/spec/units/get_token_usage_spec.rb +51 -0
  87. data/spec/units/get_tokens_spec.rb +56 -0
  88. data/spec/units/get_total_prepaid_liability_spec.rb +26 -0
  89. data/spec/units/get_transaction_spec.rb +103 -0
  90. data/spec/units/get_transaction_status_spec.rb +44 -0
  91. data/spec/units/pay_spec.rb +36 -57
  92. data/spec/units/refund_spec.rb +41 -0
  93. data/spec/units/reserve_spec.rb +41 -0
  94. data/spec/units/settle_debt_spec.rb +41 -0
  95. data/spec/units/settle_spec.rb +41 -0
  96. data/spec/units/units_helper.rb +23 -2
  97. data/spec/units/write_off_debt_spec.rb +41 -0
  98. metadata +116 -12
  99. data/lib/remit/operations/discard_results.rb +0 -18
  100. data/lib/remit/operations/get_results.rb +0 -27
  101. data/lib/remit/operations/retry_transaction.rb +0 -18
  102. data/spec/units/get_results_spec.rb +0 -49
@@ -0,0 +1,24 @@
1
+ require File.dirname(__FILE__) + '/units_helper'
2
+
3
+ describe "the GetTransaction API" do
4
+ describe "a successful response" do
5
+ it_should_behave_like 'a successful response'
6
+
7
+ before do
8
+ doc = File.read("spec/mocks/CancelTokenResponse.xml")
9
+
10
+ @response = Remit::CancelToken::Response.new(doc)
11
+ end
12
+
13
+ it "has metadata" do
14
+ @response.response_metadata
15
+ end
16
+
17
+ describe "metadata" do
18
+ it "has request_id" do
19
+ @response.response_metadata.request_id
20
+ end
21
+ end
22
+
23
+ end
24
+ end
@@ -0,0 +1,28 @@
1
+ require File.dirname(__FILE__) + '/units_helper'
2
+
3
+ describe "the FundPrepaid API" do
4
+ describe "a successful response" do
5
+ it_should_behave_like 'a successful response'
6
+
7
+ before do
8
+ doc = File.read("spec/mocks/FundPrepaidResponse.xml")
9
+
10
+ @response = Remit::FundPrepaid::Response.new(doc)
11
+ end
12
+
13
+ it "has metadata" do
14
+ @response.response_metadata.should_not be_nil
15
+ end
16
+
17
+ describe "metadata" do
18
+ it "has request_id" do
19
+ @response.response_metadata.request_id
20
+ end
21
+ end
22
+
23
+ it "has results" do
24
+ @response.fund_prepaid_result.should_not be_nil
25
+ end
26
+
27
+ end
28
+ end
@@ -0,0 +1,58 @@
1
+ require File.dirname(__FILE__) + '/units_helper'
2
+
3
+ describe "the GetAccountActivity API" do
4
+ describe "a successful response" do
5
+ it_should_behave_like 'a successful response'
6
+
7
+ before(:all) do
8
+ doc = File.read("spec/mocks/GetAccountActivityResponse.xml")
9
+
10
+ @response = Remit::GetAccountActivity::Response.new(doc)
11
+ end
12
+
13
+ it "has results" do
14
+ @response.get_account_activity_result.should_not be_nil
15
+ end
16
+
17
+ describe "the result" do
18
+ before(:all) do
19
+ @activity = @response.get_account_activity_result
20
+ end
21
+
22
+ it "should have transactions" do
23
+ @activity.transactions.should_not be_nil
24
+ end
25
+
26
+ it "should have transactions" do
27
+ @activity.transactions.size.should_not == 0
28
+ end
29
+
30
+ it "should have batch_size" do
31
+ @activity.batch_size.should_not be_nil
32
+ end
33
+
34
+ it "should have start_time_for_next_transaction" do
35
+ @activity.start_time_for_next_transaction.should_not be_nil
36
+ end
37
+
38
+ describe "a transaction" do
39
+ before(:all) do
40
+ @transaction = @activity.transactions.first
41
+ end
42
+ it "should have transaction_status" do
43
+ @transaction.transaction_status.should == "string"
44
+ end
45
+
46
+ it "should have status_code" do
47
+ @transaction.status_code.should == "string"
48
+ end
49
+
50
+ it "should have status_message" do
51
+ @transaction.status_message.should_not be_nil
52
+ end
53
+
54
+ end
55
+
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,28 @@
1
+ require File.dirname(__FILE__) + '/units_helper'
2
+
3
+ describe "the GetAccountBalance API" do
4
+ describe "a successful response" do
5
+ it_should_behave_like 'a successful response'
6
+
7
+ before do
8
+ doc = File.read("spec/mocks/GetAccountBalanceResponse.xml")
9
+
10
+ @response = Remit::GetAccountBalance::Response.new(doc)
11
+ end
12
+
13
+ it "has metadata" do
14
+ @response.response_metadata.should_not be_nil
15
+ end
16
+
17
+ it "has results" do
18
+ @response.get_account_balance_result.should_not be_nil
19
+ end
20
+
21
+ describe "the result" do
22
+ it "should have a total_balance" do
23
+ @response.get_account_balance_result.account_balance.total_balance.value.should == 0
24
+ end
25
+ end
26
+
27
+ end
28
+ end
@@ -0,0 +1,29 @@
1
+ require File.dirname(__FILE__) + '/units_helper'
2
+
3
+ describe "the GetDebtBalance API" do
4
+ describe "a successful response" do
5
+ it_should_behave_like 'a successful response'
6
+
7
+ before do
8
+ doc = File.read("spec/mocks/GetDebtBalanceResponse.xml")
9
+
10
+ @response = Remit::GetDebtBalance::Response.new(doc)
11
+ end
12
+
13
+ it "has metadata" do
14
+ @response.response_metadata.should_not be_nil
15
+ end
16
+
17
+ it "has results" do
18
+ @response.get_debt_balance_result.should_not be_nil
19
+ end
20
+
21
+ describe "the result" do
22
+ it "should have an available_balance" do
23
+ @response.get_debt_balance_result.debt_balance.available_balance.value.should == 0
24
+ end
25
+ end
26
+
27
+
28
+ end
29
+ end
@@ -0,0 +1,29 @@
1
+ require File.dirname(__FILE__) + '/units_helper'
2
+
3
+ describe "the GetOutstandingDebtBalance API" do
4
+ describe "a successful response" do
5
+ it_should_behave_like 'a successful response'
6
+
7
+ before do
8
+ doc = File.read("spec/mocks/GetOutstandingDebtBalanceResponse.xml")
9
+
10
+ @response = Remit::GetOutstandingDebtBalance::Response.new(doc)
11
+ end
12
+
13
+ it "has metadata" do
14
+ @response.response_metadata.should_not be_nil
15
+ end
16
+
17
+ it "has results" do
18
+ @response.get_outstanding_debt_balance_result.should_not be_nil
19
+ end
20
+
21
+ describe "the result" do
22
+ it "should have refund_transaction_id" do
23
+ @response.get_outstanding_debt_balance_result.outstanding_debt.outstanding_balance.value.should == 0
24
+ end
25
+ end
26
+
27
+
28
+ end
29
+ end
@@ -5,6 +5,22 @@ describe 'A pipeline', :shared => true do
5
5
  @pipeline_options = {
6
6
  :return_url => 'http://example.com/'
7
7
  }
8
+ @pipeline = remit.get_single_use_pipeline(@pipeline_options)
9
+ end
10
+
11
+ describe 'with signed url' do
12
+ before(:each) do
13
+ @uri = URI.parse(@pipeline.url)
14
+ end
15
+ it "should have a signature" do
16
+ @uri.query.should =~ /signature=/
17
+ end
18
+ it "should specify a signature version" do
19
+ @uri.query.should =~ /signatureVersion=2/
20
+ end
21
+ it "should specify a signature method" do
22
+ @uri.query.should =~ /signatureMethod=HmacSHA256/
23
+ end
8
24
  end
9
25
 
10
26
  it 'should sign its URL' do
@@ -0,0 +1,29 @@
1
+ require File.dirname(__FILE__) + '/units_helper'
2
+
3
+ describe "the GetPrepaidBalance API" do
4
+ describe "a successful response" do
5
+ it_should_behave_like 'a successful response'
6
+
7
+ before do
8
+ doc = File.read("spec/mocks/GetPrepaidBalanceResponse.xml")
9
+
10
+ @response = Remit::GetPrepaidBalance::Response.new(doc)
11
+ end
12
+
13
+ it "has metadata" do
14
+ @response.response_metadata.should_not be_nil
15
+ end
16
+
17
+ it "has results" do
18
+ @response.get_prepaid_balance_result.should_not be_nil
19
+ end
20
+
21
+ describe "the result" do
22
+ it "should have refund_transaction_id" do
23
+ @response.get_prepaid_balance_result.prepaid_balance.available_balance.value.should == 0
24
+ end
25
+ end
26
+
27
+
28
+ end
29
+ end
@@ -0,0 +1,26 @@
1
+ require File.dirname(__FILE__) + '/units_helper'
2
+
3
+ describe "the GetRecipientVerificationStatus API" do
4
+ describe "a successful response" do
5
+ it_should_behave_like 'a successful response'
6
+
7
+ before do
8
+ doc = File.read("spec/mocks/GetRecipientVerificationStatusResponse.xml")
9
+
10
+ @response = Remit::GetRecipientVerificationStatus::Response.new(doc)
11
+ end
12
+
13
+ it "has metadata" do
14
+ @response.response_metadata.should_not be_nil
15
+ end
16
+
17
+ it "has results" do
18
+ @response.get_recipient_verification_status_result.should_not be_nil
19
+ end
20
+
21
+ it "has status" do
22
+ @response.get_recipient_verification_status_result.recipient_verification_status.should_not be_nil
23
+ end
24
+
25
+ end
26
+ end
@@ -0,0 +1,56 @@
1
+ require File.dirname(__FILE__) + '/units_helper'
2
+
3
+ describe "the GetTokenByCaller API" do
4
+ describe "a successful response" do
5
+ it_should_behave_like 'a successful response'
6
+
7
+ before(:all) do
8
+ doc = File.read("spec/mocks/GetTokenByCallerResponse.xml")
9
+
10
+ @response = Remit::GetTokenByCaller::Response.new(doc)
11
+ end
12
+
13
+ it "has metadata" do
14
+ @response.response_metadata.should_not be_nil
15
+ end
16
+
17
+ it "has results" do
18
+ @response.get_token_by_caller_result.should_not be_nil
19
+ end
20
+
21
+ it "should have Token" do
22
+ @response.get_token_by_caller_result.token.should_not be_nil
23
+ end
24
+
25
+ describe "has Token" do
26
+ before(:all) do
27
+ @token = @response.get_token_by_caller_result.token
28
+ end
29
+ it "should have TokenId" do
30
+ @token.token_id.should_not be_nil
31
+ end
32
+ it "should have FriendlyName" do
33
+ @token.friendly_name.should_not be_nil
34
+ end
35
+ it "should have TokenStatus" do
36
+ @token.token_status.should_not be_nil
37
+ end
38
+ it "should have DateInstalled" do
39
+ @token.date_installed.should_not be_nil
40
+ end
41
+ it "should have CallerReference" do
42
+ @token.caller_reference.should_not be_nil
43
+ end
44
+ it "should have TokenType" do
45
+ @token.token_type.should_not be_nil
46
+ end
47
+ it "should have OldTokenId" do
48
+ @token.old_token_id.should_not be_nil
49
+ end
50
+ it "should have PaymentReason" do
51
+ @token.payment_reason.should_not be_nil
52
+ end
53
+ end
54
+
55
+ end
56
+ end
@@ -0,0 +1,51 @@
1
+ require File.dirname(__FILE__) + '/units_helper'
2
+
3
+ describe "the GetTokenUsage API" do
4
+ describe "a successful response" do
5
+ it_should_behave_like 'a successful response'
6
+
7
+ before do
8
+ doc = <<-XML
9
+ <GetTokenUsageResponse xmlns="http://fps.amazonaws.com/doc/2008-09-17/">
10
+ <GetTokenUsageResult>
11
+ <TokenUsageLimits>
12
+ <Amount>
13
+ <CurrencyCode>USD</CurrencyCode>
14
+ <Value>10.000000</Value>
15
+ </Amount>
16
+ <LastResetAmount>
17
+ <CurrencyCode>USD</CurrencyCode>
18
+ <Value>0.000000</Value>
19
+ </LastResetAmount>
20
+ <LastResetTimestamp>
21
+ 2008-01-01T02:00:00.000-08:00
22
+ </LastResetTimestamp>
23
+ </TokenUsageLimits>
24
+ <TokenUsageLimits>
25
+ <Count>1</Count>
26
+ <LastResetCount>0</LastResetCount>
27
+ <LastResetTimestamp>
28
+ 2008-01-01T02:00:00.000-08:00
29
+ </LastResetTimestamp>
30
+ </TokenUsageLimits>
31
+ </GetTokenUsageResult>
32
+ <ResponseMetadata>
33
+ <RequestId>9faeed71-9362-4eb8-9431-b99e92b441ee:0</RequestId>
34
+ </ResponseMetadata>
35
+ </GetTokenUsageResponse>
36
+ XML
37
+
38
+ @response = Remit::GetTokenUsage::Response.new(doc)
39
+ end
40
+
41
+ it "has metadata" do
42
+ @response.response_metadata.should_not be_nil
43
+ end
44
+
45
+ it "has results" do
46
+ @response.get_token_usage_result.should_not be_nil
47
+ end
48
+
49
+
50
+ end
51
+ end
@@ -0,0 +1,56 @@
1
+ require File.dirname(__FILE__) + '/units_helper'
2
+
3
+ describe "the GetTokens API" do
4
+ describe "a successful response" do
5
+ it_should_behave_like 'a successful response'
6
+
7
+ before(:all) do
8
+ doc = File.read("spec/mocks/GetTokensResponse.xml")
9
+
10
+ @response = Remit::GetTokens::Response.new(doc)
11
+ end
12
+
13
+ it "has metadata" do
14
+ @response.response_metadata.should_not be_nil
15
+ end
16
+
17
+ it "has results" do
18
+ @response.get_tokens_result.should_not be_nil
19
+ end
20
+
21
+ it "should have tokens" do
22
+ @response.get_tokens_result.tokens.length.should > 0
23
+ end
24
+
25
+ describe "Tokens" do
26
+ before(:all) do
27
+ @token = @response.get_tokens_result.tokens.first
28
+ end
29
+ it "should have a TokenId" do
30
+ @token.token_id.should_not be_nil
31
+ end
32
+ it "should have a FriendlyName" do
33
+ @token.friendly_name.should_not be_nil
34
+ end
35
+ it "should have a TokenStatus" do
36
+ @token.token_status.should_not be_nil
37
+ end
38
+ it "should have a DateInstalled" do
39
+ @token.date_installed.should_not be_nil
40
+ end
41
+ it "should have a CallerReference" do
42
+ @token.caller_reference.should_not be_nil
43
+ end
44
+ it "should have a TokenType" do
45
+ @token.token_type.should_not be_nil
46
+ end
47
+ it "should have a OldTokenId" do
48
+ @token.old_token_id.should_not be_nil
49
+ end
50
+ it "should have a PaymentReason" do
51
+ @token.payment_reason.should_not be_nil
52
+ end
53
+ end
54
+
55
+ end
56
+ end