mollie_ideal 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in mollie_ideal.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2010 Johan van Zonneveld
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,55 @@
1
+ ## Mollie iDeal [![Build Status](https://secure.travis-ci.org/jhnvz/mollie_ideal.png?branch=master)](http://travis-ci.org/jhnvz/mollie_ideal)
2
+
3
+ Wrapper for the mollie ideal api
4
+
5
+ Installation
6
+ ------------
7
+
8
+ 1. Add `gem 'mollie_ideal'` to your Gemfile.
9
+ 1. Run `bundle install`.
10
+
11
+ ## Usage
12
+ ```ruby
13
+ # for production
14
+ client = MollieIdeal::Client.new(:partner_id => your_partner_id)
15
+
16
+ # testmode
17
+ client = MollieIdeal::Client.new(:testmode => true, :partner_id => your_partner_id)
18
+
19
+ # Example of how to get the banklist and populate a selectbox
20
+ @banks = client.banklist
21
+ = select_tag :bank_id, options_for_select(@banks)
22
+
23
+ # How to setup a payment
24
+ response = client.setup_payment(
25
+ :amount => (amount_in_cents).to_i,
26
+ :bank_id => params[:bank_id],
27
+ :returnurl => "http://#{request.env['HTTP_HOST']}/ideal/return",
28
+ :reporturl => "http://#{request.env['HTTP_HOST']}/ideal/report",
29
+ :description => 'your description'
30
+ )
31
+ oder.update_attributes(:transaction_id => response.transaction_id)
32
+ redirect_to response.URL
33
+
34
+ # How to handle report on the report url
35
+ # For safety reasons mollie calls a report url for updating payment status before redirecting back to the application
36
+ order = Order.find_by_transaction_id(params[:transaction_id])
37
+ response = client.check_payment(order.transaction_id)
38
+ order.update_attributes(:payed => response.payed)
39
+
40
+ # When mollie redirects the user back you can check if the payment was succesfull bij finding the order object
41
+ @order = Order.find_by_transaction_id(params[:transaction_id])
42
+ ```
43
+ ## Note on Patches/Pull Requests
44
+
45
+ * Fork the project.
46
+ * Make your feature addition or bug fix.
47
+ * Add tests for it. This is important so I don't break it in a
48
+ future version unintentionally.
49
+ * Commit, do not mess with rakefile, version, or history.
50
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
51
+ * Send me a pull request. Bonus points for topic branches.
52
+
53
+ ## Copyright
54
+
55
+ Copyright (c) 2010 Johan van Zonneveld. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,62 @@
1
+ module MollieIdeal
2
+ class Client
3
+ include HTTParty
4
+ base_uri 'https://secure.mollie.nl/xml/ideal'
5
+
6
+ def initialize(options = {})
7
+ raise ArgumentError.new("No partner_id supplied") if options[:partnerid].nil?
8
+
9
+ @options = options
10
+ end
11
+
12
+ # get banklist
13
+ def banklist
14
+ response = Hashie::Mash.new(self.class.get('',
15
+ :query => merge_options!(:a => 'banklist'),
16
+ :format => :xml
17
+ )).response.bank
18
+
19
+ response.kind_of?(Array) ? response : [response]
20
+ end
21
+
22
+ # setup a payment and get a payment_url to redirect to
23
+ # required keys: :amount, :bank_id, :returnurl, :reporturl
24
+ # optional keys: :profile_key, :description
25
+ def setup_payment(options = {})
26
+ raise ArgumentError.new("Amount should be at least 1,80EUR") if options[:amount] && options[:amount] < 180
27
+
28
+ response = Hashie::Mash.new(self.class.get('',
29
+ :query => merge_options!(options.merge(:a => 'fetch')),
30
+ :format => :xml
31
+ )).response
32
+
33
+ if response.order
34
+ return response.order
35
+ else
36
+ raise MollieException.new(response.item.code, response.item.message, response.item.type)
37
+ end
38
+ end
39
+
40
+ def check_payment(transaction_id)
41
+ response = Hashie::Mash.new(self.class.get('',
42
+ :query => merge_options!(
43
+ :a => 'check',
44
+ :transaction_id => transaction_id
45
+ ),
46
+ :format => :xml
47
+ )).response
48
+
49
+ if response.order
50
+ return response.order
51
+ else
52
+ raise MollieException.new(response.item.code, response.item.message, response.item.type)
53
+ end
54
+ end
55
+
56
+ # merge options in query
57
+ def merge_options!(hash)
58
+ hash.merge!(@options)
59
+ end
60
+
61
+ end
62
+ end
@@ -0,0 +1,13 @@
1
+ module MollieIdeal
2
+ class MollieException < Exception
3
+ attr_accessor :errorcode
4
+ attr_accessor :message
5
+ attr_accessor :type
6
+
7
+ def initialize(errorcode, message, type)
8
+ self.errorcode = errorcode
9
+ self.message = message
10
+ self.type = type
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ module MollieIdeal
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,5 @@
1
+ require 'httparty'
2
+ require 'hashie'
3
+
4
+ require 'mollie_ideal/client'
5
+ require 'mollie_ideal/mollie_exception'
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'mollie_ideal/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "mollie_ideal"
8
+ gem.version = MollieIdeal::VERSION
9
+ gem.authors = ["Johan van Zonneveld"]
10
+ gem.email = ["johan@vzonneveld.nl"]
11
+ gem.homepage = 'https://github.com/jhnvz/mollie_ideal.git'
12
+ gem.summary = %q{wrapper for the mollie ideal api}
13
+ gem.description = %q{A simple Ruby implementation for handeling iDeal transactions with the Mollie API}
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_development_dependency 'rspec'
21
+ gem.add_development_dependency 'webmock'
22
+
23
+ gem.add_dependency 'httparty', '~> 0.8.0'
24
+ gem.add_dependency 'hashie'
25
+ end
@@ -0,0 +1,74 @@
1
+ require 'spec_helper'
2
+
3
+ describe MollieIdeal::Client do
4
+ before(:each) do
5
+ @client = MollieIdeal::Client.new(:partnerid => 855037, :testmode => true)
6
+ end
7
+
8
+ describe 'new' do
9
+ it 'should raise a MollieException if no partnerid supplied' do
10
+ running { MollieIdeal::Client.new({:testmode => true}) }.should raise_error(ArgumentError)
11
+ end
12
+ end
13
+
14
+ describe 'banklist' do
15
+ it 'should return a list of banks' do
16
+ stub_request(:get, "https://secure.mollie.nl/xml/ideal?a=banklist&partnerid=855037&testmode=true").
17
+ to_return(:status => 200, :body => fixture('banklist.xml'), :headers => {})
18
+
19
+ banks = @client.banklist
20
+
21
+ banks.should be_a_kind_of(Array)
22
+ banks.first.bank_id.should eq('0031')
23
+ banks.first.bank_name.should eq('ABN AMRO')
24
+ end
25
+ end
26
+
27
+ describe 'setup_payment' do
28
+ it 'should raise a MollieException if the amount is below 1,80EUR' do
29
+ running { @client.setup_payment(:amount => 179) }.should raise_error(ArgumentError)
30
+ end
31
+
32
+ it 'should raise a MollieException if no or wrong keys supplied' do
33
+ stub_request(:get, "https://secure.mollie.nl/xml/ideal?a=fetch&description=description&partnerid=855037&testmode=true").
34
+ to_return(:status => 200, :body => fixture("setup_payment_error.xml"), :headers => {})
35
+
36
+ running { @client.setup_payment(
37
+ :description => "description"
38
+ ) }.should raise_error(MollieIdeal::MollieException)
39
+ end
40
+
41
+ it 'should return URL and transaction_id' do
42
+ stub_request(:get, "https://secure.mollie.nl/xml/ideal?a=fetch&amount=12300&bank_id=0031&description=description&partnerid=855037&reporturl=http://test.com/ideal/report&returnurl=http://test.com/ideal/return&testmode=true").
43
+ to_return(:status => 200, :body => fixture('setup_payment.xml'), :headers => {})
44
+
45
+ response = @client.setup_payment(
46
+ :amount => 12300,
47
+ :bank_id => '0031',
48
+ :returnurl => "http://test.com/ideal/return",
49
+ :reporturl => "http://test.com/ideal/report",
50
+ :description => "description"
51
+ )
52
+
53
+ response.URL.should eq('https://mijn.postbank.nl/internetbankieren/SesamLoginServlet?sessie=ideal&trxid=003123456789123&random=123456789abcdefgh&testmode=true')
54
+ response.transaction_id.should eq('482d599bbcc7795727650330ad65fe9b')
55
+ end
56
+ end
57
+
58
+ describe 'check_payment' do
59
+ it 'should return a transaction' do
60
+ stub_request(:get, "https://secure.mollie.nl/xml/ideal?a=check&partnerid=855037&testmode=true&transaction_id=482d599bbcc7795727650330ad65fe9b").
61
+ to_return(:status => 200, :body => fixture('check_payment.xml'), :headers => {})
62
+
63
+ response = @client.check_payment('482d599bbcc7795727650330ad65fe9b')
64
+ response.payed.should eq('true')
65
+ end
66
+
67
+ it 'should raise an MollieException if no transaction was found' do
68
+ stub_request(:get, "https://secure.mollie.nl/xml/ideal?a=check&partnerid=855037&testmode=true&transaction_id=noop").
69
+ to_return(:status => 200, :body => fixture('check_payment_error.xml'), :headers => {})
70
+
71
+ running { @client.check_payment('noop') }.should raise_error(MollieIdeal::MollieException)
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,16 @@
1
+ <?xml version="1.0"?>
2
+ <response>
3
+ <bank>
4
+ <bank_id>0031</bank_id>
5
+ <bank_name>ABN AMRO</bank_name>
6
+ </bank>
7
+ <bank>
8
+ <bank_id>0721</bank_id>
9
+ <bank_name>Postbank</bank_name>
10
+ </bank>
11
+ <bank>
12
+ <bank_id>0021</bank_id>
13
+ <bank_name>Rabobank</bank_name>
14
+ </bank>
15
+ <message>This is the current list of banks and their ID's that currently support iDEAL-payments</message>
16
+ </response>
@@ -0,0 +1,15 @@
1
+ <?xml version="1.0"?>
2
+ <response>
3
+ <order>
4
+ <transaction_id>482d599bbcc7795727650330ad65fe9b</transaction_id>
5
+ <amount>123</amount>
6
+ <currency>EUR</currency>
7
+ <payed>true</payed>
8
+ <consumer>
9
+ <consumerName>Hr J Janssen</consumerName>
10
+ <consumerAccount>P001234567</consumerAccount>
11
+ <consumerCity>Amsterdam</consumerCity>
12
+ </consumer>
13
+ <message>This iDEAL-order has successfuly been payed for, and this is the first time you check it.</message>
14
+ </order>
15
+ </response>
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" ?>
2
+ <response>
3
+ <item type="error">
4
+ <errorcode>-10</errorcode>
5
+ <message>This is an unknown order.</message>
6
+ </item>
7
+ </response>
@@ -0,0 +1,10 @@
1
+ <?xml version="1.0"?>
2
+ <response>
3
+ <order>
4
+ <transaction_id>482d599bbcc7795727650330ad65fe9b</transaction_id>
5
+ <amount>123</amount>
6
+ <currency>EUR</currency>
7
+ <URL><![CDATA[https://mijn.postbank.nl/internetbankieren/SesamLoginServlet?sessie=ideal&trxid=003123456789123&random=123456789abcdefgh&testmode=true]]></URL>
8
+ <message>Your iDEAL-payment has succesfuly been setup. Your customer should visit the given URL to make the payment</message>
9
+ </order>
10
+ </response>
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" ?>
2
+ <response>
3
+ <item type="error">
4
+ <errorcode>-3</errorcode>
5
+ <message>A fetch was issued without (proper) specification of 'reporturl'</message>
6
+ </item>
7
+ </response>
@@ -0,0 +1,9 @@
1
+ require 'webmock/rspec'
2
+ require 'mollie_ideal'
3
+ require 'support'
4
+
5
+ alias :running :lambda
6
+
7
+ RSpec.configure do |config|
8
+ config.include SpecHelpers
9
+ end
data/spec/support.rb ADDED
@@ -0,0 +1,5 @@
1
+ module SpecHelpers
2
+ def fixture(name)
3
+ File.read(File.expand_path(File.join('..', 'fixtures', name), __FILE__))
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,136 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mollie_ideal
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Johan van Zonneveld
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-12-13 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: !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: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: webmock
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: httparty
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 0.8.0
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 0.8.0
62
+ - !ruby/object:Gem::Dependency
63
+ name: hashie
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ description: A simple Ruby implementation for handeling iDeal transactions with the
79
+ Mollie API
80
+ email:
81
+ - johan@vzonneveld.nl
82
+ executables: []
83
+ extensions: []
84
+ extra_rdoc_files: []
85
+ files:
86
+ - .gitignore
87
+ - Gemfile
88
+ - LICENSE.txt
89
+ - README.md
90
+ - Rakefile
91
+ - lib/mollie_ideal.rb
92
+ - lib/mollie_ideal/client.rb
93
+ - lib/mollie_ideal/mollie_exception.rb
94
+ - lib/mollie_ideal/version.rb
95
+ - mollie_ideal.gemspec
96
+ - spec/client_spec.rb
97
+ - spec/fixtures/banklist.xml
98
+ - spec/fixtures/check_payment.xml
99
+ - spec/fixtures/check_payment_error.xml
100
+ - spec/fixtures/setup_payment.xml
101
+ - spec/fixtures/setup_payment_error.xml
102
+ - spec/spec_helper.rb
103
+ - spec/support.rb
104
+ homepage: https://github.com/jhnvz/mollie_ideal.git
105
+ licenses: []
106
+ post_install_message:
107
+ rdoc_options: []
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ none: false
112
+ requirements:
113
+ - - ! '>='
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ none: false
118
+ requirements:
119
+ - - ! '>='
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ requirements: []
123
+ rubyforge_project:
124
+ rubygems_version: 1.8.24
125
+ signing_key:
126
+ specification_version: 3
127
+ summary: wrapper for the mollie ideal api
128
+ test_files:
129
+ - spec/client_spec.rb
130
+ - spec/fixtures/banklist.xml
131
+ - spec/fixtures/check_payment.xml
132
+ - spec/fixtures/check_payment_error.xml
133
+ - spec/fixtures/setup_payment.xml
134
+ - spec/fixtures/setup_payment_error.xml
135
+ - spec/spec_helper.rb
136
+ - spec/support.rb