Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Ruby Gems
/
var
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
Abraham Rodriguez
2016-01-05 15:17:49 -0600
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
669211a7967c8915eb38e70c071de62add60ddf7
669211a7
1 parent
65741dde
debug
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
8 deletions
lib/generators/var_status/templates/var_status.rb
lib/generators/var_status/var_status_generator.rb
lib/var.rb
lib/generators/var_status/templates/var_status.rb
0 → 100644
View file @
669211a
class
AddVarStatusTo
<
%=@model_name.camelize%> < ActiveRecord::Migration
def change
add_column :<%=
@model_name
.
pluralize
.
underscore
%>, :var_status, :string, default: 'pending'
end
end
lib/generators/var_status/var_status_generator.rb
0 → 100644
View file @
669211a
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
lib/var.rb
View file @
669211a
...
...
@@ -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
...
...
Please
register
or
login
to post a comment