paymill 0.2.1 → 0.2.2

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.
@@ -13,6 +13,8 @@ module Paymill
13
13
  autoload :Client, "paymill/client"
14
14
  autoload :Offer, "paymill/offer"
15
15
  autoload :Payment, "paymill/payment"
16
+ autoload :Preauthorization, "paymill/preauthorization"
17
+ autoload :Refund, "paymill/refund"
16
18
  autoload :Subscription, "paymill/subscription"
17
19
  autoload :Transaction, "paymill/transaction"
18
20
  autoload :Webhook, "paymill/webhook"
@@ -48,7 +50,12 @@ module Paymill
48
50
  https.verify_mode = OpenSSL::SSL::VERIFY_PEER
49
51
  https.ca_file = File.join(File.dirname(__FILE__), "data/paymill.crt")
50
52
  https.start do |connection|
51
- url = "/#{API_VERSION}/#{api_url}"
53
+ if api_url == "refunds"
54
+ url = "/#{API_VERSION}/#{api_url}/#{data[:id]}"
55
+ data.delete(:id)
56
+ else
57
+ url = "/#{API_VERSION}/#{api_url}"
58
+ end
52
59
  https_request = case http_method
53
60
  when :post
54
61
  Net::HTTP::Post.new(url)
@@ -73,8 +80,12 @@ module Paymill
73
80
  end
74
81
 
75
82
  def path_with_params(path, params)
76
- encoded_params = URI.encode_www_form(params)
77
- [path, encoded_params].join("?")
83
+ unless params.empty?
84
+ encoded_params = URI.encode_www_form(params)
85
+ [path, encoded_params].join("?")
86
+ else
87
+ path
88
+ end
78
89
  end
79
90
  end
80
91
  end
@@ -4,8 +4,11 @@ module Paymill
4
4
  include Paymill::Operations::Create
5
5
  include Paymill::Operations::Find
6
6
 
7
+ attr_accessor :created_at, :updated_at
8
+
7
9
  def initialize(attributes = {})
8
10
  set_attributes(attributes)
11
+ parse_timestamps
9
12
  end
10
13
 
11
14
  def set_attributes(attributes)
@@ -13,5 +16,10 @@ module Paymill
13
16
  instance_variable_set("@#{key}", value)
14
17
  end
15
18
  end
19
+
20
+ def parse_timestamps
21
+ @created_at = Time.at(created_at) if created_at
22
+ @updated_at = Time.at(updated_at) if updated_at
23
+ end
16
24
  end
17
25
  end
@@ -3,7 +3,6 @@ module Paymill
3
3
  include Paymill::Operations::Delete
4
4
  include Paymill::Operations::Update
5
5
 
6
- attr_accessor :id, :email, :description, :attributes, :created_at,
7
- :updated_at, :payment, :subscription
6
+ attr_accessor :id, :email, :description, :attributes, :payment, :subscription
8
7
  end
9
8
  end
@@ -1,6 +1,8 @@
1
1
  module Paymill
2
2
  class Payment < Base
3
+ include Paymill::Operations::Delete
4
+
3
5
  attr_accessor :id, :card_type, :country, :expire_month, :expire_year,
4
- :card_holder, :last4, :created_at, :updated_at
6
+ :card_holder, :last4
5
7
  end
6
8
  end
@@ -0,0 +1,5 @@
1
+ module Paymill
2
+ class Preauthorization < Base
3
+ attr_accessor :id, :amount, :status, :livemode, :payment, :preauthorization, :currency, :client
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module Paymill
2
+ class Refund < Base
3
+ attr_accessor :id, :transaction, :amount, :status, :description, :livemode
4
+ end
5
+ end
@@ -3,7 +3,13 @@ module Paymill
3
3
  include Paymill::Operations::Delete
4
4
  include Paymill::Operations::Update
5
5
 
6
- attr_accessor :id, :plan, :livemode, :cancel_at_period_end, :created_at, :updated_at,
7
- :canceled_at, :client, :trial_start, :trial_end
6
+ attr_accessor :id, :plan, :livemode, :cancel_at_period_end, :canceled_at, :client, :trial_start, :trial_end
7
+
8
+ def parse_timestamps
9
+ super
10
+ @canceled_at = Time.at(canceled_at) if canceled_at
11
+ @trial_start = Time.at(trial_start) if trial_start
12
+ @trial_end = Time.at(trial_end) if trial_end
13
+ end
8
14
  end
