paymill 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -3,4 +3,5 @@
3
3
  Gemfile.lock
4
4
  pkg/*
5
5
  *.html
6
- /.rvmrc
6
+ /.rvmrc
7
+ .project
data/Gemfile CHANGED
@@ -4,3 +4,4 @@ gemspec
4
4
 
5
5
  gem "rspec"
6
6
  gem "rake"
7
+ gem "webmock"
data/README.md CHANGED
@@ -41,6 +41,12 @@ operation:
41
41
 
42
42
  Paymill::Client.all
43
43
 
44
+ To sort and filter collection lists of objects, use the `all` method
45
+ with an options hash. For example to find the most recent transactions
46
+ belonging to a client you can use the following code:
47
+
48
+ Paymill::Transaction.all(client: "<client_id>", order: "created_at_desc")
49
+
44
50
  Please note that Transactions and Payments cannot be updated.
45
51
 
46
52
  Requirements
@@ -2,8 +2,8 @@ module Paymill
2
2
  module Operations
3
3
  module All
4
4
  module ClassMethods
5
- def all
6
- response = Paymill.request(:get, "#{self.name.split("::").last.downcase}s/", {})
5
+ def all(options = {})
6
+ response = Paymill.request(:get, "#{self.name.split("::").last.downcase}s/", options)
7
7
  results = []
8
8
  response["data"].each do |obj|
9
9
  results << self.new(obj)
@@ -17,4 +17,4 @@ module Paymill
17
17
  end
18
18
  end
19
19
  end
20
- end
20
+ end
@@ -1,6 +1,7 @@
1
1
  module Paymill
2
2
  class Transaction < Base
3
3
  attr_accessor :id, :amount, :status, :description, :livemode,
4
- :payment, :currency, :client, :created_at, :updated_at
4
+ :payment, :currency, :client, :created_at, :updated_at,
5
+ :response_code
5
6
  end
6
7
  end
@@ -1,3 +1,3 @@
1
1
  module Paymill
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
@@ -0,0 +1,8 @@
1
+ module Paymill
2
+ class Webhook < Base
3
+ include Paymill::Operations::Delete
4
+ include Paymill::Operations::Update
5
+
6
+ attr_accessor :id, :url, :livemode, :event_types, :created_at, :updated_at
7
+ end
8
+ end
data/lib/paymill.rb CHANGED
@@ -15,6 +15,7 @@ module Paymill
15
15
  autoload :Payment, "paymill/payment"
16
16
  autoload :Subscription, "paymill/subscription"
17
17
  autoload :Transaction, "paymill/transaction"
18
+ autoload :Webhook, "paymill/webhook"
18
19
 
19
20
  module Operations
20
21
  autoload :All, "paymill/operations/all"
@@ -49,15 +50,15 @@ module Paymill
49
50
  https.start do |connection|
50
51
  url = "/#{API_VERSION}/#{api_url}"
51
52
  https_request = case http_method
52
- when :post
53
- Net::HTTP::Post.new(url)
54
- when :put
55
- Net::HTTP::Put.new(url)
56
- when :delete
57
- Net::HTTP::Delete.new(url)
58
- else
59
- Net::HTTP::Get.new(url)
60
- end
53
+ when :post
54
+ Net::HTTP::Post.new(url)
55
+ when :put
56
+ Net::HTTP::Put.new(url)
57
+ when :delete
58
+ Net::HTTP::Delete.new(url)
59
+ else
60
+ Net::HTTP::Get.new(path_with_params(url, data))
61
+ end
61
62
  https_request.basic_auth(api_key, "")
62
63
  https_request.set_form_data(data) if [:post, :put].include? http_method
63
64
  @response = https.request(https_request)
@@ -70,5 +71,10 @@ module Paymill
70
71
 
71
72
  data
72
73
  end
74
+
75
+ def path_with_params(path, params)
76
+ encoded_params = URI.encode_www_form(params)
77
+ [path, encoded_params].join("?")
78
+ end
73
79
  end
74
80
  end
@@ -8,6 +8,7 @@ describe Paymill::Transaction do
8
8
  status: "pending",
9
9
  description: "Test transaction.",
10
10
  livemode: false,
11
+ response_code: 20000,
11
12
  payment: {
12
13
  card_type: "visa",
13
14
  country: "germany"
@@ -26,6 +27,7 @@ describe Paymill::Transaction do
26
27
  transaction.status.should eql("pending")
27
28
  transaction.description.should eql("Test transaction.")
28
29
  transaction.livemode.should eql(false)
30
+ transaction.response_code.should eql(20000)
29
31
  transaction.payment[:card_type].should eql("visa")
30
32
  transaction.payment[:country].should eql("germany")
31
33
  transaction.client.should eql("client_a013c")
@@ -47,6 +49,13 @@ describe Paymill::Transaction do
47
49
  end
48
50
  end
49
51
 
52
+ describe ".all with options" do
53
+ it "makes a new GET request using the correct API endpoint to receive all transactions" do
54
+ Paymill.should_receive(:request).with(:get, "transactions/", { client: "client_id" }).and_return("data" => {})
55
+ Paymill::Transaction.all(client: "client_id")
56
+ end
57
+ end
58
+
50
59
  describe ".create" do
51
60
  it "makes a new POST request using the correct API endpoint" do
52
61
  Paymill.should_receive(:request).with(:post, "transactions", valid_attributes).and_return("data" => {})
@@ -0,0 +1,70 @@
1
+ require "spec_helper"
2
+
3
+ describe Paymill::Webhook do
4
+ let(:valid_attributes) do
5
+ {
6
+ url: "<your-webhook-url>",
7
+ livemode:false,
8
+ event_types:["transaction.succeeded","transaction.failed"],
9
+ created_at:1360368749,
10
+ updated_at:1360368749
11
+ }
12
+ end
13
+
14
+ let (:webhook) do
15
+ Paymill::Webhook.new(valid_attributes)
16
+ end
17
+
18
+ describe "#initialize" do
19
+ it "initializes all attributes correctly" do
20
+ webhook.url.should eql("<your-webhook-url>")
21
+ webhook.livemode.should eql(false)
22
+ webhook.event_types.should eql(["transaction.succeeded","transaction.failed"])
23
+ webhook.created_at.should eql(1360368749)
24
+ webhook.updated_at.should eql(1360368749)
25
+ end
26
+ end
27
+
28
+ describe ".find" do
29
+ it "makes a new GET request using the correct API endpoint to receive a specific webhook" do
30
+ Paymill.should_receive(:request).with(:get, "webhooks/123", {}).and_return("data" => {})
31
+ Paymill::Webhook.find("123")
32
+ end
33
+ end
34
+
35
+ describe ".all" do
36
+ it "makes a new GET request using the correct API endpoint to receive all webhooks" do
37
+ Paymill.should_receive(:request).with(:get, "webhooks/", {}).and_return("data" => {})
38
+ Paymill::Webhook.all
39
+ end
40
+ end
41
+
42
+ describe ".create" do
43
+ it "makes a new POST request using the correct API endpoint" do
44
+ Paymill.should_receive(:request).with(:post, "webhooks", valid_attributes).and_return("data" => {})
45
+ Paymill::Webhook.create(valid_attributes)
46
+ end
47
+ end
48
+
49
+ describe ".delete" do
50
+ it "makes a new DELETE request using the correct API endpoint" do
51
+ Paymill.should_receive(:request).with(:delete, "webhooks/123", {}).and_return(true)
52
+ Paymill::Webhook.delete("123")
53
+ end
54
+ end
55
+
56
+ describe "#update_attributes" do
57
+ it "makes a new PUT request using the correct API endpoint" do
58
+ changed_attributes = {:url => "<new-webhook-url>"}
59
+ webhook.id = 'hook_123'
60
+ Paymill.should_receive(:request).with(:put, "webhooks/hook_123", changed_attributes).and_return("data" => changed_attributes)
61
+ webhook.update_attributes(changed_attributes)
62
+ end
63
+
64
+ it "should set the returned attributes on the instance" do
65
+ Paymill.should_receive(:request).and_return("data" => {:url => "<new-webhook-url>"})
66
+ webhook.update_attributes({})
67
+ webhook.url.should eql("<new-webhook-url>")
68
+ end
69
+ end
70
+ end
data/spec/paymill_spec.rb CHANGED
@@ -7,5 +7,22 @@ describe Paymill do
7
7
  expect { Paymill.request(:get, "clients", {}) }.to raise_error(Paymill::AuthenticationError)
8
8
  end
9
9
  end
10
+
11
+ context "with an invalid api key" do
12
+ before(:each) do
13
+ WebMock.stub_request(:any, /#{Paymill::API_BASE}/).to_return(:body => "{}")
14
+ Paymill.api_key = "your-api-key"
15
+ end
16
+
17
+ it "attempts to get a url with one param" do
18
+ Paymill.request(:get, "transactions", { param_name: "param_value" })
19
+ WebMock.should have_requested(:get, "https://#{Paymill::api_key}:@#{Paymill::API_BASE}/#{Paymill::API_VERSION}/transactions?param_name=param_value")
20
+ end
21
+
22
+ it "attempts to get a url with more than one param" do
23
+ Paymill.request(:get, "transactions", { client: "client_id", order: "created_at_desc" })
24
+ WebMock.should have_requested(:get, "https://#{Paymill::api_key}:@#{Paymill::API_BASE}/#{Paymill::API_VERSION}/transactions?client=client_id&order=created_at_desc")
25
+ end
26
+ end
10
27
  end
11
- end
28
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,8 +1,9 @@
1
1
  $LOAD_PATH.unshift(File.dirname(__FILE__))
2
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
- require 'paymill'
4
- require 'rspec'
5
- require 'rspec/autorun'
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
3
+ require "paymill"
4
+ require "rspec"
5
+ require "rspec/autorun"
6
+ require "webmock/rspec"
6
7
 
7
8
  RSpec.configure do |config|
8
- end
9
+ end
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.2.0
4
+ version: 0.2.1
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: 2013-01-29 00:00:00.000000000 Z
12
+ date: 2013-02-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
16
- requirement: &2153504740 !ruby/object:Gem::Requirement
16
+ requirement: &2153450240 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2153504740
24
+ version_requirements: *2153450240
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &2153503800 !ruby/object:Gem::Requirement
27
+ requirement: &2153464400 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *2153503800
35
+ version_requirements: *2153464400
36
36
  description: API wrapper for Paymill.
37
37
  email:
38
38
  - stefan.sprenger@dkd.de
@@ -60,12 +60,14 @@ files:
60
60
  - lib/paymill/subscription.rb
61
61
  - lib/paymill/transaction.rb
62
62
  - lib/paymill/version.rb
63
+ - lib/paymill/webhook.rb
63
64
  - paymill.gemspec
64
65
  - spec/paymill/client_spec.rb
65
66
  - spec/paymill/offer_spec.rb
66
67
  - spec/paymill/payment_spec.rb
67
68
  - spec/paymill/subscription_spec.rb
68
69
  - spec/paymill/transaction_spec.rb
70
+ - spec/paymill/webhook_spec.rb
69
71
  - spec/paymill_spec.rb
70
72
  - spec/spec_helper.rb
71
73
  homepage: https://github.com/dkd/paymill-ruby
@@ -82,7 +84,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
82
84
  version: '0'
83
85
  segments:
84
86
  - 0
85
- hash: 2201296574026171541
87
+ hash: 3327817462008033572
86
88
  required_rubygems_version: !ruby/object:Gem::Requirement
87
89
  none: false
88
90
  requirements:
@@ -91,7 +93,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
91
93
  version: '0'
92
94
  segments:
93
95
  - 0
94
- hash: 2201296574026171541
96
+ hash: 3327817462008033572
95
97
  requirements: []
96
98
  rubyforge_project:
97
99
  rubygems_version: 1.8.10
@@ -104,5 +106,6 @@ test_files:
104
106
  - spec/paymill/payment_spec.rb
105
107
  - spec/paymill/subscription_spec.rb
106
108
  - spec/paymill/transaction_spec.rb
109
+ - spec/paymill/webhook_spec.rb
107
110
  - spec/paymill_spec.rb
108
111
  - spec/spec_helper.rb