paymill 0.1.0 → 0.2.0
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/README.md +14 -4
- data/lib/paymill.rb +11 -7
- data/lib/paymill/base.rb +17 -0
- data/lib/paymill/client.rb +2 -10
- data/lib/paymill/offer.rb +2 -10
- data/lib/paymill/operations/all.rb +1 -1
- data/lib/paymill/operations/update.rb +10 -0
- data/lib/paymill/payment.rb +1 -11
- data/lib/paymill/subscription.rb +3 -11
- data/lib/paymill/transaction.rb +2 -12
- data/lib/paymill/version.rb +1 -1
- data/spec/paymill/client_spec.rb +17 -0
- data/spec/paymill/offer_spec.rb +19 -2
- data/spec/paymill/subscription_spec.rb +24 -3
- data/spec/paymill/transaction_spec.rb +2 -0
- metadata +11 -19
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Paymill ](https://travis-ci.org/dkd/paymill-ruby)
|
2
2
|
======
|
3
3
|
|
4
4
|
This is a Ruby wrapper for Paymill's API.
|
@@ -22,21 +22,31 @@ Now you can e.g. create a new client:
|
|
22
22
|
|
23
23
|
Paymill::Client.create(email: "stefan.sprenger@dkd.de", description: "He is a Ruby guy.")
|
24
24
|
|
25
|
-
Or find
|
25
|
+
Or find an existing client:
|
26
26
|
|
27
27
|
Paymill::Client.find("client_88a388d9dd48f86c3136")
|
28
28
|
|
29
|
+
Updating an existing client only works on an instance:
|
30
|
+
|
31
|
+
client = Paymill::Client.find("client_88a388d9dd48f86c3136")
|
32
|
+
client.update_attributes(email: "carl.client@example.com")
|
33
|
+
|
34
|
+
Deleting a client:
|
35
|
+
|
36
|
+
Paymill::Client.delete("client_88a388d9dd48f86c3136")
|
37
|
+
|
38
|
+
|
29
39
|
For retrieving a collection of all clients you might use the `all`
|
30
40
|
operation:
|
31
41
|
|
32
42
|
Paymill::Client.all
|
33
43
|
|
34
|
-
|
44
|
+
Please note that Transactions and Payments cannot be updated.
|
35
45
|
|
36
46
|
Requirements
|
37
47
|
=====
|
38
48
|
|
39
|
-
This gem
|
49
|
+
This gem requires Ruby 1.9 and faces version 2 of Paymill's API.
|
40
50
|
|
41
51
|
Bugs
|
42
52
|
======
|
data/lib/paymill.rb
CHANGED
@@ -9,6 +9,7 @@ module Paymill
|
|
9
9
|
|
10
10
|
@@api_key = nil
|
11
11
|
|
12
|
+
autoload :Base, "paymill/base"
|
12
13
|
autoload :Client, "paymill/client"
|
13
14
|
autoload :Offer, "paymill/offer"
|
14
15
|
autoload :Payment, "paymill/payment"
|
@@ -18,8 +19,9 @@ module Paymill
|
|
18
19
|
module Operations
|
19
20
|
autoload :All, "paymill/operations/all"
|
20
21
|
autoload :Create, "paymill/operations/create"
|
21
|
-
autoload :Delete, "paymill/operations/delete"
|
22
22
|
autoload :Find, "paymill/operations/find"
|
23
|
+
autoload :Update, "paymill/operations/update"
|
24
|
+
autoload :Delete, "paymill/operations/delete"
|
23
25
|
end
|
24
26
|
|
25
27
|
class PaymillError < StandardError
|
@@ -40,22 +42,24 @@ module Paymill
|
|
40
42
|
def request(http_method, api_url, data)
|
41
43
|
raise AuthenticationError if api_key.nil?
|
42
44
|
|
43
|
-
https
|
44
|
-
https.use_ssl
|
45
|
-
https.verify_mode
|
46
|
-
https.ca_file
|
45
|
+
https = Net::HTTP.new(API_BASE, Net::HTTP.https_default_port)
|
46
|
+
https.use_ssl = true
|
47
|
+
https.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
48
|
+
https.ca_file = File.join(File.dirname(__FILE__), "data/paymill.crt")
|
47
49
|
https.start do |connection|
|
48
50
|
url = "/#{API_VERSION}/#{api_url}"
|
49
51
|
https_request = case http_method
|
50
52
|
when :post
|
51
53
|
Net::HTTP::Post.new(url)
|
54
|
+
when :put
|
55
|
+
Net::HTTP::Put.new(url)
|
52
56
|
when :delete
|
53
57
|
Net::HTTP::Delete.new(url)
|
54
58
|
else
|
55
59
|
Net::HTTP::Get.new(url)
|
56
60
|
end
|
57
|
-
https_request.basic_auth(api_key,"")
|
58
|
-
https_request.set_form_data(data) if
|
61
|
+
https_request.basic_auth(api_key, "")
|
62
|
+
https_request.set_form_data(data) if [:post, :put].include? http_method
|
59
63
|
@response = https.request(https_request)
|
60
64
|
end
|
61
65
|
raise AuthenticationError if @response.code.to_i == 401
|
data/lib/paymill/base.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
module Paymill
|
2
|
+
class Base
|
3
|
+
include Paymill::Operations::All
|
4
|
+
include Paymill::Operations::Create
|
5
|
+
include Paymill::Operations::Find
|
6
|
+
|
7
|
+
def initialize(attributes = {})
|
8
|
+
set_attributes(attributes)
|
9
|
+
end
|
10
|
+
|
11
|
+
def set_attributes(attributes)
|
12
|
+
attributes.each_pair do |key, value|
|
13
|
+
instance_variable_set("@#{key}", value)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/paymill/client.rb
CHANGED
@@ -1,17 +1,9 @@
|
|
1
1
|
module Paymill
|
2
|
-
class Client
|
3
|
-
include Paymill::Operations::All
|
4
|
-
include Paymill::Operations::Create
|
2
|
+
class Client < Base
|
5
3
|
include Paymill::Operations::Delete
|
6
|
-
include Paymill::Operations::
|
4
|
+
include Paymill::Operations::Update
|
7
5
|
|
8
6
|
attr_accessor :id, :email, :description, :attributes, :created_at,
|
9
7
|
:updated_at, :payment, :subscription
|
10
|
-
|
11
|
-
def initialize(attributes = {})
|
12
|
-
attributes.each_pair do |key, value|
|
13
|
-
instance_variable_set("@#{key}", value)
|
14
|
-
end
|
15
|
-
end
|
16
8
|
end
|
17
9
|
end
|
data/lib/paymill/offer.rb
CHANGED
@@ -1,16 +1,8 @@
|
|
1
1
|
module Paymill
|
2
|
-
class Offer
|
3
|
-
include Paymill::Operations::All
|
4
|
-
include Paymill::Operations::Create
|
2
|
+
class Offer < Base
|
5
3
|
include Paymill::Operations::Delete
|
6
|
-
include Paymill::Operations::
|
4
|
+
include Paymill::Operations::Update
|
7
5
|
|
8
6
|
attr_accessor :id, :name, :amount, :interval, :trial_period_days, :currency
|
9
|
-
|
10
|
-
def initialize(attributes = {})
|
11
|
-
attributes.each_pair do |key, value|
|
12
|
-
instance_variable_set("@#{key}", value)
|
13
|
-
end
|
14
|
-
end
|
15
7
|
end
|
16
8
|
end
|
data/lib/paymill/payment.rb
CHANGED
@@ -1,16 +1,6 @@
|
|
1
1
|
module Paymill
|
2
|
-
class Payment
|
3
|
-
include Paymill::Operations::All
|
4
|
-
include Paymill::Operations::Create
|
5
|
-
include Paymill::Operations::Find
|
6
|
-
|
2
|
+
class Payment < Base
|
7
3
|
attr_accessor :id, :card_type, :country, :expire_month, :expire_year,
|
8
4
|
:card_holder, :last4, :created_at, :updated_at
|
9
|
-
|
10
|
-
def initialize(attributes = {})
|
11
|
-
attributes.each_pair do |key, value|
|
12
|
-
instance_variable_set("@#{key}", value)
|
13
|
-
end
|
14
|
-
end
|
15
5
|
end
|
16
6
|
end
|
data/lib/paymill/subscription.rb
CHANGED
@@ -1,17 +1,9 @@
|
|
1
1
|
module Paymill
|
2
|
-
class Subscription
|
3
|
-
include Paymill::Operations::All
|
4
|
-
include Paymill::Operations::Create
|
2
|
+
class Subscription < Base
|
5
3
|
include Paymill::Operations::Delete
|
6
|
-
include Paymill::Operations::
|
4
|
+
include Paymill::Operations::Update
|
7
5
|
|
8
6
|
attr_accessor :id, :plan, :livemode, :cancel_at_period_end, :created_at, :updated_at,
|
9
|
-
:canceled_at, :client
|
10
|
-
|
11
|
-
def initialize(attributes = {})
|
12
|
-
attributes.each_pair do |key, value|
|
13
|
-
instance_variable_set("@#{key}", value)
|
14
|
-
end
|
15
|
-
end
|
7
|
+
:canceled_at, :client, :trial_start, :trial_end
|
16
8
|
end
|
17
9
|
end
|
data/lib/paymill/transaction.rb
CHANGED
@@ -1,16 +1,6 @@
|
|
1
1
|
module Paymill
|
2
|
-
class Transaction
|
3
|
-
include Paymill::Operations::All
|
4
|
-
include Paymill::Operations::Create
|
5
|
-
include Paymill::Operations::Find
|
6
|
-
|
2
|
+
class Transaction < Base
|
7
3
|
attr_accessor :id, :amount, :status, :description, :livemode,
|
8
|
-
:payment, :client, :created_at, :updated_at
|
9
|
-
|
10
|
-
def initialize(attributes = {})
|
11
|
-
attributes.each_pair do |key, value|
|
12
|
-
instance_variable_set("@#{key}", value)
|
13
|
-
end
|
14
|
-
end
|
4
|
+
:payment, :currency, :client, :created_at, :updated_at
|
15
5
|
end
|
16
6
|
end
|
data/lib/paymill/version.rb
CHANGED
data/spec/paymill/client_spec.rb
CHANGED
@@ -43,4 +43,21 @@ describe Paymill::Client do
|
|
43
43
|
Paymill::Client.create(valid_attributes)
|
44
44
|
end
|
45
45
|
end
|
46
|
+
|
47
|
+
describe "#update_attributes" do
|
48
|
+
it "makes a new PUT request using the correct API endpoint" do
|
49
|
+
client.id = "client_123"
|
50
|
+
Paymill.should_receive(:request).with(:put, "clients/client_123", {:email => "tim.test@exmaple.com"}).and_return("data" => {})
|
51
|
+
|
52
|
+
client.update_attributes({:email => "tim.test@exmaple.com"})
|
53
|
+
end
|
54
|
+
|
55
|
+
it "updates the instance with the returned attributes" do
|
56
|
+
changed_attributes = {:email => "tim.test@example.com"}
|
57
|
+
Paymill.should_receive(:request).and_return("data" => changed_attributes)
|
58
|
+
client.update_attributes(changed_attributes)
|
59
|
+
|
60
|
+
client.email.should eql("tim.test@example.com")
|
61
|
+
end
|
62
|
+
end
|
46
63
|
end
|
data/spec/paymill/offer_spec.rb
CHANGED
@@ -3,10 +3,10 @@ require "spec_helper"
|
|
3
3
|
describe Paymill::Offer do
|
4
4
|
let(:valid_attributes) do
|
5
5
|
{
|
6
|
-
amount:
|
6
|
+
amount: 4200,
|
7
7
|
currency: "eur",
|
8
8
|
interval: "month",
|
9
|
-
name:
|
9
|
+
name: "Medium Plan"
|
10
10
|
}
|
11
11
|
end
|
12
12
|
|
@@ -50,4 +50,21 @@ describe Paymill::Offer do
|
|
50
50
|
Paymill::Offer.create(valid_attributes)
|
51
51
|
end
|
52
52
|
end
|
53
|
+
|
54
|
+
describe "#update_attributes" do
|
55
|
+
it "makes a new PUT request using the correct API endpoint" do
|
56
|
+
offer.id = "offer_123"
|
57
|
+
Paymill.should_receive(:request).with(:put, "offers/offer_123", {:name => "Large Plan"}).and_return("data" => {})
|
58
|
+
|
59
|
+
offer.update_attributes({:name => "Large Plan"})
|
60
|
+
end
|
61
|
+
|
62
|
+
it "updates the instance with the returned attributes" do
|
63
|
+
changed_attributes = {:name => "Large Plan"}
|
64
|
+
Paymill.should_receive(:request).and_return("data" => changed_attributes)
|
65
|
+
offer.update_attributes(changed_attributes)
|
66
|
+
|
67
|
+
offer.name.should eql("Large Plan")
|
68
|
+
end
|
69
|
+
end
|
53
70
|
end
|
@@ -3,14 +3,16 @@ require "spec_helper"
|
|
3
3
|
describe Paymill::Subscription do
|
4
4
|
let(:valid_attributes) do
|
5
5
|
{
|
6
|
-
plan:
|
6
|
+
plan: {
|
7
7
|
name: "Nerd special",
|
8
8
|
amount: 123,
|
9
9
|
interval: "week"
|
10
10
|
},
|
11
|
-
livemode:
|
11
|
+
livemode: false,
|
12
|
+
trial_start: 1349945681,
|
13
|
+
trial_end: 1349945682,
|
12
14
|
cancel_at_period_end: false,
|
13
|
-
client:
|
15
|
+
client: {
|
14
16
|
email: "stefan.sprenger@dkd.de"
|
15
17
|
}
|
16
18
|
}
|
@@ -28,6 +30,8 @@ describe Paymill::Subscription do
|
|
28
30
|
subscription.livemode.should be_false
|
29
31
|
subscription.cancel_at_period_end.should be_false
|
30
32
|
subscription.client[:email].should eql("stefan.sprenger@dkd.de")
|
33
|
+
subscription.trial_start.should eql(1349945681)
|
34
|
+
subscription.trial_end.should eql(1349945682)
|
31
35
|
end
|
32
36
|
end
|
33
37
|
|
@@ -58,4 +62,21 @@ describe Paymill::Subscription do
|
|
58
62
|
Paymill::Subscription.create(valid_attributes)
|
59
63
|
end
|
60
64
|
end
|
65
|
+
|
66
|
+
describe "#update_attributes" do
|
67
|
+
it "makes a new PUT request using the correct API endpoint" do
|
68
|
+
changed_attributes = {:cancel_at_period_end => true}
|
69
|
+
subscription.id = 'sub_123'
|
70
|
+
|
71
|
+
Paymill.should_receive(:request).with(:put, "subscriptions/sub_123", changed_attributes).and_return("data" => changed_attributes)
|
72
|
+
|
73
|
+
subscription.update_attributes(changed_attributes)
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should set the returned attributes on the instance" do
|
77
|
+
Paymill.should_receive(:request).and_return("data" => {:cancel_at_period_end => true})
|
78
|
+
subscription.update_attributes({})
|
79
|
+
subscription.cancel_at_period_end.should be_true
|
80
|
+
end
|
81
|
+
end
|
61
82
|
end
|
@@ -4,6 +4,7 @@ describe Paymill::Transaction do
|
|
4
4
|
let(:valid_attributes) do
|
5
5
|
{
|
6
6
|
amount: 4200,
|
7
|
+
currency: "EUR",
|
7
8
|
status: "pending",
|
8
9
|
description: "Test transaction.",
|
9
10
|
livemode: false,
|
@@ -28,6 +29,7 @@ describe Paymill::Transaction do
|
|
28
29
|
transaction.payment[:card_type].should eql("visa")
|
29
30
|
transaction.payment[:country].should eql("germany")
|
30
31
|
transaction.client.should eql("client_a013c")
|
32
|
+
transaction.currency.should eql("EUR")
|
31
33
|
end
|
32
34
|
end
|
33
35
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: paymill
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-01-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirement: &2153504740 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,15 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
25
|
-
none: false
|
26
|
-
requirements:
|
27
|
-
- - ! '>='
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: '0'
|
24
|
+
version_requirements: *2153504740
|
30
25
|
- !ruby/object:Gem::Dependency
|
31
26
|
name: rspec
|
32
|
-
requirement: !ruby/object:Gem::Requirement
|
27
|
+
requirement: &2153503800 !ruby/object:Gem::Requirement
|
33
28
|
none: false
|
34
29
|
requirements:
|
35
30
|
- - ! '>='
|
@@ -37,12 +32,7 @@ dependencies:
|
|
37
32
|
version: '0'
|
38
33
|
type: :development
|
39
34
|
prerelease: false
|
40
|
-
version_requirements:
|
41
|
-
none: false
|
42
|
-
requirements:
|
43
|
-
- - ! '>='
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
version: '0'
|
35
|
+
version_requirements: *2153503800
|
46
36
|
description: API wrapper for Paymill.
|
47
37
|
email:
|
48
38
|
- stefan.sprenger@dkd.de
|
@@ -58,12 +48,14 @@ files:
|
|
58
48
|
- Rakefile
|
59
49
|
- lib/data/paymill.crt
|
60
50
|
- lib/paymill.rb
|
51
|
+
- lib/paymill/base.rb
|
61
52
|
- lib/paymill/client.rb
|
62
53
|
- lib/paymill/offer.rb
|
63
54
|
- lib/paymill/operations/all.rb
|
64
55
|
- lib/paymill/operations/create.rb
|
65
56
|
- lib/paymill/operations/delete.rb
|
66
57
|
- lib/paymill/operations/find.rb
|
58
|
+
- lib/paymill/operations/update.rb
|
67
59
|
- lib/paymill/payment.rb
|
68
60
|
- lib/paymill/subscription.rb
|
69
61
|
- lib/paymill/transaction.rb
|
@@ -90,7 +82,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
90
82
|
version: '0'
|
91
83
|
segments:
|
92
84
|
- 0
|
93
|
-
hash:
|
85
|
+
hash: 2201296574026171541
|
94
86
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
87
|
none: false
|
96
88
|
requirements:
|
@@ -99,10 +91,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
99
91
|
version: '0'
|
100
92
|
segments:
|
101
93
|
- 0
|
102
|
-
hash:
|
94
|
+
hash: 2201296574026171541
|
103
95
|
requirements: []
|
104
96
|
rubyforge_project:
|
105
|
-
rubygems_version: 1.8.
|
97
|
+
rubygems_version: 1.8.10
|
106
98
|
signing_key:
|
107
99
|
specification_version: 3
|
108
100
|
summary: API wrapper for Paymill.
|