9
15
  end
@@ -1,7 +1,6 @@
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,
5
- :response_code
4
+ :payment, :currency, :client, :response_code
6
5
  end
7
6
  end
@@ -1,3 +1,3 @@
1
1
  module Paymill
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
@@ -2,7 +2,7 @@ module Paymill
2
2
  class Webhook < Base
3
3
  include Paymill::Operations::Delete
4
4
  include Paymill::Operations::Update
5
-
6
- attr_accessor :id, :url, :livemode, :event_types, :created_at, :updated_at
5
+
6
+ attr_accessor :id, :url, :livemode, :event_types
7
7
  end
8
- end
8
+ end
@@ -0,0 +1,19 @@
1
+ require "spec_helper"
2
+
3
+ describe Paymill::Base do
4
+ describe "#parse_timestamps" do
5
+ context "given #created_at is present" do
6
+ it "creates a Time object" do
7
+ base = Paymill::Base.new(created_at: 1362823928)
8
+ base.created_at.class.should eql(Time)
9
+ end
10
+ end
11
+
12
+ context "given #updated_at is present" do
13
+ it "creates a Time object" do
14
+ base = Paymill::Base.new(updated_at: 1362823928)
15
+ base.updated_at.class.should eql(Time)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -47,4 +47,11 @@ describe Paymill::Payment do
47
47
  Paymill::Payment.create(valid_attributes)
48
48
  end
49
49
  end
50
+
51
+ describe ".delete" do
52
+ it "makes a new DELETE request using the correct API endpoint" do
53
+ Paymill.should_receive(:request).with(:delete, "payments/123", {}).and_return(true)
54
+ Paymill::Payment.delete("123")
55
+ end
56
+ end
50
57
  end
