Class: Samurai::PaymentMethod
- Inherits:
-
Base
- Object
- ActiveResource::Base
- Base
- Samurai::PaymentMethod
- Includes:
- CacheableByToken
- Defined in:
- lib/samurai/payment_method.rb
Overview
Samurai credit card tokenization, including retaining & redacting Payment Methods
Constant Summary collapse
- KNOWN_ATTRIBUTES =
Setup the PaymentMethod schema for ActiveResource, so that new objects contain empty attributes
[ :first_name, :last_name, :address_1, :address_2, :city, :state, :zip, :card_number, :cvv, :expiry_month, :expiry_year, :sandbox, :custom ]
- EMPTY_ATTRIBUTES =
If we’re using ActiveResource pre-3.1, there’s no schema class method, so we resort to some tricks… Initialize the known attributes from the schema as empty strings, so that they can be accessed via method-missing
KNOWN_ATTRIBUTES.inject(HashWithIndifferentAccess.new) {|h, k| h[k] = ''; h}
Class Method Summary collapse
-
.for_transparent_redirect(params) ⇒ Object
Convenience method for preparing a new PaymentMethod for use with a transparent redirect form.
Instance Method Summary collapse
-
#custom_json_data ⇒ Object
Retrieves JSON formatted custom data that is encoded in the custom_data attribute.
- #id ⇒ Object
-
#initialize(attrs = {}) ⇒ PaymentMethod
constructor
A new instance of PaymentMethod.
-
#redact ⇒ Object
Redacts sensitive information from the payment method, rendering it unusable.
-
#retain ⇒ Object
Retains the payment method on ‘api.samurai.feefighters.com`.
-
#token ⇒ Object
Alias for ‘payment_method_token`.
Methods included from CacheableByToken
Methods inherited from Base
Constructor Details
#initialize(attrs = {}) ⇒ PaymentMethod
Returns a new instance of PaymentMethod.
56 57 58 |
# File 'lib/samurai/payment_method.rb', line 56 def initialize(attrs={}) super(EMPTY_ATTRIBUTES.merge(attrs)) end |
Class Method Details
.for_transparent_redirect(params) ⇒ Object
Convenience method for preparing a new PaymentMethod for use with a transparent redirect form
67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/samurai/payment_method.rb', line 67 def self.for_transparent_redirect(params) if params[:payment_method_token].blank? Samurai::PaymentMethod.new(params) else Samurai::PaymentMethod.find(params[:payment_method_token]).tap do |pm| pm.card_number = "************#{pm.last_four_digits}" pm.cvv = "***" pm.errors[:base] << 'The card number or CVV are not valid.' if !pm.is_sensitive_data_valid end end end |
Instance Method Details
#custom_json_data ⇒ Object
Retrieves JSON formatted custom data that is encoded in the custom_data attribute
32 33 34 |
# File 'lib/samurai/payment_method.rb', line 32 def custom_json_data @custom_data ||= self.custom && (JSON.parse(self.custom) rescue {}).symbolize_keys end |
#id ⇒ Object
11 12 13 |
# File 'lib/samurai/payment_method.rb', line 11 def id self.token end |
#redact ⇒ Object
Redacts sensitive information from the payment method, rendering it unusable.
27 28 29 |
# File 'lib/samurai/payment_method.rb', line 27 def redact self.post(:redact) end |
#retain ⇒ Object
Retains the payment method on ‘api.samurai.feefighters.com`. Retain a payment method if it will not be used immediately.
22 23 24 |
# File 'lib/samurai/payment_method.rb', line 22 def retain self.post(:retain) end |
#token ⇒ Object
Alias for ‘payment_method_token`
16 17 18 |
# File 'lib/samurai/payment_method.rb', line 16 def token self.attributes["payment_method_token"] end |