paypro 1.0.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/build.yml +54 -0
- data/.gitignore +8 -47
- data/.rspec +3 -0
- data/.rubocop.yml +37 -15
- data/Gemfile +12 -2
- data/LICENSE +1 -1
- data/README.md +65 -23
- data/Rakefile +5 -1
- data/bin/console +8 -0
- data/bin/setup +8 -0
- data/lib/data/{ca-bundle.crt → cacert.pem} +617 -298
- data/lib/pay_pro/api_client.rb +131 -0
- data/lib/pay_pro/client.rb +67 -0
- data/lib/pay_pro/config.rb +30 -0
- data/lib/pay_pro/endpoint.rb +19 -0
- data/lib/pay_pro/endpoints/chargebacks.rb +14 -0
- data/lib/pay_pro/endpoints/customers.rb +15 -0
- data/lib/pay_pro/endpoints/events.rb +14 -0
- data/lib/pay_pro/endpoints/installment_plan_periods.rb +13 -0
- data/lib/pay_pro/endpoints/installment_plans.rb +15 -0
- data/lib/pay_pro/endpoints/mandates.rb +15 -0
- data/lib/pay_pro/endpoints/pay_methods.rb +13 -0
- data/lib/pay_pro/endpoints/payments.rb +15 -0
- data/lib/pay_pro/endpoints/refunds.rb +14 -0
- data/lib/pay_pro/endpoints/subscription_periods.rb +13 -0
- data/lib/pay_pro/endpoints/subscriptions.rb +15 -0
- data/lib/pay_pro/endpoints/webhooks.rb +15 -0
- data/lib/pay_pro/entities/chargeback.rb +5 -0
- data/lib/pay_pro/entities/customer.rb +10 -0
- data/lib/pay_pro/entities/entity.rb +41 -0
- data/lib/pay_pro/entities/event.rb +5 -0
- data/lib/pay_pro/entities/installment_plan.rb +29 -0
- data/lib/pay_pro/entities/installment_plan_period.rb +5 -0
- data/lib/pay_pro/entities/list.rb +65 -0
- data/lib/pay_pro/entities/mandate.rb +5 -0
- data/lib/pay_pro/entities/pay_method.rb +6 -0
- data/lib/pay_pro/entities/payment.rb +23 -0
- data/lib/pay_pro/entities/refund.rb +11 -0
- data/lib/pay_pro/entities/resource.rb +13 -0
- data/lib/pay_pro/entities/subscription.rb +38 -0
- data/lib/pay_pro/entities/subscription_period.rb +5 -0
- data/lib/pay_pro/entities/webhook.rb +30 -0
- data/lib/pay_pro/errors.rb +36 -0
- data/lib/pay_pro/operations/creatable.rb +11 -0
- data/lib/pay_pro/operations/deletable.rb +11 -0
- data/lib/pay_pro/operations/getable.rb +11 -0
- data/lib/pay_pro/operations/listable.rb +11 -0
- data/lib/pay_pro/operations/requestable.rb +12 -0
- data/lib/pay_pro/operations/updatable.rb +11 -0
- data/lib/pay_pro/response.rb +21 -0
- data/lib/pay_pro/signature.rb +59 -0
- data/lib/pay_pro/util.rb +48 -0
- data/lib/{paypro → pay_pro}/version.rb +1 -1
- data/lib/pay_pro.rb +77 -0
- data/paypro.gemspec +18 -11
- metadata +67 -48
- data/.circleci/config.yml +0 -74
- data/VERSION +0 -1
- data/examples/create_payment.rb +0 -7
- data/lib/paypro/client.rb +0 -68
- data/lib/paypro/errors.rb +0 -7
- data/lib/paypro.rb +0 -16
- data/spec/paypro/client_spec.rb +0 -114
- data/spec/paypro_spec.rb +0 -13
- data/spec/spec_helper.rb +0 -7
data/examples/create_payment.rb
DELETED
data/lib/paypro/client.rb
DELETED
@@ -1,68 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module PayPro
|
4
|
-
# Client class to connect to the PayPro V1 API.
|
5
|
-
# Requires an API key to authenticate API calls, you
|
6
|
-
# can also supply your own Faraday connection instead of the default one.
|
7
|
-
# This can be useful if you want to add more middleware or want finer
|
8
|
-
# control of the connection being used.
|
9
|
-
class Client
|
10
|
-
attr_accessor :command, :params
|
11
|
-
|
12
|
-
def initialize(api_key, conn = default_conn)
|
13
|
-
@api_key = api_key
|
14
|
-
@params = {}
|
15
|
-
@conn = conn
|
16
|
-
end
|
17
|
-
|
18
|
-
# Executes the API call and handles the response. Will raise errors if
|
19
|
-
# there were problems while connecting or handeling the response.
|
20
|
-
def execute
|
21
|
-
response = @conn.post do |req|
|
22
|
-
req.body = body
|
23
|
-
end
|
24
|
-
handle_response(response)
|
25
|
-
rescue Faraday::ClientError => e
|
26
|
-
raise ConnectionError, "Could not connect to the PayPro API: #{e.inspect}"
|
27
|
-
end
|
28
|
-
|
29
|
-
# Returns the body that is used in the POST request.
|
30
|
-
def body
|
31
|
-
{
|
32
|
-
apikey: @api_key,
|
33
|
-
command: @command,
|
34
|
-
params: JSON.generate(@params)
|
35
|
-
}
|
36
|
-
end
|
37
|
-
|
38
|
-
private
|
39
|
-
|
40
|
-
def ca_bundle_file
|
41
|
-
PayPro::CA_BUNDLE_FILE
|
42
|
-
end
|
43
|
-
|
44
|
-
def cert_store
|
45
|
-
cert_store = OpenSSL::X509::Store.new
|
46
|
-
cert_store.add_file ca_bundle_file
|
47
|
-
cert_store
|
48
|
-
end
|
49
|
-
|
50
|
-
def default_conn
|
51
|
-
Faraday.new(
|
52
|
-
PayPro::API_URL,
|
53
|
-
ssl: {
|
54
|
-
cert_store: cert_store,
|
55
|
-
verify: true
|
56
|
-
}
|
57
|
-
)
|
58
|
-
end
|
59
|
-
|
60
|
-
def handle_response(response)
|
61
|
-
parsed_response = JSON.parse(response.body)
|
62
|
-
@params = {}
|
63
|
-
parsed_response
|
64
|
-
rescue JSON::ParserError
|
65
|
-
raise InvalidResponseError, "The API request returned an error or is invalid: #{response.body}"
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
data/lib/paypro/errors.rb
DELETED
data/lib/paypro.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'openssl'
|
4
|
-
require 'json'
|
5
|
-
|
6
|
-
require 'faraday'
|
7
|
-
|
8
|
-
require 'paypro/client'
|
9
|
-
require 'paypro/errors'
|
10
|
-
require 'paypro/version'
|
11
|
-
|
12
|
-
module PayPro
|
13
|
-
CA_BUNDLE_FILE = "#{File.dirname(__FILE__)}/data/ca-bundle.crt"
|
14
|
-
API_URL = 'https://www.paypro.nl/post_api'
|
15
|
-
API_VERSION = 'v1'
|
16
|
-
end
|
data/spec/paypro/client_spec.rb
DELETED
@@ -1,114 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe PayPro::Client do
|
6
|
-
let(:api_key) { 'a16e84b3ef5a80ef9af289d37788e87e' }
|
7
|
-
let(:client) { described_class.new(api_key) }
|
8
|
-
|
9
|
-
describe '#initialize' do
|
10
|
-
let(:client) { described_class.new(api_key) }
|
11
|
-
|
12
|
-
it 'sets params to an empty hash' do
|
13
|
-
expect(client.params).to eql({})
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
describe '#body' do
|
18
|
-
let(:command) { 'create_payment' }
|
19
|
-
|
20
|
-
subject { client.body }
|
21
|
-
|
22
|
-
before { client.command = command }
|
23
|
-
|
24
|
-
it { is_expected.to include(apikey: api_key) }
|
25
|
-
it { is_expected.to include(command: command) }
|
26
|
-
|
27
|
-
context 'when params is empty' do
|
28
|
-
it { is_expected.to include(params: '{}') }
|
29
|
-
end
|
30
|
-
|
31
|
-
context 'when params is not empty' do
|
32
|
-
before { client.params = { amount: 500 } }
|
33
|
-
it { is_expected.to include(params: '{"amount":500}') }
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
describe '#execute' do
|
38
|
-
let(:client) { described_class.new(api_key, conn) }
|
39
|
-
let(:conn) do
|
40
|
-
Faraday.new do |builder|
|
41
|
-
builder.adapter :test, stubs
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
subject { client.execute }
|
46
|
-
|
47
|
-
context 'when connection fails' do
|
48
|
-
let(:conn) { double }
|
49
|
-
|
50
|
-
before { allow(conn).to receive(:post).and_raise(Faraday::ClientError, 'Message') }
|
51
|
-
|
52
|
-
it 'raises a PayPro::Connection error' do
|
53
|
-
expect { subject }.to raise_error(PayPro::ConnectionError, kind_of(String))
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
context 'when body is invalid json' do
|
58
|
-
let(:stubs) do
|
59
|
-
Faraday::Adapter::Test::Stubs.new do |stub|
|
60
|
-
stub.post('/') { |_| [200, {}, 'invalid json }'] }
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
it 'raises a PayPro::InvalidResponse error' do
|
65
|
-
expect { subject }.to raise_error(
|
66
|
-
PayPro::InvalidResponseError,
|
67
|
-
'The API request returned an error or is invalid: invalid json }'
|
68
|
-
)
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
context 'when api returns an error' do
|
73
|
-
let(:stubs) do
|
74
|
-
Faraday::Adapter::Test::Stubs.new do |stub|
|
75
|
-
stub.post('/') { |_| [200, {}, 'Invalid amount'] }
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
it 'raises a PayPro::InvalidResponse error' do
|
80
|
-
expect { subject }.to raise_error(
|
81
|
-
PayPro::InvalidResponseError,
|
82
|
-
'The API request returned an error or is invalid: Invalid amount'
|
83
|
-
)
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
context 'when api call is valid' do
|
88
|
-
let(:stubs) do
|
89
|
-
Faraday::Adapter::Test::Stubs.new do |stub|
|
90
|
-
stub.post('/') do |_|
|
91
|
-
[
|
92
|
-
200,
|
93
|
-
{},
|
94
|
-
'{"payment_url":"https://paypro.nl/betalen/payment_hash","payment_hash":"payment_hash"}'
|
95
|
-
]
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
before { client.params = { amount: 500 } }
|
101
|
-
|
102
|
-
it 'returns a hash with the response' do
|
103
|
-
expect(subject).to include(
|
104
|
-
'payment_url' => 'https://paypro.nl/betalen/payment_hash',
|
105
|
-
'payment_hash' => 'payment_hash'
|
106
|
-
)
|
107
|
-
end
|
108
|
-
|
109
|
-
it 'clears the old params' do
|
110
|
-
expect { subject }.to change { client.params }.from(amount: 500).to({})
|
111
|
-
end
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
data/spec/paypro_spec.rb
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe PayPro do
|
6
|
-
it 'returns the correct api url' do
|
7
|
-
expect(described_class::API_URL).to eql 'https://www.paypro.nl/post_api'
|
8
|
-
end
|
9
|
-
|
10
|
-
it 'returns the correct path for ca-bundle.crt' do
|
11
|
-
expect(File).to exist(described_class::CA_BUNDLE_FILE)
|
12
|
-
end
|
13
|
-
end
|