paymill 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -0
- data/.rspec +1 -0
- data/Gemfile +5 -0
- data/LICENSE +23 -0
- data/README.md +51 -0
- data/Rakefile +8 -0
- data/lib/data/paymill.crt +25 -0
- data/lib/paymill.rb +64 -0
- data/lib/paymill/client.rb +16 -0
- data/lib/paymill/credit_card.rb +13 -0
- data/lib/paymill/offer.rb +15 -0
- data/lib/paymill/operations/create.rb +16 -0
- data/lib/paymill/operations/find.rb +16 -0
- data/lib/paymill/subscription.rb +16 -0
- data/lib/paymill/transaction.rb +16 -0
- data/lib/paymill/version.rb +3 -0
- data/paymill.gemspec +21 -0
- data/spec/paymill/client_spec.rb +32 -0
- data/spec/paymill/credit_card_spec.rb +29 -0
- data/spec/paymill/offer_spec.rb +39 -0
- data/spec/paymill/subscription_spec.rb +47 -0
- data/spec/paymill/transaction_spec.rb +47 -0
- data/spec/paymill_spec.rb +11 -0
- data/spec/spec_helper.rb +8 -0
- metadata +99 -0
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--colour
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
(The MIT License)
|
2
|
+
|
3
|
+
Copyright (c) 2012 Stefan Sprenger
|
4
|
+
Copyright (c) 2012 dkd Internet Service GmbH
|
5
|
+
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
7
|
+
a copy of this software and associated documentation files (the
|
8
|
+
"Software"), to deal in the Software without restriction, including
|
9
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
10
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
11
|
+
permit persons to whom the Software is furnished to do so, subject to
|
12
|
+
the following conditions:
|
13
|
+
|
14
|
+
The above copyright notice and this permission notice shall be
|
15
|
+
included in all copies or substantial portions of the Software.
|
16
|
+
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
18
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
19
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
20
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
21
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
22
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
23
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
Paymill
|
2
|
+
======
|
3
|
+
|
4
|
+
This is a Ruby wrapper for Paymill's API.
|
5
|
+
|
6
|
+
Usage
|
7
|
+
======
|
8
|
+
|
9
|
+
First, you've to install the gem
|
10
|
+
|
11
|
+
gem install paymill
|
12
|
+
|
13
|
+
and require it
|
14
|
+
|
15
|
+
require "paymill"
|
16
|
+
|
17
|
+
Then you have to set your API key:
|
18
|
+
|
19
|
+
Paymill.api_key = "your-api-key"
|
20
|
+
|
21
|
+
Now you can e.g. create a new client:
|
22
|
+
|
23
|
+
Paymill::Client.create(email: "stefan.sprenger@dkd.de", description: "He is a Ruby guy.")
|
24
|
+
|
25
|
+
We currently only support `create` and `find` operations.
|
26
|
+
|
27
|
+
Requirements
|
28
|
+
=====
|
29
|
+
|
30
|
+
This gem was developed using Ruby 1.9 and version 1 of Paymill's API. Nonetheless, it should also work with Ruby 1.8.
|
31
|
+
|
32
|
+
Bugs
|
33
|
+
======
|
34
|
+
|
35
|
+
Please report bugs at http://github.com/dkd/paymill-ruby/issues.
|
36
|
+
|
37
|
+
Note on Patches/Pull Requests
|
38
|
+
======
|
39
|
+
|
40
|
+
* Fork the project from http://github.com/dkd/paymill-ruby.
|
41
|
+
* Make your feature addition or bug fix.
|
42
|
+
* Add tests for it. This is important so I don't break it in a
|
43
|
+
future version unintentionally.
|
44
|
+
* Commit, do not mess with rakefile, version, or history.
|
45
|
+
(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)
|
46
|
+
* Send me a pull request. Bonus points for topic branches.
|
47
|
+
|
48
|
+
Copyright
|
49
|
+
======
|
50
|
+
|
51
|
+
Copyright (c) 2012 dkd Internet Service GmbH, Stefan Sprenger. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
-----BEGIN CERTIFICATE-----
|
2
|
+
MIIENjCCAx6gAwIBAgIBATANBgkqhkiG9w0BAQUFADBvMQswCQYDVQQGEwJTRTEU
|
3
|
+
MBIGA1UEChMLQWRkVHJ1c3QgQUIxJjAkBgNVBAsTHUFkZFRydXN0IEV4dGVybmFs
|
4
|
+
IFRUUCBOZXR3b3JrMSIwIAYDVQQDExlBZGRUcnVzdCBFeHRlcm5hbCBDQSBSb290
|
5
|
+
MB4XDTAwMDUzMDEwNDgzOFoXDTIwMDUzMDEwNDgzOFowbzELMAkGA1UEBhMCU0Ux
|
6
|
+
FDASBgNVBAoTC0FkZFRydXN0IEFCMSYwJAYDVQQLEx1BZGRUcnVzdCBFeHRlcm5h
|
7
|
+
bCBUVFAgTmV0d29yazEiMCAGA1UEAxMZQWRkVHJ1c3QgRXh0ZXJuYWwgQ0EgUm9v
|
8
|
+
dDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALf3GjPm8gAELTngTlvt
|
9
|
+
H7xsD821+iO2zt6bETOXpClMfZOfvUq8k+0DGuOPz+VtUFrWlymUWoCwSXrbLpX9
|
10
|
+
uMq/NzgtHj6RQa1wVsfwTz/oMp50ysiQVOnGXw94nZpAPA6sYapeFI+eh6FqUNzX
|
11
|
+
mk6vBbOmcZSccbNQYArHE504B4YCqOmoaSYYkKtMsE8jqzpPhNjfzp/haW+710LX
|
12
|
+
a0Tkx63ubUFfclpxCDezeWWkWaCUN/cALw3CknLa0Dhy2xSoRcRdKn23tNbE7qzN
|
13
|
+
E0S3ySvdQwAl+mG5aWpYIxG3pzOPVnVZ9c0p10a3CitlttNCbxWyuHv77+ldU9U0
|
14
|
+
WicCAwEAAaOB3DCB2TAdBgNVHQ4EFgQUrb2YejS0Jvf6xCZU7wO94CTLVBowCwYD
|
15
|
+
VR0PBAQDAgEGMA8GA1UdEwEB/wQFMAMBAf8wgZkGA1UdIwSBkTCBjoAUrb2YejS0
|
16
|
+
Jvf6xCZU7wO94CTLVBqhc6RxMG8xCzAJBgNVBAYTAlNFMRQwEgYDVQQKEwtBZGRU
|
17
|
+
cnVzdCBBQjEmMCQGA1UECxMdQWRkVHJ1c3QgRXh0ZXJuYWwgVFRQIE5ldHdvcmsx
|
18
|
+
IjAgBgNVBAMTGUFkZFRydXN0IEV4dGVybmFsIENBIFJvb3SCAQEwDQYJKoZIhvcN
|
19
|
+
AQEFBQADggEBALCb4IUlwtYj4g+WBpKdQZic2YR5gdkeWxQHIzZlj7DYd7usQWxH
|
20
|
+
YINRsPkyPef89iYTx4AWpb9a/IfPeHmJIZriTAcKhjW88t5RxNKWt9x+Tu5w/Rw5
|
21
|
+
6wwCURQtjr0W4MHfRnXnJK3s9EK0hZNwEGe6nQY1ShjTK3rMUUKhemPR5ruhxSvC
|
22
|
+
Nr4TDea9Y355e6cJDUCrat2PisP29owaQgVR1EX1n6diIWgVIEM8med8vSTYqZEX
|
23
|
+
c4g/VhsxOBi0cQ+azcgOno4uG+GMmIPLHzHxREzGBHNJdmAPx/i9F4BrLunMTA5a
|
24
|
+
mnkPIAou1Z5jJh5VkpTYghdae9C8x49OhgQ=
|
25
|
+
-----END CERTIFICATE-----
|
data/lib/paymill.rb
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
require "net/http"
|
2
|
+
require "net/https"
|
3
|
+
require "json"
|
4
|
+
require "paymill/version"
|
5
|
+
|
6
|
+
module Paymill
|
7
|
+
API_BASE = "api.paymill.de"
|
8
|
+
|
9
|
+
@@api_key = nil
|
10
|
+
|
11
|
+
autoload :Client, "paymill/client"
|
12
|
+
autoload :CreditCard, "paymill/credit_card"
|
13
|
+
autoload :Offer, "paymill/offer"
|
14
|
+
autoload :Subscription, "paymill/subscription"
|
15
|
+
autoload :Transaction, "paymill/transaction"
|
16
|
+
|
17
|
+
module Operations
|
18
|
+
autoload :Create, "paymill/operations/create"
|
19
|
+
autoload :Find, "paymill/operations/find"
|
20
|
+
end
|
21
|
+
|
22
|
+
class PaymillError < StandardError
|
23
|
+
end
|
24
|
+
|
25
|
+
class AuthenticationError < PaymillError; end
|
26
|
+
class APIError < PaymillError; end
|
27
|
+
|
28
|
+
class << self
|
29
|
+
def api_key
|
30
|
+
@@api_key
|
31
|
+
end
|
32
|
+
|
33
|
+
def api_key=(api_key)
|
34
|
+
@@api_key = api_key
|
35
|
+
end
|
36
|
+
|
37
|
+
def request(http_method, api_url, data, path="")
|
38
|
+
raise AuthenticationError if api_key.nil?
|
39
|
+
|
40
|
+
https = Net::HTTP.new(API_BASE, Net::HTTP.https_default_port)
|
41
|
+
https.use_ssl = true
|
42
|
+
https.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
43
|
+
https.ca_file = File.join(File.dirname(__FILE__), "data/paymill.crt")
|
44
|
+
https.start do |connection|
|
45
|
+
url = case http_method
|
46
|
+
when :post
|
47
|
+
Net::HTTP::Post.new("/v1/#{api_url}#{path}")
|
48
|
+
else
|
49
|
+
Net::HTTP::Get.new("/v1/#{api_url}#{path}")
|
50
|
+
end
|
51
|
+
url.basic_auth(api_key,"")
|
52
|
+
url.set_form_data(data) if http_method == :post
|
53
|
+
@response = https.request(url)
|
54
|
+
end
|
55
|
+
raise AuthenticationError if @response.code.to_i == 401
|
56
|
+
raise APIError if @response.code.to_i >= 500
|
57
|
+
|
58
|
+
data = JSON.parse(@response.body)
|
59
|
+
raise APIError.new(data["error"]) if data["error"]
|
60
|
+
|
61
|
+
data
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Paymill
|
2
|
+
class Client
|
3
|
+
include Paymill::Operations::Create
|
4
|
+
include Paymill::Operations::Find
|
5
|
+
|
6
|
+
attr_accessor :id, :email, :description, :attributes, :created_at,
|
7
|
+
:updated_at, :creditcard, :subscription
|
8
|
+
|
9
|
+
def initialize(attributes = {})
|
10
|
+
attributes.each_pair do |key, value|
|
11
|
+
instance_variable_set("@#{key}", value)
|
12
|
+
end
|
13
|
+
@attributes = attributes
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Paymill
|
2
|
+
class CreditCard
|
3
|
+
attr_accessor :id, :card_type, :country, :expire_month, :expire_year,
|
4
|
+
:card_holder, :last4, :created_at, :updated_at
|
5
|
+
|
6
|
+
def initialize(attributes = {})
|
7
|
+
attributes.each_pair do |key, value|
|
8
|
+
instance_variable_set("@#{key}", value)
|
9
|
+
end
|
10
|
+
@attributes = attributes
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Paymill
|
2
|
+
class Offer
|
3
|
+
include Paymill::Operations::Create
|
4
|
+
include Paymill::Operations::Find
|
5
|
+
|
6
|
+
attr_accessor :id, :name, :amount, :interval, :trial_period_days, :currency
|
7
|
+
|
8
|
+
def initialize(attributes = {})
|
9
|
+
attributes.each_pair do |key, value|
|
10
|
+
instance_variable_set("@#{key}", value)
|
11
|
+
end
|
12
|
+
@attributes = attributes
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Paymill
|
2
|
+
module Operations
|
3
|
+
module Create
|
4
|
+
module ClassMethods
|
5
|
+
def create(attributes)
|
6
|
+
response = Paymill.request(:post, "#{self.name.split("::").last.downcase}s", attributes)
|
7
|
+
self.new(response["data"])
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.included(base)
|
12
|
+
base.extend(ClassMethods)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Paymill
|
2
|
+
module Operations
|
3
|
+
module Find
|
4
|
+
module ClassMethods
|
5
|
+
def find(id)
|
6
|
+
response = Paymill.request(:get, "#{self.name.split("::").last.downcase}s", {}, "/#{id}")
|
7
|
+
self.new(response["data"])
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.included(base)
|
12
|
+
base.extend(ClassMethods)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Paymill
|
2
|
+
class Subscription
|
3
|
+
include Paymill::Operations::Create
|
4
|
+
include Paymill::Operations::Find
|
5
|
+
|
6
|
+
attr_accessor :id, :plan, :livemode, :cancel_at_period_end, :created_at, :updated_at,
|
7
|
+
:canceled_at, :client
|
8
|
+
|
9
|
+
def initialize(attributes = {})
|
10
|
+
attributes.each_pair do |key, value|
|
11
|
+
instance_variable_set("@#{key}", value)
|
12
|
+
end
|
13
|
+
@attributes = attributes
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Paymill
|
2
|
+
class Transaction
|
3
|
+
include Paymill::Operations::Create
|
4
|
+
include Paymill::Operations::Find
|
5
|
+
|
6
|
+
attr_accessor :id, :amount, :status, :description, :livemode,
|
7
|
+
:creditcard, :client, :created_at, :updated_at
|
8
|
+
|
9
|
+
def initialize(attributes = {})
|
10
|
+
attributes.each_pair do |key, value|
|
11
|
+
instance_variable_set("@#{key}", value)
|
12
|
+
end
|
13
|
+
@attributes = attributes
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/paymill.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "paymill/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "paymill"
|
7
|
+
s.version = Paymill::VERSION
|
8
|
+
s.authors = ["Stefan Sprenger"]
|
9
|
+
s.email = ["stefan.sprenger@dkd.de"]
|
10
|
+
s.homepage = "https://github.com/dkd/paymill-ruby"
|
11
|
+
s.summary = %q{API wrapper for Paymill.}
|
12
|
+
s.description = %q{API wrapper for Paymill.}
|
13
|
+
|
14
|
+
s.files = `git ls-files`.split("\n")
|
15
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
17
|
+
s.require_paths = ["lib"]
|
18
|
+
|
19
|
+
s.add_dependency "json"
|
20
|
+
s.add_development_dependency "rspec"
|
21
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Paymill::Client do
|
4
|
+
let(:valid_attributes) do
|
5
|
+
{ email: "stefan.sprenger@dkd.de", description: "First customer." }
|
6
|
+
end
|
7
|
+
|
8
|
+
let (:client) do
|
9
|
+
Paymill::Client.new(valid_attributes)
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "#initialize" do
|
13
|
+
it "initializes all attributes correctly" do
|
14
|
+
client.email.should eql("stefan.sprenger@dkd.de")
|
15
|
+
client.description.should eql("First customer.")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe ".find" do
|
20
|
+
it "makes a new GET request using the correct API endpoint" do
|
21
|
+
Paymill.should_receive(:request).with(:get, "clients", {}, "/123").and_return("data" => {})
|
22
|
+
Paymill::Client.find("123")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe ".create" do
|
27
|
+
it "makes a new POST request using the correct API endpoint" do
|
28
|
+
Paymill.should_receive(:request).with(:post, "clients", valid_attributes).and_return("data" => {})
|
29
|
+
Paymill::Client.create(valid_attributes)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Paymill::CreditCard do
|
4
|
+
let(:valid_attributes) do
|
5
|
+
{
|
6
|
+
card_type: "visa",
|
7
|
+
country: "germany",
|
8
|
+
expire_month: 12,
|
9
|
+
expire_year: 2012,
|
10
|
+
card_holder: "Stefan Sprenger",
|
11
|
+
last4: "1111"
|
12
|
+
}
|
13
|
+
end
|
14
|
+
|
15
|
+
let (:credit_card) do
|
16
|
+
Paymill::CreditCard.new(valid_attributes)
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "#initialize" do
|
20
|
+
it "initializes all attributes correctly" do
|
21
|
+
credit_card.card_type.should eql("visa")
|
22
|
+
credit_card.country.should eql("germany")
|
23
|
+
credit_card.expire_month.should eql(12)
|
24
|
+
credit_card.expire_year.should eq(2012)
|
25
|
+
credit_card.card_holder.should eql("Stefan Sprenger")
|
26
|
+
credit_card.last4.should eql("1111")
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Paymill::Offer do
|
4
|
+
let(:valid_attributes) do
|
5
|
+
{
|
6
|
+
amount: 4200,
|
7
|
+
currency: "eur",
|
8
|
+
interval: "month",
|
9
|
+
name: "Medium Plan"
|
10
|
+
}
|
11
|
+
end
|
12
|
+
|
13
|
+
let (:offer) do
|
14
|
+
Paymill::Offer.new(valid_attributes)
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "#initialize" do
|
18
|
+
it "initializes all attributes correctly" do
|
19
|
+
offer.amount.should eql(4200)
|
20
|
+
offer.currency.should eql("eur")
|
21
|
+
offer.interval.should eql("month")
|
22
|
+
offer.name.should eql("Medium Plan")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe ".find" do
|
27
|
+
it "makes a new GET request using the correct API endpoint" do
|
28
|
+
Paymill.should_receive(:request).with(:get, "offers", {}, "/123").and_return("data" => {})
|
29
|
+
Paymill::Offer.find("123")
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe ".create" do
|
34
|
+
it "makes a new POST request using the correct API endpoint" do
|
35
|
+
Paymill.should_receive(:request).with(:post, "offers", valid_attributes).and_return("data" => {})
|
36
|
+
Paymill::Offer.create(valid_attributes)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Paymill::Subscription do
|
4
|
+
let(:valid_attributes) do
|
5
|
+
{
|
6
|
+
plan: {
|
7
|
+
name: "Nerd special",
|
8
|
+
amount: 123,
|
9
|
+
interval: "week"
|
10
|
+
},
|
11
|
+
livemode: false,
|
12
|
+
cancel_at_period_end: false,
|
13
|
+
client: {
|
14
|
+
email: "stefan.sprenger@dkd.de"
|
15
|
+
}
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
let (:subscription) do
|
20
|
+
Paymill::Subscription.new(valid_attributes)
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "#initialize" do
|
24
|
+
it "initializes all attributes correctly" do
|
25
|
+
subscription.plan[:name].should eql("Nerd special")
|
26
|
+
subscription.plan[:amount].should eql(123)
|
27
|
+
subscription.plan[:interval].should eql("week")
|
28
|
+
subscription.livemode.should be_false
|
29
|
+
subscription.cancel_at_period_end.should be_false
|
30
|
+
subscription.client[:email].should eql("stefan.sprenger@dkd.de")
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe ".find" do
|
35
|
+
it "makes a new GET request using the correct API endpoint" do
|
36
|
+
Paymill.should_receive(:request).with(:get, "subscriptions", {}, "/123").and_return("data" => {})
|
37
|
+
Paymill::Subscription.find("123")
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe ".create" do
|
42
|
+
it "makes a new POST request using the correct API endpoint" do
|
43
|
+
Paymill.should_receive(:request).with(:post, "subscriptions", valid_attributes).and_return("data" => {})
|
44
|
+
Paymill::Subscription.create(valid_attributes)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Paymill::Transaction do
|
4
|
+
let(:valid_attributes) do
|
5
|
+
{
|
6
|
+
amount: 4200,
|
7
|
+
status: "pending",
|
8
|
+
description: "Test transaction.",
|
9
|
+
livemode: false,
|
10
|
+
creditcard: {
|
11
|
+
card_type: "visa",
|
12
|
+
country: "germany"
|
13
|
+
},
|
14
|
+
client: "client_a013c"
|
15
|
+
}
|
16
|
+
end
|
17
|
+
|
18
|
+
let (:transaction) do
|
19
|
+
Paymill::Transaction.new(valid_attributes)
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "#initialize" do
|
23
|
+
it "initializes all attributes correctly" do
|
24
|
+
transaction.amount.should eql(4200)
|
25
|
+
transaction.status.should eql("pending")
|
26
|
+
transaction.description.should eql("Test transaction.")
|
27
|
+
transaction.livemode.should eql(false)
|
28
|
+
transaction.creditcard[:card_type].should eql("visa")
|
29
|
+
transaction.creditcard[:country].should eql("germany")
|
30
|
+
transaction.client.should eql("client_a013c")
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe ".find" do
|
35
|
+
it "makes a new GET request using the correct API endpoint" do
|
36
|
+
Paymill.should_receive(:request).with(:get, "transactions", {}, "/123").and_return("data" => {})
|
37
|
+
Paymill::Transaction.find("123")
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe ".create" do
|
42
|
+
it "makes a new POST request using the correct API endpoint" do
|
43
|
+
Paymill.should_receive(:request).with(:post, "transactions", valid_attributes).and_return("data" => {})
|
44
|
+
Paymill::Transaction.create(valid_attributes)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Paymill do
|
4
|
+
describe ".request" do
|
5
|
+
context "given no api key exists" do
|
6
|
+
it "raises an authentication error" do
|
7
|
+
expect { Paymill.request(:get, "clients", {}) }.to raise_error(Paymill::AuthenticationError)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: paymill
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Stefan Sprenger
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-08-16 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: json
|
16
|
+
requirement: &2152735480 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *2152735480
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rspec
|
27
|
+
requirement: &2152745780 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *2152745780
|
36
|
+
description: API wrapper for Paymill.
|
37
|
+
email:
|
38
|
+
- stefan.sprenger@dkd.de
|
39
|
+
executables: []
|
40
|
+
extensions: []
|
41
|
+
extra_rdoc_files: []
|
42
|
+
files:
|
43
|
+
- .gitignore
|
44
|
+
- .rspec
|
45
|
+
- Gemfile
|
46
|
+
- LICENSE
|
47
|
+
- README.md
|
48
|
+
- Rakefile
|
49
|
+
- lib/data/paymill.crt
|
50
|
+
- lib/paymill.rb
|
51
|
+
- lib/paymill/client.rb
|
52
|
+
- lib/paymill/credit_card.rb
|
53
|
+
- lib/paymill/offer.rb
|
54
|
+
- lib/paymill/operations/create.rb
|
55
|
+
- lib/paymill/operations/find.rb
|
56
|
+
- lib/paymill/subscription.rb
|
57
|
+
- lib/paymill/transaction.rb
|
58
|
+
- lib/paymill/version.rb
|
59
|
+
- paymill.gemspec
|
60
|
+
- spec/paymill/client_spec.rb
|
61
|
+
- spec/paymill/credit_card_spec.rb
|
62
|
+
- spec/paymill/offer_spec.rb
|
63
|
+
- spec/paymill/subscription_spec.rb
|
64
|
+
- spec/paymill/transaction_spec.rb
|
65
|
+
- spec/paymill_spec.rb
|
66
|
+
- spec/spec_helper.rb
|
67
|
+
homepage: https://github.com/dkd/paymill-ruby
|
68
|
+
licenses: []
|
69
|
+
post_install_message:
|
70
|
+
rdoc_options: []
|
71
|
+
require_paths:
|
72
|
+
- lib
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ! '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
+
none: false
|
81
|
+
requirements:
|
82
|
+
- - ! '>='
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
requirements: []
|
86
|
+
rubyforge_project:
|
87
|
+
rubygems_version: 1.8.10
|
88
|
+
signing_key:
|
89
|
+
specification_version: 3
|
90
|
+
summary: API wrapper for Paymill.
|
91
|
+
test_files:
|
92
|
+
- spec/paymill/client_spec.rb
|
93
|
+
- spec/paymill/credit_card_spec.rb
|
94
|
+
- spec/paymill/offer_spec.rb
|
95
|
+
- spec/paymill/subscription_spec.rb
|
96
|
+
- spec/paymill/transaction_spec.rb
|
97
|
+
- spec/paymill_spec.rb
|
98
|
+
- spec/spec_helper.rb
|
99
|
+
has_rdoc:
|