Sha256: cdf39879e5697fca34135e24c9e5f9d30bf1564e5b7a7a89934b25c59cc063da

Contents?: true

Size: 1.23 KB

Versions: 1

Compression:

Stored size: 1.23 KB

Contents

class StripeMethod < PaymentMethod
  attr_accessor :token
  after_destroy_commit :remove

  def retrieve
    customer = Stripe::Customer.retrieve account_num
    customer_info(customer)
  end

  def customer_info(customer)
    card = customer.sources.data[0]
    return {} unless card
    {
      description: customer.description,
      address_zip: card.address_zip,
      address_zip_check: card.address_zip_check,
      brand: card.brand,
      country: card.country,
      cvc_check: card.cvc_check,
      exp_month: card.exp_month,
      exp_year: card.exp_year,
      fingerprint: card.fingerprint,
      funding: card.funding,
      last4: card.last4
    }
  end

  def update_extra
    self.update extra: retrieve.to_h
  end

  def remove
    cu = Stripe::Customer.retrieve account_num
    cu.delete
  end

  def detective_save
    begin
      customer = Stripe::Customer.create(description: "buyer_id: #{payment_references.map { |i| i.buyer_id }}", source: self.token)
      self.account_num = customer.id
      self.extra = self.customer_info(customer)
    rescue Stripe::StripeError => ex
      self.errors.add :base, ex.message
    end

    self.verified = true
    if self.errors.blank?
      self.save
    else
      false
    end
  end

end



Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rails_trade-0.0.1 app/models/rails_trade/payment_methods/stripe_method.rb