pp-adaptive 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (107) hide show
  1. data/.gitignore +6 -0
  2. data/.rspec +1 -0
  3. data/Gemfile +4 -0
  4. data/README.md +54 -0
  5. data/Rakefile +8 -0
  6. data/lib/pp-adaptive/abstract_request.rb +44 -0
  7. data/lib/pp-adaptive/abstract_response.rb +46 -0
  8. data/lib/pp-adaptive/cancel_preapproval_request.rb +7 -0
  9. data/lib/pp-adaptive/cancel_preapproval_response.rb +7 -0
  10. data/lib/pp-adaptive/client.rb +56 -0
  11. data/lib/pp-adaptive/convert_currency_request.rb +33 -0
  12. data/lib/pp-adaptive/convert_currency_response.rb +11 -0
  13. data/lib/pp-adaptive/execute_payment_request.rb +9 -0
  14. data/lib/pp-adaptive/execute_payment_response.rb +12 -0
  15. data/lib/pp-adaptive/get_payment_options_request.rb +7 -0
  16. data/lib/pp-adaptive/get_payment_options_response.rb +32 -0
  17. data/lib/pp-adaptive/pay_request.rb +64 -0
  18. data/lib/pp-adaptive/pay_response.rb +29 -0
  19. data/lib/pp-adaptive/payment_details_request.rb +9 -0
  20. data/lib/pp-adaptive/payment_details_response.rb +53 -0
  21. data/lib/pp-adaptive/preapproval_details_request.rb +8 -0
  22. data/lib/pp-adaptive/preapproval_details_response.rb +35 -0
  23. data/lib/pp-adaptive/preapproval_request.rb +36 -0
  24. data/lib/pp-adaptive/preapproval_response.rb +7 -0
  25. data/lib/pp-adaptive/refund_request.rb +14 -0
  26. data/lib/pp-adaptive/refund_response.rb +12 -0
  27. data/lib/pp-adaptive/set_payment_options_request.rb +33 -0
  28. data/lib/pp-adaptive/set_payment_options_response.rb +7 -0
  29. data/lib/pp-adaptive/support/aliases.rb +33 -0
  30. data/lib/pp-adaptive/support/coerced_array.rb +52 -0
  31. data/lib/pp-adaptive/support/json_model.rb +140 -0
  32. data/lib/pp-adaptive/support/node.rb +45 -0
  33. data/lib/pp-adaptive/support/node_list.rb +45 -0
  34. data/lib/pp-adaptive/types/account_identifier.rb +6 -0
  35. data/lib/pp-adaptive/types/address.rb +17 -0
  36. data/lib/pp-adaptive/types/address_list.rb +5 -0
  37. data/lib/pp-adaptive/types/aliases/receiver_aliases.rb +15 -0
  38. data/lib/pp-adaptive/types/aliases/receiver_list_aliases.rb +32 -0
  39. data/lib/pp-adaptive/types/base_address.rb +11 -0
  40. data/lib/pp-adaptive/types/client_details_type.rb +12 -0
  41. data/lib/pp-adaptive/types/currency_code.rb +5 -0
  42. data/lib/pp-adaptive/types/currency_conversion.rb +17 -0
  43. data/lib/pp-adaptive/types/currency_conversion_list.rb +15 -0
  44. data/lib/pp-adaptive/types/currency_conversion_table.rb +5 -0
  45. data/lib/pp-adaptive/types/currency_list.rb +5 -0
  46. data/lib/pp-adaptive/types/currency_type.rb +6 -0
  47. data/lib/pp-adaptive/types/display_options.rb +8 -0
  48. data/lib/pp-adaptive/types/error_data.rb +11 -0
  49. data/lib/pp-adaptive/types/error_list.rb +5 -0
  50. data/lib/pp-adaptive/types/fault_message.rb +23 -0
  51. data/lib/pp-adaptive/types/funding_constraint.rb +5 -0
  52. data/lib/pp-adaptive/types/funding_plan.rb +28 -0
  53. data/lib/pp-adaptive/types/funding_plan_charge.rb +11 -0
  54. data/lib/pp-adaptive/types/funding_source.rb +9 -0
  55. data/lib/pp-adaptive/types/funding_type_info.rb +5 -0
  56. data/lib/pp-adaptive/types/funding_type_list.rb +5 -0
  57. data/lib/pp-adaptive/types/initiating_entity.rb +15 -0
  58. data/lib/pp-adaptive/types/institution_customer.rb +11 -0
  59. data/lib/pp-adaptive/types/invoice_data.rb +7 -0
  60. data/lib/pp-adaptive/types/invoice_item.rb +9 -0
  61. data/lib/pp-adaptive/types/pay_error.rb +18 -0
  62. data/lib/pp-adaptive/types/pay_error_list.rb +5 -0
  63. data/lib/pp-adaptive/types/payment_info.rb +16 -0
  64. data/lib/pp-adaptive/types/payment_info_list.rb +5 -0
  65. data/lib/pp-adaptive/types/phone_number_type.rb +7 -0
  66. data/lib/pp-adaptive/types/receiver.rb +17 -0
  67. data/lib/pp-adaptive/types/receiver_identifier.rb +12 -0
  68. data/lib/pp-adaptive/types/receiver_list.rb +5 -0
  69. data/lib/pp-adaptive/types/receiver_options.rb +21 -0
  70. data/lib/pp-adaptive/types/refund_info.rb +20 -0
  71. data/lib/pp-adaptive/types/refund_info_list.rb +5 -0
  72. data/lib/pp-adaptive/types/request_envelope.rb +6 -0
  73. data/lib/pp-adaptive/types/response_envelope.rb +13 -0
  74. data/lib/pp-adaptive/types/sender_identifier.rb +5 -0
  75. data/lib/pp-adaptive/types/sender_options.rb +5 -0
  76. data/lib/pp-adaptive/version.rb +3 -0
  77. data/lib/pp-adaptive.rb +75 -0
  78. data/pp-adaptive.gemspec +25 -0
  79. data/spec/public/cancel_preapproval_request_spec.rb +15 -0
  80. data/spec/public/cancel_preapproval_response_spec.rb +6 -0
  81. data/spec/public/client_spec.rb +85 -0
  82. data/spec/public/convert_currency_request_spec.rb +29 -0
  83. data/spec/public/convert_currency_response_spec.rb +62 -0
  84. data/spec/public/execute_payment_request_spec.rb +30 -0
  85. data/spec/public/execute_payment_response_spec.rb +66 -0
  86. data/spec/public/get_payment_options_request_spec.rb +15 -0
  87. data/spec/public/get_payment_options_response_spec.rb +141 -0
  88. data/spec/public/json_model_spec.rb +56 -0
  89. data/spec/public/node_list_spec.rb +58 -0
  90. data/spec/public/node_spec.rb +54 -0
  91. data/spec/public/pay_request_spec.rb +150 -0
  92. data/spec/public/pay_response_spec.rb +197 -0
  93. data/spec/public/payment_details_request_spec.rb +30 -0
  94. data/spec/public/payment_details_response_spec.rb +211 -0
  95. data/spec/public/preapproval_details_request_spec.rb +25 -0
  96. data/spec/public/preapproval_details_response_spec.rb +200 -0
  97. data/spec/public/preapproval_request_spec.rb +110 -0
  98. data/spec/public/preapproval_response_spec.rb +14 -0
  99. data/spec/public/refund_request_spec.rb +57 -0
  100. data/spec/public/refund_response_spec.rb +116 -0
  101. data/spec/public/set_payment_options_request_spec.rb +136 -0
  102. data/spec/public/set_payment_options_response_spec.rb +6 -0
  103. data/spec/shared/a_fault_message.rb +60 -0
  104. data/spec/shared/a_request_envelope.rb +14 -0
  105. data/spec/shared/a_response_envelope.rb +36 -0
  106. data/spec/spec_helper.rb +6 -0
  107. metadata +225 -0
