spreedly_core 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -45,13 +45,13 @@ module SpreedlyCore
45
45
  end
46
46
 
47
47
  # Make a purchase against the payment method
48
- def purchase(amount, currency="USD", _gateway_token=nil)
49
- purchase_or_authorize(:purchase, amount, currency, _gateway_token)
48
+ def purchase(amount, currency=nil, _gateway_token=nil, ip_address=nil)
49
+ purchase_or_authorize(:purchase, amount, currency, _gateway_token, ip_address)
50
50
  end
51
51
 
52
52
  # Make an authorize against payment method. You can then later capture against the authorize
53
- def authorize(amount, currency="USD", _gateway_token=nil)
54
- purchase_or_authorize(:authorize, amount, currency, _gateway_token)
53
+ def authorize(amount, currency=nil, _gateway_token=nil, ip_address=nil)
54
+ purchase_or_authorize(:authorize, amount, currency, _gateway_token, ip_address)
55
55
  end
56
56
 
57
57
  # Returns the URL that CC data should be submitted to.
@@ -85,18 +85,22 @@ module SpreedlyCore
85
85
  @errors = @errors.sort
86
86
  end
87
87
 
88
- def purchase_or_authorize(tran_type, amount, currency, _gateway_token)
88
+ def purchase_or_authorize(tran_type, amount, currency, _gateway_token, ip_address)
89
89
  transaction_type = tran_type.to_s
90
90
  raise "Unknown transaction type" unless %w{purchase authorize}.include?(transaction_type)
91
91
 
92
+ currency ||= "USD"
92
93
  _gateway_token ||= self.class.gateway_token
93
94
  path = "/gateways/#{_gateway_token}/#{transaction_type}.xml"
94
- data = {:transaction => {
95
- :amount => amount,
95
+ data = {
96
+ :transaction => {
96
97
  :transaction_type => transaction_type,
97
98
  :payment_method_token => token,
98
- :currency_code => currency }}
99
-
99
+ :amount => amount,
100
+ :currency_code => currency,
101
+ :ip => ip_address
102
+ }
103
+ }
100
104
  self.class.verify_post(path, :body => data) do |response|
101
105
  klass = SpreedlyCore.const_get("#{transaction_type.capitalize}Transaction")
102
106
  klass.new(response.parsed_response["transaction"])
@@ -46,19 +46,21 @@ module SpreedlyCore
46
46
  module NullifiableTransaction
47
47
  # Void is used to cancel out authorizations and, with some gateways, to
48
48
  # cancel actual payment transactions within the first 24 hours
49
- def void
50
- self.class.verify_post("/transactions/#{token}/void.xml") do |response|
49
+ def void(ip_address=nil)
50
+ body = {:transaction => {:ip => ip_address}}
51
+ self.class.verify_post("/transactions/#{token}/void.xml",
52
+ :body => body) do |response|
51
53
  VoidedTransaction.new(response.parsed_response["transaction"])
52
54
  end
53
55
  end
54
56
 
55
57
  # Credit amount. If amount is nil, then credit the entire previous purchase
56
58
  # or captured amount
57
- def credit(amount=nil)
59
+ def credit(amount=nil, ip_address=nil)
58
60
  body = if amount.nil?
59
- {}
61
+ {:ip => ip_address}
60
62
  else
61
- {:transaction => {:amount => amount}}
63
+ {:transaction => {:amount => amount, :ip => ip_address}}
62
64
  end
63
65
  self.class.verify_post("/transactions/#{token}/credit.xml",
64
66
  :body => body) do |response|
@@ -67,7 +69,13 @@ module SpreedlyCore
67
69
  end
68
70
  end
69
71
 
72
+ module HasIpAddress
73
+ attr_reader :ip
74
+ end
75
+
70
76
  class AuthorizeTransaction < Transaction
77
+ include HasIpAddress
78
+
71
79
  handles "Authorization"
72
80
  attr_reader :payment_method
73
81
 
@@ -81,11 +89,11 @@ module SpreedlyCore
81
89
  # captured amount will the amount from the original authorization. Some
82
90
  # gateways support partial captures which can be done by specifiying an
83
91
  # amount
84
- def capture(amount=nil)
92
+ def capture(amount=nil, ip_address=nil)
85
93
  body = if amount.nil?
86
94
  {}
87
95
  else
88
- {:transaction => {:amount => amount}}
96
+ {:transaction => {:amount => amount, :ip => ip_address}}
89
97
  end
90
98
  self.class.verify_post("/transactions/#{token}/capture.xml",
91
99
  :body => body) do |response|
@@ -96,6 +104,7 @@ module SpreedlyCore
96
104
 
97
105
  class PurchaseTransaction < Transaction
98
106
  include NullifiableTransaction
107
+ include HasIpAddress
99
108
 
100
109
  handles "Purchase"
101
110
  attr_reader :payment_method
@@ -109,17 +118,22 @@ module SpreedlyCore
109
118
 
110
119
  class CaptureTransaction < Transaction
111
120
  include NullifiableTransaction
112
-
121
+ include HasIpAddress
122
+
113
123
  handles "Capture"
114
124
  attr_reader :reference_token
115
125
  end
116
126
 
117
127
  class VoidedTransaction < Transaction
128
+ include HasIpAddress
129
+
118
130
  handles "Void"
119
131
  attr_reader :reference_token
120
132
  end
121
133
 
122
134
  class CreditTransaction < Transaction
135
+ include HasIpAddress
136
+
123
137
  handles "Credit"
124
138
  attr_reader :reference_token
125
139
  end
