paymill 0.4.0 → 0.5.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.
- checksums.yaml +4 -4
- data/.gitignore +0 -1
- data/Gemfile +0 -1
- data/Gemfile.lock +46 -0
- data/README.md +33 -2
- data/lib/paymill.rb +83 -6
- data/lib/paymill/preauthorization.rb +1 -1
- data/lib/paymill/request/base.rb +0 -1
- data/lib/paymill/request/connection.rb +21 -6
- data/lib/paymill/request/helpers.rb +36 -0
- data/lib/paymill/request/info.rb +1 -1
- data/lib/paymill/transaction.rb +1 -1
- data/lib/paymill/version.rb +1 -1
- data/spec/fake_logger.rb +4 -0
- data/spec/paymill/preauthorization_spec.rb +5 -3
- data/spec/paymill/refund_spec.rb +3 -3
- data/spec/paymill/request/base_spec.rb +2 -10
- data/spec/paymill/request/connection_spec.rb +29 -0
- data/spec/paymill/subscription_spec.rb +3 -3
- data/spec/paymill/transaction_spec.rb +3 -1
- data/spec/paymill_spec.rb +38 -4
- data/spec/spec_helper.rb +9 -1
- metadata +6 -3
- data/lib/data/paymill.crt +0 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 36143c4c83a0b1a6f4262c116eed8f02f625cd84
|
4
|
+
data.tar.gz: ff5abb43f1eb3d3a5fc0a40aaacf2fb81d2ccb9e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d065ea32c4f76cc9686062c22a39cd633700654b053308bc7a7d12fcc91e458f1223af4e48f77bbadede209a57f864377b2c2301ace2f98b5fc458b767716975
|
7
|
+
data.tar.gz: c3eb4e0fc17377743acd8d61c14858533fc84342f242ae3946c4fab7c9fa7e2fe564859e7bb833c4cc2e626d19496db9db4b57687e579ad2265218dfd9c56034
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
paymill (0.5.0)
|
5
|
+
json
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: http://rubygems.org/
|
9
|
+
specs:
|
10
|
+
addressable (2.3.2)
|
11
|
+
coderay (1.0.9)
|
12
|
+
crack (0.3.2)
|
13
|
+
diff-lcs (1.2.5)
|
14
|
+
json (1.8.1)
|
15
|
+
method_source (0.8.2)
|
16
|
+
pry (0.9.12.2)
|
17
|
+
coderay (~> 1.0.5)
|
18
|
+
method_source (~> 0.8)
|
19
|
+
slop (~> 3.4)
|
20
|
+
rake (0.9.2.2)
|
21
|
+
rspec (3.1.0)
|
22
|
+
rspec-core (~> 3.1.0)
|
23
|
+
rspec-expectations (~> 3.1.0)
|
24
|
+
rspec-mocks (~> 3.1.0)
|
25
|
+
rspec-core (3.1.7)
|
26
|
+
rspec-support (~> 3.1.0)
|
27
|
+
rspec-expectations (3.1.2)
|
28
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
29
|
+
rspec-support (~> 3.1.0)
|
30
|
+
rspec-mocks (3.1.3)
|
31
|
+
rspec-support (~> 3.1.0)
|
32
|
+
rspec-support (3.1.2)
|
33
|
+
slop (3.4.6)
|
34
|
+
webmock (1.9.0)
|
35
|
+
addressable (>= 2.2.7)
|
36
|
+
crack (>= 0.1.7)
|
37
|
+
|
38
|
+
PLATFORMS
|
39
|
+
ruby
|
40
|
+
|
41
|
+
DEPENDENCIES
|
42
|
+
paymill!
|
43
|
+
pry
|
44
|
+
rake
|
45
|
+
rspec
|
46
|
+
webmock
|
data/README.md
CHANGED
@@ -26,6 +26,21 @@ Then you have to set your API key:
|
|
26
26
|
|
27
27
|
Paymill.api_key = "your-api-key"
|
28
28
|
|
29
|
+
## Configuration
|
30
|
+
|
31
|
+
You can also set the API version, base endpoint and port:
|
32
|
+
|
33
|
+
Paymill.api_version = "v1"
|
34
|
+
Paymill.api_base = "0.0.0.0"
|
35
|
+
Paymill.api_port = 3000
|
36
|
+
|
37
|
+
### Logging
|
38
|
+
|
39
|
+
Out of the box paymill-ruby will log all requests and responses to `STDOUT`, you
|
40
|
+
can use any logger you want, though:
|
41
|
+
|
42
|
+
Paymill.logger = Logger.new(STDERR)
|
43
|
+
|
29
44
|
Clients
|
30
45
|
-------
|
31
46
|
|
@@ -57,7 +72,7 @@ operation:
|
|
57
72
|
To sort and filter collection lists of objects, use the `all` method
|
58
73
|
with an options hash. For example to find the most recent transactions
|
59
74
|
belonging to a client you can use the following code:
|
60
|
-
|
75
|
+
|
61
76
|
Paymill::Transaction.all(client: "<client_id>", order: "created_at_desc")
|
62
77
|
|
63
78
|
Please note that Transactions and Payments cannot be updated.
|
@@ -89,6 +104,22 @@ operation:
|
|
89
104
|
|
90
105
|
Paymill::Payment.all
|
91
106
|
|
107
|
+
Transactions
|
108
|
+
-----------
|
109
|
+
|
110
|
+
*[Paymill documentation on transactions](https://www.paymill.com/en-gb/documentation-3/reference/api-reference/#transactions)*
|
111
|
+
|
112
|
+
A transaction can be executed as following
|
113
|
+
|
114
|
+
params = {
|
115
|
+
:amount => 2000, # cents. Must be an integer
|
116
|
+
:currency => 'USD', # iso
|
117
|
+
:client => 'client_123', # client id. Use 'Paymill::Client'
|
118
|
+
:payment => 'payment_123', # payment id. Use 'Paymill::Payment'
|
119
|
+
:description => "some comment if needed"
|
120
|
+
}
|
121
|
+
Paymill::Transaction.create(params)
|
122
|
+
|
92
123
|
Offers
|
93
124
|
------
|
94
125
|
|
@@ -185,4 +216,4 @@ Note on Patches/Pull Requests
|
|
185
216
|
Copyright
|
186
217
|
======
|
187
218
|
|
188
|
-
Copyright (c) 2012-
|
219
|
+
Copyright (c) 2012-2014 dkd Internet Service GmbH, Stefan Sprenger. See LICENSE for details.
|
data/lib/paymill.rb
CHANGED
@@ -2,13 +2,19 @@ require "net/http"
|
|
2
2
|
require "net/https"
|
3
3
|
require "json"
|
4
4
|
require "paymill/version"
|
5
|
+
require "logger"
|
5
6
|
|
6
7
|
module Paymill
|
7
|
-
API_BASE
|
8
|
-
API_VERSION
|
9
|
-
ROOT_PATH
|
8
|
+
API_BASE = "api.paymill.com"
|
9
|
+
API_VERSION = "v2"
|
10
|
+
ROOT_PATH = File.dirname(__FILE__)
|
10
11
|
|
11
|
-
@@api_key
|
12
|
+
@@api_key = nil
|
13
|
+
@@api_base = API_BASE
|
14
|
+
@@api_version = API_VERSION
|
15
|
+
@@api_port = Net::HTTP.https_default_port
|
16
|
+
@@development = false
|
17
|
+
@@logger = Logger.new(STDOUT)
|
12
18
|
|
13
19
|
autoload :Base, "paymill/base"
|
14
20
|
autoload :Client, "paymill/client"
|
@@ -23,14 +29,15 @@ module Paymill
|
|
23
29
|
module Operations
|
24
30
|
autoload :All, "paymill/operations/all"
|
25
31
|
autoload :Create, "paymill/operations/create"
|
32
|
+
autoload :Delete, "paymill/operations/delete"
|
26
33
|
autoload :Find, "paymill/operations/find"
|
27
34
|
autoload :Update, "paymill/operations/update"
|
28
|
-
autoload :Delete, "paymill/operations/delete"
|
29
35
|
end
|
30
36
|
|
31
37
|
module Request
|
32
38
|
autoload :Base, "paymill/request/base"
|
33
39
|
autoload :Connection, "paymill/request/connection"
|
40
|
+
autoload :Helpers, "paymill/request/helpers"
|
34
41
|
autoload :Info, "paymill/request/info"
|
35
42
|
autoload :Validator, "paymill/request/validator"
|
36
43
|
end
|
@@ -39,7 +46,7 @@ module Paymill
|
|
39
46
|
class AuthenticationError < PaymillError; end
|
40
47
|
class APIError < PaymillError; end
|
41
48
|
|
42
|
-
# Returns the
|
49
|
+
# Returns the api key
|
43
50
|
#
|
44
51
|
# @return [String] The api key
|
45
52
|
def self.api_key
|
@@ -53,6 +60,76 @@ module Paymill
|
|
53
60
|
@@api_key = api_key
|
54
61
|
end
|
55
62
|
|
63
|
+
# Returns the api base endpoint
|
64
|
+
#
|
65
|
+
# @return [String] The api base endpoint
|
66
|
+
def self.api_base
|
67
|
+
@@api_base
|
68
|
+
end
|
69
|
+
|
70
|
+
# Sets the api base endpoint
|
71
|
+
#
|
72
|
+
# @param [String] api_base The api base endpoint
|
73
|
+
def self.api_base=(api_base)
|
74
|
+
@@api_base = api_base
|
75
|
+
end
|
76
|
+
|
77
|
+
# Returns the api version
|
78
|
+
#
|
79
|
+
# @return [String] The api version
|
80
|
+
def self.api_version
|
81
|
+
@@api_version
|
82
|
+
end
|
83
|
+
|
84
|
+
# Sets the api version
|
85
|
+
#
|
86
|
+
# @param [String] api_version The api version
|
87
|
+
def self.api_version=(api_version)
|
88
|
+
@@api_version = api_version
|
89
|
+
end
|
90
|
+
|
91
|
+
# Returns the api port
|
92
|
+
#
|
93
|
+
# @return [String] The api port
|
94
|
+
def self.api_port
|
95
|
+
@@api_port
|
96
|
+
end
|
97
|
+
|
98
|
+
# Sets the api port
|
99
|
+
#
|
100
|
+
# @param [String] api_port The api port
|
101
|
+
def self.api_port=(api_port)
|
102
|
+
@@api_port = api_port
|
103
|
+
end
|
104
|
+
|
105
|
+
# Returns true if the development mode is on
|
106
|
+
#
|
107
|
+
# @return [Boolean] Development mode on or not
|
108
|
+
def self.development?
|
109
|
+
@@development
|
110
|
+
end
|
111
|
+
|
112
|
+
# Sets the development mode
|
113
|
+
#
|
114
|
+
# @param [Boolean] development Development mode on or not
|
115
|
+
def self.development=(development)
|
116
|
+
@@development = development
|
117
|
+
end
|
118
|
+
|
119
|
+
# Returns the current logger
|
120
|
+
#
|
121
|
+
# @return [Logger] The current logger
|
122
|
+
def self.logger
|
123
|
+
@@logger
|
124
|
+
end
|
125
|
+
|
126
|
+
# Sets the logger for Paymill
|
127
|
+
#
|
128
|
+
# @param [Logger] logger The logger instance to be used
|
129
|
+
def self.logger=(logger)
|
130
|
+
@@logger = logger
|
131
|
+
end
|
132
|
+
|
56
133
|
# Makes a request against the Paymill API
|
57
134
|
#
|
58
135
|
# @param [Symbol] http_method The http method to use, must be one of :get, :post, :put and :delete
|
@@ -2,6 +2,6 @@ module Paymill
|
|
2
2
|
class Preauthorization < Base
|
3
3
|
include Paymill::Operations::Delete
|
4
4
|
|
5
|
-
attr_accessor :id, :amount, :status, :livemode, :payment, :preauthorization, :currency, :client
|
5
|
+
attr_accessor :id, :amount, :status, :livemode, :payment, :preauthorization, :currency, :client, :source
|
6
6
|
end
|
7
7
|
end
|
data/lib/paymill/request/base.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
module Paymill
|
2
2
|
module Request
|
3
3
|
class Connection
|
4
|
+
include Helpers
|
4
5
|
attr_reader :https
|
5
6
|
|
6
7
|
def initialize(request_info)
|
@@ -8,19 +9,19 @@ module Paymill
|
|
8
9
|
end
|
9
10
|
|
10
11
|
def setup_https
|
11
|
-
@https = Net::HTTP.new(
|
12
|
+
@https = Net::HTTP.new(Paymill.api_base, Paymill.api_port)
|
12
13
|
@https.use_ssl = true
|
13
|
-
@https.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
14
|
-
@https.ca_file = File.join(ROOT_PATH, "data/paymill.crt")
|
15
14
|
end
|
16
15
|
|
17
16
|
def request
|
18
|
-
https.start do |connection|
|
17
|
+
response = https.start do |connection|
|
19
18
|
https.request(https_request)
|
20
19
|
end
|
20
|
+
log_request_info(response)
|
21
|
+
response
|
21
22
|
end
|
22
23
|
|
23
|
-
|
24
|
+
private
|
24
25
|
|
25
26
|
def https_request
|
26
27
|
https_request = case @info.http_method
|
@@ -34,9 +35,23 @@ module Paymill
|
|
34
35
|
Net::HTTP::Get.new(@info.path_with_params(@info.url, @info.data))
|
35
36
|
end
|
36
37
|
https_request.basic_auth(Paymill.api_key, "")
|
37
|
-
|
38
|
+
|
39
|
+
if [:post, :put].include?(@info.http_method)
|
40
|
+
https_request.set_form_data(normalize_params(@info.data))
|
41
|
+
end
|
42
|
+
|
38
43
|
https_request
|
39
44
|
end
|
45
|
+
|
46
|
+
def log_request_info(response)
|
47
|
+
if @info
|
48
|
+
Paymill.logger.info "[Paymill] [#{current_time}] #{@info.http_method.upcase} #{@info.url} #{response.code}"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def current_time
|
53
|
+
Time.now.utc.strftime("%d/%b/%Y %H:%M:%S %Z")
|
54
|
+
end
|
40
55
|
end
|
41
56
|
end
|
42
57
|
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Paymill
|
2
|
+
module Request
|
3
|
+
module Helpers
|
4
|
+
def flatten_hash_keys(old_hash, new_hash={}, keys=nil)
|
5
|
+
old_hash.each do |key, value|
|
6
|
+
key = key.to_s
|
7
|
+
if value.is_a?(Hash)
|
8
|
+
all_keys_formatted = keys + "[#{key}]"
|
9
|
+
flatten_hash_keys(value, new_hash, all_keys_formatted)
|
10
|
+
else
|
11
|
+
new_hash[key] = value
|
12
|
+
end
|
13
|
+
end
|
14
|
+
new_hash
|
15
|
+
end
|
16
|
+
|
17
|
+
def normalize_params(params, key=nil)
|
18
|
+
params = flatten_hash_keys(params) if params.is_a?(Hash)
|
19
|
+
result = {}
|
20
|
+
params.each do |key, value|
|
21
|
+
case value
|
22
|
+
when Hash
|
23
|
+
result[key.to_s] = normalize_params(value)
|
24
|
+
when Array
|
25
|
+
value.each_with_index do |item_value, index|
|
26
|
+
result["#{key.to_s}[#{index}]"] = item_value.to_s
|
27
|
+
end
|
28
|
+
else
|
29
|
+
result[key.to_s] = value.to_s
|
30
|
+
end
|
31
|
+
end
|
32
|
+
result
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/paymill/request/info.rb
CHANGED
data/lib/paymill/transaction.rb
CHANGED
data/lib/paymill/version.rb
CHANGED
data/spec/fake_logger.rb
ADDED
@@ -2,10 +2,11 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
describe Paymill::Preauthorization do
|
4
4
|
let(:valid_attributes) do
|
5
|
-
{
|
6
|
-
payment: "pay_d43cf0ee969d9847512b",
|
5
|
+
{
|
6
|
+
payment: "pay_d43cf0ee969d9847512b",
|
7
7
|
amount: 4200,
|
8
|
-
currency: "EUR"
|
8
|
+
currency: "EUR",
|
9
|
+
source: "paymill-ruby"
|
9
10
|
}
|
10
11
|
end
|
11
12
|
|
@@ -18,6 +19,7 @@ describe Paymill::Preauthorization do
|
|
18
19
|
preauthorization.payment.should eql("pay_d43cf0ee969d9847512b")
|
19
20
|
preauthorization.amount.should eql(4200)
|
20
21
|
preauthorization.currency.should eql("EUR")
|
22
|
+
preauthorization.source.should eql("paymill-ruby")
|
21
23
|
end
|
22
24
|
end
|
23
25
|
|
data/spec/paymill/refund_spec.rb
CHANGED
@@ -2,13 +2,13 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
describe Paymill::Refund do
|
4
4
|
let(:valid_attributes) do
|
5
|
-
{
|
5
|
+
{
|
6
6
|
id: "refund_87bc404a95d5ce616049",
|
7
7
|
amount: "042",
|
8
8
|
status: "refunded",
|
9
9
|
description: nil,
|
10
10
|
livemode: false,
|
11
|
-
created_at: 1349947042,
|
11
|
+
created_at: 1349947042,
|
12
12
|
updated_at: 1349947042,
|
13
13
|
transaction: {
|
14
14
|
id: "tran_2848cb20a6bb578177db",
|
@@ -68,7 +68,7 @@ describe Paymill::Refund do
|
|
68
68
|
refund.amount.should eql("042")
|
69
69
|
refund.status.should eql("refunded")
|
70
70
|
refund.description.should be_nil
|
71
|
-
refund.livemode.should
|
71
|
+
refund.livemode.should eql(false)
|
72
72
|
=begin
|
73
73
|
refund.transaction[:refunds].should eql(
|
74
74
|
[
|
@@ -2,18 +2,10 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
describe Paymill::Request::Base do
|
4
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
5
|
it "performs an https request" do
|
14
6
|
Paymill.stub(:api_key).and_return("some key")
|
15
|
-
connection =
|
16
|
-
validator
|
7
|
+
connection = double
|
8
|
+
validator = double
|
17
9
|
Paymill::Request::Connection.stub(:new).and_return(connection)
|
18
10
|
Paymill::Request::Validator.stub(:new).and_return(validator)
|
19
11
|
|
@@ -21,5 +21,34 @@ describe Paymill::Request::Connection do
|
|
21
21
|
|
22
22
|
connection.request
|
23
23
|
end
|
24
|
+
|
25
|
+
it 'logs information about the request' do
|
26
|
+
info = double(http_method: :post, url: "/some/path", data: params)
|
27
|
+
connection = Paymill::Request::Connection.new(info)
|
28
|
+
connection.setup_https
|
29
|
+
connection.stub(:https_request)
|
30
|
+
connection.https.stub(:request).and_return(double(code: 200))
|
31
|
+
|
32
|
+
Paymill.logger.should_receive(:info)
|
33
|
+
|
34
|
+
connection.request
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "#https_request" do
|
39
|
+
it "correctly formats the form data" do
|
40
|
+
info = double(http_method: :post, url: "/some/path", data: params)
|
41
|
+
connection = Paymill::Request::Connection.new(info)
|
42
|
+
connection.setup_https
|
43
|
+
|
44
|
+
connection.__send__(:https_request).body.downcase.should eq("email=abc_abc.com&event_types%5b0%5d=transaction.created&event_types%5b1%5d=transaction.failed&event_types%5b2%5d=refund.created&event_types%5b3%5d=invoice.available")
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def params
|
49
|
+
{
|
50
|
+
email: "abc_abc.com",
|
51
|
+
event_types: ["transaction.created","transaction.failed", "refund.created", "invoice.available"]
|
52
|
+
}
|
24
53
|
end
|
25
54
|
end
|
@@ -31,8 +31,8 @@ describe Paymill::Subscription do
|
|
31
31
|
subscription.offer[:name].should eql("Nerd special")
|
32
32
|
subscription.offer[:amount].should eql(123)
|
33
33
|
subscription.offer[:interval].should eql("week")
|
34
|
-
subscription.livemode.should
|
35
|
-
subscription.cancel_at_period_end.should
|
34
|
+
subscription.livemode.should eql(false)
|
35
|
+
subscription.cancel_at_period_end.should eql(false)
|
36
36
|
subscription.client[:email].should eql("stefan.sprenger@dkd.de")
|
37
37
|
subscription.payment[:id].should eql("pay_3af44644dd6d25c820a8")
|
38
38
|
subscription.trial_start.to_i.should eql(1349945681)
|
@@ -118,7 +118,7 @@ describe Paymill::Subscription do
|
|
118
118
|
it "should set the returned attributes on the instance" do
|
119
119
|
Paymill.should_receive(:request).and_return("data" => {:cancel_at_period_end => true})
|
120
120
|
subscription.update_attributes({})
|
121
|
-
subscription.cancel_at_period_end.should
|
121
|
+
subscription.cancel_at_period_end.should eql(true)
|
122
122
|
end
|
123
123
|
end
|
124
124
|
end
|
@@ -17,7 +17,8 @@ describe Paymill::Transaction do
|
|
17
17
|
client: "client_a013c",
|
18
18
|
refunds: [
|
19
19
|
{:id => "refund_abc"}
|
20
|
-
]
|
20
|
+
],
|
21
|
+
source: 'paymill-ruby'
|
21
22
|
}
|
22
23
|
end
|
23
24
|
|
@@ -41,6 +42,7 @@ describe Paymill::Transaction do
|
|
41
42
|
transaction.refunds.should_not be_empty
|
42
43
|
transaction.refunds.first.should_not be_nil
|
43
44
|
transaction.refunds.first[:id].should eql("refund_abc")
|
45
|
+
transaction.source.should eql("paymill-ruby")
|
44
46
|
end
|
45
47
|
end
|
46
48
|
|
data/spec/paymill_spec.rb
CHANGED
@@ -4,30 +4,64 @@ describe Paymill do
|
|
4
4
|
describe ".request" do
|
5
5
|
context "given no api key exists" do
|
6
6
|
it "raises an authentication error" do
|
7
|
+
WebMock.stub_request(:get, /#{Paymill.api_base}/).to_return(:body => "{}", :status => 401)
|
7
8
|
expect { Paymill.request(:get, "clients", {}) }.to raise_error(Paymill::AuthenticationError)
|
8
9
|
end
|
9
10
|
end
|
10
11
|
|
11
12
|
context "with an invalid api key" do
|
12
13
|
before(:each) do
|
13
|
-
WebMock.stub_request(:any, /#{Paymill
|
14
|
+
WebMock.stub_request(:any, /#{Paymill.api_base}/).to_return(:body => "{}")
|
14
15
|
Paymill.api_key = "your-api-key"
|
15
16
|
end
|
16
17
|
|
17
18
|
it "attempts to get a url with one param" do
|
18
19
|
Paymill.request(:get, "transactions", { param_name: "param_value" })
|
19
|
-
WebMock.should have_requested(:get, "https://#{Paymill::api_key}:@#{Paymill::
|
20
|
+
WebMock.should have_requested(:get, "https://#{Paymill::api_key}:@#{Paymill::api_base}/#{Paymill::api_version}/transactions?param_name=param_value")
|
20
21
|
end
|
21
22
|
|
22
23
|
it "attempts to get a url with more than one param" do
|
23
24
|
Paymill.request(:get, "transactions", { client: "client_id", order: "created_at_desc" })
|
24
|
-
WebMock.should have_requested(:get, "https://#{Paymill::api_key}:@#{Paymill::
|
25
|
+
WebMock.should have_requested(:get, "https://#{Paymill::api_key}:@#{Paymill::api_base}/#{Paymill::api_version}/transactions?client=client_id&order=created_at_desc")
|
25
26
|
end
|
26
27
|
|
27
28
|
it "doesn't add a question mark if no params" do
|
28
29
|
Paymill.request(:get, "transactions", {})
|
29
|
-
WebMock.should have_requested(:get, "https://#{Paymill::api_key}:@#{Paymill::
|
30
|
+
WebMock.should have_requested(:get, "https://#{Paymill::api_key}:@#{Paymill::api_base}/#{Paymill::api_version}/transactions")
|
30
31
|
end
|
31
32
|
end
|
32
33
|
end
|
34
|
+
|
35
|
+
describe 'configurations' do
|
36
|
+
it 'allows you to set an api key' do
|
37
|
+
Paymill.api_key = 'xpto'
|
38
|
+
expect(Paymill.api_key).to eq 'xpto'
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'allows you to set an api base endpoint' do
|
42
|
+
Paymill.api_base = 'xpto'
|
43
|
+
expect(Paymill.api_base).to eq 'xpto'
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'allows you to set an api version' do
|
47
|
+
Paymill.api_version = 'v1'
|
48
|
+
expect(Paymill.api_version).to eq 'v1'
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'allows you to set an api port' do
|
52
|
+
Paymill.api_port = 3000
|
53
|
+
expect(Paymill.api_port).to eq 3000
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'allows to turn on development mode' do
|
57
|
+
Paymill.development = true
|
58
|
+
expect(Paymill.development?).to eql(true)
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'allows to choose a logger' do
|
62
|
+
logger = double(:logger)
|
63
|
+
Paymill.logger = logger
|
64
|
+
expect(Paymill.logger).to eq logger
|
65
|
+
end
|
66
|
+
end
|
33
67
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -2,9 +2,17 @@ $LOAD_PATH.unshift(File.dirname(__FILE__))
|
|
2
2
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
|
3
3
|
require "paymill"
|
4
4
|
require "rspec"
|
5
|
-
require "rspec/autorun"
|
6
5
|
require "webmock/rspec"
|
7
6
|
require "pry"
|
8
7
|
|
8
|
+
require "fake_logger"
|
9
|
+
Paymill.logger = FakeLogger.new
|
10
|
+
|
9
11
|
RSpec.configure do |config|
|
12
|
+
config.expect_with :rspec do |c|
|
13
|
+
c.syntax = [:should, :expect]
|
14
|
+
end
|
15
|
+
config.mock_with :rspec do |c|
|
16
|
+
c.syntax = [:should, :expect]
|
17
|
+
end
|
10
18
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: paymill
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stefan Sprenger
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-10-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -49,10 +49,10 @@ files:
|
|
49
49
|
- .rspec
|
50
50
|
- .travis.yml
|
51
51
|
- Gemfile
|
52
|
+
- Gemfile.lock
|
52
53
|
- LICENSE
|
53
54
|
- README.md
|
54
55
|
- Rakefile
|
55
|
-
- lib/data/paymill.crt
|
56
56
|
- lib/paymill.rb
|
57
57
|
- lib/paymill/base.rb
|
58
58
|
- lib/paymill/client.rb
|
@@ -67,6 +67,7 @@ files:
|
|
67
67
|
- lib/paymill/refund.rb
|
68
68
|
- lib/paymill/request/base.rb
|
69
69
|
- lib/paymill/request/connection.rb
|
70
|
+
- lib/paymill/request/helpers.rb
|
70
71
|
- lib/paymill/request/info.rb
|
71
72
|
- lib/paymill/request/validator.rb
|
72
73
|
- lib/paymill/subscription.rb
|
@@ -74,6 +75,7 @@ files:
|
|
74
75
|
- lib/paymill/version.rb
|
75
76
|
- lib/paymill/webhook.rb
|
76
77
|
- paymill.gemspec
|
78
|
+
- spec/fake_logger.rb
|
77
79
|
- spec/paymill/base_spec.rb
|
78
80
|
- spec/paymill/client_spec.rb
|
79
81
|
- spec/paymill/offer_spec.rb
|
@@ -113,6 +115,7 @@ signing_key:
|
|
113
115
|
specification_version: 4
|
114
116
|
summary: API wrapper for Paymill.
|
115
117
|
test_files:
|
118
|
+
- spec/fake_logger.rb
|
116
119
|
- spec/paymill/base_spec.rb
|
117
120
|
- spec/paymill/client_spec.rb
|
118
121
|
- spec/paymill/offer_spec.rb
|
data/lib/data/paymill.crt
DELETED
@@ -1,25 +0,0 @@
|
|
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-----
|