lago-ruby-client 0.15.1.pre.alpha → 0.18.0.pre.alpha

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: a85aba24c145cd3473895ebd058d026ac59651368ba36be71fc1ae4223224918
4
- data.tar.gz: 2fe6bc15aa9a3b7c32ac4b8ba24158de1eeffeaaed68db2b04b87940e005dd2c
3
+ metadata.gz: 4de2ae6f7cb42002cb3657858eaa66c140bc8371e635746b6491063b09b66924
4
+ data.tar.gz: 7d6328c8f7deb3ce00b048de9d402d50fdf331b333e9e12b91a244a52987b8cc
5
5
  SHA512:
6
- metadata.gz: fa379557b825d4d3dfebfadb56886084abdd9eddb488aa2b7d5108f0baaa32d2cbb706a7e6e7ac9e594ff30326a6c141b2188a4ddec461f7f0e0e65123b4542d
7
- data.tar.gz: 7ab4e1b50482619e3cc7e9dbedb65678b2be3a114557100b287e40ac04eb6698b379cac4a678c87af036bf5228749a638933c65439b0c5bb26cc5cdb92d623d2
6
+ metadata.gz: ce0bcc5352cff84a4afe4c186fedf4f2642d4ff3818b9d0c2e95b3c67dcfbedc7fc67dd800295d4c7356a7f409e38b9040bc7c2e73d17c4d388a95e73579ccdb
7
+ data.tar.gz: 7a075b428a2324e0c26deb7230e27b64fe0d272c9b685d4c1cc412ff5ed442f2fcf2a7b956ae20ee295b7a0c0b97c5f54ae2fe5664df7e55bde998b8733c566c
@@ -2,8 +2,8 @@
2
2
 
3
3
  module Lago
4
4
  module Api
5
- BASE_URL = 'https://api.getlago.com/'.freeze
6
- API_PATH = 'api/v1/'.freeze
5
+ BASE_URL = 'https://api.getlago.com/'
6
+ API_PATH = 'api/v1/'
7
7
 
8
8
  class Client
9
9
  attr_reader :api_key, :api_url
@@ -51,6 +51,10 @@ module Lago
51
51
  Lago::Api::Resources::BillableMetric.new(self)
52
52
  end
53
53
 
54
+ def credit_notes
55
+ Lago::Api::Resources::CreditNote.new(self)
56
+ end
57
+
54
58
  def plans
55
59
  Lago::Api::Resources::Plan.new(self)
56
60
  end
@@ -74,6 +78,10 @@ module Lago
74
78
  def wallet_transactions
75
79
  Lago::Api::Resources::WalletTransaction.new(self)
76
80
  end
81
+
82
+ def webhooks
83
+ Lago::Api::Resources::Webhook.new(self)
84
+ end
77
85
  end
78
86
  end
79
87
  end
@@ -86,6 +86,8 @@ module Lago
86
86
  raise_error(response) unless RESPONSE_SUCCESS_CODES.include?(response.code.to_i)
87
87
 
88
88
  response.body.empty? ? true : JSON.parse(response.body)
89
+ rescue JSON::ParserError
90
+ response.body
89
91
  end
90
92
 
91
93
  def http_client
@@ -19,7 +19,7 @@ module Lago
19
19
  add_on_code: params[:add_on_code],
20
20
  amount_cents: params[:amount_cents],
21
21
  amount_currency: params[:amount_currency]
22
- }
22
+ }.compact
23
23
  }
24
24
  end
25
25
  end
@@ -18,8 +18,11 @@ module Lago
18
18
  external_customer_id: params[:external_customer_id],
19
19
  coupon_code: params[:coupon_code],
20
20
  amount_cents: params[:amount_cents],
21
+ percentage_rate: params[:percentage_rate],
22
+ frequency: params[:frequency],
23
+ frequency_duration: params[:frequency_duration],
21
24
  amount_currency: params[:amount_currency]
22
- }
25
+ }.compact
23
26
  }
24
27
  end
25
28
  end
