tipalti-ruby 0.3.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 03acb5dc31ac3a0e27fa741be01e2907a530f7aae8eb1bd595b2102fa252157a
4
- data.tar.gz: 9c8f59917796065a0f429d512c57a3f58075ce162d95be2088584ed087c1599c
3
+ metadata.gz: fbb867289f56f9dfd500df89903857d6c73fe258000f0084fe15f9b9d491e515
4
+ data.tar.gz: 0bea49d4b1bca9b722280b59063229769a17e6d6e2b842ab719f37c552bf6faa
5
5
  SHA512:
6
- metadata.gz: ceb685c7bd0d0d340be0615905b96778144bf9877c5be553da23eb3a65f56e6449ab1448d6327b574e9f858b1ba84b772311e2ca35e456fbb84b90678b9fef44
7
- data.tar.gz: e39a013089b6ba6ee17d192f2a72fda89c49ab979d6efd7058a092c2df386bf6fcb03c883b84d71f1fdefccbd2a8afdd82c921735ed743a44eb82d944cb53297
6
+ metadata.gz: 745877696d1638187c04880bb3d0408f6b2a7dcbe2a8d6ca1b9e027ef12d00acb5906d481f5b3e1bac0fba339dcbb19e81da1d1355e03f95efc1dd16177f24cf
7
+ data.tar.gz: ac4053987f5eae061d1edf031467894cc3948d51ebd8f6730c5109f0c49d44979629920e1c9935dd94d0adf8f232028ff895bda13062a64f5f798ceae6b912a5
data/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ ## v0.5.0
2
+
3
+ - Made token refresh use form encoded body
4
+
5
+ ## v0.4.0
6
+
7
+ - Added IPN verification
8
+
9
+ ## v0.3.0
10
+
11
+ - Added payment get endpoint
12
+ - Added payment batch create endpoint
13
+ - Added payment batch instructions get endpoint
14
+
1
15
  ## v0.2.0
2
16
 
3
17
  - Added payees get endpoint
data/README.md CHANGED
@@ -18,6 +18,8 @@ Then `bundle install`.
18
18
 
19
19
  ## Usage
20
20
 
21
+ ### API Client
22
+
21
23
  The Tipalti API uses OAuth to authenticate API requests.
22
24
 
