global_collect 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING +11 -0
- data/README.markdown +109 -0
- data/Rakefile +34 -0
- data/VERSION +1 -0
- data/examples/cancel_payment.rb +14 -0
- data/examples/convert_amount.rb +14 -0
- data/examples/get_order_status.rb +15 -0
- data/examples/insert_order_with_payment.rb +37 -0
- data/examples/process_challenged.rb +13 -0
- data/examples/set_payment.rb +23 -0
- data/examples/test_connection.rb +13 -0
- data/global_collect.gemspec +170 -0
- data/lib/global_collect/api_client.rb +71 -0
- data/lib/global_collect/builders/do_refund/credit_card_payment.rb +12 -0
- data/lib/global_collect/builders/do_refund/payment.rb +39 -0
- data/lib/global_collect/builders/insert_order_with_payment/credit_card_online_payment.rb +38 -0
- data/lib/global_collect/builders/insert_order_with_payment/hosted_credit_card_online_payment.rb +4 -0
- data/lib/global_collect/builders/insert_order_with_payment/order.rb +75 -0
- data/lib/global_collect/builders/insert_order_with_payment/payment.rb +25 -0
- data/lib/global_collect/builders/set_payment/payment.rb +23 -0
- data/lib/global_collect/const/payment_product.rb +38 -0
- data/lib/global_collect/const/payment_status.rb +90 -0
- data/lib/global_collect/field_validator.rb +47 -0
- data/lib/global_collect/request_models/base.rb +37 -0
- data/lib/global_collect/request_models/do_refund/credit_card_payment.rb +12 -0
- data/lib/global_collect/request_models/do_refund/payment.rb +39 -0
- data/lib/global_collect/request_models/insert_order_with_payment/credit_card_online_payment.rb +44 -0
- data/lib/global_collect/request_models/insert_order_with_payment/hosted_credit_card_online_payment.rb +19 -0
- data/lib/global_collect/request_models/insert_order_with_payment/order.rb +67 -0
- data/lib/global_collect/request_models/insert_order_with_payment/payment.rb +17 -0
- data/lib/global_collect/request_models/set_payment/payment.rb +17 -0
- data/lib/global_collect/requests/base.rb +43 -0
- data/lib/global_collect/requests/cancel_payment.rb +22 -0
- data/lib/global_collect/requests/composite.rb +23 -0
- data/lib/global_collect/requests/convert_amount.rb +29 -0
- data/lib/global_collect/requests/do_refund.rb +8 -0
- data/lib/global_collect/requests/get_order_status.rb +24 -0
- data/lib/global_collect/requests/insert_order_with_payment.rb +10 -0
- data/lib/global_collect/requests/process_challenged.rb +22 -0
- data/lib/global_collect/requests/set_payment.rb +9 -0
- data/lib/global_collect/requests/simple.rb +39 -0
- data/lib/global_collect/requests/test_connection.rb +8 -0
- data/lib/global_collect/responses/base.rb +73 -0
- data/lib/global_collect/responses/convert_amount/response_methods.rb +8 -0
- data/lib/global_collect/responses/do_refund/response_methods.rb +24 -0
- data/lib/global_collect/responses/get_order_status/v1_response_methods.rb +49 -0
- data/lib/global_collect/responses/get_order_status/v2_response_methods.rb +67 -0
- data/lib/global_collect/responses/insert_order_with_payment/credit_card_online_payment_response_methods.rb +31 -0
- data/lib/global_collect/responses/insert_order_with_payment/hosted_merchant_link_payment_response_methods.rb +16 -0
- data/lib/global_collect/responses/success_row.rb +15 -0
- data/lib/global_collect.rb +81 -0
- data/spec/api_client_spec.rb +93 -0
- data/spec/builders/do_refund/credit_card_payment_spec.rb +32 -0
- data/spec/builders/do_refund/payment_spec.rb +51 -0
- data/spec/builders/insert_order_with_payment/credit_card_online_payment_spec.rb +59 -0
- data/spec/builders/insert_order_with_payment/hosted_credit_card_online_payment_spec.rb +59 -0
- data/spec/builders/insert_order_with_payment/order_spec.rb +88 -0
- data/spec/builders/insert_order_with_payment/payment_spec.rb +37 -0
- data/spec/builders/set_payment/payment_spec.rb +35 -0
- data/spec/field_validator_spec.rb +79 -0
- data/spec/global_collect_spec.rb +43 -0
- data/spec/request_models/base_spec.rb +31 -0
- data/spec/request_models/insert_order_with_payment/credit_card_online_payment_spec.rb +11 -0
- data/spec/request_models/insert_order_with_payment/hosted_credit_card_online_payment_spec.rb +38 -0
- data/spec/requests/base_spec.rb +40 -0
- data/spec/requests/composite_spec.rb +48 -0
- data/spec/requests/convert_amount.rb +34 -0
- data/spec/requests/insert_order_with_payment_spec.rb +60 -0
- data/spec/requests/simple_spec.rb +37 -0
- data/spec/responses/base_spec.rb +59 -0
- data/spec/responses/convert_amount/response_methods_spec.rb +13 -0
- data/spec/responses/do_refund/response_methods_spec.rb +15 -0
- data/spec/responses/get_order_status/v1_response_methods_spec.rb +28 -0
- data/spec/responses/get_order_status/v2_response_methods_spec.rb +28 -0
- data/spec/responses/insert_order_with_payment/credit_card_online_payment_response_methods_spec.rb +13 -0
- data/spec/responses/insert_order_with_payment/hosted_merchant_link_payment_response_methods_spec.rb +13 -0
- data/spec/responses/succcess_row_spec.rb +26 -0
- data/spec/spec_helper.rb +130 -0
- data/spec/support/challenged_iowp_response.xml +51 -0
- data/spec/support/successful_convert_amount_response.xml +29 -0
- data/spec/support/successful_do_refund_response.xml +36 -0
- data/spec/support/successful_get_order_status_v1_response.xml +72 -0
- data/spec/support/successful_get_order_status_v2_response.xml +50 -0
- data/spec/support/successful_hosted_iowp_response.xml +60 -0
- data/spec/support/successful_iowp_response.xml +49 -0
- data/spec/support/successful_process_challenged_response.xml +26 -0
- data/spec/support/unsuccessful_do_refund_response.xml +29 -0
- data/spec/support/unsuccessful_iowp_response.xml +42 -0
- data/spec/support/unsuccessful_process_challenged_response.xml +30 -0
- metadata +213 -0
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'the GC module' do
|
4
|
+
before(:each) do
|
5
|
+
GlobalCollect.instance_variable_set(:@wire_logger, nil)
|
6
|
+
end
|
7
|
+
after(:each) do
|
8
|
+
GlobalCollect.instance_variable_set(:@wire_logger, nil)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should default to version 1.0" do
|
12
|
+
GlobalCollect.default_api_version.should == "1.0"
|
13
|
+
end
|
14
|
+
it "should error on an invalid environment" do
|
15
|
+
GlobalCollect.environment = :foo
|
16
|
+
lambda { GlobalCollect.merchant_link_client }.should raise_error(ArgumentError)
|
17
|
+
end
|
18
|
+
it "should error on an invalid auth scheme" do
|
19
|
+
GlobalCollect.authentication_scheme = :foo
|
20
|
+
lambda { GlobalCollect.merchant_link_client }.should raise_error(ArgumentError)
|
21
|
+
end
|
22
|
+
it "should return a merchant link client" do
|
23
|
+
GlobalCollect.authentication_scheme = :ip_check
|
24
|
+
GlobalCollect.environment = :test
|
25
|
+
GlobalCollect.merchant_link_client.should_not be_nil
|
26
|
+
end
|
27
|
+
it "should write to a log file, if provided" do
|
28
|
+
begin
|
29
|
+
GlobalCollect.wire_log_file = File.join(File.dirname(__FILE__), "support", "test_log.log")
|
30
|
+
GlobalCollect.wire_logger.debug("foo")
|
31
|
+
log = File.open(GlobalCollect.wire_log_file, "r").read.strip.should include('foo')
|
32
|
+
ensure
|
33
|
+
FileUtils.rm_f(GlobalCollect.wire_log_file)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should write to your logger if provided" do
|
38
|
+
logger = mock(:logger)
|
39
|
+
logger.should_receive(:debug).with("foo")
|
40
|
+
GlobalCollect.wire_logger = logger
|
41
|
+
GlobalCollect.wire_logger.debug("foo")
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'spec_helper')
|
2
|
+
class TestRequestModel < GlobalCollect::RequestModels::Base
|
3
|
+
def fields; {"PLACEHOLDER" => ["AN12", "R"]}; end
|
4
|
+
end
|
5
|
+
|
6
|
+
describe "the base model" do
|
7
|
+
it "should validate cleanly on good attributes" do
|
8
|
+
base = TestRequestModel.new("PLACEHOLDER" => "FOOBAR")
|
9
|
+
base.validate.should be_true
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should not validate on empty attributes" do
|
13
|
+
base = TestRequestModel.new({})
|
14
|
+
base.validate.should be_false
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should not validate on bad attributes" do
|
18
|
+
base = TestRequestModel.new("PLACEHOLDER" => "FOOBARFOOBARFOOBAR")
|
19
|
+
base.validate.should be_false
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should not allow a bad key to be set" do
|
23
|
+
base = TestRequestModel.new("PLACEHOLDER" => "FOOBAR")
|
24
|
+
lambda { base["FOO"] = "BAR" }.should raise_error(ArgumentError)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should not allow a bad key to be read" do
|
28
|
+
base = TestRequestModel.new("PLACEHOLDER" => "FOOBAR")
|
29
|
+
lambda { base["FOO"] }.should raise_error(ArgumentError)
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper')
|
2
|
+
|
3
|
+
describe "the credit card online payment model" do
|
4
|
+
it "should return the proper suggested mixins" do
|
5
|
+
model = GlobalCollect::RequestModels::InsertOrderWithPayment::CreditCardOnlinePayment.new({})
|
6
|
+
model.suggested_response_mixins.should == [
|
7
|
+
GlobalCollect::Responses::SuccessRow,
|
8
|
+
GlobalCollect::Responses::InsertOrderWithPayment::CreditCardOnlinePaymentResponseMethods
|
9
|
+
]
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper')
|
2
|
+
|
3
|
+
describe "the hosted credit card online payment model" do
|
4
|
+
it "should set HOSTEDINDICATOR to '1' when not provided" do
|
5
|
+
model = GlobalCollect::RequestModels::InsertOrderWithPayment::HostedCreditCardOnlinePayment.new(
|
6
|
+
"PAYMENTPRODUCTID" => "1",
|
7
|
+
"AMOUNT" => "1",
|
8
|
+
"CURRENCYCODE" => "USD",
|
9
|
+
"LANGUAGECODE" => "en",
|
10
|
+
"COUNTRYCODE" => "US"
|
11
|
+
)
|
12
|
+
model["HOSTEDINDICATOR"].should == "1"
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should set HOSTEDINDICATOR to '1' when it is set to something invalid" do
|
16
|
+
model = GlobalCollect::RequestModels::InsertOrderWithPayment::HostedCreditCardOnlinePayment.new(
|
17
|
+
"PAYMENTPRODUCTID" => "1",
|
18
|
+
"AMOUNT" => "1",
|
19
|
+
"CURRENCYCODE" => "USD",
|
20
|
+
"LANGUAGECODE" => "en",
|
21
|
+
"COUNTRYCODE" => "US",
|
22
|
+
"HOSTEDINDICATOR" => "2123123213"
|
23
|
+
)
|
24
|
+
model["HOSTEDINDICATOR"].should == "1"
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should set HOSTEDINDICATOR to '1' when it is set to the wrong thing" do
|
28
|
+
model = GlobalCollect::RequestModels::InsertOrderWithPayment::HostedCreditCardOnlinePayment.new(
|
29
|
+
"PAYMENTPRODUCTID" => "1",
|
30
|
+
"AMOUNT" => "1",
|
31
|
+
"CURRENCYCODE" => "USD",
|
32
|
+
"LANGUAGECODE" => "en",
|
33
|
+
"COUNTRYCODE" => "US",
|
34
|
+
"HOSTEDINDICATOR" => "0"
|
35
|
+
)
|
36
|
+
model["HOSTEDINDICATOR"].should == "1"
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'spec_helper')
|
2
|
+
|
3
|
+
describe "the base request" do
|
4
|
+
before(:all) do
|
5
|
+
GlobalCollect.merchant_id = 666
|
6
|
+
GlobalCollect.authentication_scheme = :ip_check
|
7
|
+
GlobalCollect.ip_address = '0.0.0.0'
|
8
|
+
GlobalCollect::default_api_version = "2.0"
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should have the correct wrapping xml elements" do
|
12
|
+
request = GlobalCollect::Requests::Base.new("FOO_ACTION")
|
13
|
+
xml = request.to_xml do |params_node|
|
14
|
+
end
|
15
|
+
xml.should have_xpath("/XML/REQUEST")
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should render the action" do
|
19
|
+
request = GlobalCollect::Requests::Base.new("FOO_ACTION")
|
20
|
+
xml = request.to_xml do |params_node|; end
|
21
|
+
xml.should match_xpath("/XML/REQUEST/ACTION", "FOO_ACTION")
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should render contents" do
|
25
|
+
request = GlobalCollect::Requests::Base.new("FOO_ACTION")
|
26
|
+
xml = request.to_xml do |params_node|
|
27
|
+
params_node.tag!("FOO_NODE")
|
28
|
+
end
|
29
|
+
xml.should have_xpath("/XML/REQUEST/PARAMS/FOO_NODE")
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should have the correct meta fields" do
|
33
|
+
request = GlobalCollect::Requests::Base.new("FOO_ACTION")
|
34
|
+
|
35
|
+
xml = request.to_xml do |params_node|; end
|
36
|
+
xml.should match_xpath("/XML/REQUEST/META/IPADDRESS", "0.0.0.0")
|
37
|
+
xml.should match_xpath("/XML/REQUEST/META/VERSION", "2.0")
|
38
|
+
xml.should match_xpath("/XML/REQUEST/META/MERCHANTID", "666")
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'spec_helper')
|
2
|
+
|
3
|
+
class TestModel
|
4
|
+
attr_reader :validate
|
5
|
+
def initialize(valid);@validate=valid;end
|
6
|
+
def suggested_response_mixins;[];end
|
7
|
+
def errors; {}; end
|
8
|
+
end
|
9
|
+
class TestModelBuilder
|
10
|
+
def initialize(model);end
|
11
|
+
def build(node)
|
12
|
+
node.tag!("FOO_NODE")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
module MixinTest
|
17
|
+
end
|
18
|
+
class TestMixinModel < TestModel
|
19
|
+
def suggested_response_mixins
|
20
|
+
[MixinTest, MixinTest]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "the composite request" do
|
25
|
+
it "should build properly from model-builder pairs" do
|
26
|
+
pair = [TestModel.new(true), TestModelBuilder]
|
27
|
+
request = GlobalCollect::Requests::Composite.new("FOO_ACTION", [pair])
|
28
|
+
xml = request.to_xml
|
29
|
+
xml.should have_xpath("/XML/REQUEST/PARAMS/FOO_NODE")
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should fail on an invalid model" do
|
33
|
+
pair = [TestModel.new(false), TestModelBuilder]
|
34
|
+
request = GlobalCollect::Requests::Composite.new("FOO_ACTION", [pair])
|
35
|
+
lambda { request.to_xml }.should raise_error(Exception, /Invalid model/)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should fail on unpaired models and builders" do
|
39
|
+
pair = [TestModel.new(false)]
|
40
|
+
lambda { GlobalCollect::Requests::Composite.new("FOO_ACTION", [pair]) }.should raise_error(ArgumentError, /pairs/)
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should not suggest duplicate mixins" do
|
44
|
+
pair = [TestMixinModel.new(true), TestModelBuilder]
|
45
|
+
request = GlobalCollect::Requests::Composite.new("FOO_ACTION", [pair])
|
46
|
+
request.suggested_response_mixins.size.should == 1
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'spec_helper')
|
2
|
+
|
3
|
+
describe "the convert amount request" do
|
4
|
+
before(:each) do
|
5
|
+
@request = GlobalCollect::Requests::ConvertAmount.new(
|
6
|
+
"100",
|
7
|
+
"USD",
|
8
|
+
"GBP"
|
9
|
+
)
|
10
|
+
end
|
11
|
+
it "should build the right action" do
|
12
|
+
xml = @request.to_xml
|
13
|
+
xml.should match_xpath("/XML/REQUEST/ACTION", "CONVERT_AMOUNT")
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should build basic fields" do
|
17
|
+
xml = @request.to_xml
|
18
|
+
xml.should match_xpath("/XML/REQUEST/PARAMS/GENERAL/AMOUNT", "100")
|
19
|
+
xml.should match_xpath("/XML/REQUEST/PARAMS/GENERAL/SOURCECURRENCYCODE", "USD")
|
20
|
+
xml.should match_xpath("/XML/REQUEST/PARAMS/GENERAL/TARGETCURRENCYCODE", "GBP")
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should wrap the fields" do
|
24
|
+
xml = @request.to_xml
|
25
|
+
xml.should have_xpath("/XML/REQUEST/PARAMS/GENERAL")
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should suggest the correct mixins" do
|
29
|
+
@request.suggested_response_mixins.should == [
|
30
|
+
GlobalCollect::Responses::SuccessRow,
|
31
|
+
GlobalCollect::Responses::ConvertAmount::ResponseMethods
|
32
|
+
]
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'spec_helper')
|
2
|
+
class AirlineDataBuilder
|
3
|
+
def initialize(data);end
|
4
|
+
def build(node)
|
5
|
+
node.tag!("AIRLINEDATA") do |airline_node|
|
6
|
+
airline_node.tag!("FOO")
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
class AirlineDataModel
|
11
|
+
def validate;true;end
|
12
|
+
def suggested_response_mixins;[];end
|
13
|
+
end
|
14
|
+
describe "the insert order with payment request" do
|
15
|
+
before(:each) do
|
16
|
+
@order = GlobalCollect::RequestModels::InsertOrderWithPayment::Order.new(
|
17
|
+
"ORDERID" => "1234567890",
|
18
|
+
"AMOUNT" => "1234",
|
19
|
+
"CURRENCYCODE" => "USD",
|
20
|
+
"LANGUAGECODE" => "en",
|
21
|
+
"COUNTRYCODE" => "US",
|
22
|
+
"MERCHANTREFERENCE" => "ASDASDASD"
|
23
|
+
)
|
24
|
+
@payment = GlobalCollect::RequestModels::InsertOrderWithPayment::Payment.new(
|
25
|
+
"PAYMENTPRODUCTID" => "1",
|
26
|
+
"AMOUNT" => "1234",
|
27
|
+
"CURRENCYCODE" => "USD",
|
28
|
+
"LANGUAGECODE" => "en",
|
29
|
+
"COUNTRYCODE" => "US"
|
30
|
+
)
|
31
|
+
@request = GlobalCollect::Requests::InsertOrderWithPayment.new(
|
32
|
+
[ @order, GlobalCollect::Builders::InsertOrderWithPayment::Order ],
|
33
|
+
[ @payment, GlobalCollect::Builders::InsertOrderWithPayment::Payment ]
|
34
|
+
)
|
35
|
+
end
|
36
|
+
it "should have the correct action" do
|
37
|
+
xml = @request.to_xml
|
38
|
+
xml.should match_xpath("/XML/REQUEST/ACTION", "INSERT_ORDERWITHPAYMENT")
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should have a payment node" do
|
42
|
+
xml = @request.to_xml
|
43
|
+
xml.should have_xpath("/XML/REQUEST/PARAMS/PAYMENT")
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should have an order node" do
|
47
|
+
xml = @request.to_xml
|
48
|
+
xml.should have_xpath("/XML/REQUEST/PARAMS/ORDER")
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should allow extra builders, like AIRLINEDATA" do
|
52
|
+
@request = GlobalCollect::Requests::InsertOrderWithPayment.new(
|
53
|
+
[ @order, GlobalCollect::Builders::InsertOrderWithPayment::Order ],
|
54
|
+
[ @payment, GlobalCollect::Builders::InsertOrderWithPayment::Payment ],
|
55
|
+
[ AirlineDataModel.new, AirlineDataBuilder ]
|
56
|
+
)
|
57
|
+
xml = @request.to_xml
|
58
|
+
xml.should have_xpath("/XML/REQUEST/PARAMS/AIRLINEDATA/FOO")
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'spec_helper')
|
2
|
+
|
3
|
+
class SimpleTestRequest < GlobalCollect::Requests::Simple
|
4
|
+
def fields
|
5
|
+
{
|
6
|
+
"FOO" => ["N10", "R"]
|
7
|
+
}
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
class WrappedSimpleTestRequest < SimpleTestRequest
|
12
|
+
def wrapper;"PARAPPA";end
|
13
|
+
end
|
14
|
+
describe "the simple request" do
|
15
|
+
it "should build the right action" do
|
16
|
+
request = SimpleTestRequest.new("WHAM",{"FOO" => "123"})
|
17
|
+
xml = request.to_xml
|
18
|
+
xml.should match_xpath("/XML/REQUEST/ACTION", "WHAM")
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should build basic fields" do
|
22
|
+
request = SimpleTestRequest.new("WHAM",{"FOO" => "123"})
|
23
|
+
xml = request.to_xml
|
24
|
+
xml.should match_xpath("/XML/REQUEST/PARAMS/FOO", "123")
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should wrap the fields" do
|
28
|
+
request = WrappedSimpleTestRequest.new("WHAM",{"FOO" => "123"})
|
29
|
+
xml = request.to_xml
|
30
|
+
xml.should match_xpath("/XML/REQUEST/PARAMS/PARAPPA/FOO", "123")
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should validate fields" do
|
34
|
+
request = SimpleTestRequest.new("WHAM",{"FOO" => "abc"})
|
35
|
+
lambda { request.to_xml }.should raise_error(Exception, /Invalid field 'FOO'/)
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'spec_helper')
|
2
|
+
|
3
|
+
describe "the base response" do
|
4
|
+
describe "on a successful response" do
|
5
|
+
before(:each) do
|
6
|
+
@response = load_canned_response('successful_iowp_response.xml')
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should identify success" do
|
10
|
+
@response.success?.should == true
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should identify meta fields correctly" do
|
14
|
+
@response.request_id.should == "3000852"
|
15
|
+
@response.response_datetime.should == Time.parse("Fri Apr 09 02:03:09 -0700 2010")
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should give you the raw hash to access" do
|
19
|
+
@response.hash.should_not be_blank
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should not provide the errors" do
|
23
|
+
@response.errors.should be_empty
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should provide the raw and parsed response" do
|
27
|
+
@response.response_hash.should be_a(Hash)
|
28
|
+
xml = @response.raw_response
|
29
|
+
xml.should have_xpath("/XML/REQUEST/META")
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "on an unsuccessful response" do
|
34
|
+
before(:each) do
|
35
|
+
@response = load_canned_response('unsuccessful_iowp_response.xml')
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should identify success" do
|
39
|
+
@response.success?.should == false
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should identify meta fields correctly" do
|
43
|
+
@response.request_id.should == "3000854"
|
44
|
+
@response.response_datetime.should == Time.parse("Fri Apr 09 02:03:28 -0700 2010")
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should provide the errors" do
|
48
|
+
@response.errors.should_not be_empty
|
49
|
+
@response.errors.first.code.should_not be_blank
|
50
|
+
@response.errors.first.message.should_not be_blank
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should provide the raw and parsed response" do
|
54
|
+
@response.response_hash.should be_a(Hash)
|
55
|
+
xml = @response.raw_response
|
56
|
+
xml.should have_xpath("/XML/REQUEST/META")
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper')
|
2
|
+
|
3
|
+
describe "the convert amount response methods" do
|
4
|
+
before(:each) do
|
5
|
+
@response = load_canned_response('successful_convert_amount_response.xml')
|
6
|
+
@response.extend(GlobalCollect::Responses::SuccessRow)
|
7
|
+
@response.extend(GlobalCollect::Responses::ConvertAmount::ResponseMethods)
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should see the methods" do
|
11
|
+
@response.converted_amount.should == "1174"
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper')
|
2
|
+
|
3
|
+
describe "the do refund response methods" do
|
4
|
+
before(:each) do
|
5
|
+
@response = load_canned_response('successful_do_refund_response.xml')
|
6
|
+
@response.extend(GlobalCollect::Responses::SuccessRow)
|
7
|
+
@response.extend(GlobalCollect::Responses::DoRefund::ResponseMethods)
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should see the methods" do
|
11
|
+
@response.status_id.should == "800"
|
12
|
+
@response.payment_status.should_not be_nil
|
13
|
+
@response.payment_status.code.should be(800)
|
14
|
+
end
|
15
|
+
end
|