From 173ac3dddd8958e3dafe4724716b546090d19083 Mon Sep 17 00:00:00 2001 From: Nathaniel Talbott Date: Fri, 12 Apr 2013 15:24:10 -0400 Subject: [PATCH] Fix issue with multiple error values Closes #2. Also changes api_login to environment_key and api_secret to access_secret in a backwards compatible manner. --- CHANGELOG.md | 8 ++++ README.md | 36 +++++++------- lib/spreedly-core-ruby.rb | 57 +++++++++++++---------- lib/spreedly-core-ruby/base.rb | 33 +++++++------ lib/spreedly-core-ruby/payment_method.rb | 12 ++--- lib/spreedly-core-ruby/test_extensions.rb | 14 +++--- lib/spreedly-core-ruby/transactions.rb | 2 +- lib/spreedly-core-ruby/version.rb | 2 +- spreedly-core-ruby.gemspec | 5 +- test/configuration_test.rb | 20 ++++---- test/spreedly_core_test.rb | 44 +++++++++++------ test/test_common.rb | 4 +- 12 files changed, 140 insertions(+), 97 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bb70c24..b4ebdd3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +0.3.0 / April 12, 2013 +---------- + +* api_login -> environment_key +* api_secret -> access_secret +* spreedlycore.com -> core.spreedly.com +* Fixed an issue with multiple errors in a PaymentMethod + 0.2.2 / October 18, 2012 ---------- diff --git a/README.md b/README.md index 2660f95..69bcc6c 100644 --- a/README.md +++ b/README.md @@ -1,20 +1,20 @@ -SpreedlyCore +Spreedly ====== -spreedly-core-ruby is a Ruby library for accessing the [Spreedly Core API](https://spreedlycore.com/). Spreedly Core is a Software-as-a-Service billing solution that serves two major functions for companies and developers. +spreedly-core-ruby is a Ruby library for accessing the [Spreedly API](https://spreedly.com/). Spreedly is a Software-as-a-Service billing solution that serves two major functions for companies and developers. -* First, it removes your [PCI Compliance](https://www.pcisecuritystandards.org/) requirement by pushing the card data handling and storage outside of your application. This is possible by having your customers POST their credit card info to the Spreedly Core service while embedding a transparent redirect URL back to your application (see "Submit payment form" on [the quick start guide](https://spreedlycore.com/manual/quickstart)). +* First, it removes your [PCI Compliance](https://www.pcisecuritystandards.org/) requirement by pushing the card data handling and storage outside of your application. This is possible by having your customers POST their credit card info to the Spreedly service while embedding a transparent redirect URL back to your application (see "Submit payment form" on [the quick start guide](https://spreedly.com/manual/quickstart)). * Second, it removes any possibility of your gateway locking you in by owning your customer billing data (yes, this happens). By allowing you to charge any card against whatever gateways you as a company have signed up for, you retain all of your customer data and can switch between gateways as you please. Also, expanding internationally won't require an additional technical integration with yet another gateway. Credit where credit is due: our friends over at [403 Labs](http://www.403labs.com/) carried most of the weight in cutting the initial version of this gem, and we can't thank them enough for their work. Quickstart ---------- -Head over to the [Spreedly Core Website](https://www.spreedlycore.com) to sign up for an account. It's free to get started and play with test gateways/transactions using our specified test card data. +Head over to the [Spreedly Website](https://www.spreedly.com) to sign up for an account. It's free to get started and play with test gateways/transactions using our specified test card data. RubyGems: - export SPREEDLYCORE_API_LOGIN=your_login_here - export SPREEDLYCORE_API_SECRET=your_secret_here + export SPREEDLYCORE_ENVIRONMENT_KEY=your_environment_key_here + export SPREEDLYCORE_ACCESS_SECRET=your_secret_here gem install spreedly-core-ruby irb require 'rubygems' @@ -26,12 +26,12 @@ The first thing we'll need to do is set up a test gateway that we can run transa tg = SpreedlyCore::TestGateway.get_or_create tg.use! -Now that you have a test gateway set up, we'll need to set up your payment form to post the credit card data directly to Spreedly Core. Spreedly Core will receive your customer's credit card data, and immediately transfer them back to the location you define inside the web payments form. The user won't know that they're being taken off site to record to the card data, and you as the developer will be left with a token identifier. The token identifier is used to make your charges against, and to access the customer's non-sensitive billing information. +Now that you have a test gateway set up, we'll need to set up your payment form to post the credit card data directly to Spreedly. Spreedly will receive your customer's credit card data, and immediately transfer them back to the location you define inside the web payments form. The user won't know that they're being taken off site to record to the card data, and you as the developer will be left with a token identifier. The token identifier is used to make your charges against, and to access the customer's non-sensitive billing information. -
+
- + @@ -52,11 +52,11 @@ Now that you have a test gateway set up, we'll need to set up your payment form
-Take special note of the **api_login** and **redirect_url** params hidden in the form, as Spreedly Core will use both of these fields to authenticate the developer's account and to send the customer back to the right location in your app. +Take special note of the **environment_key** and **redirect_url** params hidden in the form, as Spreedly will use both of these fields to authenticate the developer's account and to send the customer back to the right location in your app. A note about test card data ---------------- -If you've just signed up and have not entered your billing information (or selected a Heroku paid plan), you will only be permitted to deal with [test credit card data](https://spreedlycore.com/manual/test-data). +If you've just signed up and have not entered your billing information (or selected a Heroku paid plan), you will only be permitted to deal with [test credit card data](https://core.spreedly.com/manual/test-data). Once you've created your web form and submitted one of the test cards above, you should be returned to your app with a token identifier by which to identify your newly created payment method. Let's go ahead and look up that payment method by the token returned to your app, and we'll charge $5.50 to it. @@ -71,7 +71,7 @@ Once you've created your web form and submitted one of the test cards above, you Saving Payment Methods ---------- -Spreedly Core allows you to retain payment methods provided by your customer for future use. In general, removing the friction from your checkout process is one of the best things you can do for your application, and using Spreedly Core will allow you to avoid making your customer input their payment details for every purchase. +Spreedly allows you to retain payment methods provided by your customer for future use. In general, removing the friction from your checkout process is one of the best things you can do for your application, and using Spreedly will allow you to avoid making your customer input their payment details for every purchase. payment_token = 'abc123' # extracted from the URL params payment_method = SpreedlyCore::PaymentMethod.find(payment_token) @@ -81,7 +81,7 @@ Spreedly Core allows you to retain payment methods provided by your customer for retain_transaction.succeeded? # true end -Payment methods that you no longer want to retain can be redacted from Spreedly Core. A redacted payment method has its sensitive information removed. +Payment methods that you no longer want to retain can be redacted from Spreedly. A redacted payment method has its sensitive information removed. payment_token = 'abc123' # extracted from the URL params payment_method = SpreedlyCore::PaymentMethod.find(payment_token) @@ -128,7 +128,7 @@ Handling Exceptions -------- There are 3 types of exceptions which can be raised by the library: -1. SpreedlyCore::TimeOutError is raised if communication with Spreedly Core takes longer than 10 seconds +1. SpreedlyCore::TimeOutError is raised if communication with Spreedly takes longer than 10 seconds 2. SpreedlyCore::InvalidResponse is raised when the response code is unexpected (I.E. we expect a HTTP response code of 200 bunt instead got a 500) or if the response does not contain an expected attribute. For example, the response from retaining a payment method should contain an XML attribute of "transaction". If this is not found (for example a HTTP response 404 or 500 is returned), then an InvalidResponse is raised. 3. SpreedlyCore::UnprocessableRequest is raised when the response code is 422. This denotes a validation error where one or more of the data fields submitted were not valid, or the whole record was unable to be saved/updated. Inspection of the exception message will give an explanation of the issue. @@ -144,12 +144,12 @@ For example, let's look up a payment method that does not exist: end -Configuring SpreedlyCore for Use in Production (Rails example) +Configuring Spreedly for Use in Production (Rails example) ---------- When you're ready for primetime, you'll need to complete a couple more steps to start processing real transactions. -1. First, you'll need to get your business (or personal) payment details on file with Spreedly Core so that we can collect transaction and card retention fees. For those of you using Heroku, simply change your Spreedly Core addon to the paid tier. -2. Second, you'll need to acquire a gateway that you can plug into the back of Spreedly Core. Any of the major players will work, and you're not at risk of lock-in because Spreedly Core happily plays middle man. Please consult our [list of supported gateways](https://www.spreedlycore.com/manual/gateways) to see exactly what information you'll need to pass to Spreedly Core when creating your gateway profile. +1. First, you'll need to get your business (or personal) payment details on file with Spreedly so that we can collect transaction and card retention fees. For those of you using Heroku, simply change your Spreedly addon to the paid tier. +2. Second, you'll need to acquire a gateway that you can plug into the back of Spreedly. Any of the major players will work, and you're not at risk of lock-in because Spreedly happily plays middle man. Please consult our [list of supported gateways](https://core.spreedly.com/manual/gateways) to see exactly what information you'll need to pass to Spreedly when creating your gateway profile. For this example, I will be using an Authorize.net account that only has a login and password credential. @@ -163,7 +163,7 @@ For this example, I will be using an Authorize.net account that only has a login For most users, you will start off using only one gateway token, and as such can configure it as an environment variable to hold your gateway token. In addition to the previous environment variables, the `SpreedlyCore.configure` method will also look for a SPREEDLYCORE_GATEWAY_TOKEN environment value. # create an initializer at config/initializers/spreedly_core.rb - # values already set for ENV['SPREEDLYCORE_API_LOGIN'], ENV['SPREEDLYCORE_API_SECRET'], and ENV['SPREEDLYCORE_GATEWAY_TOKEN'] + # values already set for ENV['SPREEDLYCORE_ENVIRONMENT_KEY'], ENV['SPREEDLYCORE_ACCESS_SECRET'], and ENV['SPREEDLYCORE_GATEWAY_TOKEN'] SpreedlyCore.configure If you wish to require additional credit card fields, the initializer is the best place to set this up. diff --git a/lib/spreedly-core-ruby.rb b/lib/spreedly-core-ruby.rb index d3e9b8b..a4f9e81 100644 --- a/lib/spreedly-core-ruby.rb +++ b/lib/spreedly-core-ruby.rb @@ -12,7 +12,7 @@ require 'active_support/core_ext/hash/conversions' module SpreedlyCore - # Hash of user friendly credit card name to SpreedlyCore API name + # Hash of user friendly credit card name to Spreedly API name CARD_TYPES = { "Visa" => "visa", "MasterCard" => "master", @@ -22,7 +22,7 @@ module SpreedlyCore class Error < RuntimeError; end - # Custom exception which occurs when a request to SpreedlyCore times out + # Custom exception which occurs when a request to Spreedly times out # See SpreedlyCore::Base.default_timeout class TimeOutError < Error; end class InvalidResponse < Error @@ -42,23 +42,23 @@ def initialize(errors) end end - # Configure SpreedlyCore with a particular account. + # Configure Spreedly with a particular account. # Strongly prefers environment variables for credentials # and will issue a stern warning should they not be present. - # Reluctantly accepts :login and :secret as options + # Reluctantly accepts :environment_key and :access_secret as options def self.configure(options = {}) - login = ENV['SPREEDLYCORE_API_LOGIN'] - secret = ENV['SPREEDLYCORE_API_SECRET'] + environment_key = (ENV["SPREEDLYCORE_ENVIRONMENT_KEY"] || ENV['SPREEDLYCORE_API_LOGIN']) + secret = (ENV["SPREEDLYCORE_ACCESS_SECRET"] || ENV['SPREEDLYCORE_API_SECRET']) gateway_token = ENV['SPREEDLYCORE_GATEWAY_TOKEN'] - if options[:api_login] - Kernel.warn("ENV and arg both present for api_login. Defaulting to arg value") if login - login = options[:api_login] + if(options[:environment_key] || options[:api_login]) + Kernel.warn("ENV and arg both present for environment_key. Defaulting to arg value") if environment_key + environment_key = (options[:environment_key] || options[:api_login]) end - if options[:api_secret] - Kernel.warn("ENV and arg both present for api_secret. Defaulting to arg value") if secret - secret = options[:api_secret] + if(options[:access_secret] || options[:api_secret]) + Kernel.warn("ENV and arg both present for access_secret. Defaulting to arg value") if secret + secret = (options[:access_secret] || options[:api_secret]) end if options[:gateway_token] @@ -67,18 +67,18 @@ def self.configure(options = {}) end options[:gateway_token] ||= gateway_token - if options[:api_login] || options[:api_secret] - Kernel.warn("It is STRONGLY preferred that you house your Spreedly Core credentials only in environment variables.") - Kernel.warn("This gem prefers only environment variables named SPREEDLYCORE_API_LOGIN, SPREEDLYCORE_API_SECRET, and optionally SPREEDLYCORE_GATEWAY_TOKEN.") + if(options[:environment_key] || options[:access_secret]) + Kernel.warn("It is STRONGLY preferred that you house your Spreedly credentials only in environment variables.") + Kernel.warn("This gem prefers only environment variables named SPREEDLYCORE_ENVIRONMENT_KEY, SPREEDLYCORE_ACCESS_SECRET, and optionally SPREEDLYCORE_GATEWAY_TOKEN.") end - if login.nil? || secret.nil? - raise ArgumentError.new("You must provide a login and a secret. Gem will look for ENV['SPREEDLYCORE_API_LOGIN'] and ENV['SPREEDLYCORE_API_SECRET'], but you may also pass in a hash with :api_login and :api_secret keys.") + if environment_key.nil? || secret.nil? + raise ArgumentError.new("You must provide a environment_key and a secret. Gem will look for ENV['SPREEDLYCORE_ENVIRONMENT_KEY'] and ENV['SPREEDLYCORE_ACCESS_SECRET'], but you may also pass in a hash with :environment_key and :access_secret keys.") end - options[:endpoint] ||= "https://spreedlycore.com/#{SpreedlyCore::API_VERSION}" + options[:endpoint] ||= "https://core.spreedly.com/#{SpreedlyCore::API_VERSION}" - Base.configure(login, secret, options) + Base.configure(environment_key, secret, options) end def self.gateway_token=(gateway_token) @@ -89,13 +89,22 @@ def self.gateway_token Base.gateway_token end - # returns the configured SpreedlyCore login - def self.login; Base.login; end + # returns the configured Spreedly environment key + def self.environment_key; Base.environment_key; end # A container for a response from a payment gateway class Response < Base - attr_reader(:success, :message, :avs_code, :avs_message, :cvv_code, - :cvv_message, :error_code, :error_detail, :created_at, - :updated_at) + attr_reader( + :success, + :message, + :avs_code, + :avs_message, + :cvv_code, + :cvv_message, + :error_code, + :error_detail, + :created_at, + :updated_at + ) end end diff --git a/lib/spreedly-core-ruby/base.rb b/lib/spreedly-core-ruby/base.rb index 3ebdde5..89ad9ec 100644 --- a/lib/spreedly-core-ruby/base.rb +++ b/lib/spreedly-core-ruby/base.rb @@ -1,7 +1,7 @@ require 'spreedly-core-ruby/version' module SpreedlyCore - # Base class for all SpreedlyCore API requests + # Base class for all Spreedly API requests class Base include HTTParty @@ -14,14 +14,14 @@ class Base format :xml default_timeout 75 - def self.configure(login, secret, options = {}) - @@login = login - self.basic_auth(@@login, secret) + def self.configure(environment_key, secret, options = {}) + @@environment_key = environment_key + self.basic_auth(@@environment_key, secret) base_uri options[:endpoint] @@gateway_token = options.delete(:gateway_token) end - def self.login; @@login; end + def self.environment_key; @@environment_key; end def self.gateway_token; @@gateway_token; end def self.gateway_token=(gateway_token); @@gateway_token = gateway_token; end @@ -58,7 +58,7 @@ def self.verify_request(request_type, path, options, *allowed_codes, &block) begin response = self.send(request_type, path, options) rescue Timeout::Error, Errno::ETIMEDOUT => e - raise TimeOutError.new("Request to #{path} timed out. Is Spreedly Core down?") + raise TimeOutError.new("Request to #{path} timed out. Is Spreedly down?") end if allowed_codes.any? && !allowed_codes.include?(response.code) @@ -87,13 +87,20 @@ def initialize(attrs={}) instance_variable_set("@#{k}", v) end # errors may be nil, empty, a string, or an array of strings. - @errors = if @errors.nil? || @errors["error"].blank? - [] - elsif @errors["error"].is_a?(String) - [@errors["error"]] - else - @errors["error"] - end + @errors = if(@errors.nil? || @errors["error"].blank?) + [] + elsif @errors["error"].is_a?(String) + [@errors["error"]] + else + @errors["error"].collect do |error| + case error + when Hash + error["__content__"] + else + error + end + end + end end end end diff --git a/lib/spreedly-core-ruby/payment_method.rb b/lib/spreedly-core-ruby/payment_method.rb index b68b8ff..8f783f2 100644 --- a/lib/spreedly-core-ruby/payment_method.rb +++ b/lib/spreedly-core-ruby/payment_method.rb @@ -91,12 +91,12 @@ def validate @has_been_validated = true self.class.additional_required_cc_fields.each do |field| if instance_variable_get("@#{field}").blank? - str_field= field.to_s - friendly_name = if str_field.respond_to?(:humanize) - str_field.humanize - else - str_field.split("_").join(" ") - end + str_field = field.to_s + friendly_name = if(str_field.respond_to?(:humanize)) + str_field.humanize + else + str_field.split("_").join(" ") + end @errors << "#{friendly_name.capitalize} can't be blank" end diff --git a/lib/spreedly-core-ruby/test_extensions.rb b/lib/spreedly-core-ruby/test_extensions.rb index 55daa34..d175ceb 100644 --- a/lib/spreedly-core-ruby/test_extensions.rb +++ b/lib/spreedly-core-ruby/test_extensions.rb @@ -4,18 +4,18 @@ module SpreedlyCore module TestHelper extend self - + def cc_data(cc_type, options={}) - + card_numbers = {:master => [5555555555554444, 5105105105105100], :visa => [4111111111111111, 4012888888881881], :american_express => [378282246310005, 371449635398431], :discover => [6011111111111117, 6011000990139424] } - + card_number = options[:card_number] == :failed ? :last : :first number = card_numbers[cc_type].send(card_number) - + { :credit_card => { :first_name => "John", :last_name => "Foo", @@ -26,7 +26,7 @@ def cc_data(cc_type, options={}) :year => Time.now.year + 1 }.merge(options[:credit_card] || {}) } end - + # Return the base uri as a mocking framework would expect def mocked_base_uri_string uri = URI.parse(Base.base_uri) @@ -38,9 +38,9 @@ def mocked_base_uri_string end class PaymentMethod - # Call spreedly core to create a test token. + # Call spreedly to create a test token. # pass_through_data will be added as the "data" field. - # + # def self.create_test_token(cc_overrides = {}) card = { :first_name => "John", diff --git a/lib/spreedly-core-ruby/transactions.rb b/lib/spreedly-core-ruby/transactions.rb index f7d19b9..8d07b4d 100644 --- a/lib/spreedly-core-ruby/transactions.rb +++ b/lib/spreedly-core-ruby/transactions.rb @@ -1,5 +1,5 @@ module SpreedlyCore - # Abstract class for all the different spreedly core transactions + # Abstract class for all the different spreedly transactions class Transaction < Base attr_reader(:amount, :on_test_gateway, :created_at, :updated_at, :currency_code, :succeeded, :token, :message, :transaction_type, :gateway_token, diff --git a/lib/spreedly-core-ruby/version.rb b/lib/spreedly-core-ruby/version.rb index 34b58d2..25eb059 100644 --- a/lib/spreedly-core-ruby/version.rb +++ b/lib/spreedly-core-ruby/version.rb @@ -1,4 +1,4 @@ module SpreedlyCore - Version = VERSION = "0.2.2" + Version = VERSION = "0.3.0" ApiVersion = API_VERSION = "v1" end diff --git a/spreedly-core-ruby.gemspec b/spreedly-core-ruby.gemspec index 4dd6dc7..0a862b9 100644 --- a/spreedly-core-ruby.gemspec +++ b/spreedly-core-ruby.gemspec @@ -5,11 +5,12 @@ Gem::Specification.new do |s| s.name = "spreedly-core-ruby" s.version = SpreedlyCore::VERSION s.date = Time.now.strftime('%Y-%m-%d') - s.summary = "Ruby interface for Spreedly Core" + s.summary = "Ruby interface for Spreedly" s.homepage = "http://github.com/spreedly/spreedly-core-ruby" s.email = "support@spreedly.com" s.authors = [ "Spreedly", "403 Labs" ] - s.description = "Spreedly Core is a cloud service that allows you to store credit cards and run transactions against them, enabling you to accept payments on your website while avoiding all liability and PCI compliance requirements." + s.license = "LGPL" + s.description = "Spreedly is a cloud service that allows you to store credit cards and run transactions against them, enabling you to accept payments on your website while avoiding all liability and PCI compliance requirements." s.files = %w( README.md Rakefile LICENSE ) s.files += Dir.glob("lib/**/*") diff --git a/test/configuration_test.rb b/test/configuration_test.rb index 8422d9b..9d37afe 100644 --- a/test/configuration_test.rb +++ b/test/configuration_test.rb @@ -6,25 +6,25 @@ class ConfigureTest < Test::Unit::TestCase def test_configure old_verbose, $VERBOSE = $VERBOSE, nil - old_api_login = ENV['SPREEDLYCORE_API_LOGIN'] - old_api_secret = ENV['SPREEDLYCORE_API_SECRET'] + old_environment_key = ENV['SPREEDLYCORE_ENVIRONMENT_KEY'] + old_access_secret = ENV['SPREEDLYCORE_ACCESS_SECRET'] old_gateway_token = ENV['SPREEDLYCORE_GATEWAY_TOKEN'] - ENV['SPREEDLYCORE_API_LOGIN'] = nil - ENV['SPREEDLYCORE_API_SECRET'] = nil + ENV['SPREEDLYCORE_ENVIRONMENT_KEY'] = nil + ENV['SPREEDLYCORE_ACCESS_SECRET'] = nil ENV['SPREEDLYCORE_GATEWAY_TOKEN'] = nil assert_nothing_raised ArgumentError do - SpreedlyCore.configure :api_login => "test", - :api_secret => "secret", + SpreedlyCore.configure :environment_key => "test", + :access_secret => "secret", :gateway_token => "token" end - + assert_raises ArgumentError do SpreedlyCore.configure end - ENV['SPREEDLYCORE_API_LOGIN'] = old_api_login - ENV['SPREEDLYCORE_API_SECRET'] = old_api_secret + ENV['SPREEDLYCORE_ENVIRONMENT_KEY'] = old_environment_key + ENV['SPREEDLYCORE_ACCESS_SECRET'] = old_access_secret ENV['SPREEDLYCORE_GATEWAY_TOKEN'] = 'any_value' SpreedlyCore.gateway_token = nil @@ -37,6 +37,6 @@ def test_configure ensure $VERBOSE = old_verbose end - + end end diff --git a/test/spreedly_core_test.rb b/test/spreedly_core_test.rb index 2a4baf4..a25620a 100644 --- a/test/spreedly_core_test.rb +++ b/test/spreedly_core_test.rb @@ -3,7 +3,7 @@ # In order to run tests # 1. cp test/config/spreedly_core.yml.example to test/config/spreedly_core.yml -# 2. Add your spreedly core credentials to test/config/spreedly_core.yml +# 2. Add your spreedly credentials to test/config/spreedly_core.yml module SpreedlyCore class SpreedlyCoreTest < Test::Unit::TestCase include TestCommon @@ -29,6 +29,24 @@ def test_can_get_payment_token assert_equal 2015, payment_method.year end + def test_payment_token_with_multiple_errors + response = HTTParty.post( + "https://core.spreedly.com/v1/payment_methods", + body: [ + "environment_key=#{SpreedlyCore.environment_key}", + "redirect_url=http://example.com", + "credit_card[number]=4111111111111111" + ].join("&"), + format: :plain, + follow_redirects: false + ) + token = response.headers["location"].split("token=").last + assert payment_method = SpreedlyCore::PaymentMethod.find(token) + assert_nil payment_method.first_name + assert_nil payment_method.last_name + assert !payment_method.errors.empty?, payment_method.errors.inspect + end + def test_can_find_payment_method payment_method = given_a_payment_method assert PaymentMethod.find(payment_method.token) @@ -44,7 +62,7 @@ def test_can_retain_payment_method given_a_retained_transaction end - # Here we change the token to get an invalid response from spreedly core + # Here we change the token to get an invalid response from spreedly def test_bad_response_on_retain payment_method = given_a_payment_method payment_method.instance_variable_set("@token", "NOT-FOUND") @@ -66,7 +84,7 @@ def test_can_redact_payment_method given_a_redacted_transaction end - # Here we change the token to get an invalid response from spreedly core + # Here we change the token to get an invalid response from spreedly def test_bad_response_on_redact payment_method = given_a_payment_method payment_method.instance_variable_set("@token", "NOT-FOUND") @@ -79,7 +97,7 @@ def test_can_make_purchase given_a_purchase end - # Here we change the token to get an invalid response from spreedly core + # Here we change the token to get an invalid response from spreedly def test_bad_response_on_purchase payment_method = given_a_payment_method payment_method.instance_variable_set("@token", "NOT-FOUND") @@ -92,7 +110,7 @@ def test_can_authorize given_an_authorized_transaction end - # Here we change the token to get an invalid response from spreedly core + # Here we change the token to get an invalid response from spreedly def test_bad_response_on_authorize payment_method = given_a_payment_method payment_method.instance_variable_set("@token", "NOT-FOUND") @@ -106,10 +124,10 @@ def test_payment_failed assert transaction = payment_method.purchase(100) assert !transaction.succeeded? - assert_equal("Unable to process the transaction.", + assert_equal("Unable to process the purchase transaction.", transaction.message) - assert_equal("Unable to process the transaction.", transaction.response.message) + assert_equal("Unable to process the purchase transaction.", transaction.response.message) end def test_can_capture_after_authorize @@ -120,7 +138,7 @@ def test_can_capture_partial_after_authorize given_a_capture 50 end - # Here we change the token to get an invalid response from spreedly core + # Here we change the token to get an invalid response from spreedly def test_bad_response_on_capture_after_authorize transaction = given_an_authorized_transaction transaction.instance_variable_set("@token", "NOT-FOUND") @@ -133,7 +151,7 @@ def test_can_void_after_purchase given_a_purchase_void end - # Here we change the token to get an invalid response from spreedly core + # Here we change the token to get an invalid response from spreedly def test_bad_response_on_void purchase = given_a_purchase purchase.instance_variable_set("@token", "NOT-FOUND") @@ -150,7 +168,7 @@ def test_can_credit_after_purchase given_a_purchase_credit end - # Here we change the token to get an invalid response from spreedly core + # Here we change the token to get an invalid response from spreedly def test_bad_response_on_credit purchase = given_a_purchase purchase.instance_variable_set("@token", "NOT-FOUND") @@ -171,7 +189,6 @@ def test_can_credit_partial_after_capture given_a_capture_credit(50, 25) end - def test_can_enforce_additional_payment_method_validations PaymentMethod.additional_required_cc_fields :state @@ -182,8 +199,9 @@ def test_can_enforce_additional_payment_method_validations assert_equal "State can't be blank", payment_method.errors.first - token = PaymentMethod. - create_test_token(cc_data(:master, :credit_card => {:state => "IL"})) + token = PaymentMethod.create_test_token( + cc_data(:master, :credit_card => {:state => "IL"}) + ) assert payment_method = PaymentMethod.find(token) diff --git a/test/test_common.rb b/test/test_common.rb index be702dc..65c2a1a 100644 --- a/test/test_common.rb +++ b/test/test_common.rb @@ -6,7 +6,7 @@ module TestCommon include TestFactory def setup - raise "environment variables for SPREEDLYCORE_API_LOGIN and SPREEDLYCORE_API_SECRET must be set" unless ENV['SPREEDLYCORE_API_LOGIN'] && ENV['SPREEDLYCORE_API_SECRET'] + raise "environment variables for SPREEDLYCORE_ENVIRONMENT_KEY and SPREEDLYCORE_ACCESS_SECRET must be set" unless ENV['SPREEDLYCORE_ENVIRONMENT_KEY'] && ENV['SPREEDLYCORE_ACCESS_SECRET'] SpreedlyCore.configure unless SpreedlyCore.gateway_token @@ -17,4 +17,4 @@ def setup PaymentMethod.reset_additional_required_cc_fields end end -end \ No newline at end of file +end