@@ -1,3 +1,3 @@
1
1
  module SpreedlyCore
2
- Version = VERSION = "0.0.3"
2
+ Version = VERSION = "0.0.4"
3
3
  end
@@ -1,3 +1,3 @@
1
1
  login: 'Ud8NWIpG66s5ki5EX1n3ijCdGCe'
2
2
  secret: 'lS1jRuOr642CapweB4Au74oM48k9et935YXluG2Gd9sj0qCedUfG44qT3F1HNFnt'
3
- gateway_token: 'JncEWj22g59t3CRB1VnPXmUUgKc'
3
+ gateway_token: 'AY801m8Y2VIIIL56bwX3z0ac2db'
@@ -18,12 +18,13 @@ class SpreedlyCoreTest < Test::Unit::TestCase
18
18
  payment_method
19
19
  end
20
20
 
21
- def given_a_purchase(purchase_amount=100)
21
+ def given_a_purchase(purchase_amount=100, ip_address='127.0.0.1')
22
22
  payment_method = given_a_payment_method
23
- assert transaction = payment_method.purchase(purchase_amount)
23
+ assert transaction = payment_method.purchase(purchase_amount, nil, nil, ip_address=nil)
24
24
  assert_equal purchase_amount, transaction.amount
25
25
  assert_equal "USD", transaction.currency_code
26
26
  assert_equal "Purchase", transaction.transaction_type
27
+ assert_equal ip_address, transaction.ip
27
28
  assert transaction.succeeded?
28
29
  transaction
29
30
  end
@@ -46,55 +47,60 @@ class SpreedlyCoreTest < Test::Unit::TestCase
46
47
  transaction
47
48
  end
48
49
 
49
- def given_an_authorized_transaction(amount=100)
50
+ def given_an_authorized_transaction(amount=100, ip_address='127.0.0.1')
50
51
  payment_method = given_a_payment_method
51
- assert transaction = payment_method.authorize(100)
52
+ assert transaction = payment_method.authorize(100, nil, nil, ip_address)
52
53
  assert_equal 100, transaction.amount
53
54
  assert_equal "USD", transaction.currency_code
55
+ assert_equal ip_address, transaction.ip
54
56
  assert_equal SpreedlyCore::AuthorizeTransaction, transaction.class
55
57
  transaction
56
58
  end
57
59
 
58
- def given_a_capture(amount=100)
59
- transaction = given_an_authorized_transaction
60
- capture = transaction.capture(amount)
60
+ def given_a_capture(amount=100, ip_address='127.0.0.1')
61
+ transaction = given_an_authorized_transaction(amount, ip_address)
62
+ capture = transaction.capture(amount, ip_address)
61
63
  assert capture.succeeded?
62
64
  assert_equal amount, capture.amount
63
65
  assert_equal "Capture", capture.transaction_type
66
+ assert_equal ip_address, capture.ip
64
67
  assert_equal SpreedlyCore::CaptureTransaction, capture.class
65
68
  capture
66
69
  end
67
70
 
68
- def given_a_purchase_void
71
+ def given_a_purchase_void(ip_address='127.0.0.1')
69
72
  purchase = given_a_purchase
70
- assert void = purchase.void
73
+ assert void = purchase.void(ip_address)
71
74
  assert_equal purchase.token, void.reference_token
75
+ assert_equal ip_address, void.ip
72
76
  assert void.succeeded?
73
77
  void
74
78
  end
75
79
 
76
- def given_a_capture_void
80
+ def given_a_capture_void(ip_address='127.0.0.1')
77
81
  capture = given_a_capture
78
- assert void = capture.void
82
+ assert void = capture.void(ip_address)
79
83
  assert_equal capture.token, void.reference_token
84
+ assert_equal ip_address, void.ip
80
85
  assert void.succeeded?
81
86
  void
82
87
  end
83
88
 
84
- def given_a_purchase_credit(purchase_amount=100, credit_amount=100)
85
- purchase = given_a_purchase(purchase_amount)
86
- given_a_credit(purchase, credit_amount)
89
+ def given_a_purchase_credit(purchase_amount=100, credit_amount=100, ip_address='127.0.0.1')
90
+ purchase = given_a_purchase(purchase_amount, ip_address)
91
+ given_a_credit(purchase, credit_amount, ip_address)
87
92
  end
88
93
 
89
- def given_a_capture_credit(capture_amount=100, credit_amount=100)
90
- capture = given_a_capture(capture_amount)
91
- given_a_credit(capture, credit_amount)
94
+ def given_a_capture_credit(capture_amount=100, credit_amount=100, ip_address='127.0.0.1')
95
+ capture = given_a_capture(capture_amount, ip_address)
96
+ given_a_credit(capture, credit_amount, ip_address)
92
97
  end
93
98
 
94
- def given_a_credit(trans, credit_amount=100)
95
- assert credit = trans.credit(credit_amount)
99
+ def given_a_credit(trans, credit_amount=100, ip_address='127.0.0.1')
100
+ assert credit = trans.credit(credit_amount, ip_address)
96
101
  assert_equal trans.token, credit.reference_token
97
102
  assert_equal credit_amount, credit.amount
103
+ assert_equal ip_address, credit.ip
98
104
  assert credit.succeeded?
99
105
  assert SpreedlyCore::CreditTransaction, credit.class
100
106
  credit
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spreedly_core
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 3
10
- version: 0.0.3
9
+ - 4
10
+ version: 0.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - 403 Labs
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-08-23 00:00:00 -05:00
18
+ date: 2011-09-13 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency