-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Robert Falkén
committed
Aug 5, 2014
0 parents
commit 2c040fd
Showing
56 changed files
with
1,007 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
.bundle/ | ||
log/*.log | ||
pkg/ | ||
test/dummy/db/*.sqlite3 | ||
test/dummy/db/*.sqlite3-journal | ||
test/dummy/log/*.log | ||
test/dummy/tmp/ | ||
test/dummy/.sass-cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
source "https://rubygems.org" | ||
|
||
# Declare your gem's dependencies in mondido_sdk.gemspec. | ||
# Bundler will treat runtime dependencies like base dependencies, and | ||
# development dependencies will be added by default to the :development group. | ||
gemspec | ||
|
||
# Declare any dependencies that are still in development here instead of in | ||
# your gemspec. These might include edge Rails or gems from your path or | ||
# Git. Remember to move these dependencies to your gemspec before releasing | ||
# your gem to rubygems.org. | ||
|
||
# To use debugger | ||
# gem 'debugger' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
PATH | ||
remote: . | ||
specs: | ||
mondido_sdk (0.0.1) | ||
rails (~> 4.1.4) | ||
|
||
GEM | ||
remote: https://rubygems.org/ | ||
specs: | ||
actionmailer (4.1.4) | ||
actionpack (= 4.1.4) | ||
actionview (= 4.1.4) | ||
mail (~> 2.5.4) | ||
actionpack (4.1.4) | ||
actionview (= 4.1.4) | ||
activesupport (= 4.1.4) | ||
rack (~> 1.5.2) | ||
rack-test (~> 0.6.2) | ||
actionview (4.1.4) | ||
activesupport (= 4.1.4) | ||
builder (~> 3.1) | ||
erubis (~> 2.7.0) | ||
activemodel (4.1.4) | ||
activesupport (= 4.1.4) | ||
builder (~> 3.1) | ||
activerecord (4.1.4) | ||
activemodel (= 4.1.4) | ||
activesupport (= 4.1.4) | ||
arel (~> 5.0.0) | ||
activesupport (4.1.4) | ||
i18n (~> 0.6, >= 0.6.9) | ||
json (~> 1.7, >= 1.7.7) | ||
minitest (~> 5.1) | ||
thread_safe (~> 0.1) | ||
tzinfo (~> 1.1) | ||
arel (5.0.1.20140414130214) | ||
builder (3.2.2) | ||
erubis (2.7.0) | ||
hike (1.2.3) | ||
i18n (0.6.11) | ||
json (1.8.1) | ||
mail (2.5.4) | ||
mime-types (~> 1.16) | ||
treetop (~> 1.4.8) | ||
mime-types (1.25.1) | ||
minitest (5.4.0) | ||
multi_json (1.10.1) | ||
polyglot (0.3.5) | ||
rack (1.5.2) | ||
rack-test (0.6.2) | ||
rack (>= 1.0) | ||
rails (4.1.4) | ||
actionmailer (= 4.1.4) | ||
actionpack (= 4.1.4) | ||
actionview (= 4.1.4) | ||
activemodel (= 4.1.4) | ||
activerecord (= 4.1.4) | ||
activesupport (= 4.1.4) | ||
bundler (>= 1.3.0, < 2.0) | ||
railties (= 4.1.4) | ||
sprockets-rails (~> 2.0) | ||
railties (4.1.4) | ||
actionpack (= 4.1.4) | ||
activesupport (= 4.1.4) | ||
rake (>= 0.8.7) | ||
thor (>= 0.18.1, < 2.0) | ||
rake (10.3.2) | ||
sprockets (2.12.1) | ||
hike (~> 1.2) | ||
multi_json (~> 1.0) | ||
rack (~> 1.0) | ||
tilt (~> 1.1, != 1.3.0) | ||
sprockets-rails (2.1.3) | ||
actionpack (>= 3.0) | ||
activesupport (>= 3.0) | ||
sprockets (~> 2.8) | ||
sqlite3 (1.3.9) | ||
thor (0.19.1) | ||
thread_safe (0.3.4) | ||
tilt (1.4.1) | ||
treetop (1.4.15) | ||
polyglot | ||
polyglot (>= 0.3.1) | ||
tzinfo (1.2.1) | ||
thread_safe (~> 0.1) | ||
|
||
PLATFORMS | ||
ruby | ||
|
||
DEPENDENCIES | ||
mondido_sdk! | ||
sqlite3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
Copyright 2014 YOURNAME | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
"Software"), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
= MondidoSdk | ||
|
||
This project rocks and uses MIT-LICENSE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
begin | ||
require 'bundler/setup' | ||
rescue LoadError | ||
puts 'You must `gem install bundler` and `bundle install` to run rake tasks' | ||
end | ||
|
||
require 'rdoc/task' | ||
|
||
RDoc::Task.new(:rdoc) do |rdoc| | ||
rdoc.rdoc_dir = 'rdoc' | ||
rdoc.title = 'MondidoSdk' | ||
rdoc.options << '--line-numbers' | ||
rdoc.rdoc_files.include('README.rdoc') | ||
rdoc.rdoc_files.include('lib/**/*.rb') | ||
end | ||
|
||
|
||
|
||
|
||
Bundler::GemHelper.install_tasks | ||
|
||
require 'rake/testtask' | ||
|
||
Rake::TestTask.new(:test) do |t| | ||
t.libs << 'lib' | ||
t.libs << 'test' | ||
t.pattern = 'test/**/*_test.rb' | ||
t.verbose = false | ||
end | ||
|
||
|
||
task default: :test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module MondidoSDK | ||
require 'mondido_sdk/config' | ||
require 'mondido_sdk/mondido_model' | ||
require 'mondido_sdk/transaction/transaction' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
module MondidoSDK | ||
module Config | ||
unless Rails.root.nil? | ||
config_file = File.join(Rails.root, 'config', 'mondido.yml') | ||
if File.exist?(config_file) | ||
yaml = YAML.load(File.read(config_file)) | ||
else | ||
raise 'Could not find app/mondido.yml' | ||
end | ||
|
||
private | ||
|
||
@@merchant_id = yaml['merchant_id'] or raise 'Mondido merchant ID not set in config/mondido.yml' | ||
@@secret = yaml['secret'] or raise 'Mondido secret not set in config/mondido.yml' | ||
@@password = yaml['password'] or raise 'Mondido password not set in config/mondido.yml' | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module MondidoSDK | ||
class MondidoModel | ||
def update_from_response(attributes) | ||
attributes.each do |attribute, value| | ||
attribute_symbol = "@#{attribute}".to_sym | ||
setter_symbol = "#{attribute}=".to_sym | ||
instance_variable_set attribute_symbol, value if respond_to?(setter_symbol) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
|
||
module MondidoSDK | ||
module Transaction | ||
class CreditCardPayment < MondidoModel | ||
include MondidoSDK::Config | ||
include ActiveModel::Model | ||
|
||
attr_accessor :id, | ||
:amount, | ||
:currency, | ||
:card_number, | ||
:card_holder, | ||
:card_cvv, | ||
:card_expiry, | ||
:card_type, | ||
:payment_ref, | ||
:metadata, | ||
:items, | ||
:created_at, | ||
:merchant_id, | ||
:vat_amount, | ||
:test, | ||
:status, | ||
:transaction_type, | ||
:cost, | ||
:stored_card, | ||
:customer, | ||
:subscription, | ||
:payment_details | ||
|
||
validates :currency, | ||
presence: { message: 'errors.currency.missing' } | ||
|
||
validates :amount, | ||
presence: { message: 'errors.amount.missing' } | ||
|
||
validates :card_number, | ||
presence: { message: 'errors.card_number.missing' } | ||
|
||
validates :card_cvv, | ||
presence: { message: 'errors.card_cvv.missing' } | ||
|
||
validates :card_expiry, | ||
presence: { message: 'errors.card_expiry.missing' } | ||
|
||
validates :card_type, | ||
presence: { message: 'errors.card_type.missing' } | ||
|
||
|
||
|
||
def self.create(attributes) | ||
transaction = MondidoSDK::Transaction::CreditCardPayment.new(attributes) | ||
return transaction unless transaction.valid? | ||
|
||
unhashed = [@@merchant_id, attributes[:payment_ref], attributes[:amount], attributes[:currency], @@secret] | ||
attributes['hash'] = Digest::MD5.hexdigest(unhashed.join) | ||
uri = URI.parse 'http://api.localmondido.com:3000/v1/transactions?extend=payment_details' | ||
http = Net::HTTP.new(uri.host, uri.port) | ||
# http.use_ssl = true | ||
request = Net::HTTP::Post.new(uri.path) | ||
request.basic_auth(@@merchant_id, @@password) | ||
request.set_form_data(attributes) | ||
response = http.start { |http| http.request(request) } | ||
|
||
if (200..299).include?(response.code.to_i) | ||
transaction.update_from_response(JSON.parse(response.body)) | ||
else | ||
transaction.errors.add(:response, 'errorous') | ||
end | ||
return transaction | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module MondidoSDK | ||
module Transaction | ||
require 'mondido_sdk/transaction/credit_card_payment' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module MondidoSDK | ||
VERSION = "0.0.1" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# desc "Explaining what the task does" | ||
# task :mondido_sdk do | ||
# # Task goes here | ||
# end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
$:.push File.expand_path("../lib", __FILE__) | ||
|
||
# Maintain your gem's version: | ||
require "mondido_sdk/version" | ||
|
||
# Describe your gem and declare its dependencies: | ||
Gem::Specification.new do |s| | ||
s.name = "mondido_sdk" | ||
s.version = MondidoSDK::VERSION | ||
s.authors = ["TODO: Your name"] | ||
s.email = ["TODO: Your email"] | ||
s.homepage = "TODO" | ||
s.summary = "TODO: Summary of MondidoSDK." | ||
s.description = "TODO: Description of MondidoSDK." | ||
s.license = "MIT" | ||
|
||
s.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.rdoc"] | ||
s.test_files = Dir["test/**/*"] | ||
|
||
s.add_dependency "rails", "~> 4.0.3" | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
== README | ||
|
||
This README would normally document whatever steps are necessary to get the | ||
application up and running. | ||
|
||
Things you may want to cover: | ||
|
||
* Ruby version | ||
|
||
* System dependencies | ||
|
||
* Configuration | ||
|
||
* Database creation | ||
|
||
* Database initialization | ||
|
||
* How to run the test suite | ||
|
||
* Services (job queues, cache servers, search engines, etc.) | ||
|
||
* Deployment instructions | ||
|
||
* ... | ||
|
||
|
||
Please feel free to use a different markup language if you do not plan to run | ||
<tt>rake doc:app</tt>. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Add your own tasks in files placed in lib/tasks ending in .rake, | ||
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. | ||
|
||
require File.expand_path('../config/application', __FILE__) | ||
|
||
Rails.application.load_tasks |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// This is a manifest file that'll be compiled into application.js, which will include all the files | ||
// listed below. | ||
// | ||
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, | ||
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path. | ||
// | ||
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the | ||
// compiled file. | ||
// | ||
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details | ||
// about supported directives. | ||
// | ||
//= require_tree . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* | ||
* This is a manifest file that'll be compiled into application.css, which will include all the files | ||
* listed below. | ||
* | ||
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets, | ||
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path. | ||
* | ||
* You're free to add application-wide styles to this file and they'll appear at the bottom of the | ||
* compiled file so the styles you add here take precedence over styles defined in any styles | ||
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new | ||
* file per style scope. | ||
* | ||
*= require_tree . | ||
*= require_self | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class ApplicationController < ActionController::Base | ||
# Prevent CSRF attacks by raising an exception. | ||
# For APIs, you may want to use :null_session instead. | ||
protect_from_forgery with: :exception | ||
end |
Empty file.
Oops, something went wrong.