Class: Samurai::PaymentMethod

Inherits:
Base show all
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

Instance Method Summary collapse

Methods included from ActiveResourceSupport

included

Methods included from CacheableByToken

included, #save

Methods inherited from Base

#has_errors?, setup_site!

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_dataObject

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

#idObject



11
12
13
# File 'lib/samurai/payment_method.rb', line 11

def id
  self.token
end

#redactObject

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

#retainObject

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

#tokenObject

Alias for ‘payment_method_token`



16
17
18
# File 'lib/samurai/payment_method.rb', line 16

def token
  self.attributes["payment_method_token"]
end