Abraham Rodriguez

debug

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