Sha256: 0205fd627172c5c15a944d72f7b481fc0c9810894972eff28bd488c10721f670

Contents?: true

Size: 1.07 KB

Versions: 1

Compression:

Stored size: 1.07 KB

Contents

module Conekta
  class Card < APIResource
    include Conekta::APIOperations::Update

    attr_accessor :customer
    
    def customer
      @customer
    end

    def customer=(customer)
      @customer = customer
    end

    def delete
      response, api_key = Conekta.request(:delete, url, @api_key)
      refresh_from(response, api_key)
      deleted_card = self
      i = 0
      for card in self.customer.cards
        if deleted_card.id == card.id
          self.customer.cards.delete_at(i)
          break
        end
        i = i + 1
      end
      deleted_card
    end

    def url
      unless id = self['id']
        raise ParameterValidationError.new("Could not determine which URL to request: #{self.class} instance has invalid ID: #{id.inspect}", 'id')
      end
      unless customer = self.customer
        raise ParameterValidationError.new("Could not determine which URL to request: #{self.class} instance has invalid customer: #{customer.inspect}", 'customer')
      end
      "#{Conekta::Customer.url}/#{CGI.escape(customer.id)}/cards/#{CGI.escape(id)}"
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
conekta-0.3.3 lib/conekta/card.rb