Class: Samurai::PaymentMethod
- Inherits:
-
Base
- Object
- ActiveResource::Base
- Base
- Samurai::PaymentMethod
- Includes:
- ActiveResourceSupport, 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 ]
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
-
#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 ActiveResourceSupport
Methods included from CacheableByToken
Methods inherited from Base
Class Method Details
.for_transparent_redirect(params) ⇒ Object
Convenience method for preparing a new PaymentMethod for use with a transparent redirect form
59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/samurai/payment_method.rb', line 59 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.add :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
34 35 36 |
# File 'lib/samurai/payment_method.rb', line 34 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.
28 29 30 31 |
# File 'lib/samurai/payment_method.rb', line 28 def redact resp = self.post(:redact, {}, '<payment_method></payment_method>') self.load_attributes_from_response(resp) 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 25 |
# File 'lib/samurai/payment_method.rb', line 22 def retain resp = self.post(:retain, {}, '<payment_method></payment_method>') self.load_attributes_from_response(resp) 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 |