@@ -0,0 +1,30 @@
1
+ require "spec_helper"
2
+
3
+ describe Paymill::Preauthorization do
4
+ let(:valid_attributes) do
5
+ {
6
+ payment: "pay_d43cf0ee969d9847512b",
7
+ amount: 4200,
8
+ currency: "EUR"
9
+ }
10
+ end
11
+
12
+ let (:preauthorization) do
13
+ Paymill::Preauthorization.new(valid_attributes)
14
+ end
15
+
16
+ describe "#initialize" do
17
+ it "initializes all attributes correctly" do
18
+ preauthorization.payment.should eql("pay_d43cf0ee969d9847512b")
19
+ preauthorization.amount.should eql(4200)
20
+ preauthorization.currency.should eql("EUR")
21
+ end
22
+ end
23
+
24
+ describe ".create" do
25
+ it "makes a new POST request using the correct API endpoint" do
26
+ Paymill.should_receive(:request).with(:post, "preauthorizations", valid_attributes).and_return("data" => {})
27
+ Paymill::Preauthorization.create(valid_attributes)
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,120 @@
1
+ require "spec_helper"
2
+
3
+ describe Paymill::Refund do
4
+ let(:valid_attributes) do
5
+ {
6
+ id: "refund_87bc404a95d5ce616049",
7
+ amount: "042",
8
+ status: "refunded",
9
+ description: nil,
10
+ livemode: false,
11
+ created_at: 1349947042,
12
+ updated_at: 1349947042,
13
+ transaction: {
14
+ id: "tran_2848cb20a6bb578177db",
15
+ amount: "378",
16
+ origin_amount: 420,
17
+ status: "partial_refunded",
18
+ description: nil,
19
+ livemode: false,
20
+ created_at: 1349946216,
21
+ updated_at: 1349947042,
22
+ response_code: 20000,
23
+ refunds: [
24
+ {
25
+ id: "refund_87bc404a95d5ce616049",
26
+ amount: "042",
27
+ status: "refunded",
28
+ description: nil,
29
+ livemode: false,
30
+ created_at: 1349947042,
31
+ updated_at: 1349947042,
32
+ response_code: 20000
33
+ }
34
+ ],
35
+ payment: {
36
+ id: "pay_95ba26ba2c613ebb0ca8",
37
+ type: "debit",
38
+ client: "client_64b025ee5955abd5af66",
39
+ code: "860555000",
40
+ holder: "Max Mustermann",
41
+ account: "******2345",
42
+ created_at: 1349945681,
43
+ updated_at: 1349945681
44
+ },
45
+ client: {
46
+ id: "client_64b025ee5955abd5af66",
47
+ email: "lovely-client@example.com",
48
+ description: nil,
49
+ created_at: 1349945644,
50
+ updated_at: 1349945644,
51
+ payment: [
52
+ "pay_95ba26ba2c613ebb0ca8"
53
+ ],
54
+ subscription: nil
55
+ },
56
+ preauthorization: nil
57
+ }
58
+ }
59
+ end
60
+
61
+ let (:refund) do
62
+ Paymill::Refund.new(valid_attributes)
63
+ end
64
+
65
+ describe "#initialize" do
66
+ it "initializes all attributes correctly" do
67
+ refund.id.should eql("refund_87bc404a95d5ce616049")
68
+ refund.amount.should eql("042")
69
+ refund.status.should eql("refunded")
70
+ refund.description.should be_nil
71
+ refund.livemode.should be_false
72
+ =begin
73
+ refund.transaction[:refunds].should eql(
74
+ [
75
+ {
76
+ id: "refund_87bc404a95d5ce616049",
77
+ amount: "042",
78
+ status: "refunded",
79
+ description: nil,
80
+ livemode: false,
81
+ created_at: 1349947042,
82
+ updated_at: 1349947042,
83
+ response_code: 20000
84
+ }
85
+ ]
86
+ )
87
+ refund.transaction[:payment].should eql(
88
+ {
89
+ id: "pay_95ba26ba2c613ebb0ca8",
90
+ type: "debit",
91
+ client: "client_64b025ee5955abd5af66",
92
+ code: "860555000",
93
+ holder: "Max Mustermann",
94
+ account: "******2345",
95
+ created_at: 1349945681,
96
+ updated_at: 1349945681
97
+ }
98
+ )
99
+ refund.transaction[:client].should eql(
100
+ id: "client_64b025ee5955abd5af66",
101
+ email: "lovely-client@example.com",
102
+ description: nil,
103
+ created_at: 1349945644,
104
+ updated_at: 1349945644,
105
+ payment: [
106
+ "pay_95ba26ba2c613ebb0ca8"
107
+ ],
108
+ subscription: nil
109
+ )
110
+ =end
111
+ end
112
+ end
113
+
114
+ describe ".create" do
115
+ it "makes a new POST request using the correct API endpoint" do
116
+ Paymill.should_receive(:request).with(:post, "refunds", valid_attributes).and_return("data" => {})
117
+ Paymill::Refund.create(valid_attributes)
118
+ end
119
+ end
120
+ end
@@ -30,8 +30,31 @@ describe Paymill::Subscription do
30
30
  subscription.livemode.should be_false
31
31
  subscription.cancel_at_period_end.should be_false
32
32
  subscription.client[:email].should eql("stefan.sprenger@dkd.de")
33
- subscription.trial_start.should eql(1349945681)
34
- subscription.trial_end.should eql(1349945682)
33
+ subscription.trial_start.to_i.should eql(1349945681)
34
+ subscription.trial_end.to_i.should eql(1349945682)
35
+ end
36
+ end
37
+
38
+ describe "#parse_timestamps" do
39
+ context "given #canceled_at is present" do
40
+ it "creates a Time object" do
41
+ subscription = Paymill::Subscription.new(canceled_at: 1362823928)
42
+ subscription.canceled_at.class.should eql(Time)
43
+ end
44
+ end
45
+
46
+ context "given #trial_start is present" do
47
+ it "creates a Time object" do
48
+ subscription = Paymill::Subscription.new(trial_start: 1362823928)
49
+ subscription.trial_start.class.should eql(Time)
50
+ end
51
+ end
52
+
53
+ context "given #trial_end is present" do
54
+ it "creates a Time object" do
55
+ subscription = Paymill::Subscription.new(trial_end: 1362823928)
56
+ subscription.trial_end.class.should eql(Time)
57
+ end
35
58
  end
36
59
  end
37
60
 
