paypro 0.0.1 → 2.0.0

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