Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Stash work on validation of parameters.

  • Loading branch information...
commit 713d1ec9915a5fd6306ad2594e9fb1d04d5dc1ef 1 parent ce0cbfe
@alloy alloy authored
View
58 .kick
@@ -1,33 +1,35 @@
-process do |files|
- if files.any? { |f| f =~ /lib\/.+\.rb$/ }
- execute "yardoc --no-private"
- execute(%{osascript -e 'tell application "Safari"
- do JavaScript "window.location.reload()" in first document
- end tell'})
+options.on('--doc', 'Also generate docs.') do
+ process do |files|
+ if files.any? { |f| f =~ /lib\/.+\.rb$/ }
+ execute "yardoc --no-private"
+ execute(%{osascript -e 'tell application "Safari"
+ do JavaScript "window.location.reload()" in first document
+ end tell'})
+ end
end
end
-#recipe :ruby
+recipe :ruby
-#process do |files|
- #specs = files.take_and_map do |file|
- #case file
- #when "spec/spec_helper.rb"
- #Dir.glob("spec/**/*_spec.rb")
- #when "spec/api/spec_helper.rb"
- #Dir.glob("spec/api/*_spec.rb")
- #when "lib/adyen/api.rb"
- #"spec/api/api_spec.rb"
- #when "lib/adyen/api/xml_querier.rb"
- #["spec/api/payment_service_spec.rb", "spec/api/recurring_service_spec.rb"]
- #when "lib/adyen/api/simple_soap_client.rb"
- #["spec/api/simple_soap_client_spec.rb", "spec/api/payment_service_spec.rb", "spec/api/recurring_service_spec.rb"]
- #when "lib/adyen/api/response.rb"
- #["spec/api/response_spec.rb", "spec/api/payment_service_spec.rb", "spec/api/recurring_service_spec.rb"]
- #when %r{lib/adyen/api/templates/(.+)\.rb$}, %r{lib/adyen/api/(.+)\.rb$}
- #"spec/api/#{$1}_spec.rb"
- #end
- #end
- #Ruby.run_tests(specs)
-#end
+process do |files|
+ specs = files.take_and_map do |file|
+ case file
+ when "spec/spec_helper.rb"
+ Dir.glob("spec/**/*_spec.rb")
+ when "spec/api/spec_helper.rb"
+ Dir.glob("spec/api/*_spec.rb")
+ when "lib/adyen/api.rb"
+ "spec/api/api_spec.rb"
+ when "lib/adyen/api/xml_querier.rb"
+ ["spec/api/payment_service_spec.rb", "spec/api/recurring_service_spec.rb"]
+ when "lib/adyen/api/simple_soap_client.rb"
+ ["spec/api/simple_soap_client_spec.rb", "spec/api/payment_service_spec.rb", "spec/api/recurring_service_spec.rb"]
+ when "lib/adyen/api/response.rb"
+ ["spec/api/response_spec.rb", "spec/api/payment_service_spec.rb", "spec/api/recurring_service_spec.rb"]
+ when %r{lib/adyen/api/templates/(.+)\.rb$}, %r{lib/adyen/api/(.+)\.rb$}
+ "spec/api/#{$1}_spec.rb"
+ end
+ end
+ Ruby.run_tests(specs)
+end
View
22 lib/adyen/api/payment_service.rb
@@ -80,7 +80,28 @@ def make_payment_request(data, response_class)
call_webservice_action('authorise', data, response_class)
end
+ def validate_parameter_value!(param, value)
+ if value.blank?
+ raise ArgumentError, "The required parameter `:#{param}' is missing."
+ end
+ end
+
+ def validate_parameters!(*params)
+ params.each do |param|
+ case param
+ when Symbol
+ validate_parameter_value!(param, @params[param])
+ when Hash
+ param.each do |name, attrs|
+ validate_parameter_value!(name, @params[name])
+ attrs.each { |attr| validate_parameter_value!("#{name} => :#{attr}", @params[name][attr]) }
+ end
+ end
+ end
+ end
+
def authorise_payment_request_body
+ validate_parameters!(:merchant_account)
content = card_partial
content << ENABLE_RECURRING_CONTRACTS_PARTIAL if @params[:recurring]
payment_request_body(content)
@@ -127,6 +148,7 @@ def amount_partial
end
def card_partial
+ validate_parameters!(:card => [:holder_name, :number, :cvc, :expiry_year, :expiry_month])
card = @params[:card].values_at(:holder_name, :number, :cvc, :expiry_year)
card << @params[:card][:expiry_month].to_i
CARD_PARTIAL % card
View
27 spec/api/payment_service_spec.rb
@@ -78,6 +78,33 @@
@payment = @object = Adyen::API::PaymentService.new(@params)
end
+ describe Adyen::API, "authorise_payment parameter validation" do
+ before :all do
+ Net::HTTP.stubbing_enabled = true
+ end
+
+ after :all do
+ Net::HTTP.stubbing_enabled = false
+ end
+
+ it "raises if the merchant account is missing" do
+ @payment.params[:merchant_account] = ''
+ lambda { @payment.authorise_payment }.should raise_error(ArgumentError)
+ end
+
+ it "raises if the card info is missing" do
+ @payment.params[:card] = nil
+ lambda { @payment.authorise_payment }.should raise_error(ArgumentError)
+ end
+
+ [:holder_name, :number, :cvc, :expiry_year, :expiry_month].each do |attr|
+ it "raises if the card #{attr} is missing" do
+ @payment.params[:card][attr] = ''
+ lambda { @payment.authorise_payment }.should raise_error(ArgumentError)
+ end
+ end
+ end
+
describe_request_body_of :authorise_payment do
it_should_behave_like "payment requests"
Please sign in to comment.
Something went wrong with that request. Please try again.