Abraham Rodriguez

initial commint

/.bundle/
/.yardoc
/Gemfile.lock
/_yardoc/
/coverage/
/doc/
/pkg/
/spec/reports/
/tmp/
language: ruby
rvm:
- 2.1.5
before_install: gem install bundler -v 1.10.0.pre.2
source 'https://rubygems.org'
# Specify your gem's dependencies in var.gemspec
gemspec
# Var
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/var`. To experiment with that code, run `bin/console` for an interactive prompt.
TODO: Delete this and the text above, and describe your gem
## Installation
Add this line to your application's Gemfile:
```ruby
gem 'var'
```
And then execute:
$ bundle
Or install it yourself as:
$ gem install var
## Usage
TODO: Write usage instructions here
## Development
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
## Contributing
1. Fork it ( https://github.com/[my-github-username]/var/fork )
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create a new Pull Request
require "bundler/gem_tasks"
#!/usr/bin/env ruby
require "bundler/setup"
require "var"
# You can add fixtures and/or initialization code here to make experimenting
# with your gem easier. You can also use a different console, if you like.
# (If you use this, don't forget to add pry to your Gemfile!)
# require "pry"
# Pry.start
require "irb"
IRB.start
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'
bundle install
# Do any other automated setup that you need to do here
require "var/version"
require 'conekta'
module Var
@@valid_services = [:conekta]
def self.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
object.charge_with(:conekta, options)
end
private
end
module ActsAsChargeable
extend ActiveSupport::Concern
module ClassMethods
def acts_as_chargeable(keys = {})
include ChargeableInstanceMethods
cattr_accessor :sync_attributes
self.sync_attributes = keys
end
end
module ChargeableInstanceMethods
def charge_with(service, options)
begin
self.send("charge_with_#{service.to_s}", options)
rescue => exception
return { error_message: exception.message }
end
end
def charge_with_conekta(options)
if(!options.include? :card_token)
error_message = "Conekta needs a card token sent as a third paramater"
return { error_message: error_message}
end
@charge ||= Conekta::Charge.create({
description: self.sync_attribute('description'),
amount: self.sync_attribute('amount'),
currency: "MXN",
reference_id: self.sync_attribute('reference_id'),
card: options[:card_token],
details: {
name: self.sync_attribute('details_name'),
email: self.sync_attribute('details_email'),
line_items: [{
name: self.sync_attribute('details_name'),
description: self.sync_attribute('description'),
unit_price: self.sync_attribute('amount'),
quantity: 1,
}]
}
})
end
def find_charge(service)
begin
if(!Var.valid_services.include?(service))
return { error_message: 'Service is not supported' }
end
self.send("find_#{service.to_s}_charge")
rescue => exception
return { error_message: exception.message }
end
end
def find_conekta_charge
ref_id = self.sync_attribute('reference_id')
Conekta::Charge.where({'status.ne'=>'paid', 'reference_id'=> ref_id})
end
def sync_attribute(key)
return self.send(key) unless self.sync_attributes.include? key.to_sym
self.send(sync_attributes[key.to_sym])
end
end
end
ActiveRecord::Base.send(:include, ActsAsChargeable) if defined? ActiveRecord::Base
\ No newline at end of file
module Var
VERSION = "0.1.0"
end
No preview for this file type
# coding: utf-8
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'var/version'
Gem::Specification.new do |spec|
spec.name = "var"
spec.version = Var::VERSION
spec.authors = ["abrahamrq"]
spec.email = ["abraham.rq03@gmail.com"]
spec.summary = %q{summary of var}
spec.description = %q{description of var}
spec.homepage = "https://github.com/abrahamrq"
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
# delete this section to allow pushing this gem to any host.
if spec.respond_to?(:metadata)
spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
else
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
end
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
spec.bindir = "exe"
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]
spec.add_dependency 'conekta', "~> 0.5"
spec.add_development_dependency "bundler", "~> 1.10.a"
spec.add_development_dependency "rake", "~> 10.0"
end