Class: SpreedlyCore::PaymentMethod
- Defined in:
- lib/spreedly-core-ruby/payment_method.rb,
lib/spreedly-core-ruby/test_extensions.rb
Instance Attribute Summary collapse
-
#address1 ⇒ Object
readonly
Returns the value of attribute address1.
-
#address2 ⇒ Object
readonly
Returns the value of attribute address2.
-
#card_type ⇒ Object
readonly
Returns the value of attribute card_type.
-
#city ⇒ Object
readonly
Returns the value of attribute city.
-
#country ⇒ Object
readonly
Returns the value of attribute country.
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#email ⇒ Object
readonly
Returns the value of attribute email.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#first_name ⇒ Object
readonly
Returns the value of attribute first_name.
-
#last_four_digits ⇒ Object
readonly
Returns the value of attribute last_four_digits.
-
#last_name ⇒ Object
readonly
Returns the value of attribute last_name.
-
#month ⇒ Object
readonly
Returns the value of attribute month.
-
#number ⇒ Object
readonly
Returns the value of attribute number.
-
#payment_method_type ⇒ Object
readonly
Returns the value of attribute payment_method_type.
-
#phone_number ⇒ Object
readonly
Returns the value of attribute phone_number.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
-
#updated_at ⇒ Object
readonly
Returns the value of attribute updated_at.
-
#verification_value ⇒ Object
readonly
Returns the value of attribute verification_value.
-
#year ⇒ Object
readonly
Returns the value of attribute year.
-
#zip ⇒ Object
readonly
Returns the value of attribute zip.
Class Method Summary collapse
-
.additional_required_cc_fields(*fields) ⇒ Object
configure additional required fiels.
- .create(credit_card) ⇒ Object
-
.create_test_token(cc_overrides = {}) ⇒ Object
Call spreedly to create a test token.
-
.find(token) ⇒ Object
Lookup the PaymentMethod by token.
-
.reset_additional_required_cc_fields ⇒ Object
clear the configured additional required fields.
-
.submit_url ⇒ Object
Returns the URL that CC data should be submitted to.
Instance Method Summary collapse
-
#authorize(amount, *args) ⇒ Object
Make an authorize against payment method.
-
#initialize(attrs = {}) ⇒ PaymentMethod
constructor
Create a new PaymentMethod based on the attrs hash and then validate.
-
#purchase(amount, *args) ⇒ Object
Make a purchase against the payment method.
-
#redact ⇒ Object
Redact the payment method.
-
#retain ⇒ Object
Retain the payment method.
-
#update(attributes) ⇒ Object
Update the attributes of a payment method.
- #valid? ⇒ Boolean
Methods inherited from Base
configure, environment_key, gateway_token, gateway_token=, verify_get, verify_options, verify_post, verify_put, verify_request
Constructor Details
#initialize(attrs = {}) ⇒ PaymentMethod
Create a new PaymentMethod based on the attrs hash and then validate
35 36 37 38 |
# File 'lib/spreedly-core-ruby/payment_method.rb', line 35 def initialize(attrs={}) super(attrs) validate end |
Instance Attribute Details
#address1 ⇒ Object (readonly)
Returns the value of attribute address1.
3 4 5 |
# File 'lib/spreedly-core-ruby/payment_method.rb', line 3 def address1 @address1 end |
#address2 ⇒ Object (readonly)
Returns the value of attribute address2.
3 4 5 |
# File 'lib/spreedly-core-ruby/payment_method.rb', line 3 def address2 @address2 end |
#card_type ⇒ Object (readonly)
Returns the value of attribute card_type.
3 4 5 |
# File 'lib/spreedly-core-ruby/payment_method.rb', line 3 def card_type @card_type end |
#city ⇒ Object (readonly)
Returns the value of attribute city.
3 4 5 |
# File 'lib/spreedly-core-ruby/payment_method.rb', line 3 def city @city end |
#country ⇒ Object (readonly)
Returns the value of attribute country.
3 4 5 |
# File 'lib/spreedly-core-ruby/payment_method.rb', line 3 def country @country end |
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
3 4 5 |
# File 'lib/spreedly-core-ruby/payment_method.rb', line 3 def created_at @created_at end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
3 4 5 |
# File 'lib/spreedly-core-ruby/payment_method.rb', line 3 def data @data end |
#email ⇒ Object (readonly)
Returns the value of attribute email.
3 4 5 |
# File 'lib/spreedly-core-ruby/payment_method.rb', line 3 def email @email end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
3 4 5 |
# File 'lib/spreedly-core-ruby/payment_method.rb', line 3 def errors @errors end |
#first_name ⇒ Object (readonly)
Returns the value of attribute first_name.
3 4 5 |
# File 'lib/spreedly-core-ruby/payment_method.rb', line 3 def first_name @first_name end |
#last_four_digits ⇒ Object (readonly)
Returns the value of attribute last_four_digits.
3 4 5 |
# File 'lib/spreedly-core-ruby/payment_method.rb', line 3 def last_four_digits @last_four_digits end |
#last_name ⇒ Object (readonly)
Returns the value of attribute last_name.
3 4 5 |
# File 'lib/spreedly-core-ruby/payment_method.rb', line 3 def last_name @last_name end |
#month ⇒ Object (readonly)
Returns the value of attribute month.
3 4 5 |
# File 'lib/spreedly-core-ruby/payment_method.rb', line 3 def month @month end |
#number ⇒ Object (readonly)
Returns the value of attribute number.
3 4 5 |
# File 'lib/spreedly-core-ruby/payment_method.rb', line 3 def number @number end |
#payment_method_type ⇒ Object (readonly)
Returns the value of attribute payment_method_type.
3 4 5 |
# File 'lib/spreedly-core-ruby/payment_method.rb', line 3 def payment_method_type @payment_method_type end |
#phone_number ⇒ Object (readonly)
Returns the value of attribute phone_number.
3 4 5 |
# File 'lib/spreedly-core-ruby/payment_method.rb', line 3 def phone_number @phone_number end |
#state ⇒ Object (readonly)
Returns the value of attribute state.
3 4 5 |
# File 'lib/spreedly-core-ruby/payment_method.rb', line 3 def state @state end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
3 4 5 |
# File 'lib/spreedly-core-ruby/payment_method.rb', line 3 def token @token end |
#updated_at ⇒ Object (readonly)
Returns the value of attribute updated_at.
3 4 5 |
# File 'lib/spreedly-core-ruby/payment_method.rb', line 3 def updated_at @updated_at end |
#verification_value ⇒ Object (readonly)
Returns the value of attribute verification_value.
3 4 5 |
# File 'lib/spreedly-core-ruby/payment_method.rb', line 3 def verification_value @verification_value end |
#year ⇒ Object (readonly)
Returns the value of attribute year.
3 4 5 |
# File 'lib/spreedly-core-ruby/payment_method.rb', line 3 def year @year end |
#zip ⇒ Object (readonly)
Returns the value of attribute zip.
3 4 5 |
# File 'lib/spreedly-core-ruby/payment_method.rb', line 3 def zip @zip end |
Class Method Details
.additional_required_cc_fields(*fields) ⇒ Object
configure additional required fiels. Like :address1, :city, :state
9 10 11 12 |
# File 'lib/spreedly-core-ruby/payment_method.rb', line 9 def self.additional_required_cc_fields *fields @@additional_required_fields ||= Set.new @@additional_required_fields += fields end |
.create(credit_card) ⇒ Object
28 29 30 31 32 |
# File 'lib/spreedly-core-ruby/payment_method.rb', line 28 def self.create(credit_card) verify_post("/payment_methods.xml", :body => {:payment_method => { :credit_card => credit_card }}) do |response| AddPaymentMethodTransaction.new(response.parsed_response["transaction"]) end end |
.create_test_token(cc_overrides = {}) ⇒ Object
Call spreedly to create a test token. pass_through_data will be added as the “data” field.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/spreedly-core-ruby/test_extensions.rb', line 44 def self.create_test_token(cc_overrides = {}) card = { :first_name => "John", :last_name => "Foo", :card_type => :visa, :number => '4111111111111111', :verification_value => 123, :month => 4, :year => Time.now.year + 1 } if cc_overrides.is_a?(Hash) overrides = cc_overrides[:credit_card] || cc_overrides["credit_card"] || cc_overrides card.merge!(overrides) end pm = PaymentMethod.create(card) pm.payment_method["token"] end |
.find(token) ⇒ Object
Lookup the PaymentMethod by token
20 21 22 23 24 25 26 |
# File 'lib/spreedly-core-ruby/payment_method.rb', line 20 def self.find(token) return nil if token.nil? verify_get("/payment_methods/#{token}.xml", :has_key => "payment_method") do |response| new(response.parsed_response["payment_method"]) end end |
.reset_additional_required_cc_fields ⇒ Object
clear the configured additional required fields
15 16 17 |
# File 'lib/spreedly-core-ruby/payment_method.rb', line 15 def self.reset_additional_required_cc_fields @@additional_required_fields = Set.new end |
.submit_url ⇒ Object
Returns the URL that CC data should be submitted to.
77 78 79 |
# File 'lib/spreedly-core-ruby/payment_method.rb', line 77 def self.submit_url Base.base_uri + '/payment_methods' end |
Instance Method Details
#authorize(amount, *args) ⇒ Object
Make an authorize against payment method. You can then later capture against the authorize
60 61 62 |
# File 'lib/spreedly-core-ruby/payment_method.rb', line 60 def (amount, *args) (:authorize, amount, *args) end |
#purchase(amount, *args) ⇒ Object
Make a purchase against the payment method
55 56 57 |
# File 'lib/spreedly-core-ruby/payment_method.rb', line 55 def purchase(amount, *args) (:purchase, amount, *args) end |
#redact ⇒ Object
Redact the payment method
48 49 50 51 52 |
# File 'lib/spreedly-core-ruby/payment_method.rb', line 48 def redact self.class.verify_put("/payment_methods/#{token}/redact.xml", :body => {}, :has_key => "transaction") do |response| RedactTransaction.new(response.parsed_response["transaction"]) end end |
#retain ⇒ Object
Retain the payment method
41 42 43 44 45 |
# File 'lib/spreedly-core-ruby/payment_method.rb', line 41 def retain self.class.verify_put("/payment_methods/#{token}/retain.xml", :body => {}, :has_key => "transaction") do |response| RetainTransaction.new(response.parsed_response["transaction"]) end end |
#update(attributes) ⇒ Object
Update the attributes of a payment method
65 66 67 68 69 70 71 72 73 74 |
# File 'lib/spreedly-core-ruby/payment_method.rb', line 65 def update(attributes) opts = { :headers => {"Content-Type" => "application/xml"}, :body => attributes.to_xml(:root => "payment_method", :dasherize => false) } self.class.verify_put("/payment_methods/#{token}.xml", opts) do |response| PaymentMethod.new(response.parsed_response["payment_method"]) end end |
#valid? ⇒ Boolean
81 82 83 |
# File 'lib/spreedly-core-ruby/payment_method.rb', line 81 def valid? @errors.empty? end |