dinero_mail_checkout 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +59 -0
- data/Rakefile +2 -0
- data/dinero_mail_checkout.gemspec +19 -0
- data/lib/dinero_mail_checkout.rb +7 -0
- data/lib/dinero_mail_checkout/checkout_data.rb +28 -0
- data/lib/dinero_mail_checkout/client.rb +11 -0
- data/lib/dinero_mail_checkout/configuration.rb +34 -0
- data/lib/dinero_mail_checkout/version.rb +3 -0
- data/spec/checkout_data_spec.rb +51 -0
- data/spec/client_spec.rb +20 -0
- data/spec/configuration_spec.rb +38 -0
- data/spec/spec_helper.rb +2 -0
- metadata +75 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Josemar Davi Luedke
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
# DineroMailCheckout
|
2
|
+
|
3
|
+
Dineromail simple checkout integration with Ruby
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'dinero_mail_checkout'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install dinero_mail_checkout
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
### General Configuration
|
22
|
+
|
23
|
+
DineroMailCheckout.configure do |config|
|
24
|
+
config.payment_method = 'all'
|
25
|
+
config.merchant = 'merchant_number'
|
26
|
+
config.logo_url = 'http://localhost:3000/assets/logo.png'
|
27
|
+
config.success_url = 'http://localhost:3000/success_page'
|
28
|
+
config.error_url = 'http://localhost:3000/error_page'
|
29
|
+
config.currency = DineroMailCheckout::Configuration::Currency::CLP
|
30
|
+
config.country_id = 2
|
31
|
+
end
|
32
|
+
|
33
|
+
### Example rails controller
|
34
|
+
|
35
|
+
class DineromailController < ApplicationController
|
36
|
+
def pay
|
37
|
+
transaction_id = (Digest::MD5.hexdigest "#{SecureRandom.hex(5)}-#{DateTime.now.to_s}")[1..20].downcase
|
38
|
+
data = DineroMailCheckout::CheckoutData.validate({item_name_1: "Product",
|
39
|
+
item_quantity_1: 1,
|
40
|
+
item_currency_1: DineroMailCheckout.configuration.currency,
|
41
|
+
change_quantity: 0,
|
42
|
+
item_ammount_1: 100,
|
43
|
+
buyer_name: "Customer Name",
|
44
|
+
buyer_email: "email@gmail.com",
|
45
|
+
transaction_id: transaction_id})
|
46
|
+
redirect_to DineroMailCheckout::Client.get_uri(data)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
### IPN
|
50
|
+
|
51
|
+
For IPN, use the [dinero_mail_ipn](http://github.com/etagwerker/dinero_mail_ipn) gem.
|
52
|
+
|
53
|
+
## Contributing
|
54
|
+
|
55
|
+
1. Fork it
|
56
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
57
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
58
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
59
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/dinero_mail_checkout/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Josemar Davi Luedke"]
|
6
|
+
gem.email = ["josemarluedke@gmail.com"]
|
7
|
+
gem.description = %q{DineroMail checkout library for Ruby}
|
8
|
+
gem.summary = %q{DineroMail checkout}
|
9
|
+
gem.homepage = "http://github.com/josemarluedke/dinero_mail_checkout"
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "dinero_mail_checkout"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = DineroMailCheckout::VERSION
|
17
|
+
|
18
|
+
gem.add_development_dependency "rspec"
|
19
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module DineroMailCheckout
|
2
|
+
|
3
|
+
class MissingItemNameError < StandardError ; end
|
4
|
+
class MissingItemQuantityError < StandardError ; end
|
5
|
+
class MissingItemAmmountError < StandardError ; end
|
6
|
+
class MissingMerchantError < StandardError ; end
|
7
|
+
class MissingCountryIdError < StandardError ; end
|
8
|
+
|
9
|
+
class CheckoutData
|
10
|
+
class << self
|
11
|
+
def validate(attributes = {})
|
12
|
+
attributes[:merchant] = (DineroMailCheckout.configuration.merchant || nil ) if attributes[:merchant].nil?
|
13
|
+
attributes[:country_id] = (DineroMailCheckout.configuration.country_id || nil ) if attributes[:country_id].nil?
|
14
|
+
raise(MissingMerchantError) if attributes[:merchant].nil?
|
15
|
+
raise(MissingCountryIdError) if attributes[:country_id].nil?
|
16
|
+
raise(MissingItemNameError) if attributes[:item_name_1].nil?
|
17
|
+
raise(MissingItemQuantityError) if attributes[:item_quantity_1].nil?
|
18
|
+
raise(MissingItemAmmountError) if attributes[:item_ammount_1].nil?
|
19
|
+
attributes[:payment_method_available] = (DineroMailCheckout.configuration.payment_method || 'all' ) if attributes[:payment_method_available].nil?
|
20
|
+
attributes[:ok_url] = DineroMailCheckout.configuration.success_url if attributes[:ok_url].nil?
|
21
|
+
attributes[:error_url] = DineroMailCheckout.configuration.error_url if attributes[:error_url].nil?
|
22
|
+
attributes[:currency] = DineroMailCheckout.configuration.currency if attributes[:currency].nil?
|
23
|
+
attributes[:header_image] = DineroMailCheckout.configuration.logo_url if attributes[:header_image].nil?
|
24
|
+
attributes
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module DineroMailCheckout
|
2
|
+
class Configuration
|
3
|
+
attr_accessor :payment_url, :merchant, :logo_url, :success_url, :error_url, :payment_method, :currency, :country_id
|
4
|
+
CHECKOUT_URL = "https://checkout.dineromail.com/CheckOut"
|
5
|
+
|
6
|
+
class Currency
|
7
|
+
ARS = "ars"
|
8
|
+
MXN = "mxn"
|
9
|
+
CLP = "clp"
|
10
|
+
BRL = "brl"
|
11
|
+
USD = "usd"
|
12
|
+
end
|
13
|
+
class << self
|
14
|
+
def country_name(id)
|
15
|
+
case id
|
16
|
+
when 1 then "argentina"
|
17
|
+
when 2 then "brasil"
|
18
|
+
when 3 then "chile"
|
19
|
+
when 4 then "mexico"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
class << self
|
27
|
+
attr_accessor :configuration
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.configure
|
31
|
+
self.configuration ||= Configuration.new
|
32
|
+
yield configuration
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe DineroMailCheckout do
|
4
|
+
describe "validations" do
|
5
|
+
before do
|
6
|
+
DineroMailCheckout.configure do |config|
|
7
|
+
config.payment_method = 'all'
|
8
|
+
config.merchant = 'merchant'
|
9
|
+
config.logo_url = 'http://localhost:3000/assets/logo.png'
|
10
|
+
config.success_url = 'http://localhost:3000/success_page'
|
11
|
+
config.error_url = 'http://localhost:3000/error_page'
|
12
|
+
config.currency = DineroMailCheckout::Configuration::Currency::CLP
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should raise error on miss merchant" do
|
17
|
+
DineroMailCheckout.configuration.merchant = nil
|
18
|
+
lambda{ DineroMailCheckout::CheckoutData.validate }.should raise_error(DineroMailCheckout::MissingMerchantError)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should raise error on miss country id" do
|
22
|
+
lambda{ DineroMailCheckout::CheckoutData.validate }.should raise_error(DineroMailCheckout::MissingCountryIdError)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should raise error on miss item name" do
|
26
|
+
data = {country_id: 2}
|
27
|
+
lambda{ DineroMailCheckout::CheckoutData.validate(data) }.should raise_error(DineroMailCheckout::MissingItemNameError)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should raise error on miss item quantity" do
|
31
|
+
data = {country_id: 2, item_name_1: "Name"}
|
32
|
+
lambda{ DineroMailCheckout::CheckoutData.validate(data) }.should raise_error(DineroMailCheckout::MissingItemQuantityError)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should raise error on miss item ammount" do
|
36
|
+
data = {country_id: 2, item_name_1: "Name", item_quantity_1: 1}
|
37
|
+
lambda{ DineroMailCheckout::CheckoutData.validate(data) }.should raise_error(DineroMailCheckout::MissingItemAmmountError)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should don't have a error" do
|
41
|
+
data = {country_id: 2, item_name_1: "Name", item_quantity_1: 1, item_ammount_1: 10}
|
42
|
+
lambda{ DineroMailCheckout::CheckoutData.validate(data) }.should_not raise_error
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should return the all data" do
|
46
|
+
data = {country_id: 2, item_name_1: "Name", item_quantity_1: 1, item_ammount_1: 10}
|
47
|
+
DineroMailCheckout::CheckoutData.validate(data).should == {country_id: 2, item_name_1: "Name", item_quantity_1: 1, item_ammount_1: 10, merchant: "merchant", payment_method_available: "all", ok_url: "http://localhost:3000/success_page", error_url: "http://localhost:3000/error_page", currency: "clp", :header_image=>"http://localhost:3000/assets/logo.png"}
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
data/spec/client_spec.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe DineroMailCheckout do
|
4
|
+
describe "validations" do
|
5
|
+
before do
|
6
|
+
DineroMailCheckout.configure do |config|
|
7
|
+
config.payment_method = 'all'
|
8
|
+
config.merchant = 'merchant'
|
9
|
+
config.logo_url = 'http://localhost:3000/assets/logo.png'
|
10
|
+
config.success_url = 'http://localhost:3000/success_page'
|
11
|
+
config.error_url = 'http://localhost:3000/error_page'
|
12
|
+
config.currency = DineroMailCheckout::Configuration::Currency::CLP
|
13
|
+
end
|
14
|
+
end
|
15
|
+
it "should redirect to DineroMail checkout page" do
|
16
|
+
data = {country_id: 2, item_name_1: "Name", item_quantity_1: 1, item_ammount_1: 10}
|
17
|
+
DineroMailCheckout::Client.get_uri(data).should =~ /checkout.dineromail.com\/CheckOut\?country_id=2&item_name_1=Name&item_quantity_1=1&item_ammount_1=10&merchant=merchant&payment_method_available=all&ok_url=http%3A%2F%2Flocalhost%3A3000%2Fsuccess_page&error_url=http%3A%2F%2Flocalhost%3A3000%2Ferror_page¤cy=clp/
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe DineroMailCheckout do
|
4
|
+
subject do
|
5
|
+
DineroMailCheckout.configure do |config|
|
6
|
+
config.payment_method = 'all'
|
7
|
+
config.merchant = 'merchant_number'
|
8
|
+
config.logo_url = 'http://localhost:3000/assets/logo.png'
|
9
|
+
config.success_url = 'http://localhost:3000/success_page'
|
10
|
+
config.error_url = 'http://localhost:3000/error_page'
|
11
|
+
config.currency = DineroMailCheckout::Configuration::Currency::CLP
|
12
|
+
config.country_id = 2
|
13
|
+
end
|
14
|
+
DineroMailCheckout.configuration
|
15
|
+
end
|
16
|
+
its(:payment_method){ should == "all" }
|
17
|
+
its(:merchant){ should == "merchant_number" }
|
18
|
+
its(:logo_url){ should == "http://localhost:3000/assets/logo.png" }
|
19
|
+
its(:success_url){ should == "http://localhost:3000/success_page" }
|
20
|
+
its(:error_url){ should == "http://localhost:3000/error_page" }
|
21
|
+
its(:currency){ should == DineroMailCheckout::Configuration::Currency::CLP }
|
22
|
+
its(:country_id){ should == 2 }
|
23
|
+
|
24
|
+
describe "country name feature" do
|
25
|
+
it "with 1, should return argentina" do
|
26
|
+
DineroMailCheckout::Configuration.country_name(1).should == "argentina"
|
27
|
+
end
|
28
|
+
it "with 2, should return brasil" do
|
29
|
+
DineroMailCheckout::Configuration.country_name(2).should == "brasil"
|
30
|
+
end
|
31
|
+
it "with 3, should return chile" do
|
32
|
+
DineroMailCheckout::Configuration.country_name(3).should == "chile"
|
33
|
+
end
|
34
|
+
it "with 4, should return mexico" do
|
35
|
+
DineroMailCheckout::Configuration.country_name(4).should == "mexico"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dinero_mail_checkout
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Josemar Davi Luedke
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-07-16 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: &70148851731520 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70148851731520
|
25
|
+
description: DineroMail checkout library for Ruby
|
26
|
+
email:
|
27
|
+
- josemarluedke@gmail.com
|
28
|
+
executables: []
|
29
|
+
extensions: []
|
30
|
+
extra_rdoc_files: []
|
31
|
+
files:
|
32
|
+
- .gitignore
|
33
|
+
- Gemfile
|
34
|
+
- LICENSE
|
35
|
+
- README.md
|
36
|
+
- Rakefile
|
37
|
+
- dinero_mail_checkout.gemspec
|
38
|
+
- lib/dinero_mail_checkout.rb
|
39
|
+
- lib/dinero_mail_checkout/checkout_data.rb
|
40
|
+
- lib/dinero_mail_checkout/client.rb
|
41
|
+
- lib/dinero_mail_checkout/configuration.rb
|
42
|
+
- lib/dinero_mail_checkout/version.rb
|
43
|
+
- spec/checkout_data_spec.rb
|
44
|
+
- spec/client_spec.rb
|
45
|
+
- spec/configuration_spec.rb
|
46
|
+
- spec/spec_helper.rb
|
47
|
+
homepage: http://github.com/josemarluedke/dinero_mail_checkout
|
48
|
+
licenses: []
|
49
|
+
post_install_message:
|
50
|
+
rdoc_options: []
|
51
|
+
require_paths:
|
52
|
+
- lib
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ! '>='
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
none: false
|
61
|
+
requirements:
|
62
|
+
- - ! '>='
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
65
|
+
requirements: []
|
66
|
+
rubyforge_project:
|
67
|
+
rubygems_version: 1.8.10
|
68
|
+
signing_key:
|
69
|
+
specification_version: 3
|
70
|
+
summary: DineroMail checkout
|
71
|
+
test_files:
|
72
|
+
- spec/checkout_data_spec.rb
|
73
|
+
- spec/client_spec.rb
|
74
|
+
- spec/configuration_spec.rb
|
75
|
+
- spec/spec_helper.rb
|