@@ -19,8 +19,13 @@ module Lago
19
19
  code: params[:code],
20
20
  amount_cents: params[:amount_cents],
21
21
  amount_currency: params[:amount_currency],
22
+ percentage_rate: params[:percentage_rate],
23
+ coupon_type: params[:coupon_type],
24
+ reusable: params[:reusable],
25
+ frequency: params[:frequency],
26
+ frequency_duration: params[:frequency_duration],
22
27
  expiration: params[:expiration],
23
- expiration_duration: params[:expiration_duration]
28
+ expiration_date: params[:expiration_date]
24
29
  }.compact
25
30
  }
26
31
  end
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Lago
4
+ module Api
5
+ module Resources
6
+ class CreditNote < Base
7
+ def api_resource
8
+ 'credit_notes'
9
+ end
10
+
11
+ def root_name
12
+ 'credit_note'
13
+ end
14
+
15
+ def whitelist_params(params)
16
+ result_hash = {
17
+ invoice_id: params[:invoice_id],
18
+ reason: params[:reason],
19
+ refund_status: params[:refund_status]
20
+ }.compact
21
+
22
+ whitelist_items(params[:items] || []).tap do |items|
23
+ result_hash[:items] = items unless items.empty?
24
+ end
25
+
26
+ { root_name => result_hash }
27
+ end
28
+
29
+ def whitelist_items(items)
30
+ items.each_with_object([]) do |item, result|
31
+ filtered_item = (item || {}).slice(
32
+ :fee_id, :credit_amount_cents, :refund_amount_cents
33
+ )
34
+
35
+ result << filtered_item unless filtered_item.empty?
36
+ end
37
+ end
38
+
39
+ def download(credit_note_id)
40
+ path = "/api/v1/credit_notes/#{credit_note_id}/download"
41
+ response = connection.post({}, path)
42
+
43
+ JSON.parse(response.to_json, object_class: OpenStruct)
44
+ end
45
+
46
+ def void(credit_note_id)
47
+ path = "/api/v1/credit_notes/#{credit_note_id}/void"
48
+ response = connection.put(
49
+ path,
50
+ identifier: nil,
51
+ body: {}
52
+ )
53
+
54
+ JSON.parse(response.to_json, object_class: OpenStruct)
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -50,6 +50,7 @@ module Lago
50
50
  :payment_provider,
51
51
  :provider_customer_id,
52
52
  :sync,
53
+ :sync_with_provider,
53
54
  :vat_rate,
54
55
  )
55
56
  end
@@ -22,8 +22,8 @@ module Lago
22
22
  def whitelist_params(params)
23
23
  {
24
24
  root_name => {
25
- status: params[:status]
26
- }
25
+ payment_status: params[:payment_status],
26
+ },
27
27
  }
28
28
  end
29
29
  end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Lago
4
+ module Api
5
+ module Resources
6
+ class Webhook < Base
7
+ def api_resource
8
+ 'webhooks'
9
+ end
10
+
11
+ def public_key
12
+ path = '/api/v1/webhooks/public_key'
13
+
14
+ webhooks_public_key = connection.get(path, identifier: nil)
15
+ OpenSSL::PKey::RSA.new(Base64.decode64(webhooks_public_key))
16
+ end
17
+
18
+ def valid_signature?(signature, webhook_payload, cached_key = public_key)
19
+ decoded_signature = JWT.decode(
20
+ signature,
21
+ cached_key,
22
+ true,
23
+ {
24
+ algorithm: 'RS256',
25
+ iss: client.api_url || Lago::Api::BASE_URL,
26
+ verify_iss: true,
27
+ },
28
+ ).first
29
+
30
+ decoded_signature['data'] == webhook_payload.to_json
31
+ rescue JWT::InvalidIssuerError, JWT::VerificationError
32
+ false
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
data/lib/lago/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Lago
4
- VERSION = '0.15.1-alpha'
4
+ VERSION = '0.18.0-alpha'
5
5
  end
