pp-adaptive 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +6 -0
- data/.rspec +1 -0
- data/Gemfile +4 -0
- data/README.md +54 -0
- data/Rakefile +8 -0
- data/lib/pp-adaptive/abstract_request.rb +44 -0
- data/lib/pp-adaptive/abstract_response.rb +46 -0
- data/lib/pp-adaptive/cancel_preapproval_request.rb +7 -0
- data/lib/pp-adaptive/cancel_preapproval_response.rb +7 -0
- data/lib/pp-adaptive/client.rb +56 -0
- data/lib/pp-adaptive/convert_currency_request.rb +33 -0
- data/lib/pp-adaptive/convert_currency_response.rb +11 -0
- data/lib/pp-adaptive/execute_payment_request.rb +9 -0
- data/lib/pp-adaptive/execute_payment_response.rb +12 -0
- data/lib/pp-adaptive/get_payment_options_request.rb +7 -0
- data/lib/pp-adaptive/get_payment_options_response.rb +32 -0
- data/lib/pp-adaptive/pay_request.rb +64 -0
- data/lib/pp-adaptive/pay_response.rb +29 -0
- data/lib/pp-adaptive/payment_details_request.rb +9 -0
- data/lib/pp-adaptive/payment_details_response.rb +53 -0
- data/lib/pp-adaptive/preapproval_details_request.rb +8 -0
- data/lib/pp-adaptive/preapproval_details_response.rb +35 -0
- data/lib/pp-adaptive/preapproval_request.rb +36 -0
- data/lib/pp-adaptive/preapproval_response.rb +7 -0
- data/lib/pp-adaptive/refund_request.rb +14 -0
- data/lib/pp-adaptive/refund_response.rb +12 -0
- data/lib/pp-adaptive/set_payment_options_request.rb +33 -0
- data/lib/pp-adaptive/set_payment_options_response.rb +7 -0
- data/lib/pp-adaptive/support/aliases.rb +33 -0
- data/lib/pp-adaptive/support/coerced_array.rb +52 -0
- data/lib/pp-adaptive/support/json_model.rb +140 -0
- data/lib/pp-adaptive/support/node.rb +45 -0
- data/lib/pp-adaptive/support/node_list.rb +45 -0
- data/lib/pp-adaptive/types/account_identifier.rb +6 -0
- data/lib/pp-adaptive/types/address.rb +17 -0
- data/lib/pp-adaptive/types/address_list.rb +5 -0
- data/lib/pp-adaptive/types/aliases/receiver_aliases.rb +15 -0
- data/lib/pp-adaptive/types/aliases/receiver_list_aliases.rb +32 -0
- data/lib/pp-adaptive/types/base_address.rb +11 -0
- data/lib/pp-adaptive/types/client_details_type.rb +12 -0
- data/lib/pp-adaptive/types/currency_code.rb +5 -0
- data/lib/pp-adaptive/types/currency_conversion.rb +17 -0
- data/lib/pp-adaptive/types/currency_conversion_list.rb +15 -0
- data/lib/pp-adaptive/types/currency_conversion_table.rb +5 -0
- data/lib/pp-adaptive/types/currency_list.rb +5 -0
- data/lib/pp-adaptive/types/currency_type.rb +6 -0
- data/lib/pp-adaptive/types/display_options.rb +8 -0
- data/lib/pp-adaptive/types/error_data.rb +11 -0
- data/lib/pp-adaptive/types/error_list.rb +5 -0
- data/lib/pp-adaptive/types/fault_message.rb +23 -0
- data/lib/pp-adaptive/types/funding_constraint.rb +5 -0
- data/lib/pp-adaptive/types/funding_plan.rb +28 -0
- data/lib/pp-adaptive/types/funding_plan_charge.rb +11 -0
- data/lib/pp-adaptive/types/funding_source.rb +9 -0
- data/lib/pp-adaptive/types/funding_type_info.rb +5 -0
- data/lib/pp-adaptive/types/funding_type_list.rb +5 -0
- data/lib/pp-adaptive/types/initiating_entity.rb +15 -0
- data/lib/pp-adaptive/types/institution_customer.rb +11 -0
- data/lib/pp-adaptive/types/invoice_data.rb +7 -0
- data/lib/pp-adaptive/types/invoice_item.rb +9 -0
- data/lib/pp-adaptive/types/pay_error.rb +18 -0
- data/lib/pp-adaptive/types/pay_error_list.rb +5 -0
- data/lib/pp-adaptive/types/payment_info.rb +16 -0
- data/lib/pp-adaptive/types/payment_info_list.rb +5 -0
- data/lib/pp-adaptive/types/phone_number_type.rb +7 -0
- data/lib/pp-adaptive/types/receiver.rb +17 -0
- data/lib/pp-adaptive/types/receiver_identifier.rb +12 -0
- data/lib/pp-adaptive/types/receiver_list.rb +5 -0
- data/lib/pp-adaptive/types/receiver_options.rb +21 -0
- data/lib/pp-adaptive/types/refund_info.rb +20 -0
- data/lib/pp-adaptive/types/refund_info_list.rb +5 -0
- data/lib/pp-adaptive/types/request_envelope.rb +6 -0
- data/lib/pp-adaptive/types/response_envelope.rb +13 -0
- data/lib/pp-adaptive/types/sender_identifier.rb +5 -0
- data/lib/pp-adaptive/types/sender_options.rb +5 -0
- data/lib/pp-adaptive/version.rb +3 -0
- data/lib/pp-adaptive.rb +75 -0
- data/pp-adaptive.gemspec +25 -0
- data/spec/public/cancel_preapproval_request_spec.rb +15 -0
- data/spec/public/cancel_preapproval_response_spec.rb +6 -0
- data/spec/public/client_spec.rb +85 -0
- data/spec/public/convert_currency_request_spec.rb +29 -0
- data/spec/public/convert_currency_response_spec.rb +62 -0
- data/spec/public/execute_payment_request_spec.rb +30 -0
- data/spec/public/execute_payment_response_spec.rb +66 -0
- data/spec/public/get_payment_options_request_spec.rb +15 -0
- data/spec/public/get_payment_options_response_spec.rb +141 -0
- data/spec/public/json_model_spec.rb +56 -0
- data/spec/public/node_list_spec.rb +58 -0
- data/spec/public/node_spec.rb +54 -0
- data/spec/public/pay_request_spec.rb +150 -0
- data/spec/public/pay_response_spec.rb +197 -0
- data/spec/public/payment_details_request_spec.rb +30 -0
- data/spec/public/payment_details_response_spec.rb +211 -0
- data/spec/public/preapproval_details_request_spec.rb +25 -0
- data/spec/public/preapproval_details_response_spec.rb +200 -0
- data/spec/public/preapproval_request_spec.rb +110 -0
- data/spec/public/preapproval_response_spec.rb +14 -0
- data/spec/public/refund_request_spec.rb +57 -0
- data/spec/public/refund_response_spec.rb +116 -0
- data/spec/public/set_payment_options_request_spec.rb +136 -0
- data/spec/public/set_payment_options_response_spec.rb +6 -0
- data/spec/shared/a_fault_message.rb +60 -0
- data/spec/shared/a_request_envelope.rb +14 -0
- data/spec/shared/a_response_envelope.rb +36 -0
- data/spec/spec_helper.rb +6 -0
- metadata +225 -0
@@ -0,0 +1,141 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe AdaptivePayments::GetPaymentOptionsResponse do
|
4
|
+
it_behaves_like "a ResponseEnvelope"
|
5
|
+
it_behaves_like "a FaultMessage"
|
6
|
+
|
7
|
+
let(:response) do
|
8
|
+
AdaptivePayments::GetPaymentOptionsResponse.from_json(
|
9
|
+
{
|
10
|
+
:initiatingEntity => {
|
11
|
+
:institutionCustomer => {
|
12
|
+
:institutionId => "inst123",
|
13
|
+
:firstName => "Bob",
|
14
|
+
:lastName => "Cat",
|
15
|
+
:displayName => "Bobcat",
|
16
|
+
:institutionCustomerId => "77",
|
17
|
+
:countryCode => "AU",
|
18
|
+
:email => "bob@site.com"
|
19
|
+
}
|
20
|
+
},
|
21
|
+
:displayOptions => {
|
22
|
+
:emailHeaderImageUrl => "http://site.com/email.png",
|
23
|
+
:emailMarketingImageUrl => "http://site.com/marketing.png",
|
24
|
+
:headerImageUrl => "http://site.com/header.png",
|
25
|
+
:businessName => "Bobcats R us"
|
26
|
+
},
|
27
|
+
:shippingAddressId => "addr123",
|
28
|
+
:senderOptions => {
|
29
|
+
:requireShippingAddressSelection => true
|
30
|
+
},
|
31
|
+
:receiverOptions => [
|
32
|
+
{
|
33
|
+
:description => "Primary receiver",
|
34
|
+
:customId => "cust123",
|
35
|
+
:invoiceData => {
|
36
|
+
:item => [
|
37
|
+
{
|
38
|
+
:name => "Video Game",
|
39
|
+
:identifier => "ident123",
|
40
|
+
:price => "20.00",
|
41
|
+
:item_price => "10.00",
|
42
|
+
:item_count => "2"
|
43
|
+
}
|
44
|
+
],
|
45
|
+
:total_tax => "2.00",
|
46
|
+
:total_shipping => "0.00"
|
47
|
+
}
|
48
|
+
}
|
49
|
+
]
|
50
|
+
}.to_json
|
51
|
+
)
|
52
|
+
end
|
53
|
+
|
54
|
+
it "maps ['initiatingEntity']['institutionCustomer']['institutionId'] to #institution_id" do
|
55
|
+
response.institution_id.should == "inst123"
|
56
|
+
end
|
57
|
+
|
58
|
+
it "maps ['initiatingEntity']['institutionCustomer']['firstName'] to #customer_first_name" do
|
59
|
+
response.customer_first_name.should == "Bob"
|
60
|
+
end
|
61
|
+
|
62
|
+
it "maps ['initiatingEntity']['institutionCustomer']['lastName'] to #customer_last_name" do
|
63
|
+
response.customer_last_name.should == "Cat"
|
64
|
+
end
|
65
|
+
|
66
|
+
it "maps ['initiatingEntity']['institutionCustomer']['displayName'] to #customer_display_name" do
|
67
|
+
response.customer_display_name.should == "Bobcat"
|
68
|
+
end
|
69
|
+
|
70
|
+
it "maps ['initiatingEntity']['institutionCustomer']['institutionCustomerId'] to #institution_customer_id" do
|
71
|
+
response.institution_customer_id.should == "77"
|
72
|
+
end
|
73
|
+
|
74
|
+
it "maps ['initiatingEntity']['institutionCustomer']['countryCode'] to #customer_country_code" do
|
75
|
+
response.customer_country_code.should == "AU"
|
76
|
+
end
|
77
|
+
|
78
|
+
it "maps ['initiatingEntity']['institutionCustomer']['email'] to #customer_email" do
|
79
|
+
response.customer_email.should == "bob@site.com"
|
80
|
+
end
|
81
|
+
|
82
|
+
it "maps ['displayOptions']['emailHeaderImageUrl'] to #email_header_image_url" do
|
83
|
+
response.email_header_image_url.should == "http://site.com/email.png"
|
84
|
+
end
|
85
|
+
|
86
|
+
it "maps ['displayOptions']['emailMarketingImageUrl'] to #email_marketing_image_url" do
|
87
|
+
response.email_marketing_image_url.should == "http://site.com/marketing.png"
|
88
|
+
end
|
89
|
+
|
90
|
+
it "maps ['displayOptions']['headerImageUrl'] to #header_image_url" do
|
91
|
+
response.header_image_url.should == "http://site.com/header.png"
|
92
|
+
end
|
93
|
+
|
94
|
+
it "maps ['displayOptions']['businessName'] to #business_na,e" do
|
95
|
+
response.business_name.should == "Bobcats R us"
|
96
|
+
end
|
97
|
+
|
98
|
+
it "maps ['shippingAddressId'] to #shipping_address_id" do
|
99
|
+
response.shipping_address_id.should == "addr123"
|
100
|
+
end
|
101
|
+
|
102
|
+
it "maps ['senderOptions']['requireShippingAddressSelection'] to #require_shipping_address_selection? " do
|
103
|
+
response.require_shipping_address_selection?.should be_true
|
104
|
+
end
|
105
|
+
|
106
|
+
it "maps ['receiverOptions'][0]['description'] to #receiver_options.first.description" do
|
107
|
+
response.receiver_options.first.description.should == "Primary receiver"
|
108
|
+
end
|
109
|
+
|
110
|
+
it "maps ['receiverOptions'][0]['customId'] to #receiver_options.first.custom_id" do
|
111
|
+
response.receiver_options.first.custom_id.should == "cust123"
|
112
|
+
end
|
113
|
+
|
114
|
+
it "maps ['receiverOptions'][0]['invoiceData']['totalTax'] to #receiver_options.first.invoice_data.total_tax" do
|
115
|
+
response.receiver_options.first.invoice_data.total_tax.should == BigDecimal("2.00")
|
116
|
+
end
|
117
|
+
|
118
|
+
it "maps ['receiverOptions'][0]['invoiceData']['totalShipping'] to #receiver_options.first.invoice_data.total_shipping" do
|
119
|
+
response.receiver_options.first.invoice_data.total_shipping.should == BigDecimal("0.00")
|
120
|
+
end
|
121
|
+
|
122
|
+
it "maps ['receiverOptions'][0]['invoiceData']['item'][0]['name'] to #receiver_options.first.invoice_data.items.first.name" do
|
123
|
+
response.receiver_options.first.invoice_data.items.first.name.should == "Video Game"
|
124
|
+
end
|
125
|
+
|
126
|
+
it "maps ['receiverOptions'][0]['invoiceData']['item'][0]['identifier'] to #receiver_options.first.invoice_data.items.first.identifier" do
|
127
|
+
response.receiver_options.first.invoice_data.items.first.identifier.should == "ident123"
|
128
|
+
end
|
129
|
+
|
130
|
+
it "maps ['receiverOptions'][0]['invoiceData']['item'][0]['price'] to #receiver_options.first.invoice_data.items.first.price" do
|
131
|
+
response.receiver_options.first.invoice_data.items.first.price.should == BigDecimal("20.00")
|
132
|
+
end
|
133
|
+
|
134
|
+
it "maps ['receiverOptions'][0]['invoiceData']['item'][0]['itemPrice'] to #receiver_options.first.invoice_data.items.first.item_price" do
|
135
|
+
response.receiver_options.first.invoice_data.items.first.item_price.should == BigDecimal("10.00")
|
136
|
+
end
|
137
|
+
|
138
|
+
it "maps ['receiverOptions'][0]['invoiceData']['item'][0]['itemCount'] to #receiver_options.first.invoice_data.items.first.item_count" do
|
139
|
+
response.receiver_options.first.invoice_data.items.first.item_count.should == 2
|
140
|
+
end
|
141
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "virtus"
|
3
|
+
|
4
|
+
describe AdaptivePayments::JsonModel do
|
5
|
+
let(:model) do
|
6
|
+
Class.new(AdaptivePayments::JsonModel) do
|
7
|
+
attribute :an_example, Virtus::Attribute::String, :param => "anExample"
|
8
|
+
attribute :simple, Virtus::Attribute::String
|
9
|
+
attribute :numeric, Virtus::Attribute::Decimal
|
10
|
+
attribute :optional, Virtus::Attribute::String, :default => "test"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "coercion" do
|
15
|
+
let(:object) { model.new(:an_example => "string", :numeric => 20) }
|
16
|
+
|
17
|
+
it "casts inputs to the correct type" do
|
18
|
+
object.an_example.should == "string"
|
19
|
+
object.numeric.should == BigDecimal("20.00")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "default values" do
|
24
|
+
let(:object) { model.new }
|
25
|
+
|
26
|
+
it "reads the :default option for a default value" do
|
27
|
+
object.optional.should == "test"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "#to_json" do
|
32
|
+
context "with empty values" do
|
33
|
+
let(:json) { model.new.to_json }
|
34
|
+
|
35
|
+
it "omits the empty values" do
|
36
|
+
json.should == '{"optional":"test"}'
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context "with decimal values" do
|
41
|
+
let(:json) { model.new(:numeric => 10).to_json }
|
42
|
+
|
43
|
+
it "formats the decimal to scale 2" do
|
44
|
+
json.should == '{"numeric":"10.00","optional":"test"}'
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context "with a :param option" do
|
49
|
+
let(:json) { model.new(:an_example => "whatever").to_json }
|
50
|
+
|
51
|
+
it "uses the param as the key" do
|
52
|
+
json.should == '{"anExample":"whatever","optional":"test"}'
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe AdaptivePayments::NodeList do
|
4
|
+
let(:child_model) do
|
5
|
+
Class.new(AdaptivePayments::JsonModel) do
|
6
|
+
attribute :example, String
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
let(:model) do
|
11
|
+
klass = child_model
|
12
|
+
Class.new(AdaptivePayments::JsonModel) do
|
13
|
+
attribute :children, AdaptivePayments::NodeList[klass]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "default type" do
|
18
|
+
it "is a kind of Array" do
|
19
|
+
model.new.children.should be_a_kind_of(Array)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "coercion" do
|
24
|
+
context "when appending to" do
|
25
|
+
let(:object) { model.new.tap { |o| o.children << { :example => "anything" } } }
|
26
|
+
|
27
|
+
it "coerces hash to instances of the given type" do
|
28
|
+
object.children.first.should be_an_instance_of(child_model)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context "when overwriting" do
|
33
|
+
let(:object) { model.new.tap { |o| o.children = [{ :example => "anything" }] } }
|
34
|
+
|
35
|
+
it "coerces each member to instances of the given type" do
|
36
|
+
object.children.first.should be_an_instance_of(child_model)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "#to_json" do
|
42
|
+
context "when not empty" do
|
43
|
+
let(:json) { model.new(:children => [{ :example => "whatever" }]).to_json }
|
44
|
+
|
45
|
+
it "is present as a child in the output" do
|
46
|
+
json.should == '{"children":[{"example":"whatever"}]}'
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
context "when empty" do
|
51
|
+
let(:json) { model.new.to_json }
|
52
|
+
|
53
|
+
it "is omitted from the output" do
|
54
|
+
json.should == '{}'
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe AdaptivePayments::Node do
|
4
|
+
let(:child_model) do
|
5
|
+
Class.new(AdaptivePayments::JsonModel) do
|
6
|
+
attribute :example, String
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
let(:model) do
|
11
|
+
klass = child_model
|
12
|
+
Class.new(AdaptivePayments::JsonModel) do
|
13
|
+
attribute :child, AdaptivePayments::Node[klass]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "default type" do
|
18
|
+
let(:child) { model.new.child }
|
19
|
+
|
20
|
+
it "is an instance of the boxed type" do
|
21
|
+
child.should be_an_instance_of(child_model)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "coercion" do
|
26
|
+
let(:object) { model.new(:child => { :example => "anything" }) }
|
27
|
+
|
28
|
+
it "coerces hash to instances of the given type" do
|
29
|
+
object.child.should be_an_instance_of(child_model)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "maintains the original keys" do
|
33
|
+
object.child.example.should == "anything"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "#to_json" do
|
38
|
+
context "when not empty" do
|
39
|
+
let(:json) { model.new(:child => { :example => "whatever" }).to_json }
|
40
|
+
|
41
|
+
it "is present as a child in the output" do
|
42
|
+
json.should == '{"child":{"example":"whatever"}}'
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context "when empty" do
|
47
|
+
let(:json) { model.new.to_json }
|
48
|
+
|
49
|
+
it "is omitted from the output" do
|
50
|
+
json.should == '{}'
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,150 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe AdaptivePayments::PayRequest do
|
4
|
+
it_behaves_like "a RequestEnvelope"
|
5
|
+
|
6
|
+
subject { AdaptivePayments::PayRequest }
|
7
|
+
its(:operation) { should == :Pay }
|
8
|
+
|
9
|
+
let(:request) do
|
10
|
+
AdaptivePayments::PayRequest.new(
|
11
|
+
:receivers => [ { :email => "receiver1@site.com", :amount => 20 }, { :email => "receiver2@site.com", :amount => 5, :primary => true } ],
|
12
|
+
:action_type => "PAY",
|
13
|
+
:payment_type => "DIGITALGOODS",
|
14
|
+
:allowed_funding_types => ["CREDITCARD", "BALANCE"],
|
15
|
+
:invoice_id => "42",
|
16
|
+
:preapproval_key => "ABCD-1234",
|
17
|
+
:pin => "1234",
|
18
|
+
:currency_code => "USD",
|
19
|
+
:cancel_url => "http://site.com/cancelled",
|
20
|
+
:return_url => "http://site.com/success",
|
21
|
+
:ipn_notification_url => "http://site.com/ipn",
|
22
|
+
:sender_email => "sender@site.com",
|
23
|
+
:sender_phone_country_code => "61",
|
24
|
+
:sender_phone_number => "0431300200",
|
25
|
+
:sender_phone_extension => "033",
|
26
|
+
:reverse_parallel_payments_on_error => false,
|
27
|
+
:tracking_id => "anything.id",
|
28
|
+
:memo => "a personal note"
|
29
|
+
)
|
30
|
+
end
|
31
|
+
|
32
|
+
let(:json) { JSON.parse(request.to_json) }
|
33
|
+
|
34
|
+
it "maps #receivers.first.email to ['receiverList']['receiver'][0]['email']" do
|
35
|
+
json["receiverList"]["receiver"][0]["email"].should == "receiver1@site.com"
|
36
|
+
end
|
37
|
+
|
38
|
+
it "maps #receivers.last.email to ['receiverList']['receiver'][1]['email']" do
|
39
|
+
json["receiverList"]["receiver"][1]["email"].should == "receiver2@site.com"
|
40
|
+
end
|
41
|
+
|
42
|
+
it "maps #receivers.first.amount to ['receiverList']['receiver'][0]['amount']" do
|
43
|
+
json["receiverList"]["receiver"][0]["amount"].should == "20.00"
|
44
|
+
end
|
45
|
+
|
46
|
+
it "maps #receivers.last.amount to ['receiverList']['receiver'][1]['amount']" do
|
47
|
+
json["receiverList"]["receiver"][1]["amount"].should == "5.00"
|
48
|
+
end
|
49
|
+
|
50
|
+
it "maps #receivers.last.primary to ['receiverList']['receiver'][1]['primary']" do
|
51
|
+
json["receiverList"]["receiver"][1]["primary"].should == true
|
52
|
+
end
|
53
|
+
|
54
|
+
it "maps #payment_type to ['receiverList']['receiver'][0]['paymentType']" do
|
55
|
+
json["receiverList"]["receiver"][0]["paymentType"].should == "DIGITALGOODS"
|
56
|
+
end
|
57
|
+
|
58
|
+
it "maps #allowed_funding_types.first to ['fundingConstraint']['allowedFundingType']['fundingTypeInfo'][0]['fundingType']" do
|
59
|
+
json["fundingConstraint"]["allowedFundingType"]["fundingTypeInfo"][0]["fundingType"].should == "CREDITCARD"
|
60
|
+
end
|
61
|
+
|
62
|
+
it "maps #allowed_funding_types.last to ['fundingConstraint']['allowedFundingType']['fundingTypeInfo'][1]['fundingType']" do
|
63
|
+
json["fundingConstraint"]["allowedFundingType"]["fundingTypeInfo"][1]["fundingType"].should == "BALANCE"
|
64
|
+
end
|
65
|
+
|
66
|
+
it "maps #invoice_id to ['receiverList']['receiver'][0]['invoiceId']" do
|
67
|
+
json["receiverList"]["receiver"][0]["invoiceId"].should == "42"
|
68
|
+
end
|
69
|
+
|
70
|
+
it "allows setting the first receiver email with #receiver_email" do
|
71
|
+
request.receiver_email = "another@receiver.com"
|
72
|
+
json["receiverList"]["receiver"][0]["email"].should == "another@receiver.com"
|
73
|
+
end
|
74
|
+
|
75
|
+
it "allows setting the first receiver amount with #receiver_amount" do
|
76
|
+
request.receiver_amount = 30
|
77
|
+
json["receiverList"]["receiver"][0]["amount"].should == "30.00"
|
78
|
+
end
|
79
|
+
|
80
|
+
it "allows setting the first receiver phone number with #receiver_phone_number" do
|
81
|
+
request.receiver_phone_number = "0431301201"
|
82
|
+
json["receiverList"]["receiver"][0]["phone"]["phoneNumber"].should == "0431301201"
|
83
|
+
end
|
84
|
+
|
85
|
+
it "allows setting the first receiver phone country code with #receiver_phone_country_code" do
|
86
|
+
request.receiver_phone_country_code = "61"
|
87
|
+
json["receiverList"]["receiver"][0]["phone"]["countryCode"].should == "61"
|
88
|
+
end
|
89
|
+
|
90
|
+
it "allows setting the first receiver phone extension with #receiver_phone_extension" do
|
91
|
+
request.receiver_phone_extension = "033"
|
92
|
+
json["receiverList"]["receiver"][0]["phone"]["extension"].should == "033"
|
93
|
+
end
|
94
|
+
|
95
|
+
it "maps #action_type to ['actionType']" do
|
96
|
+
json["actionType"].should == "PAY"
|
97
|
+
end
|
98
|
+
|
99
|
+
it "maps #preapproval_key to ['preapprovalKey']" do
|
100
|
+
json["preapprovalKey"].should == "ABCD-1234"
|
101
|
+
end
|
102
|
+
|
103
|
+
it "maps #pin to ['pin']" do
|
104
|
+
json["pin"].should == "1234"
|
105
|
+
end
|
106
|
+
|
107
|
+
it "maps #currency_code to ['currencyCode']" do
|
108
|
+
json["currencyCode"].should == "USD"
|
109
|
+
end
|
110
|
+
|
111
|
+
it "maps #cancel_url to ['cancelUrl']" do
|
112
|
+
json["cancelUrl"].should == "http://site.com/cancelled"
|
113
|
+
end
|
114
|
+
|
115
|
+
it "maps #return_url to ['returnUrl']" do
|
116
|
+
json["returnUrl"].should == "http://site.com/success"
|
117
|
+
end
|
118
|
+
|
119
|
+
it "maps #ipn_notification_url to ['ipnNotificationUrl']" do
|
120
|
+
json["ipnNotificationUrl"].should == "http://site.com/ipn"
|
121
|
+
end
|
122
|
+
|
123
|
+
it "maps #sender_email to ['sender']['email']" do
|
124
|
+
json["sender"]["email"].should == "sender@site.com"
|
125
|
+
end
|
126
|
+
|
127
|
+
it "maps #sender_phone_country_code to ['sender']['phone']['countryCode']" do
|
128
|
+
json["sender"]["phone"]["countryCode"].should == "61"
|
129
|
+
end
|
130
|
+
|
131
|
+
it "maps #sender_phone_number to ['sender']['phone']['phoneNumber']" do
|
132
|
+
json["sender"]["phone"]["phoneNumber"].should == "0431300200"
|
133
|
+
end
|
134
|
+
|
135
|
+
it "maps #sender_phone_extension to ['sender']['phone']['extension']" do
|
136
|
+
json["sender"]["phone"]["extension"].should == "033"
|
137
|
+
end
|
138
|
+
|
139
|
+
it "maps #reverse_parallel_payments_on_error to ['reverseAllParallelPaymentsOnError']" do
|
140
|
+
json["reverseAllParallelPaymentsOnError"].should == false
|
141
|
+
end
|
142
|
+
|
143
|
+
it "maps #tracking_id to ['trackingId']" do
|
144
|
+
json["trackingId"].should == "anything.id"
|
145
|
+
end
|
146
|
+
|
147
|
+
it "maps #memo to 'memo'" do
|
148
|
+
json["memo"].should == "a personal note"
|
149
|
+
end
|
150
|
+
end
|
@@ -0,0 +1,197 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe AdaptivePayments::PayResponse do
|
4
|
+
it_behaves_like "a ResponseEnvelope"
|
5
|
+
it_behaves_like "a FaultMessage"
|
6
|
+
|
7
|
+
let(:response) do
|
8
|
+
AdaptivePayments::PayResponse.from_json(
|
9
|
+
{
|
10
|
+
:payKey => "ABCD-1234",
|
11
|
+
:paymentExecStatus => "COMPLETED",
|
12
|
+
:defaultFundingPlan => {
|
13
|
+
:fundingPlanId => "XXX123",
|
14
|
+
:fundingAmount => {
|
15
|
+
:amount => "100.00",
|
16
|
+
:code => "USD"
|
17
|
+
},
|
18
|
+
:senderFees => {
|
19
|
+
:amount => "6.00",
|
20
|
+
:code => "USD"
|
21
|
+
},
|
22
|
+
:backupFundingSource => {
|
23
|
+
:fundingSourceId => "9876",
|
24
|
+
:lastFourOfAccountNumber => "0000",
|
25
|
+
:displayName => "Primary Account",
|
26
|
+
:type => "CREDITCARD",
|
27
|
+
:allowed => true
|
28
|
+
},
|
29
|
+
:currencyConversion => {
|
30
|
+
:from => {
|
31
|
+
:amount => "83.33",
|
32
|
+
:code => "GBP"
|
33
|
+
},
|
34
|
+
:to => {
|
35
|
+
:amount => "100.00",
|
36
|
+
:code => "USD"
|
37
|
+
},
|
38
|
+
:exchangeRate => "0.8333"
|
39
|
+
},
|
40
|
+
:charge => [
|
41
|
+
:charge => {
|
42
|
+
:amount => "5.00",
|
43
|
+
:code => "USD"
|
44
|
+
},
|
45
|
+
:fundingSource => {
|
46
|
+
:fundingSourceId => "1234"
|
47
|
+
}
|
48
|
+
]
|
49
|
+
},
|
50
|
+
:payErrorList => {
|
51
|
+
:payError => [
|
52
|
+
{
|
53
|
+
:receiver => {
|
54
|
+
:email => "bob@site.com",
|
55
|
+
:amount => "5.00"
|
56
|
+
},
|
57
|
+
:error => {
|
58
|
+
:domain => "APPLICATION",
|
59
|
+
:message => "there was an error"
|
60
|
+
}
|
61
|
+
},
|
62
|
+
{
|
63
|
+
:receiver => {
|
64
|
+
:email => "sally@site.com",
|
65
|
+
:amount => "10.00"
|
66
|
+
},
|
67
|
+
:error => {
|
68
|
+
:domain => "APPLICATION",
|
69
|
+
:message => "there was another error"
|
70
|
+
}
|
71
|
+
}
|
72
|
+
]
|
73
|
+
}
|
74
|
+
}.to_json
|
75
|
+
)
|
76
|
+
end
|
77
|
+
|
78
|
+
it "maps ['payKey'] to #pay_key" do
|
79
|
+
response.pay_key.should == "ABCD-1234"
|
80
|
+
end
|
81
|
+
|
82
|
+
it "maps ['paymentExecStatus'] to #payment_exec_status" do
|
83
|
+
response.payment_exec_status.should == "COMPLETED"
|
84
|
+
end
|
85
|
+
|
86
|
+
it "maps ['defaultFundingPlan']['fundingPlanId'] to #funding_plan_id" do
|
87
|
+
response.funding_plan_id.should == "XXX123"
|
88
|
+
end
|
89
|
+
|
90
|
+
it "maps ['defaultFundingPlan']['fundingAmount']['amount'] to #funding_amount" do
|
91
|
+
response.funding_amount.should == BigDecimal("100.00")
|
92
|
+
end
|
93
|
+
|
94
|
+
it "maps ['defaultFundingPlan']['fundingAmount']['code'] to #funding_currency_code" do
|
95
|
+
response.funding_currency_code.should == "USD"
|
96
|
+
end
|
97
|
+
|
98
|
+
it "maps ['defaultFundingPlan']['senderFees']['amount'] to #sender_fees_amount" do
|
99
|
+
response.sender_fees_amount.should == BigDecimal("6.00")
|
100
|
+
end
|
101
|
+
|
102
|
+
it "maps ['defaultFundingPlan']['senderFees']['code'] to #sender_fees_currency_code" do
|
103
|
+
response.sender_fees_currency_code.should == "USD"
|
104
|
+
end
|
105
|
+
|
106
|
+
it "maps ['defaultFundingPlan']['backupFundingSource']['fundingSourceId'] to #backup_funding_source.id" do
|
107
|
+
response.backup_funding_source.id.should == "9876"
|
108
|
+
end
|
109
|
+
|
110
|
+
it "maps ['defaultFundingPlan']['backupFundingSource']['lastFourOfAccountNumber'] to #backup_funding_source.last_four_digits_of_account" do
|
111
|
+
response.backup_funding_source.last_four_digits_of_account.should == "0000"
|
112
|
+
end
|
113
|
+
|
114
|
+
it "maps ['defaultFundingPlan']['backupFundingSource']['displayName'] to #backup_funding_source.display_name" do
|
115
|
+
response.backup_funding_source.display_name.should == "Primary Account"
|
116
|
+
end
|
117
|
+
|
118
|
+
it "maps ['defaultFundingPlan']['backupFundingSource']['type'] to #backup_funding_source.type" do
|
119
|
+
response.backup_funding_source.type.should == "CREDITCARD"
|
120
|
+
end
|
121
|
+
|
122
|
+
it "maps ['defaultFundingPlan']['backupFundingSource']['allowed'] to #backup_funding_source.allowed? " do
|
123
|
+
response.backup_funding_source.should be_allowed
|
124
|
+
end
|
125
|
+
|
126
|
+
it "maps ['defaultFundingPlan']['currencyConversion']['from']['amount'] to #from_currency_amount" do
|
127
|
+
response.from_currency_amount.should == BigDecimal("83.33")
|
128
|
+
end
|
129
|
+
|
130
|
+
it "maps ['defaultFundingPlan']['currencyConversion']['from']['code'] to #from_currency_code" do
|
131
|
+
response.from_currency_code.should == "GBP"
|
132
|
+
end
|
133
|
+
|
134
|
+
it "maps ['defaultFundingPlan']['currencyConversion']['to']['amount'] to #to_currency_amount" do
|
135
|
+
response.to_currency_amount.should == BigDecimal("100.00")
|
136
|
+
end
|
137
|
+
|
138
|
+
it "maps ['defaultFundingPlan']['currencyConversion']['to']['code'] to #to_currency_code" do
|
139
|
+
response.to_currency_code.should == "USD"
|
140
|
+
end
|
141
|
+
|
142
|
+
it "maps ['defaultFundingPlan']['currencyConversion']['exchangeRate'] to #exchange_rate" do
|
143
|
+
response.exchange_rate.should == BigDecimal("0.8333")
|
144
|
+
end
|
145
|
+
|
146
|
+
it "maps ['defaultFundingPlan']['charge'][0]['charge']['amount'] to #charges.first.amount" do
|
147
|
+
response.charges.first.amount.should == BigDecimal("5.00")
|
148
|
+
end
|
149
|
+
|
150
|
+
it "maps ['defaultFundingPlan']['charge'][0]['charge']['code'] to #charges.first.currency_code" do
|
151
|
+
response.charges.first.currency_code.should == "USD"
|
152
|
+
end
|
153
|
+
|
154
|
+
it "maps ['defaultFundingPlan']['charge'][0]['fundingSource']['fundingSourceId'] to #charges.first.funding_source.id" do
|
155
|
+
response.charges.first.funding_source.id.should == "1234"
|
156
|
+
end
|
157
|
+
|
158
|
+
it "maps ['payErrorList']['payError'][0]['receiver']['email'] to #pay_errors.first.receiver.email" do
|
159
|
+
response.pay_errors.first.receiver.email.should == "bob@site.com"
|
160
|
+
end
|
161
|
+
|
162
|
+
it "allows access to ['payErrorList']['payError'][0]['receiver']['email'] with #pay_errors.first.receiver_email" do
|
163
|
+
response.pay_errors.first.receiver_email.should == "bob@site.com"
|
164
|
+
end
|
165
|
+
|
166
|
+
it "maps ['payErrorList']['payError'][0]['receiver']['amount'] to #pay_errors.first.receiver.amount" do
|
167
|
+
response.pay_errors.first.receiver.amount.should == BigDecimal("5.00")
|
168
|
+
end
|
169
|
+
|
170
|
+
it "allows access to ['payErrorList']['payError'][0]['receiver']['amount'] with #pay_errors.first.receiver_amount" do
|
171
|
+
response.pay_errors.first.receiver_amount.should == BigDecimal("5.00")
|
172
|
+
end
|
173
|
+
|
174
|
+
it "maps ['payErrorList']['payError'][0]['error']['domain'] to #pay_errors.first.error.domain" do
|
175
|
+
response.pay_errors.first.error.domain.should == "APPLICATION"
|
176
|
+
end
|
177
|
+
|
178
|
+
it "allows access to ['payErrorList']['payError'][0]['error']['domain'] with #pay_errors.first.error_domain" do
|
179
|
+
response.pay_errors.first.error_domain.should == "APPLICATION"
|
180
|
+
end
|
181
|
+
|
182
|
+
it "maps ['payErrorList']['payError'][0]['error']['message'] to #pay_errors.first.error.message" do
|
183
|
+
response.pay_errors.first.error.message.should == "there was an error"
|
184
|
+
end
|
185
|
+
|
186
|
+
it "allows access to ['payErrorList']['payError'][0]['error']['message'] with #pay_errors.first.error_message" do
|
187
|
+
response.pay_errors.first.error_message.should == "there was an error"
|
188
|
+
end
|
189
|
+
|
190
|
+
it "maps ['payErrorList']['payError'][1]['receiver']['email'] to #pay_errors.last.receiver.email" do
|
191
|
+
response.pay_errors.last.receiver.email.should == "sally@site.com"
|
192
|
+
end
|
193
|
+
|
194
|
+
it "maps ['payErrorList']['payError'][0]['error']['message'] to #pay_errors.last.error.message" do
|
195
|
+
response.pay_errors.last.error.message.should == "there was another error"
|
196
|
+
end
|
197
|
+
end
|