@@ -0,0 +1,15 @@
1
+ module AdaptivePayments
2
+ class InitiatingEntity < JsonModel
3
+ attribute :institution_customer, Node[InstitutionCustomer], :param => "institutionCustomer"
4
+
5
+ alias_params :institution_customer, {
6
+ :institution_id => :institution_id,
7
+ :customer_first_name => :first_name,
8
+ :customer_last_name => :last_name,
9
+ :customer_display_name => :display_name,
10
+ :institution_customer_id => :institution_customer_id,
11
+ :customer_country_code => :country_code,
12
+ :customer_email => :email
13
+ }
14
+ end
15
+ end
@@ -0,0 +1,11 @@
1
+ module AdaptivePayments
2
+ class InstitutionCustomer < JsonModel
3
+ attribute :institution_id, String, :param => "institutionId"
4
+ attribute :first_name, String, :param => "firstName"
5
+ attribute :last_name, String, :param => "lastName"
6
+ attribute :display_name, String, :param => "displayName"
7
+ attribute :institution_customer_id, String, :param => "institutionCustomerId"
8
+ attribute :country_code, String, :param => "countryCode"
9
+ attribute :email, String
10
+ end
11
+ end
@@ -0,0 +1,7 @@
1
+ module AdaptivePayments
2
+ class InvoiceData < JsonModel
3
+ attribute :items, NodeList[InvoiceItem], :param => "item"
4
+ attribute :total_tax, Decimal, :param => "totalTax"
5
+ attribute :total_shipping, Decimal, :param => "totalShipping"
6
+ end
7
+ end
@@ -0,0 +1,9 @@
1
+ module AdaptivePayments
2
+ class InvoiceItem < JsonModel
3
+ attribute :name, String
4
+ attribute :identifier, String
5
+ attribute :price, Decimal
6
+ attribute :item_price, Decimal, :param => "itemPrice"
7
+ attribute :item_count, Integer, :param => "itemCount"
8
+ end
9
+ end
@@ -0,0 +1,18 @@
1
+ module AdaptivePayments
2
+ class PayError < JsonModel
3
+ attribute :receiver, Node[Receiver]
4
+ attribute :error, Node[ErrorData]
5
+
6
+ include ReceiverAliases
7
+
8
+ alias_params :error, {
9
+ :error_id => :id,
10
+ :error_domain => :domain,
11
+ :error_subdomain => :subdomain,
12
+ :error_severity => :severity,
13
+ :error_category => :category,
14
+ :error_message => :message,
15
+ :error_parameters => :parameters
16
+ }
17
+ end
18
+ end
@@ -0,0 +1,5 @@
1
+ module AdaptivePayments
2
+ class PayErrorList < JsonModel
3
+ attribute :pay_errors, NodeList[PayError], :param => "payError"
4
+ end
5
+ end
@@ -0,0 +1,16 @@
1
+ module AdaptivePayments
2
+ class PaymentInfo < JsonModel
3
+ attribute :transaction_id, String, :param => "transactionId"
4
+ attribute :transaction_status, String, :param => "transactionStatus"
5
+ attribute :receiver, Node[Receiver]
6
+ attribute :refunded_amount, Decimal, :param => "refundedAmount"
7
+ attribute :pending_refund, Boolean, :param => "pendingRefund"
8
+ attribute :sender_transaction_id, String, :param => "senderTransactionId"
9
+ attribute :sender_transaction_status, String, :param => "senderTransactionStatus"
10
+ attribute :pending_reason, String, :param => "pendingReason"
11
+
12
+ include ReceiverAliases
13
+ end
14
+
15
+ # FIXME: Add predicates for the transaction_status
16
+ end
@@ -0,0 +1,5 @@
1
+ module AdaptivePayments
2
+ class PaymentInfoList < JsonModel
3
+ attribute :payment_info, NodeList[PaymentInfo], :param => "paymentInfo"
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ module AdaptivePayments
2
+ class PhoneNumberType < JsonModel
3
+ attribute :country_code, String, :param => "countryCode"
4
+ attribute :phone_number, String, :param => "phoneNumber"
5
+ attribute :extension, String, :param => "extension"
6
+ end
7
+ end
@@ -0,0 +1,17 @@
1
+ module AdaptivePayments
2
+ class Receiver < JsonModel
3
+ attribute :phone, Node[PhoneNumberType]
4
+ attribute :email, String
5
+ attribute :amount, Decimal
6
+ attribute :payment_type, String, :param => "paymentType"
7
+ attribute :payment_subtype, String, :param => "paymentSubType"
8
+ attribute :primary, Boolean
9
+ attribute :invoice_id, String, :param => "invoiceId"
10
+
11
+ alias_params :phone, {
12
+ :phone_country_code => :country_code,
13
+ :phone_number => :phone_number,
14
+ :phone_extension => :extension
15
+ }
16
+ end
17
+ end
@@ -0,0 +1,12 @@
1
+ module AdaptivePayments
2
+ class ReceiverIdentifier < JsonModel
3
+ attribute :email, String
4
+ attribute :phone, Node[PhoneNumberType]
5
+
6
+ alias_params :phone, {
7
+ :phone_country_code => :country_code,
8
+ :phone_number => :phone_number,
9
+ :phone_extension => :extension
10
+ }
11
+ end
12
+ end
@@ -0,0 +1,5 @@
1
+ module AdaptivePayments
2
+ class ReceiverList < JsonModel
3
+ attribute :receivers, NodeList[Receiver], :param => "receiver"
4
+ end
5
+ end
@@ -0,0 +1,21 @@
1
+ module AdaptivePayments
2
+ class ReceiverOptions < JsonModel
3
+ attribute :description, String
4
+ attribute :custom_id, String, :param => "customId"
5
+ attribute :invoice_data, Node[InvoiceData], :param => "invoiceData"
6
+ attribute :receiver, Node[ReceiverIdentifier], :param => "receiver"
7
+
8
+ alias_params :invoice_data, {
9
+ :items => :items,
10
+ :total_tax => :total_tax,
11
+ :total_shipping => :total_shipping
12
+ }
13
+
14
+ alias_params :receiver, {
15
+ :receiver_email => :email,
16
+ :receiver_phone_country_code => :phone_country_code,
17
+ :receiver_phone_number => :phone_number,
18
+ :receiver_phone_extension => :phone_extension
19
+ }
20
+ end
21
+ end
@@ -0,0 +1,20 @@
1
+ module AdaptivePayments
2
+ class RefundInfo < JsonModel
3
+ attribute :receiver, Node[Receiver]
4
+ attribute :refund_status, String, :param => "refundStatus"
5
+ attribute :refund_net_amount, Decimal, :param => "refundNetAmount"
6
+ attribute :refund_fee_amount, Decimal, :param => "refundFeeAmount"
7
+ attribute :refund_gross_amount, Decimal, :param => "refundGrossAmount"
8
+ attribute :total_of_all_refunds, Decimal, :param => "totalOfAllRefunds"
9
+ attribute :refund_has_become_full, Boolean, :param => "refundHasBecomeFull"
10
+ attribute :encrypted_refund_transaction_id, String, :param => "encryptedRefundTransactionId"
11
+ attribute :refund_transaction_status, String, :param => "refundTransactionStatus"
12
+ attribute :error_list, Node[ErrorList], :param => "errorList"
13
+
14
+ include ReceiverAliases
15
+
16
+ alias_params :error_list, {
17
+ :errors => :errors
18
+ }
19
+ end
20
+ end
@@ -0,0 +1,5 @@
1
+ module AdaptivePayments
2
+ class RefundInfoList < JsonModel
3
+ attribute :refund_info, NodeList[RefundInfo], :param => "refundInfo"
4
+ end
5
+ end
@@ -0,0 +1,6 @@
1
+ module AdaptivePayments
2
+ class RequestEnvelope < JsonModel
3
+ attribute :detail_level, String, :param => "detailLevel"
4
+ attribute :error_language, String, :param => "errorLanguage", :default => "en_US"
5
+ end
6
+ end
@@ -0,0 +1,13 @@
1
+ module AdaptivePayments
2
+ class ResponseEnvelope < JsonModel
3
+ attribute :ack_code, String, :param => "ack"
4
+ attribute :build, String, :param => "build"
5
+ attribute :correlation_id, String, :param => "correlationId"
6
+ attribute :time, DateTime, :param => "timestamp"
7
+
8
+ ["Success", "Failure", "Warning", "SuccessWithWarning", "FailureWithWarning"].each do |ack|
9
+ method = ack.split(/(?=[A-Z])/).map{ |w| w.downcase }.join("_") + "?"
10
+ define_method(method) { ack_code == ack }
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,5 @@
1
+ module AdaptivePayments
2
+ class SenderIdentifier < AccountIdentifier
3
+ attribute :use_credentials, Boolean, :param => "useCredentials"
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module AdaptivePayments
2
+ class SenderOptions < JsonModel
3
+ attribute :require_shipping_address_selection, Boolean, :param => "requireShippingAddressSelection"
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module AdaptivePayments
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,75 @@
1
+ require "pp-adaptive/version"
2
+
3
+ require "pp-adaptive/support/aliases"
4
+ require "pp-adaptive/support/json_model"
5
+ require "pp-adaptive/support/coerced_array"
6
+ require "pp-adaptive/support/node"
7
+ require "pp-adaptive/support/node_list"
8
+
9
+ require "pp-adaptive/types/aliases/receiver_aliases"
10
+ require "pp-adaptive/types/aliases/receiver_list_aliases"
11
+
12
+ require "pp-adaptive/types/client_details_type"
13
+ require "pp-adaptive/types/request_envelope"
14
+ require "pp-adaptive/types/phone_number_type"
15
+ require "pp-adaptive/types/receiver"
16
+ require "pp-adaptive/types/receiver_list"
17
+ require "pp-adaptive/types/account_identifier"
18
+ require "pp-adaptive/types/sender_identifier"
19
+ require "pp-adaptive/types/funding_type_info"
20
+ require "pp-adaptive/types/funding_type_list"
21
+ require "pp-adaptive/types/funding_constraint"
22
+ require "pp-adaptive/types/response_envelope"
23
+ require "pp-adaptive/types/error_data"
24
+ require "pp-adaptive/types/error_list"
25
+ require "pp-adaptive/types/fault_message"
26
+ require "pp-adaptive/types/base_address"
27
+ require "pp-adaptive/types/address"
28
+ require "pp-adaptive/types/address_list"
29
+ require "pp-adaptive/types/currency_type"
30
+ require "pp-adaptive/types/currency_code"
31
+ require "pp-adaptive/types/currency_list"
32
+ require "pp-adaptive/types/currency_conversion"
33
+ require "pp-adaptive/types/currency_conversion_list"
34
+ require "pp-adaptive/types/currency_conversion_table"
35
+ require "pp-adaptive/types/funding_source"
36
+ require "pp-adaptive/types/funding_plan_charge"
37
+ require "pp-adaptive/types/funding_plan"
38
+ require "pp-adaptive/types/invoice_item"
39
+ require "pp-adaptive/types/invoice_data"
40
+ require "pp-adaptive/types/institution_customer"
41
+ require "pp-adaptive/types/initiating_entity"
42
+ require "pp-adaptive/types/receiver_identifier"
43
+ require "pp-adaptive/types/display_options"
44
+ require "pp-adaptive/types/sender_options"
45
+ require "pp-adaptive/types/receiver_options"
46
+ require "pp-adaptive/types/pay_error"
47
+ require "pp-adaptive/types/pay_error_list"
48
+ require "pp-adaptive/types/payment_info"
49
+ require "pp-adaptive/types/payment_info_list"
50
+ require "pp-adaptive/types/refund_info"
51
+ require "pp-adaptive/types/refund_info_list"
52
+
53
+ require "pp-adaptive/abstract_request"
54
+ require "pp-adaptive/abstract_response"
55
+ require "pp-adaptive/pay_request"
56
+ require "pp-adaptive/pay_response"
57
+ require "pp-adaptive/payment_details_request"
58
+ require "pp-adaptive/payment_details_response"
59
+ require "pp-adaptive/execute_payment_request"
60
+ require "pp-adaptive/execute_payment_response"
61
+ require "pp-adaptive/get_payment_options_request"
62
+ require "pp-adaptive/get_payment_options_response"
63
+ require "pp-adaptive/set_payment_options_request"
64
+ require "pp-adaptive/set_payment_options_response"
65
+ require "pp-adaptive/preapproval_request"
66
+ require "pp-adaptive/preapproval_response"
67
+ require "pp-adaptive/preapproval_details_request"
68
+ require "pp-adaptive/preapproval_details_response"
69
+ require "pp-adaptive/cancel_preapproval_request"
70
+ require "pp-adaptive/cancel_preapproval_response"
71
+ require "pp-adaptive/refund_request"
72
+ require "pp-adaptive/refund_response"
73
+ require "pp-adaptive/convert_currency_request"
74
+ require "pp-adaptive/convert_currency_response"
75
+ require "pp-adaptive/client"
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "pp-adaptive/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "pp-adaptive"
7
+ s.version = AdaptivePayments::VERSION
8
+ s.authors = ["d11wtq"]
9
+ s.email = ["chris@w3style.co.uk"]
10
+ s.homepage = "https://github.com/"
11
+ s.summary = %q{Rubygem for working with PayPal's Adaptive Payments API}
12
+ s.description = %q{Currently provides just a subset of PayPal's API, for setting up preapproval agreements and taking payments}
13
+
14
+ s.rubyforge_project = "pp-adaptive"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_runtime_dependency "rest-client"
22
+ s.add_runtime_dependency "virtus", ">= 0.0.9"
23
+ s.add_runtime_dependency "json"
24
+ s.add_development_dependency "rspec", ">= 2.6"
25
+ end
@@ -0,0 +1,15 @@
1
+ require "spec_helper"
2
+
3
+ describe AdaptivePayments::CancelPreapprovalRequest do
4
+ it_behaves_like "a RequestEnvelope"
5
+
6
+ subject { AdaptivePayments::CancelPreapprovalRequest }
7
+ its(:operation) { should == :CancelPreapproval }
8
+
9
+ let(:request) { AdaptivePayments::CancelPreapprovalRequest.new(:preapproval_key => "ABCD-1234") }
10
+ let(:json) { JSON.parse(request.to_json) }
11
+
12
+ it "maps #preapproval_key to ['preapprovalKey']" do
13
+ json["preapprovalKey"].should == "ABCD-1234"
14
+ end
15
+ end
@@ -0,0 +1,6 @@
1
+ require "spec_helper"
2
+
3
+ describe AdaptivePayments::CancelPreapprovalResponse do
4
+ it_behaves_like "a ResponseEnvelope"
5
+ it_behaves_like "a FaultMessage"
6
+ end
@@ -0,0 +1,85 @@
1
+ require "spec_helper"
2
+
3
+ describe AdaptivePayments::Client do
4
+ let(:rest_client) { double(:post => nil).tap { |d| d.stub(:[] => d) } }
5
+ let(:request_class) { stub(:operation => :Test, :build_response => nil) }
6
+ let(:request) { stub(:class => request_class, :to_json => '{}') }
7
+ let(:client) { AdaptivePayments::Client.new }
8
+
9
+ before(:each) do
10
+ RestClient::Resource.stub(:new).and_return(rest_client)
11
+ end
12
+
13
+ it "uses the production endpoint by default" do
14
+ RestClient::Resource.should_receive(:new) \
15
+ .with("https://svcs.paypal.com/AdaptivePayments", an_instance_of(Hash)) \
16
+ .and_return(rest_client)
17
+ client.execute(request)
18
+ end
19
+
20
+ it "uses the sandbox when sandbox? is true" do
21
+ client.sandbox = true
22
+ RestClient::Resource.should_receive(:new) \
23
+ .with("https://svcs.sandbox.paypal.com/AdaptivePayments", an_instance_of(Hash)) \
24
+ .and_return(rest_client)
25
+ client.execute(request)
26
+ end
27
+
28
+ it "sends the user ID in the headers to the endpoint" do
29
+ client.user_id = "a.user.id"
30
+ RestClient::Resource.should_receive(:new) \
31
+ .with(/^https:\/\/.*/, :headers => hash_including("X-PAYPAL-SECURITY-USERID" => "a.user.id")) \
32
+ .and_return(rest_client)
33
+ client.execute(request)
34
+ end
35
+
36
+ it "sends the password in the headers to the endpoint" do
37
+ client.password = "123456"
38
+ RestClient::Resource.should_receive(:new) \
39
+ .with(/^https:\/\/.*/, :headers => hash_including("X-PAYPAL-SECURITY-PASSWORD" => "123456")) \
40
+ .and_return(rest_client)
41
+ client.execute(request)
42
+ end
43
+
44
+ it "sends the signature in the headers to the endpoint" do
45
+ client.signature = "a.signature"
46
+ RestClient::Resource.should_receive(:new) \
47
+ .with(/^https:\/\/.*/, :headers => hash_including("X-PAYPAL-SECURITY-SIGNATURE" => "a.signature")) \
48
+ .and_return(rest_client)
49
+ client.execute(request)
50
+ end
51
+
52
+ it "sends the application ID in the headers to the endpoint" do
53
+ client.app_id = "an.app.id"
54
+ RestClient::Resource.should_receive(:new) \
55
+ .with(/^https:\/\/.*/, :headers => hash_including("X-PAYPAL-APPLICATION-ID" => "an.app.id")) \
56
+ .and_return(rest_client)
57
+ client.execute(request)
58
+ end
59
+
60
+ it "sets the request format to JSON" do
61
+ RestClient::Resource.should_receive(:new) \
62
+ .with(/^https:\/\/.*/, :headers => hash_including("X-PAYPAL-REQUEST-DATA-FORMAT" => "JSON")) \
63
+ .and_return(rest_client)
64
+ client.execute(request)
65
+ end
66
+
67
+ it "sets the response format to JSON" do
68
+ RestClient::Resource.should_receive(:new) \
69
+ .with(/^https:\/\/.*/, :headers => hash_including("X-PAYPAL-RESPONSE-DATA-FORMAT" => "JSON")) \
70
+ .and_return(rest_client)
71
+ client.execute(request)
72
+ end
73
+
74
+ it "sends requests to the given API operation" do
75
+ request.class.stub(:operation => :Preapproval)
76
+ rest_client.should_receive(:[]).with("Preapproval")
77
+ client.execute(request)
78
+ end
79
+
80
+ it "uses the request class to build a response" do
81
+ response = stub(:response)
82
+ request_class.should_receive(:build_response).and_return(response)
83
+ client.execute(request).should == response
84
+ end
85
+ end
@@ -0,0 +1,29 @@
1
+ require "spec_helper"
2
+
3
+ describe AdaptivePayments::ConvertCurrencyRequest do
4
+ it_behaves_like "a RequestEnvelope"
5
+
6
+ subject { AdaptivePayments::ConvertCurrencyRequest }
7
+ its(:operation) { should == :ConvertCurrency }
8
+
9
+ let(:request) do
10
+ AdaptivePayments::ConvertCurrencyRequest.new(
11
+ :currencies => [ { :amount => '14.99', :code => 'USD' },
12
+ { :amount => '129.99', :code => 'USD' } ],
13
+ :convert_to_currencies => ['JPY'],
14
+ :country_code => 'JP',
15
+ :conversion_type => 'SENDER_SIDE'
16
+ )
17
+ end
18
+
19
+ let(:json) { JSON.parse(request.to_json) }
20
+
21
+ it "maps #currency.first.amount to ['baseAmountList']['currency'][0]['amount']" do
22
+ json["baseAmountList"]["currency"][0]["amount"].should == "14.99"
23
+ end
24
+
25
+ it "maps #currency.first.amount to ['baseAmountList']['currency'][1]['amount']" do
26
+ json["baseAmountList"]["currency"][1]["amount"].should == "129.99"
27
+ end
28
+
29
+ end
@@ -0,0 +1,62 @@
1
+ require "spec_helper"
2
+
3
+ describe AdaptivePayments::ConvertCurrencyResponse do
4
+ it_behaves_like "a ResponseEnvelope"
5
+ it_behaves_like "a FaultMessage"
6
+
7
+ let(:response) do
8
+ AdaptivePayments::ConvertCurrencyResponse.from_json(
9
+ {
10
+ :estimatedAmountTable => {
11
+ :currencyConversionList => [
12
+ {
13
+ :baseAmount => {
14
+ :code => "USD",
15
+ :amount => "14.99"
16
+ },
17
+ :currencyList => {
18
+ :currency => [
19
+ {
20
+ :code => "JPY",
21
+ :amount => "1733"
22
+ }
23
+ ]
24
+ }
25
+ },
26
+ {
27
+ :baseAmount => {
28
+ :code => "USD",
29
+ :amount => "129.99"
30
+ },
31
+ :currencyList => {
32
+ :currency => [
33
+ {
34
+ :code => "JPY",
35
+ :amount => "15036"
36
+ }
37
+ ]
38
+ }
39
+ }
40
+ ]
41
+ }
42
+ }.to_json
43
+ )
44
+ end
45
+
46
+ it "maps ['estimatedAmountTable']['currencyConversionList']['baseAmount']['code'] to #currency_conversions[0].base_currency_code" do
47
+ response.currency_conversions.first.base_currency_code.should == "USD"
48
+ end
49
+
50
+ it "maps ['estimatedAmountTable']['currencyConversionList']['baseAmount']['amount'] to #currency_conversions[0].base_currency_amount" do
51
+ response.currency_conversions.first.base_currency_amount.should == BigDecimal.new("14.99")
52
+ end
53
+
54
+ it "maps ['estimatedAmountTable']['currencyConversionList']['currencyList']['currency][0]['code'] to #currency_conversions[0].currencies[0].currency_code" do
55
+ response.currency_conversions.first.currencies.first.code.should == "JPY"
56
+ end
57
+
58
+ it "maps ['estimatedAmountTable']['currencyConversionList']['currencyList']['currency][0]['amount'] to #currency_conversions[0].currencies[0].currency_amount" do
59
+ response.currency_conversions.first.currencies.first.amount.should == BigDecimal.new("1733")
60
+ end
61
+
62
+ end
@@ -0,0 +1,30 @@
1
+ require "spec_helper"
2
+
3
+ describe AdaptivePayments::ExecutePaymentRequest do
4
+ it_behaves_like "a RequestEnvelope"
5
+
6
+ subject { AdaptivePayments::ExecutePaymentRequest }
7
+ its(:operation) { should == :ExecutePayment }
8
+
9
+ let(:request) do
10
+ AdaptivePayments::ExecutePaymentRequest.new(
11
+ :action_type => "PAY",
12
+ :pay_key => "ABCD-1234",
13
+ :funding_plan_id => "funding123"
14
+ )
15
+ end
16
+
17
+ let(:json) { JSON.parse(request.to_json) }
18
+
19
+ it "maps #action_type to ['actionType']" do
20
+ json["actionType"].should == "PAY"
21
+ end
22
+
23
+ it "maps #pay_key to ['payKey']" do
24
+ json["payKey"].should == "ABCD-1234"
25
+ end
26
+
27
+ it "maps #funding_plan_id to ['fundingPlanId']" do
28
+ json["fundingPlanId"].should == "funding123"
29
+ end
30
+ end
@@ -0,0 +1,66 @@
1
+ require "spec_helper"
2
+
3
+ describe AdaptivePayments::ExecutePaymentResponse do
4
+ it_behaves_like "a ResponseEnvelope"
5
+ it_behaves_like "a FaultMessage"
6
+
7
+ let(:response) do
8
+ AdaptivePayments::ExecutePaymentResponse.from_json(
9
+ {
10
+ :paymentExecStatus => "Completed",
11
+ :payErrorList => {
12
+ :payError => [
13
+ {
14
+ :receiver => {
15
+ :email => "bob@site.com",
16
+ :amount => "5.00"
17
+ },
18
+ :error => {
19
+ :domain => "APPLICATION",
20
+ :message => "there was an error"
21
+ }
22
+ },
23
+ {
24
+ :receiver => {
25
+ :email => "sally@site.com",
26
+ :amount => "10.00"
27
+ },
28
+ :error => {
29
+ :domain => "APPLICATION",
30
+ :message => "there was another error"
31
+ }
32
+ }
33
+ ]
34
+ }
35
+ }.to_json
36
+ )
37
+ end
38
+
39
+ it "maps ['paymentExecStatus'] to #payment_exec_status" do
40
+ response.payment_exec_status.should == "Completed"
41
+ end
42
+
43
+ it "maps ['payErrorList']['payError'][0]['receiver']['email'] to #pay_errors.first.receiver_email" do
44
+ response.pay_errors.first.receiver_email.should == "bob@site.com"
45
+ end
46
+
47
+ it "maps ['payErrorList']['payError'][0]['receiver']['amount'] to #pay_errors.first.receiver_amount" do
48
+ response.pay_errors.first.receiver_amount.should == BigDecimal("5.00")
49
+ end
50
+
51
+ it "maps ['payErrorList']['payError'][0]['error']['domain'] to #pay_errors.first.error_domain" do
52
+ response.pay_errors.first.error_domain.should == "APPLICATION"
53
+ end
54
+
55
+ it "maps ['payErrorList']['payError'][0]['error']['message'] to #pay_errors.first.error_message" do
56
+ response.pay_errors.first.error_message.should == "there was an error"
57
+ end
58
+
59
+ it "maps ['payErrorList']['payError'][1]['receiver']['email'] to #pay_errors.last.receiver_email" do
60
+ response.pay_errors.last.receiver_email.should == "sally@site.com"
61
+ end
62
+
63
+ it "maps ['payErrorList']['payError'][1]['error']['message'] to #pay_errors.last.error_message" do
64
+ response.pay_errors.last.error_message.should == "there was another error"
65
+ end
66
+ end
@@ -0,0 +1,15 @@
1
+ require "spec_helper"
2
+
3
+ describe AdaptivePayments::GetPaymentOptionsRequest do
4
+ it_behaves_like "a RequestEnvelope"
5
+
6
+ subject { AdaptivePayments::GetPaymentOptionsRequest }
7
+ its(:operation) { should == :GetPaymentOptions }
8
+
9
+ let(:request) { AdaptivePayments::GetPaymentOptionsRequest.new(:pay_key => "ABCD-1234") }
10
+ let(:json) { JSON.parse(request.to_json) }
11
+
12
+ it "maps #pay_key to ['payKey']" do
13
+ json["payKey"].should == "ABCD-1234"
14
+ end
15
+ end