@@ -3,6 +3,8 @@
3
3
  require 'net/http'
4
4
  require 'uri'
5
5
  require 'json'
6
+ require 'openssl'
7
+ require 'jwt'
6
8
 
7
9
  require 'lago/version'
8
10
  require 'lago/api/client'
@@ -10,17 +12,19 @@ require 'lago/api/connection'
10
12
  require 'lago/api/http_error'
11
13
 
12
14
  require 'lago/api/resources/base'
13
- require 'lago/api/resources/applied_coupon'
15
+ require 'lago/api/resources/add_on'
14
16
  require 'lago/api/resources/applied_add_on'
17
+ require 'lago/api/resources/applied_coupon'
18
+ require 'lago/api/resources/billable_metric'
19
+ require 'lago/api/resources/coupon'
20
+ require 'lago/api/resources/credit_note'
15
21
  require 'lago/api/resources/customer'
16
- require 'lago/api/resources/invoice'
17
22
  require 'lago/api/resources/event'
18
23
  require 'lago/api/resources/group'
19
- require 'lago/api/resources/subscription'
20
- require 'lago/api/resources/billable_metric'
21
- require 'lago/api/resources/plan'
22
- require 'lago/api/resources/coupon'
23
- require 'lago/api/resources/add_on'
24
+ require 'lago/api/resources/invoice'
24
25
  require 'lago/api/resources/organization'
26
+ require 'lago/api/resources/plan'
27
+ require 'lago/api/resources/subscription'
25
28
  require 'lago/api/resources/wallet'
26
29
  require 'lago/api/resources/wallet_transaction'
30
+ require 'lago/api/resources/webhook'
metadata CHANGED
@@ -1,15 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lago-ruby-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.15.1.pre.alpha
4
+ version: 0.18.0.pre.alpha
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lovro Colic
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-11-21 00:00:00.000000000 Z
11
+ date: 2022-12-15 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: jwt
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: openssl
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
13
41
  - !ruby/object:Gem::Dependency
14
42
  name: debug
15
43
  requirement: !ruby/object:Gem::Requirement
@@ -94,7 +122,7 @@ dependencies:
94
122
  - - ">="
95
123
  - !ruby/object:Gem::Version
96
124
  version: '0'
97
- description:
125
+ description:
98
126
  email:
99
127
  - lovro@getlago.com
100
128
  executables: []
@@ -111,6 +139,7 @@ files:
111
139
  - lib/lago/api/resources/base.rb
112
140
  - lib/lago/api/resources/billable_metric.rb
113
141
  - lib/lago/api/resources/coupon.rb
142
+ - lib/lago/api/resources/credit_note.rb
114
143
  - lib/lago/api/resources/customer.rb
115
144
  - lib/lago/api/resources/event.rb
116
145
  - lib/lago/api/resources/group.rb
@@ -120,6 +149,7 @@ files:
120
149
  - lib/lago/api/resources/subscription.rb
121
150
  - lib/lago/api/resources/wallet.rb
122
151
  - lib/lago/api/resources/wallet_transaction.rb
152
+ - lib/lago/api/resources/webhook.rb
123
153
  - lib/lago/version.rb
124
154
  homepage: https://github.com/getlago/lago-ruby-client
125
155
  licenses:
@@ -128,7 +158,7 @@ metadata:
128
158
  homepage_uri: https://www.getlago.com/
129
159
  source_code_uri: https://github.com/getlago/lago-ruby-client
130
160
  documentation_uri: https://doc.getlago.com
131
- post_install_message:
161
+ post_install_message:
132
162
  rdoc_options: []
133
163
  require_paths:
134
164
  - lib
@@ -143,8 +173,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
143
173
  - !ruby/object:Gem::Version
144
174
  version: 1.3.1
145
175
  requirements: []
146
- rubygems_version: 3.2.15
147
- signing_key:
176
+ rubygems_version: 3.2.33
177
+ signing_key:
148
178
  specification_version: 4
149
179
  summary: Lago Rest API client
150
180
  test_files: []