Abraham Rodriguez

debug

class AddVarStatusTo<%=@model_name.camelize%> < ActiveRecord::Migration
def change
add_column :<%=@model_name.pluralize.underscore%>, :var_status, :string, default: 'pending'
end
end
require 'rails/generators'
class VarStatusGenerator < Rails::Generators::NamedBase
source_root File.expand_path('../templates', __FILE__)
desc "This generator generates layout file with navigation."
def generate_status
d = Time.now.strftime('%Y%m%d%H%M%S')
@model_name = name
template "var_status.rb",
"db/migrate/#{d}_add_var_status_to_#{name.pluralize.underscore}.rb"
end
end
......@@ -5,19 +5,18 @@ require 'paypal-sdk-rest'
module Var
# TODO: add paypal
# @@valid_services = [:conekta, :paypal]
@@valid_services = [:conekta]
VALID_SERVICES = [:conekta]
def self.valid_services
@@valid_services
VALID_SERVICES
end
def self.create_charge(service, object, options = {})
if(!@@valid_services.include?(service))
return { error_message: 'Service is not supported' }
end
if(!object.respond_to?(:charge_with))
return { error_message: "#{object.class.to_s} doesn't support charges"}
end
binding.pry
return { error_message: 'Service is not supported' }
unless VALID_SERVICES.include? service
return { error_message: "#{object.class.to_s} doesn't support charges"}
unless object.respond_to?(:charge_with)
object.charge_with(service, options)
end
end
......@@ -48,6 +47,7 @@ module ActsAsChargeable
end
def charge_with_conekta(options)
binding.pry
if(!options.include? :card_token)
error_message = "Conekta needs a card token sent as a third paramater"
return { error_message: error_message}
......@@ -71,6 +71,7 @@ module ActsAsChargeable
}
})
rescue => exception
self.update_columns(var_status: 'failed')
return { error_message: exception.message }
end
end
......