spook_and_pay 0.2.2.alpha → 0.2.3.alpha

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 819eadd06fa953890cbc5674a90ace23148993be
4
- data.tar.gz: 9cf26a26f26a7fa4973255f97de3803f62b634f6
3
+ metadata.gz: 36337e6bc05a6c51b5f0b89042c43e9953061eda
4
+ data.tar.gz: 1f1debb4bcb3efd35d7ef032297ada9e2fd017eb
5
5
  SHA512:
6
- metadata.gz: e7b5505360ce9039c343464e4649ce76623568efb7cf61617046532af72c872b34a21971822cfe6ebf93dcd1e03a050cc8cfa27b56c15f3e8fb075370e3512e9
7
- data.tar.gz: 5c24b231970c807a41310cf5ce385e54844e783604ed3b7885128dfa119944e4483b08501985187b883585f80ad82fb5e5bf97b9347df5e6d7256365dc2c614c
6
+ metadata.gz: c2d55cb04f26b634d0d915fcbdd4a240f238488baa614975eb249aa0a953d6a18c63af4bc71e646e43b96d2c40ea1ff8ab11a87807176da34ecadb148e101888
7
+ data.tar.gz: 10a674a7f2371a7e5dd0bc8758dd904a1640ed33b86d11c36bfdda68495cd3cd1baabd79dae89faddd561077c3eb9bc315b021f59d17d32c09a299dacb1228ce
@@ -7,7 +7,7 @@ module SpookAndPay
7
7
  extend SpookAndPay::ErroringReader
8
8
 
9
9
  # The basic attributes of the credit card.
10
- attr_reader :provider, :id
10
+ attr_reader :provider, :id, :raw
11
11
 
12
12
  # The fields required for a credit card
13
13
  FIELDS = [:number, :expiration_month, :expiration_year, :cvv, :card_type, :name, :valid, :expired].freeze
@@ -32,9 +32,11 @@ module SpookAndPay
32
32
  # @option vals String :name
33
33
  # @option vals [true, false] :expired
34
34
  # @option vals [true, false] :valid
35
- def initialize(provider, id, vals)
35
+ # @param Class raw
36
+ def initialize(provider, id, vals, raw = nil)
36
37
  @provider = provider
37
- @id = id
38
+ @id = id
39
+ @raw = raw
38
40
  FIELDS.each {|f| instance_variable_set(:"@#{f}", vals[f]) if vals.has_key?(f)}
39
41
  end
40
42
 
@@ -47,9 +49,13 @@ module SpookAndPay
47
49
  if @number.nil? or @number.empty?
48
50
  nil
49
51
  else
50
- case card_type
51
- when 'american_express' then "XXXX-XXXXXX-#{@number}"
52
- else "XXXX-XXXX-XXXX-#{@number}"
52
+ if @number.length < 12
53
+ case card_type
54
+ when 'american_express' then "XXXX-XXXXXX-#{@number}"
55
+ else "XXXX-XXXX-XXXX-#{@number}"
56
+ end
57
+ else
58
+ @number
53
59
  end
54
60
  end
55
61
  end
@@ -63,9 +63,8 @@ module SpookAndPay
63
63
  # Confirms the submission of payment details to the provider.
64
64
  #
65
65
  # @param String query_string
66
- #
67
66
  # @return SpookAndPay::Result
68
- def confirm_payment_submission(query_string)
67
+ def confirm_payment_submission(query_string, opts = {})
69
68
  result = adapter.confirm(query_string)
70
69
 
71
70
  case result
@@ -48,24 +48,22 @@ module SpookAndPay
48
48
  # Confirms the submission of payment details to Spreedly Core.
49
49
  #
50
50
  # @param String query_string
51
+ # @param Hash opts
52
+ # @option opts [String, Numeric] :amount
53
+ # @option opts [:purchase, :authorize, :store] :execute
51
54
  # @return SpookAndPay::Result
52
- def confirm_payment_submission(query_string)
55
+ def confirm_payment_submission(query_string, opts)
53
56
  token = Rack::Utils.parse_nested_query(query_string)["token"]
54
- credit_card = spreedly.find_payment_method(token)
55
-
56
- if credit_card.valid?
57
- SpookAndPay::Result.new(
58
- true,
59
- credit_card,
60
- :credit_card => coerce_credit_card(credit_card)
61
- )
57
+ card = credit_card(token)
58
+
59
+ if card.valid?
60
+ case opts[:execute]
61
+ when :authorize then card.authorize!(opts[:amount])
62
+ when :purchase then card.purchase!(opts[:amount])
63
+ when :store then SpookAndPay::Result.new(true, nil, :credit_card => card)
64
+ end
62
65
  else
63
- SpookAndPay::Result.new(
64
- false,
65
- credit_card,
66
- :credit_card => coerce_credit_card(credit_card),
67
- :errors => extract_card_errors(credit_card)
68
- )
66
+ SpookAndPay::Result.new(false, nil, :credit_card => card, :errors => extract_card_errors(card.raw))
69
67
  end
70
68
  end
71
69
 
@@ -128,7 +126,7 @@ module SpookAndPay
128
126
  }
129
127
 
130
128
  if result.respond_to?(:payment_method)
131
- opts[:card] = coerce_credit_card(result.payment_method)
129
+ opts[:credit_card] = coerce_credit_card(result.payment_method)
132
130
  end
133
131
 
134
132
  SpookAndPay::Result.new(result.succeeded, result, opts)
@@ -203,10 +201,11 @@ module SpookAndPay
203
201
  :number => card.number,
204
202
  :name => card.full_name,
205
203
  :expiration_month => card.month,
206
- :expiration_year => card.year
204
+ :expiration_year => card.year,
205
+ :valid => card.valid?
207
206
  }
208
207
 
209
- SpookAndPay::CreditCard.new(self, card.token, fields)
208
+ SpookAndPay::CreditCard.new(self, card.token, fields, card)
210
209
  end
211
210
 
212
211
  # Takes a transaction generated by the Spreedly lib and coerces it into a
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spook_and_pay
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2.alpha
4
+ version: 0.2.3.alpha
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luke Sutton
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-11-21 00:00:00.000000000 Z
12
+ date: 2013-11-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: braintree