paymill 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 97d64dc5417661a01bc61539a1605beb58f7ce24
4
+ data.tar.gz: dab4a339218ed07e109c789b847af5028b98ada1
5
+ SHA512:
6
+ metadata.gz: da26f07aa02c6349a0a7264552549321247e19195c65bfbae42106a23b19a509ec4659d72bcd69458142798cbf1765042656b08dc356525720d2eff29e68221c
7
+ data.tar.gz: 9ca1f1ed9334e209b795716c52c4f5a412cea6c8da6f901be0ce1520115d161d9387f760cc2686d3d7cf13163f1439353683af26bc664ac839ff2d0498c19cd6
data/.gitignore CHANGED
@@ -5,3 +5,5 @@ pkg/*
5
5
  *.html
6
6
  /.rvmrc
7
7
  .project
8
+ .ruby-version
9
+ .ruby-gemset
data/Gemfile CHANGED
@@ -5,3 +5,4 @@ gemspec
5
5
  gem "rspec"
6
6
  gem "rake"
7
7
  gem "webmock"
8
+ gem "pry"
data/README.md CHANGED
@@ -3,6 +3,14 @@ Paymill [![Build Status](https://secure.travis-ci.org/dkd/paymill-ruby.png)](htt
3
3
 
4
4
  This is a Ruby wrapper for Paymill's API.
5
5
 
6
+ Documentation
7
+ =====
8
+
9
+ We use RubyDoc for documentation.
10
+
11
+ The documentation of the current release can be found here:
12
+ http://rubydoc.info/gems/paymill/frames/index
13
+
6
14
  Usage
7
15
  ======
8
16
 
@@ -18,7 +26,12 @@ Then you have to set your API key:
18
26
 
19
27
  Paymill.api_key = "your-api-key"
20
28
 
21
- Now you can e.g. create a new client:
29
+ Clients
30
+ -------
31
+
32
+ *[Paymill documentation on clients](https://www.paymill.com/en-gb/documentation-3/reference/api-reference/#clients)*
33
+
34
+ Creating a new client:
22
35
 
23
36
  Paymill::Client.create(email: "stefan.sprenger@dkd.de", description: "He is a Ruby guy.")
24
37
 
@@ -49,6 +62,105 @@ belonging to a client you can use the following code:
49
62
 
50
63
  Please note that Transactions and Payments cannot be updated.
51
64
 
65
+ Payments
66
+ -------
67
+
68
+ *[Paymill documentation on payments](https://www.paymill.com/en-gb/documentation-3/reference/api-reference/#document-payments)*
69
+
70
+ Creating a new credit card payment:
71
+
72
+ Paymill::Payment.create(token: "098f6bcd4621d373cade4e832627b4f6")
73
+
74
+ Creating a new debit card payment:
75
+
76
+ Paymill::Payment.create(type: "debit", code: "12345678", account: "1234512345", holder: "Max Mustermann")
77
+
78
+ Or finding an existing payment:
79
+
80
+ Paymill::Payment.find("pay_3af44644dd6d25c820a8")
81
+
82
+ Deleting a payment:
83
+
84
+ Paymill::Payment.delete("pay_3af44644dd6d25c820a8")
85
+
86
+
87
+ For retrieving a collection of all payments you might use the `all`
88
+ operation:
89
+
90
+ Paymill::Payment.all
91
+
92
+ Offers
93
+ ------
94
+
95
+ *[Paymill documentation on offers](https://www.paymill.com/en-gb/documentation-3/reference/api-reference/#offers)*
96
+
97
+ Creating a new offer:
98
+
99
+ Paymill::Offer.create(name: "Monthly", interval: "1 month", amount: 1000, currency: "GBP", trial_period_days: 0)
100
+
101
+ Updating an offer (works on an Offer instance and only the name can be changed):
102
+
103
+ offer = Paymill::Offer.find("offer_08064e30032afa3aa046")
104
+ offer.update_attributes(name: "New name")
105
+
106
+ Deleting an offer:
107
+
108
+ Paymill::Offer.delete('offer_08064e30032afa3aa046')
109
+
110
+ Retrieving an offer:
111
+
112
+ Paymill::Offer.find("offer_753480df39aeb114f2f3")
113
+
114
+ Retrieving all offers:
115
+
116
+ Paymill::Offer.all
117
+
118
+
119
+ Webhooks
120
+ ------
121
+
122
+ *[Paymill documentation on webhooks](https://www.paymill.com/en-gb/documentation-3/reference/api-reference/#webhooks)*
123
+
124
+ Creating a new webhook:
125
+
126
+ Paymill::Webhook.create(email: "email@bob.com", event_types: ["transaction.succeeded", "subscription.succeeded"])
127
+
128
+ Updating a webhook works on an instance (url/email and the event types can be changed):
129
+
130
+ hook = Paymill::Webhook.find("hook_940143bcdc0c40e7756f")
131
+ hook.update_attributes(email: "bob@email.com")
132
+
133
+ Deleting a webhook:
134
+
135
+ Paymill::Webhook.delete("hook_940143bcdc0c40e7756f")
136
+
137
+ Retrieving a webhook:
138
+
139
+ hook = Paymill::Webhook.find("hook_940143bcdc0c40e7756f")
140
+
141
+ Retrieving all webhooks:
142
+
143
+ Paymill::Webhook.all
144
+
145
+
146
+ Refunds
147
+ ------
148
+
149
+ *[Paymill documentation on refunds](https://www.paymill.com/en-gb/documentation-3/reference/api-reference/#refunds)*
150
+
151
+ Creating a new refund:
152
+
153
+ Paymill::Refund.create(id: "tran_023d3b5769321c649435", amount: 4200)
154
+
155
+ Retrieving a refund:
156
+
157
+ refund = Paymill::Refund.find("refund_87bc404a95d5ce616049")
158
+
159
+ Retrieving all refunds:
160
+
161
+ Paymill::Refund.all
162
+
163
+
52
164
  Requirements
53
165
  =====
54
166
 
data/lib/paymill.rb CHANGED
@@ -6,6 +6,7 @@ require "paymill/version"
6
6
  module Paymill
7
7
  API_BASE = "api.paymill.com"
8
8
  API_VERSION = "v2"
9
+ ROOT_PATH = File.dirname(__FILE__)
9
10
 
10
11
  @@api_key = nil
11
12
 
@@ -27,82 +28,39 @@ module Paymill
27
28
  autoload :Delete, "paymill/operations/delete"
28
29
  end
29
30
 
30
- class PaymillError < StandardError
31
+ module Request
32
+ autoload :Base, "paymill/request/base"
33
+ autoload :Connection, "paymill/request/connection"
34
+ autoload :Info, "paymill/request/info"
35
+ autoload :Validator, "paymill/request/validator"
31
36
  end
32
37
 
38
+ class PaymillError < StandardError; end
33
39
  class AuthenticationError < PaymillError; end
34
40
  class APIError < PaymillError; end
35
41
 
36
- class << self
37
- # Returns the set api key
38
- #
39
- # @return [String] The api key
40
- def api_key
41
- @@api_key
42
- end
43
-
44
- # Sets the api key
45
- #
46
- # @param [String] api_key The api key
47
- def api_key=(api_key)
48
- @@api_key = api_key
49
- end
50
-
51
- # Makes a request against the Paymill API
52
- #
53
- # @param [Symbol] http_method The http method to use, must be one of :get, :post, :put and :delete
54
- # @param [String] api_url The API url to use
55
- # @param [Hash] data The data to send, e.g. used when creating new objects.
56
- # @return [Array] The parsed JSON response.
57
- def request(http_method, api_url, data)
58
- raise AuthenticationError if api_key.nil?
59
-
60
- https = Net::HTTP.new(API_BASE, Net::HTTP.https_default_port)
61
- https.use_ssl = true
62
- https.verify_mode = OpenSSL::SSL::VERIFY_PEER
63
- https.ca_file = File.join(File.dirname(__FILE__), "data/paymill.crt")
64
- https.start do |connection|
65
- if api_url == "refunds"
66
- url = "/#{API_VERSION}/#{api_url}/#{data[:id]}"
67
- data.delete(:id)
68
- else
69
- url = "/#{API_VERSION}/#{api_url}"
70
- end
71
- https_request = case http_method
72
- when :post
73
- Net::HTTP::Post.new(url)
74
- when :put
75
- Net::HTTP::Put.new(url)
76
- when :delete
77
- Net::HTTP::Delete.new(url)
78
- else
79
- Net::HTTP::Get.new(path_with_params(url, data))
80
- end
81
- https_request.basic_auth(api_key, "")
82
- https_request.set_form_data(data) if [:post, :put].include? http_method
83
- @response = https.request(https_request)
84
- end
85
- raise AuthenticationError if @response.code.to_i == 401
86
- raise APIError if @response.code.to_i >= 500
87
-
88
- data = JSON.parse(@response.body)
89
- raise APIError.new(data["error"]) if data["error"]
42
+ # Returns the set api key
43
+ #
44
+ # @return [String] The api key
45
+ def self.api_key
46
+ @@api_key
47
+ end
90
48
 
91
- data
92
- end
49
+ # Sets the api key
50
+ #
51
+ # @param [String] api_key The api key
52
+ def self.api_key=(api_key)
53
+ @@api_key = api_key
54
+ end
93
55
 
94
- # Builds and encodes a URI using given path and params.
95
- #
96
- # @param [String] path The path to use
97
- # @param [Array] params The params to use
98
- # @return [String] The built URI.
99
- def path_with_params(path, params)
100
- unless params.empty?
101
- encoded_params = URI.encode_www_form(params)
102
- [path, encoded_params].join("?")
103
- else
104
- path
105
- end
106
- end
56
+ # Makes a request against the Paymill API
57
+ #
58
+ # @param [Symbol] http_method The http method to use, must be one of :get, :post, :put and :delete
59
+ # @param [String] api_url The API url to use
60
+ # @param [Hash] data The data to send, e.g. used when creating new objects.
61
+ # @return [Array] The parsed JSON response.
62
+ def self.request(http_method, api_url, data)
63
+ info = Request::Info.new(http_method, api_url, data)
64
+ Request::Base.new(info).perform
107
65
  end
108
66
  end
@@ -8,6 +8,11 @@ module Paymill
8
8
  # @return [Array] The available objects
9
9
  def all(options = {})
10
10
  response = Paymill.request(:get, "#{self.name.split("::").last.downcase}s/", options)
11
+ results_from response
12
+ end
13
+
14
+ private
15
+ def results_from(response)
11
16
  results = []
12
17
  response["data"].each do |obj|
13
18
  results << self.new(obj)
@@ -19,6 +24,7 @@ module Paymill
19
24
  def self.included(base)
20
25
  base.extend(ClassMethods)
21
26
  end
27
+
22
28
  end
23
29
  end
24
30
  end
@@ -1,6 +1,21 @@
1
1
  module Paymill
2
2
  module Operations
3
3
  module Update
4
+
5
+ module ClassMethods
6
+ # Updates a object
7
+ # @param [Integer] id The id of the object that should be updated
8
+ # @param [Hash] attributes The attributes that should be updated
9
+ def update_attributes(id, attributes)
10
+ response = Paymill.request(:put, "#{self.name.split("::").last.downcase}s/#{id}", attributes)
11
+ self.new(response["data"])
12
+ end
13
+ end
14
+
15
+ def self.included(base)
16
+ base.extend(ClassMethods)
17
+ end
18
+
4
19
  # Updates a object
5
20
  #
6
21
  # @param [Hash] attributes The attributes that should be updated
@@ -3,6 +3,7 @@ module Paymill
3
3
  include Paymill::Operations::Delete
4
4
 
5
5
  attr_accessor :id, :card_type, :country, :expire_month, :expire_year,
6
- :card_holder, :last4
6
+ :card_holder, :holder, :last4, :account, :code, :client,
7
+ :type
7
8
  end
8
9
  end
@@ -1,5 +1,7 @@
1
1
  module Paymill
2
2
  class Preauthorization < Base
3
+ include Paymill::Operations::Delete
4
+
3
5
  attr_accessor :id, :amount, :status, :livemode, :payment, :preauthorization, :currency, :client
4
6
  end
5
7
  end
@@ -0,0 +1,34 @@
1
+ module Paymill
2
+ module Request
3
+ class Base
4
+ attr_reader :info
5
+ attr_accessor :response
6
+
7
+ def initialize(info)
8
+ @info = info
9
+ end
10
+
11
+ def perform
12
+ raise AuthenticationError if Paymill.api_key.nil?
13
+ connection.setup_https
14
+ send_request
15
+
16
+ validator.validated_data_for(response)
17
+ end
18
+
19
+ protected
20
+
21
+ def send_request
22
+ self.response = connection.request
23
+ end
24
+
25
+ def connection
26
+ @connection ||= Connection.new(info)
27
+ end
28
+
29
+ def validator
30
+ @validator ||= Validator.new(info)
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,42 @@
1
+ module Paymill
2
+ module Request
3
+ class Connection
4
+ attr_reader :https
5
+
6
+ def initialize(request_info)
7
+ @info = request_info
8
+ end
9
+
10
+ def setup_https
11
+ @https = Net::HTTP.new(API_BASE, Net::HTTP.https_default_port)
12
+ @https.use_ssl = true
13
+ @https.verify_mode = OpenSSL::SSL::VERIFY_PEER
14
+ @https.ca_file = File.join(ROOT_PATH, "data/paymill.crt")
15
+ end
16
+
17
+ def request
18
+ https.start do |connection|
19
+ https.request(https_request)
20
+ end
21
+ end
22
+
23
+ protected
24
+
25
+ def https_request
26
+ https_request = case @info.http_method
27
+ when :post
28
+ Net::HTTP::Post.new(@info.url)
29
+ when :put
30
+ Net::HTTP::Put.new(@info.url)
31
+ when :delete
32
+ Net::HTTP::Delete.new(@info.url)
33
+ else
34
+ Net::HTTP::Get.new(@info.path_with_params(@info.url, @info.data))
35
+ end
36
+ https_request.basic_auth(Paymill.api_key, "")
37
+ https_request.set_form_data(@info.data) if [:post, :put].include?(@info.http_method)
38
+ https_request
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,38 @@
1
+ module Paymill
2
+ module Request
3
+ class Info
4
+ attr_accessor :http_method, :api_url, :data
5
+
6
+ def initialize(http_method, api_url, data)
7
+ @http_method = http_method
8
+ @api_url = api_url
9
+ @data = data
10
+ end
11
+
12
+ def url
13
+ url = "/#{API_VERSION}/#{api_url}"
14
+ if is_refund?
15
+ url += "/#{data[:id]}"
16
+ data.delete(:id)
17
+ end
18
+
19
+ url
20
+ end
21
+
22
+ def path_with_params(path, params)
23
+ unless params.empty?
24
+ encoded_params = URI.encode_www_form(params)
25
+ [path, encoded_params].join("?")
26
+ else
27
+ path
28
+ end
29
+ end
30
+
31
+ protected
32
+
33
+ def is_refund?
34
+ api_url == "refunds"
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,31 @@
1
+ module Paymill
2
+ module Request
3
+ class Validator
4
+ attr_reader :info
5
+ attr_accessor :response
6
+
7
+ def initialize(info)
8
+ @info = info
9
+ end
10
+
11
+ def validated_data_for(incoming_response)
12
+ self.response = incoming_response
13
+ verify_response_code
14
+ info.data = JSON.parse(response.body)
15
+ validate_response_data
16
+ info.data
17
+ end
18
+
19
+ protected
20
+
21
+ def verify_response_code
22
+ raise AuthenticationError if response.code.to_i == 401
23
+ raise APIError if response.code.to_i >= 500
24
+ end
25
+
26
+ def validate_response_data
27
+ raise APIError.new(info.data["error"]) if info.data["error"]
28
+ end
29
+ end
30
+ end
31
+ end
@@ -3,14 +3,16 @@ module Paymill
3
3
  include Paymill::Operations::Delete
4
4
  include Paymill::Operations::Update
5
5
 
6
- attr_accessor :id, :offer, :livemode, :cancel_at_period_end, :canceled_at, :client, :trial_start, :trial_end
6
+ attr_accessor :id, :offer, :livemode, :cancel_at_period_end, :canceled_at, :client,
7
+ :trial_start, :trial_end, :next_capture_at, :payment
7
8
 
8
9
  # Parses UNIX timestamps and creates Time objects
9
10
  def parse_timestamps
10
11
  super
11
- @canceled_at = Time.at(canceled_at) if canceled_at
12
- @trial_start = Time.at(trial_start) if trial_start
13
- @trial_end = Time.at(trial_end) if trial_end
12
+ @next_capture_at = Time.at(next_capture_at) if next_capture_at
13
+ @canceled_at = Time.at(canceled_at) if canceled_at
14
+ @trial_start = Time.at(trial_start) if trial_start
15
+ @trial_end = Time.at(trial_end) if trial_end
14
16
  end
15
17
  end
16
18
  end
@@ -1,6 +1,9 @@
1
1
  module Paymill
2
2
  class Transaction < Base
3
+ include Paymill::Operations::Update
4
+
3
5
  attr_accessor :id, :amount, :status, :description, :livemode,
4
- :payment, :currency, :client, :response_code
6
+ :payment, :currency, :client, :response_code,
7
+ :origin_amount, :refunds
5
8
  end
6
9
  end
@@ -1,3 +1,3 @@
1
1
  module Paymill
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -27,4 +27,11 @@ describe Paymill::Preauthorization do
27
27
  Paymill::Preauthorization.create(valid_attributes)
28
28
  end
29
29
  end
30
+
31
+ describe ".delete" do
32
+ it "makes a new DELETE request using the correct API endpoint" do
33
+ Paymill.should_receive(:request).with(:delete, "preauthorizations/123", {}).and_return(true)
34
+ Paymill::Preauthorization.delete("123")
35
+ end
36
+ end
30
37
  end
@@ -0,0 +1,27 @@
1
+ require "spec_helper"
2
+
3
+ describe Paymill::Request::Base do
4
+ context "#perform" do
5
+ it "checks for an api key" do
6
+ Paymill.stub(:api_key).and_return(nil)
7
+
8
+ expect{
9
+ Paymill::Request::Base.new(nil).perform
10
+ }.to raise_error Paymill::AuthenticationError
11
+ end
12
+
13
+ it "performs an https request" do
14
+ Paymill.stub(:api_key).and_return("some key")
15
+ connection = stub
16
+ validator = stub
17
+ Paymill::Request::Connection.stub(:new).and_return(connection)
18
+ Paymill::Request::Validator.stub(:new).and_return(validator)
19
+
20
+ connection.should_receive(:setup_https)
21
+ connection.should_receive(:request)
22
+ validator.should_receive(:validated_data_for)
23
+
24
+ Paymill::Request::Base.new(nil).perform
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,25 @@
1
+ require "spec_helper"
2
+
3
+ describe Paymill::Request::Connection do
4
+ describe "#setup_https" do
5
+ it "creates a https object" do
6
+ connection = Paymill::Request::Connection.new(nil)
7
+
8
+ connection.setup_https
9
+
10
+ connection.https.should_not be_nil
11
+ end
12
+ end
13
+
14
+ describe "#request" do
15
+ it "performs the actual request" do
16
+ connection = Paymill::Request::Connection.new(nil)
17
+ connection.setup_https
18
+ connection.stub(:https_request)
19
+
20
+ connection.https.should_receive(:request)
21
+
22
+ connection.request
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,27 @@
1
+ require "spec_helper"
2
+
3
+ describe Paymill::Request::Info do
4
+ describe "#url" do
5
+ it "constructs the url" do
6
+ info = Paymill::Request::Info.new(:get, "random", OpenStruct.new(id: 1))
7
+
8
+ info.url.should =~ /random/
9
+ end
10
+ end
11
+
12
+ describe "#path_with_params" do
13
+ it "does nothing when no params" do
14
+ info = Paymill::Request::Info.new(:get, "random", nil)
15
+ path = "/path/to/someplace"
16
+
17
+ info.path_with_params(path, {}).should eq path
18
+ end
19
+
20
+ it "constructs the path with params" do
21
+ info = Paymill::Request::Info.new(:get, "random", nil)
22
+ path = "/path/to/someplace"
23
+
24
+ info.path_with_params(path, {random: "stuff"}).should eq "#{path}?random=stuff"
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,13 @@
1
+ require "spec_helper"
2
+
3
+ describe Paymill::Request::Validator do
4
+ describe "#validated_data_for" do
5
+ it "validates the data" do
6
+ info = Paymill::Request::Info.new(:get, "random", OpenStruct.new(id: 1))
7
+ validator = Paymill::Request::Validator.new info
8
+ response = OpenStruct.new(body: '{"response":"ok"}', code: 200)
9
+
10
+ validator.validated_data_for(response).should eq "response" => "ok"
11
+ end
12
+ end
13
+ end
@@ -9,11 +9,15 @@ describe Paymill::Subscription do
9
9
  interval: "week"
10
10
  },
11
11
  livemode: false,
12
+ next_capture_at: 1349945681,
12
13
  trial_start: 1349945681,
13
14
  trial_end: 1349945682,
14
15
  cancel_at_period_end: false,
15
16
  client: {
16
17
  email: "stefan.sprenger@dkd.de"
18
+ },
19
+ payment: {
20
+ id: "pay_3af44644dd6d25c820a8",
17
21
  }
18
22
  }
19
23
  end
@@ -30,6 +34,7 @@ describe Paymill::Subscription do
30
34
  subscription.livemode.should be_false
31
35
  subscription.cancel_at_period_end.should be_false
32
36
  subscription.client[:email].should eql("stefan.sprenger@dkd.de")
37
+ subscription.payment[:id].should eql("pay_3af44644dd6d25c820a8")
33
38
  subscription.trial_start.to_i.should eql(1349945681)
34
39
  subscription.trial_end.to_i.should eql(1349945682)
35
40
  end
@@ -56,6 +61,13 @@ describe Paymill::Subscription do
56
61
  subscription.trial_end.class.should eql(Time)
57
62
  end
58
63
  end
64
+
65
+ context "given #next_capture_at is present" do
66
+ it "creates a Time object" do
67
+ subscription = Paymill::Subscription.new(next_capture_at: 1362823928)
68
+ subscription.next_capture_at.class.should eql(Time)
69
+ end
70
+ end
59
71
  end
60
72
 
61
73
  describe ".find" do
@@ -86,10 +98,17 @@ describe Paymill::Subscription do
86
98
  end
87
99
  end
88
100
 
101
+ describe ".update_attributes" do
102
+ it "makes a new PUT request using the correct API endpoint" do
103
+ Paymill.should_receive(:request).with(:put, "subscriptions/sub_123", {:offer => 50 }).and_return("data" => {})
104
+ Paymill::Subscription.update_attributes("sub_123", {:offer => 50 })
105
+ end
106
+ end
107
+
89
108
  describe "#update_attributes" do
90
109
  it "makes a new PUT request using the correct API endpoint" do
91
110
  changed_attributes = {:cancel_at_period_end => true}
92
- subscription.id = 'sub_123'
111
+ subscription.id = "sub_123"
93
112
 
94
113
  Paymill.should_receive(:request).with(:put, "subscriptions/sub_123", changed_attributes).and_return("data" => changed_attributes)
95
114
 
@@ -4,6 +4,7 @@ describe Paymill::Transaction do
4
4
  let(:valid_attributes) do
5
5
  {
6
6
  amount: 4200,
7
+ origin_amount: 4200,
7
8
  currency: "EUR",
8
9
  status: "pending",
9
10
  description: "Test transaction.",
@@ -13,7 +14,10 @@ describe Paymill::Transaction do
13
14
  card_type: "visa",
14
15
  country: "germany"
15
16
  },
16
- client: "client_a013c"
17
+ client: "client_a013c",
18
+ refunds: [
19
+ {:id => "refund_abc"}
20
+ ]
17
21
  }
18
22
  end
19
23
 
@@ -24,6 +28,7 @@ describe Paymill::Transaction do
24
28
  describe "#initialize" do
25
29
  it "initializes all attributes correctly" do
26
30
  transaction.amount.should eql(4200)
31
+ transaction.origin_amount.should eql(4200)
27
32
  transaction.status.should eql("pending")
28
33
  transaction.description.should eql("Test transaction.")
29
34
  transaction.livemode.should eql(false)
@@ -32,6 +37,10 @@ describe Paymill::Transaction do
32
37
  transaction.payment[:country].should eql("germany")
33
38
  transaction.client.should eql("client_a013c")
34
39
  transaction.currency.should eql("EUR")
40
+ transaction.refunds.should_not be_nil
41
+ transaction.refunds.should_not be_empty
42
+ transaction.refunds.first.should_not be_nil
43
+ transaction.refunds.first[:id].should eql("refund_abc")
35
44
  end
36
45
  end
37
46
 
@@ -62,4 +71,21 @@ describe Paymill::Transaction do
62
71
  Paymill::Transaction.create(valid_attributes)
63
72
  end
64
73
  end
74
+
75
+ describe "#update_attributes" do
76
+ it "makes a new PUT request using the correct API endpoint" do
77
+ transaction.id = "trans_123"
78
+ Paymill.should_receive(:request).with(:put, "transactions/trans_123", {:description => "Transaction Description"}).and_return("data" => {})
79
+
80
+ transaction.update_attributes({:description => "Transaction Description"})
81
+ end
82
+
83
+ it "updates the instance with the returned attributes" do
84
+ changed_attributes = {:description => "Transaction Description"}
85
+ Paymill.should_receive(:request).and_return("data" => changed_attributes)
86
+ transaction.update_attributes(changed_attributes)
87
+
88
+ transaction.description.should eql("Transaction Description")
89
+ end
90
+ end
65
91
  end
@@ -14,7 +14,7 @@ describe Paymill::Webhook do
14
14
  let (:webhook) do
15
15
  Paymill::Webhook.new(valid_attributes)
16
16
  end
17
-
17
+
18
18
  describe "#initialize" do
19
19
  it "initializes all attributes correctly" do
20
20
  webhook.url.should eql("<your-webhook-url>")
@@ -24,7 +24,7 @@ describe Paymill::Webhook do
24
24
  webhook.updated_at.to_i.should eql(1360368749)
25
25
  end
26
26
  end
27
-
27
+
28
28
  describe ".find" do
29
29
  it "makes a new GET request using the correct API endpoint to receive a specific webhook" do
30
30
  Paymill.should_receive(:request).with(:get, "webhooks/123", {}).and_return("data" => {})
@@ -45,18 +45,18 @@ describe Paymill::Webhook do
45
45
  Paymill::Webhook.create(valid_attributes)
46
46
  end
47
47
  end
48
-
48
+
49
49
  describe ".delete" do
50
50
  it "makes a new DELETE request using the correct API endpoint" do
51
51
  Paymill.should_receive(:request).with(:delete, "webhooks/123", {}).and_return(true)
52
52
  Paymill::Webhook.delete("123")
53
53
  end
54
54
  end
55
-
55
+
56
56
  describe "#update_attributes" do
57
57
  it "makes a new PUT request using the correct API endpoint" do
58
58
  changed_attributes = {:url => "<new-webhook-url>"}
59
- webhook.id = 'hook_123'
59
+ webhook.id = "hook_123"
60
60
  Paymill.should_receive(:request).with(:put, "webhooks/hook_123", changed_attributes).and_return("data" => changed_attributes)
61
61
  webhook.update_attributes(changed_attributes)
62
62
  end
data/spec/spec_helper.rb CHANGED
@@ -4,6 +4,7 @@ require "paymill"
4
4
  require "rspec"
5
5
  require "rspec/autorun"
6
6
  require "webmock/rspec"
7
+ require "pry"
7
8
 
8
9
  RSpec.configure do |config|
9
10
  end
metadata CHANGED
@@ -1,46 +1,41 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paymill
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
5
- prerelease:
4
+ version: 0.4.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Stefan Sprenger
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-04-08 00:00:00.000000000 Z
11
+ date: 2013-09-02 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: json
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - '>='
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rspec
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - '>='
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - '>='
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0'
46
41
  description: API wrapper for Paymill.
@@ -70,6 +65,10 @@ files:
70
65
  - lib/paymill/payment.rb
71
66
  - lib/paymill/preauthorization.rb
72
67
  - lib/paymill/refund.rb
68
+ - lib/paymill/request/base.rb
69
+ - lib/paymill/request/connection.rb
70
+ - lib/paymill/request/info.rb
71
+ - lib/paymill/request/validator.rb
73
72
  - lib/paymill/subscription.rb
74
73
  - lib/paymill/transaction.rb
75
74
  - lib/paymill/version.rb
@@ -81,6 +80,10 @@ files:
81
80
  - spec/paymill/payment_spec.rb
82
81
  - spec/paymill/preauthorization_spec.rb
83
82
  - spec/paymill/refund_spec.rb
83
+ - spec/paymill/request/base_spec.rb
84
+ - spec/paymill/request/connection_spec.rb
85
+ - spec/paymill/request/info_spec.rb
86
+ - spec/paymill/request/validator_spec.rb
84
87
  - spec/paymill/subscription_spec.rb
85
88
  - spec/paymill/transaction_spec.rb
86
89
  - spec/paymill/webhook_spec.rb
@@ -88,33 +91,26 @@ files:
88
91
  - spec/spec_helper.rb
89
92
  homepage: https://github.com/dkd/paymill-ruby
90
93
  licenses: []
94
+ metadata: {}
91
95
  post_install_message:
92
96
  rdoc_options: []
93
97
  require_paths:
94
98
  - lib
95
99
  required_ruby_version: !ruby/object:Gem::Requirement
96
- none: false
97
100
  requirements:
98
- - - ! '>='
101
+ - - '>='
99
102
  - !ruby/object:Gem::Version
100
103
  version: '0'
101
- segments:
102
- - 0
103
- hash: 957344793951118701
104
104
  required_rubygems_version: !ruby/object:Gem::Requirement
105
- none: false
106
105
  requirements:
107
- - - ! '>='
106
+ - - '>='
108
107
  - !ruby/object:Gem::Version
109
108
  version: '0'
110
- segments:
111
- - 0
112
- hash: 957344793951118701
113
109
  requirements: []
114
110
  rubyforge_project:
115
- rubygems_version: 1.8.19
111
+ rubygems_version: 2.0.5
116
112
  signing_key:
117
- specification_version: 3
113
+ specification_version: 4
118
114
  summary: API wrapper for Paymill.
119
115
  test_files:
120
116
  - spec/paymill/base_spec.rb
@@ -123,6 +119,10 @@ test_files:
123
119
  - spec/paymill/payment_spec.rb
124
120
  - spec/paymill/preauthorization_spec.rb
125
121
  - spec/paymill/refund_spec.rb
122
+ - spec/paymill/request/base_spec.rb
123
+ - spec/paymill/request/connection_spec.rb
124
+ - spec/paymill/request/info_spec.rb
125
+ - spec/paymill/request/validator_spec.rb
126
126
  - spec/paymill/subscription_spec.rb
127
127
  - spec/paymill/transaction_spec.rb
128
128
  - spec/paymill/webhook_spec.rb