@@ -20,8 +20,8 @@ describe Paymill::Webhook do
20
20
  webhook.url.should eql("<your-webhook-url>")
21
21
  webhook.livemode.should eql(false)
22
22
  webhook.event_types.should eql(["transaction.succeeded","transaction.failed"])
23
- webhook.created_at.should eql(1360368749)
24
- webhook.updated_at.should eql(1360368749)
23
+ webhook.created_at.to_i.should eql(1360368749)
24
+ webhook.updated_at.to_i.should eql(1360368749)
25
25
  end
26
26
  end
27
27
 
@@ -67,4 +67,4 @@ describe Paymill::Webhook do
67
67
  webhook.url.should eql("<new-webhook-url>")
68
68
  end
69
69
  end
70
- end
70
+ end
@@ -23,6 +23,11 @@ describe Paymill do
23
23
  Paymill.request(:get, "transactions", { client: "client_id", order: "created_at_desc" })
24
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
25
  end
26
+
27
+ it "doesn't add a question mark if no params" do
28
+ Paymill.request(:get, "transactions", {})
29
+ WebMock.should have_requested(:get, "https://#{Paymill::api_key}:@#{Paymill::API_BASE}/#{Paymill::API_VERSION}/transactions")
30
+ end
26
31
  end
27
32
  end
28
33
  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.1
4
+ version: 0.2.2
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-02-18 00:00:00.000000000 Z
12
+ date: 2013-03-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
16
- requirement: &2153450240 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,15 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2153450240
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: rspec
27
- requirement: &2153464400 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ! '>='
@@ -32,7 +37,12 @@ dependencies:
32
37
  version: '0'
33
38
  type: :development
34
39
  prerelease: false
35
- version_requirements: *2153464400
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
36
46
  description: API wrapper for Paymill.
37
47
  email:
38
48
  - stefan.sprenger@dkd.de
@@ -57,14 +67,19 @@ files:
57
67
  - lib/paymill/operations/find.rb
58
68
  - lib/paymill/operations/update.rb
59
69
  - lib/paymill/payment.rb
70
+ - lib/paymill/preauthorization.rb
71
+ - lib/paymill/refund.rb
60
72
  - lib/paymill/subscription.rb
61
73
  - lib/paymill/transaction.rb
62
74
  - lib/paymill/version.rb
63
75
  - lib/paymill/webhook.rb
64
76
  - paymill.gemspec
77
+ - spec/paymill/base_spec.rb
65
78
  - spec/paymill/client_spec.rb
66
79
  - spec/paymill/offer_spec.rb
67
80
  - spec/paymill/payment_spec.rb
81
+ - spec/paymill/preauthorization_spec.rb
82
+ - spec/paymill/refund_spec.rb
68
83
  - spec/paymill/subscription_spec.rb
69
84
  - spec/paymill/transaction_spec.rb
70
85
  - spec/paymill/webhook_spec.rb
@@ -84,7 +99,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
84
99
  version: '0'
85
100
  segments:
86
101
  - 0
87
- hash: 3327817462008033572
102
+ hash: 216517499575340974
88
103
  required_rubygems_version: !ruby/object:Gem::Requirement
89
104
  none: false
90
105
  requirements:
@@ -93,17 +108,20 @@ required_rubygems_version: !ruby/object:Gem::Requirement
93
108
  version: '0'
94
109
  segments:
95
110
  - 0
96
- hash: 3327817462008033572
111
+ hash: 216517499575340974
97
112
  requirements: []
98
113
  rubyforge_project:
99
- rubygems_version: 1.8.10
114
+ rubygems_version: 1.8.19
100
115
  signing_key:
101
116
  specification_version: 3
102
117
  summary: API wrapper for Paymill.
103
118
  test_files:
119
+ - spec/paymill/base_spec.rb
104
120
  - spec/paymill/client_spec.rb
105
121
  - spec/paymill/offer_spec.rb
106
122
  - spec/paymill/payment_spec.rb
123
+ - spec/paymill/preauthorization_spec.rb
124
+ - spec/paymill/refund_spec.rb
107
125
  - spec/paymill/subscription_spec.rb
108
126
  - spec/paymill/transaction_spec.rb
109
127
  - spec/paymill/webhook_spec.rb