Skip to content
This repository has been archived by the owner on Aug 27, 2024. It is now read-only.

Commit

Permalink
Adding optional field support for Transactions
Browse files Browse the repository at this point in the history
Now supports :order_id, :description, :merchant_name_descriptor,
:merchant_location_descriptor

Closes #6.
  • Loading branch information
fsainz authored and ntalbott committed Jun 24, 2013
1 parent 173ac3d commit d9dfd23
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
4 changes: 4 additions & 0 deletions lib/spreedly-core-ruby/payment_method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ def purchase_or_authorize(tran_type, amount, *args)
:amount => amount,
:currency_code => currency,
:ip => options[:ip_address],
:order_id => options[:order_id],
:description => options[:description],
:merchant_name_descriptor => options[:merchant_name_descriptor],
:merchant_location_descriptor => options[:merchant_location_descriptor],
:redirect_url => options[:redirect_url],
:callback_url => options[:callback_url]
}
Expand Down
3 changes: 2 additions & 1 deletion lib/spreedly-core-ruby/transactions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ module SpreedlyCore
class Transaction < Base
attr_reader(:amount, :on_test_gateway, :created_at, :updated_at, :currency_code,
:succeeded, :token, :message, :transaction_type, :gateway_token,
:response, :signed, :state, :checkout_url)
:response, :signed, :state, :checkout_url,
:order_id, :description, :merchant_name_descriptor, :merchant_location_descriptor)
alias :succeeded? :succeeded

# Breaks enacapsulation a bit, but allow subclasses to register the 'transaction_type'
Expand Down
18 changes: 15 additions & 3 deletions test/test_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,25 @@ def given_a_payment_method(cc_card=:master, card_options={})
payment_method
end

def given_a_purchase(purchase_amount=100, ip_address='127.0.0.1')
def given_a_purchase(purchase_amount=100, ip_address='127.0.0.1', additional_options={})
default_additional_options = {:order_id => "123", :description => 'purchase description', :merchant_name_descriptor => 'merchant name', :merchant_location_descriptor => 'merchant location'}
options = default_additional_options.merge(additional_options)
options[:ip_address] = ip_address

payment_method = given_a_payment_method
assert transaction = payment_method.purchase(purchase_amount, nil, nil, ip_address=nil)

assert transaction = payment_method.purchase(purchase_amount, options)
assert_equal purchase_amount, transaction.amount
assert_equal "USD", transaction.currency_code
assert_equal "Purchase", transaction.transaction_type
assert_equal ip_address, transaction.ip
assert_equal options[:ip_address], transaction.ip
assert_equal options[:order_id], transaction.order_id
assert_equal options[:description], transaction.description
assert_equal options[:merchant_name_descriptor], transaction.merchant_name_descriptor
assert_equal options[:merchant_location_descriptor], transaction.merchant_location_descriptor



assert transaction.succeeded?
transaction
end
Expand Down

0 comments on commit d9dfd23

Please sign in to comment.