23
25
  First you need ot get an access code externally by following the [Tipalti authorization flow](https://documentation.tipalti.com/docs/authorization-flow).
@@ -43,7 +45,7 @@ client = Tipalti::Client.new(
43
45
  )
44
46
  ```
45
47
 
46
- ### Endpoints
48
+ ### API Endpoints
47
49
 
48
50
  For use of each endpoint and available attributes or filtering criteria, please consult the [Tipalti API reference](https://documentation.tipalti.com/reference/introduction).
49
51
 
@@ -93,6 +95,7 @@ Example: `client.payment_batch_instructions_get('3456789')`
93
95
 
94
96
  [API docs](https://documentation.tipalti.com/reference/get_api-v1-payments-id)
95
97
 
98
+
96
99
  Example: `client.payment_get('123abc')`
97
100
 
98
101
  ### Token Management
@@ -123,6 +126,33 @@ Any error code returned by the Tipalti API will result in one of the following e
123
126
  |503| Tipalti::ServiceUnavailable|
124
127
  |500| Tipalti::ServerError|
125
128
 
129
+ ### IPNs
130
+
131
+ Tiplati uses an IPN (instance payment notification) messaging service that enables you to receive notifications from Tipalti. Notifications are triggered when defined events occur (e.g., changes in payee details, system events and payment statuses).
132
+
133
+ To manage IPNs you will need to instantiate a IPN instance like so.
134
+
135
+ ```ruby
136
+ ipn = Tipalti::Ipn.new(
137
+ payload: '...', # The raw payload received to your server from the Tipalti IPN
138
+ )
139
+ ```
140
+
141
+ You can use the Tipalti sandbox by setting `ipn.sanbox = true` or as part of the initialization
142
+
143
+ ```ruby
144
+ ipn = Tipalti::Ipn.new(
145
+ ...
146
+ sandbox: true
147
+ )
148
+ ```
149
+
150
+ #### Verify
151
+
152
+ [API docs](https://support.tipalti.com/Content/Topics/Development/IPNs/ipnprotocol.htm#AcknowledgeAndVerifyIPN)
153
+
154
+ Example: `ipn.verify`
155
+
126
156
  ## License
127
157
 
128
158
  Copyright (C) 2023 Jordan Ell. See [LICENSE](https://github.com/riipen/tipalti-ruby/blob/master/LICENSE.md) for details.
@@ -3,13 +3,19 @@
3
3
  module Tipalti
4
4
  module Actions
5
5
  module Token
6
- def token_refresh
6
+ def token_refresh # rubocop:disable Metrics/MethodLength
7
7
  response = connection_token.post("/connect/token",
8
- client_id: @client_id,
9
- client_secret: @client_secret,
10
- grant_type: "refresh_token",
11
- refresh_token: @refresh_token,
12
- code_verifier: @code_verifier)
8
+ {
9
+ client_id: @client_id,
10
+ client_secret: @client_secret,
11
+ grant_type: "refresh_token",
12
+ refresh_token: @refresh_token,
13
+ code_verifier: @code_verifier
14
+ },
15
+ {
16
+ body: :form,
17
+ content_type: "application/x-www-form-urlencoded"
18
+ })
13
19
 
14
20
  # Refresh the client values inline
15
21
  @access_token = response["access_token"]
@@ -32,7 +32,7 @@ module Tipalti
32
32
  end
33
33
 
34
34
  def connection_token
35
- Connection.new(access_token: @access_token, url: token_url)
35
+ Connection.new(url: token_url)
36
36
  end
37
37
 
38
38
  def token_url
@@ -23,20 +23,23 @@ module Tipalti
23
23
  request(:head, path, params)
24
24
  end
25
25
 
26
- def post(path, **params)
27
- request(:post, path, params)
26
+ def post(path, params = {}, options = {})
27
+ request(:post, path, params, options)
28
28
  end
29
29
 
30
30
  def put(path, **params)
31
31
  request(:put, path, params)
32
32
  end
33
33
 
34
- private
35
-
36
- def request(method, path, params)
34
+ def request(method, path, params, options = {}) # rubocop:disable Metrics/MethodLength
37
35
  response = connection.public_send(method, path, params) do |request|
38
36
  request.headers["accept"] = "application/json"
39
37
  request.headers["authorization"] = "Bearer #{@access_token}" if @access_token
38
+
39
+ if options[:body] == :form
40
+ request.headers["Content-Type"] = "application/x-www-form-urlencoded"
41
+ request.body = URI.encode_www_form(params)
42
+ end
40
43
  end
41
44
 
42
45
  error = Error.from_response(response)
@@ -46,6 +49,8 @@ module Tipalti
46
49
  response.body
47
50
  end
48
51
 
52
+ private
53
+
49
54
  def connection
50
55
  @connection ||= Faraday.new(url: @url) do |c|
51
56
  c.request :json, content_type: /\bjson$/
@@ -2,6 +2,8 @@
2
2
 
3
3
  module Tipalti
4
4
  class Error < StandardError
5
+ attr_reader :response
6
+
5
7
  def self.from_response(response) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength:
6
8
  klass =
7
9
  case response.status
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Tipalti
4
+ class Ipn
5
+ BASE_URL_P = "https://console.tipalti.com"
6
+ BASE_URL_S = "https://console.sandbox.tipalti.com"
7
+
8
+ attr_accessor :sandbox
9
+
10
+ def initialize(payload:, sandbox: false)
11
+ @payload = payload
12
+ @sandbox = sandbox
13
+ end
14
+
15
+ def base_url
16
+ @sandbox ? BASE_URL_S : BASE_URL_P
17
+ end
18
+
19
+ def connection
20
+ Connection.new(url: base_url)
21
+ end
22
+
23
+ def verify
24
+ connection.request(:post, "/notif/ipn.aspx", @payload)
25
+ end
26
+ end
27
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Tipalti
4
- VERSION = "0.3.0"
4
+ VERSION = "0.5.0"
5
5
  end
data/lib/tipalti-ruby.rb CHANGED
@@ -9,4 +9,5 @@ require "tipalti-ruby/actions/token"
9
9
  require "tipalti-ruby/client"
10
10
  require "tipalti-ruby/connection"
11
11
  require "tipalti-ruby/error"
12
+ require "tipalti-ruby/ipn"
12
13
  require "tipalti-ruby/version"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tipalti-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jordan Ell
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-08-10 00:00:00.000000000 Z
11
+ date: 2023-09-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -44,7 +44,7 @@ dependencies:
44
44
  - - "~>"
45
45
  - !ruby/object:Gem::Version
46
46
  version: '2.0'
47
- description: An API client for Tipalti in ruby.
47
+ description: Access the Tipalti REST API via OAuth2.
48
48
  email:
49
49
  - me@jordanell.com
50
50
  executables: []
@@ -68,6 +68,7 @@ files:
68
68
  - lib/tipalti-ruby/client.rb
69
69
  - lib/tipalti-ruby/connection.rb
70
70
  - lib/tipalti-ruby/error.rb
71
+ - lib/tipalti-ruby/ipn.rb
71
72
  - lib/tipalti-ruby/version.rb
72
73
  homepage: https://github.com/riipen/tipalti-ruby
73
74
  licenses: