mollie-api-ruby 4.13.0 → 4.15.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/build.yml +1 -1
  3. data/CHANGELOG.md +13 -1
  4. data/README.md +4 -4
  5. data/examples/balances/get-primary.rb +1 -0
  6. data/examples/balances/get-report.rb +2 -0
  7. data/examples/balances/get.rb +1 -0
  8. data/examples/balances/list-transactions.rb +2 -0
  9. data/examples/balances/list.rb +1 -0
  10. data/examples/connect/authorize.rb +1 -1
  11. data/examples/connect/tokens.rb +1 -1
  12. data/examples/payment-links/create.rb +5 -0
  13. data/examples/payment-links/delete.rb +1 -0
  14. data/examples/payment-links/get.rb +1 -0
  15. data/examples/payment-links/list-payments.rb +2 -0
  16. data/examples/payment-links/list.rb +1 -0
  17. data/examples/payment-links/update.rb +5 -0
  18. data/lib/mollie/balance/report.rb +25 -0
  19. data/lib/mollie/balance/transaction.rb +41 -0
  20. data/lib/mollie/balance.rb +53 -0
  21. data/lib/mollie/base.rb +2 -0
  22. data/lib/mollie/list.rb +1 -1
  23. data/lib/mollie/method.rb +12 -0
  24. data/lib/mollie/payment_link.rb +70 -0
  25. data/lib/mollie/version.rb +1 -1
  26. data/lib/mollie.rb +4 -0
  27. data/mollie-api-ruby.gemspec +8 -1
  28. data/test/fixtures/balances/get.json +38 -0
  29. data/test/fixtures/balances/list.json +34 -0
  30. data/test/fixtures/balances/list_transactions.json +65 -0
  31. data/test/fixtures/balances/report.json +149 -0
  32. data/test/fixtures/payment_links/create.json +7 -0
  33. data/test/fixtures/payment_links/get.json +32 -0
  34. data/test/fixtures/payment_links/list-payments.json +31 -0
  35. data/test/fixtures/payment_links/list.json +31 -0
  36. data/test/fixtures/payment_links/update.json +4 -0
  37. data/test/mollie/balance/transaction_test.rb +36 -0
  38. data/test/mollie/balance_test.rb +108 -0
  39. data/test/mollie/payment_link_test.rb +100 -0
  40. metadata +79 -6
  41. data/.travis.yml +0 -15
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 58916be713b9cf5128476188f1b0e61dc51f04d9e41b48b09c053b923e9daf39
4
- data.tar.gz: 2f514f685d55211565be7197d5b9b36e587894582bdc515f4eb75ce19c481f10
3
+ metadata.gz: 06f14768975850db4a88530cf6cfbe4d4b80f274c2616736ba6af908e83a044c
4
+ data.tar.gz: d7eae71e95f7d0b06646fcc39b069658dc0d808874654fdfd9b2353f1af70d3c
5
5
  SHA512:
6
- metadata.gz: f3dd1ed54bf737169dbd652f3314ce258c03a87d3b73ed0f8e2473ff2acfef1c08cd5b06349d370f564ee318964a78757978fc948d975f6e0733b1d60a69ff52
7
- data.tar.gz: cad4e544c9cb525bbc94d1a4caf5585590456345ec1bd74fe08f4fe73a5292d4c721b7df2226f6721311487f3ef319bc69d8664863ca864792399cd48f067669
6
+ metadata.gz: d450cb135d44a6b17b51cdb5921aa03fa9a3796c540b427fb8796251177c776f5d3541f4bccf10739f1bf17fdc65611a318ae6ed17938718d915d487000ac435
7
+ data.tar.gz: 9a8fad769b51f90ecf0a4d464661b5e22cda7304b32388091019bb754d66eed1abe731f598547778e8357e302500f32a33a2c740a60b725625e03ed261ec29a2
@@ -12,7 +12,7 @@ jobs:
12
12
  runs-on: ubuntu-latest
13
13
  strategy:
14
14
  matrix:
15
- ruby-version: ['2.3', '2.4', '2.5', '2.6', '2.7', '3.0']
15
+ ruby-version: ['2.5', '2.6', '2.7', '3.0', '3.1', '3.2', '3.3']
16
16
 
17
17
  name: Ruby (${{ matrix.ruby-version }})
18
18
  steps:
data/CHANGELOG.md CHANGED
@@ -4,7 +4,19 @@
4
4
 
5
5
  All notable changes to this project will be documented in this file.
6
6
 
7
- ## 4.13.0 - 2023-05-22
7
+ ## 4.15.0 - 2024-12-01
8
+
9
+ - (f659c19) Add Balance API
10
+
11
+ ## 4.14.0 - 2024-11-02
12
+
13
+ - (0876f2b) Add Payment Links API
14
+ - (9ab5e1b) Fix dependency warnings (#176)
15
+ - (87a6c9a) Update supported payment methods
16
+ - (afb6251) IMP-610: Use correct authorize URL
17
+ - (002708c) changelog_uri to gemspec
18
+
19
+ ## 4.13.0 - 2024-05-22
8
20
 
9
21
  - (09489be) Add HTTP response details to RequestError
10
22
  - (fe5d114) Add Terminals API
data/README.md CHANGED
@@ -1,9 +1,9 @@
1
1
  <p align="center">
2
- <img src="https://info.mollie.com/hubfs/github/ruby/logo.png" width="128" height="128"/>
2
+ <img src="https://github.com/mollie/mollie-api-ruby/assets/39294/5d35df48-e5c0-4de6-8541-159d9d8aa6f6.png" width="128" height="128"/>
3
3
  </p>
4
4
  <h1 align="center">Mollie API client for Ruby</h1>
5
5
 
6
- <img src="https://info.mollie.com/hubfs/github/ruby/editor.png" />
6
+ <img src="https://github.com/mollie/mollie-api-ruby/assets/39294/4838e149-4707-41c7-9aeb-bb86e68adc2c.png" />
7
7
 
8
8
  > LOOKING FOR VERSION v2.2.X README? [CLICK HERE](https://github.com/mollie/mollie-api-ruby/tree/v2.2.1)
9
9
 
@@ -24,11 +24,11 @@ To use the Mollie API client, the following things are required:
24
24
 
25
25
  ## Installation
26
26
 
27
- By far the easiest way to install the Mollie API client is to install it with [gem](http://rubygems.org/). Note: v4.8.0 and higher are not published on rubygems.org, see [GH-140](https://github.com/mollie/mollie-api-ruby/issues/140) for details.
27
+ By far the easiest way to install the Mollie API client is to install it with [gem](http://rubygems.org/).
28
28
 
29
29
  ```
30
30
  # Gemfile
31
- gem "mollie-api-ruby", github: "mollie/mollie-api-ruby", tag: "v4.11.0"
31
+ gem "mollie-api-ruby"
32
32
 
33
33
  $ gem install mollie-api-ruby
34
34
  ```
@@ -0,0 +1 @@
1
+ primary_balance = Mollie::Balance.primary
@@ -0,0 +1,2 @@
1
+ balance = Mollie::Balance.get("bal_gVMhHKqSSRYJyPsuoPNFH")
2
+ report = balance.report
@@ -0,0 +1 @@
1
+ balance = Mollie::Balance.get("bal_gVMhHKqSSRYJyPsuoPNFH")
@@ -0,0 +1,2 @@
1
+ balance = Mollie::Balance.get("bal_gVMhHKqSSRYJyPsuoPNFH")
2
+ transactions = balance.transactions
@@ -0,0 +1 @@
1
+ balances = Mollie::Balance.all
@@ -5,7 +5,7 @@ client = Rack::OAuth2::Client.new(
5
5
  secret: secret,
6
6
  state: 'some_state',
7
7
  redirect_uri: redirect_url,
8
- authorization_endpoint: 'https://www.mollie.com/oauth2/authorize',
8
+ authorization_endpoint: 'https://my.mollie.com/oauth2/authorize',
9
9
  token_endpoint: 'https://api.mollie.com/oauth2/tokens'
10
10
  )
11
11
 
@@ -5,7 +5,7 @@ client = Rack::OAuth2::Client.new(
5
5
  secret: secret,
6
6
  state: 'some_state',
7
7
  redirect_uri: redirect_url,
8
- authorization_endpoint: 'https://www.mollie.com/oauth2/authorize',
8
+ authorization_endpoint: 'https://my.mollie.com/oauth2/authorize',
9
9
  token_endpoint: 'https://api.mollie.com/oauth2/tokens'
10
10
  )
11
11
 
@@ -0,0 +1,5 @@
1
+ payment_link = Mollie::PaymentLink.create(
2
+ description: "Bicycle tires",
3
+ amount: { currency: "EUR", value: "24.95" }
4
+ )
5
+
@@ -0,0 +1 @@
1
+ Mollie::PaymentLink.delete("pl_4Y0eZitmBnQ6IDoMqZQKh")
@@ -0,0 +1 @@
1
+ payment_link = Mollie::PaymentLink.get("pl_4Y0eZitmBnQ6IDoMqZQKh")
@@ -0,0 +1,2 @@
1
+ payment_link = Mollie::PaymentLink.get("pl_4Y0eZitmBnQ6IDoMqZQKh")
2
+ payments = payment_link.payments
@@ -0,0 +1 @@
1
+ payment_links = Mollie::PaymentLink.all
@@ -0,0 +1,5 @@
1
+ payment_link = Mollie::PaymentLink.update(
2
+ "pl_4Y0eZitmBnQ6IDoMqZQKh",
3
+ description: "Bicycle tires",
4
+ archived: true
5
+ )
@@ -0,0 +1,25 @@
1
+ module Mollie
2
+ class Balance
3
+ class Report < Base
4
+ attr_accessor :balance_id,
5
+ :time_zone,
6
+ :grouping,
7
+ :totals,
8
+ :_links
9
+
10
+ attr_reader :from,
11
+ :until
12
+
13
+ alias links _links
14
+
15
+ def from=(from)
16
+ @from = Date.parse(from)
17
+ end
18
+
19
+ def until=(until_date)
20
+ # `until` is a reserved keyword
21
+ @until = Date.parse(until_date)
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,41 @@
1
+ module Mollie
2
+ class Balance
3
+ class Transaction < Base
4
+ attr_accessor :id,
5
+ :type,
6
+ :_links
7
+
8
+ attr_reader :result_amount,
9
+ :initial_amount,
10
+ :deductions,
11
+ :context,
12
+ :created_at
13
+
14
+ alias links _links
15
+
16
+ def self.embedded_resource_name
17
+ "balance_transactions"
18
+ end
19
+
20
+ def result_amount=(amount)
21
+ @result_amount = Mollie::Amount.new(amount)
22
+ end
23
+
24
+ def initial_amount=(amount)
25
+ @initial_amount = Mollie::Amount.new(amount)
26
+ end
27
+
28
+ def deductions=(amount)
29
+ @deductions = Mollie::Amount.new(amount)
30
+ end
31
+
32
+ def context=(context)
33
+ @context = OpenStruct.new(context) if context.is_a?(Hash)
34
+ end
35
+
36
+ def created_at=(created_at)
37
+ @created_at = Time.parse(created_at.to_s)
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,53 @@
1
+ module Mollie
2
+ class Balance < Base
3
+ attr_accessor :id,
4
+ :mode,
5
+ :currency,
6
+ :description,
7
+ :status,
8
+ :transfer_frequency,
9
+ :transfer_reference,
10
+ :_links
11
+
12
+ attr_reader :transfer_threshold,
13
+ :transfer_destination,
14
+ :available_amount,
15
+ :pending_amount,
16
+ :created_at
17
+
18
+ alias links _links
19
+
20
+ def self.primary(options = {})
21
+ get('primary', options)
22
+ end
23
+
24
+ def transfer_threshold=(amount)
25
+ @transfer_threshold = Mollie::Amount.new(amount)
26
+ end
27
+
28
+ def transfer_destination=(transfer_destination)
29
+ @transfer_destination = OpenStruct.new(transfer_destination) if transfer_destination.is_a?(Hash)
30
+ end
31
+
32
+ def available_amount=(amount)
33
+ @available_amount = Mollie::Amount.new(amount)
34
+ end
35
+
36
+ def pending_amount=(amount)
37
+ @pending_amount = Mollie::Amount.new(amount)
38
+ end
39
+
40
+ def created_at=(created_at)
41
+ @created_at = Time.parse(created_at.to_s)
42
+ end
43
+
44
+ def report(options = {})
45
+ response = Client.instance.perform_http_call("GET", "balances/#{id}", "report", {}, options)
46
+ Balance::Report.new(response)
47
+ end
48
+
49
+ def transactions(options = {})
50
+ Balance::Transaction.all(options.merge(balance_id: id))
51
+ end
52
+ end
53
+ end
data/lib/mollie/base.rb CHANGED
@@ -71,6 +71,8 @@ module Mollie
71
71
  path.last
72
72
  end
73
73
  end
74
+
75
+ alias_method :embedded_resource_name, :resource_name
74
76
  end
75
77
 
76
78
  def update(data = {})
data/lib/mollie/list.rb CHANGED
@@ -9,7 +9,7 @@ module Mollie
9
9
  @klass = klass
10
10
 
11
11
  list_attributes['items'] ||= if list_attributes['_embedded']
12
- list_attributes['_embedded'].fetch(klass.resource_name, [])
12
+ list_attributes['_embedded'].fetch(klass.embedded_resource_name, [])
13
13
  else
14
14
  []
15
15
  end
data/lib/mollie/method.rb CHANGED
@@ -1,21 +1,33 @@
1
1
  module Mollie
2
2
  class Method < Base
3
+ ALMA = 'alma'.freeze
3
4
  APPLEPAY = 'applepay'.freeze
4
5
  BANCONTACT = 'bancontact'.freeze
6
+ BANCOMAT_PAY = 'bancomatpay'.freeze
5
7
  BANKTRANSFER = 'banktransfer'.freeze
6
8
  BELFIUS = 'belfius'.freeze
9
+ BILLIE = 'billie'.freeze
10
+ BLIK = 'bilk'.freeze
7
11
  CREDITCARD = 'creditcard'.freeze
8
12
  DIRECTDEBIT = 'directdebit'.freeze
9
13
  EPS = 'eps'.freeze
10
14
  GIFTCARD = 'giftcard'.freeze
11
15
  GIROPAY = 'giropay'.freeze
12
16
  IDEAL = 'ideal'.freeze
17
+ IN3 = 'in3'.freeze
13
18
  INGHOMEPAY = 'inghomepay'.freeze
14
19
  KBC = 'kbc'.freeze
20
+ MYBANK = 'mybank'.freeze
15
21
  PAYPAL = 'paypal'.freeze
16
22
  PAYSAFECARD = 'paysafecard'.freeze
17
23
  PRZELEWY24 = 'przelewy24'.freeze
24
+ RIVERTY = 'riverty'.freeze
18
25
  SOFORT = 'sofort'.freeze
26
+ SATISPAY = 'satispay'.freeze
27
+ TRUSTLY = 'trustly'.freeze
28
+ TWINT = 'twint'.freeze
29
+ VOUCHER = 'voucher'.freeze
30
+ KLARNA = 'klarna'.freeze
19
31
  KLARNASLICEIT = 'klarnasliceit'.freeze
20
32
  KLARNAPAYLATER = 'klarnapaylater'.freeze
21
33
 
@@ -0,0 +1,70 @@
1
+ module Mollie
2
+ class PaymentLink < Base
3
+ attr_accessor :id,
4
+ :mode,
5
+ :description,
6
+ :archived,
7
+ :redirect_url,
8
+ :webhook_url,
9
+ :profile_id,
10
+ :_links
11
+
12
+ attr_reader :amount,
13
+ :created_at,
14
+ :paid_at,
15
+ :updated_at,
16
+ :expires_at
17
+
18
+ alias_method :links, :_links
19
+
20
+ def self.embedded_resource_name(_parent_id = nil)
21
+ "payment_links"
22
+ end
23
+
24
+ def self.resource_name(_parent_id = nil)
25
+ "payment-links"
26
+ end
27
+
28
+ def amount=(amount)
29
+ @amount = Mollie::Amount.new(amount)
30
+ end
31
+
32
+ def archived?
33
+ archived
34
+ end
35
+
36
+ def created_at=(created_at)
37
+ @created_at = Time.parse(created_at.to_s)
38
+ end
39
+
40
+ def paid_at=(paid_at)
41
+ @paid_at = Time.parse(paid_at.to_s)
42
+ rescue
43
+ nil
44
+ end
45
+
46
+ def updated_at=(updated_at)
47
+ @updated_at = Time.parse(updated_at.to_s)
48
+ rescue
49
+ nil
50
+ end
51
+
52
+ def expires_at=(expires_at)
53
+ @expires_at = Time.parse(expires_at.to_s)
54
+ rescue
55
+ nil
56
+ end
57
+
58
+ def payment_link
59
+ Util.extract_url(links, "payment_link")
60
+ end
61
+
62
+ def payments(options = {})
63
+ resource_url = Util.extract_url(links, "self")
64
+ payments_url = File.join(resource_url, "/payments")
65
+
66
+ response = Mollie::Client.instance.perform_http_call("GET", payments_url, nil, {}, options)
67
+ Mollie::List.new(response, Mollie::Payment)
68
+ end
69
+ end
70
+ end
@@ -1,3 +1,3 @@
1
1
  module Mollie
2
- VERSION = '4.13.0'.freeze
2
+ VERSION = '4.15.0'.freeze
3
3
  end
data/lib/mollie.rb CHANGED
@@ -13,6 +13,7 @@ require 'mollie/version'
13
13
 
14
14
  require 'mollie/base'
15
15
  require 'mollie/amount'
16
+ require 'mollie/balance'
16
17
  require 'mollie/chargeback'
17
18
  require 'mollie/client'
18
19
  require 'mollie/customer'
@@ -23,6 +24,7 @@ require 'mollie/order'
23
24
  require 'mollie/organization'
24
25
  require 'mollie/partner'
25
26
  require 'mollie/payment'
27
+ require 'mollie/payment_link'
26
28
  require 'mollie/permission'
27
29
  require 'mollie/profile'
28
30
  require 'mollie/refund'
@@ -30,6 +32,8 @@ require 'mollie/settlement'
30
32
  require 'mollie/subscription'
31
33
  require 'mollie/terminal'
32
34
 
35
+ require 'mollie/balance/report'
36
+ require 'mollie/balance/transaction'
33
37
  require 'mollie/customer/mandate'
34
38
  require 'mollie/customer/payment'
35
39
  require 'mollie/customer/subscription'
@@ -16,11 +16,18 @@ Gem::Specification.new do |s|
16
16
  s.email = ['info@mollie.com']
17
17
  s.homepage = 'https://github.com/mollie/mollie-api-ruby'
18
18
  s.license = 'BSD'
19
- s.required_ruby_version = '>= 2.3.8'
19
+ s.metadata = {
20
+ 'changelog_uri' => 'https://github.com/mollie/mollie-api-ruby/blob/master/CHANGELOG.md'
21
+ }
22
+
23
+ s.required_ruby_version = '>= 2.5'
20
24
 
21
25
  s.files = `git ls-files`.split("\n")
22
26
  s.test_files = Dir['test/**/*']
23
27
 
28
+ s.add_dependency('ostruct', '~> 0.6.0')
29
+ s.add_dependency('bigdecimal', '~> 3.1', '>= 3.1.8')
30
+
24
31
  s.add_development_dependency('rake')
25
32
  s.add_development_dependency('rubocop', '~> 0.57.2')
26
33
  s.add_development_dependency('test-unit')
@@ -0,0 +1,38 @@
1
+ {
2
+ "resource": "balance",
3
+ "id": "bal_gVMhHKqSSRYJyPsuoPNFH",
4
+ "mode": "live",
5
+ "currency": "EUR",
6
+ "description": "Primary balance",
7
+ "availableAmount": {
8
+ "currency": "EUR",
9
+ "value": "905.25"
10
+ },
11
+ "pendingAmount": {
12
+ "currency": "EUR",
13
+ "value": "0.00"
14
+ },
15
+ "transferFrequency": "twice-a-month",
16
+ "transferThreshold": {
17
+ "currency": "EUR",
18
+ "value": "5.00"
19
+ },
20
+ "transferReference": "Mollie settlement",
21
+ "transferDestination": {
22
+ "type": "bank-account",
23
+ "beneficiaryName": "John Doe",
24
+ "bankAccount": "NL55INGB0000000000"
25
+ },
26
+ "status": "active",
27
+ "createdAt": "2019-01-10T12:06:28+00:00",
28
+ "_links": {
29
+ "self": {
30
+ "href": "https://api.mollie.com/v2/balances/bal_gVMhHKqSSRYJyPsuoPNFH",
31
+ "type": "application/hal+json"
32
+ },
33
+ "documentation": {
34
+ "href": "https://docs.mollie.com/reference/get-balance",
35
+ "type": "text/html"
36
+ }
37
+ }
38
+ }
@@ -0,0 +1,34 @@
1
+ {
2
+ "count": 1,
3
+ "_embedded": {
4
+ "balances": [
5
+ {
6
+ "resource": "balance",
7
+ "id": "bal_one"
8
+ },
9
+ {
10
+ "resource": "balance",
11
+ "id": "bal_two"
12
+ },
13
+ {
14
+ "resource": "balance",
15
+ "id": "bal_three"
16
+ }
17
+ ]
18
+ },
19
+ "_links": {
20
+ "documentation": {
21
+ "href": "https://docs.mollie.com/reference/v2/balances-api/list-balances",
22
+ "type": "text/html"
23
+ },
24
+ "self": {
25
+ "href": "https://api.mollie.com/v2/balances?limit=5",
26
+ "type": "application/hal+json"
27
+ },
28
+ "previous": null,
29
+ "next": {
30
+ "href": "https://api.mollie.com/v2/balances?from=bal_gVMhHKqSSRYJyPsuoPABC&limit=5",
31
+ "type": "application/hal+json"
32
+ }
33
+ }
34
+ }
@@ -0,0 +1,65 @@
1
+ {
2
+ "count": 2,
3
+ "_embedded": {
4
+ "balance_transactions": [
5
+ {
6
+ "resource": "balance_transaction",
7
+ "id": "baltr_QM24QwzUWR4ev4Xfgyt29A",
8
+ "type": "refund",
9
+ "resultAmount": {
10
+ "currency": "EUR",
11
+ "value": "-10.25"
12
+ },
13
+ "initialAmount": {
14
+ "currency": "EUR",
15
+ "value": "-10.00"
16
+ },
17
+ "deductions": {
18
+ "currency": "EUR",
19
+ "value": "-0.25"
20
+ },
21
+ "context": {
22
+ "paymentId": "tr_7UhSN1zuXS",
23
+ "refundId": "re_4qqhO89gsT"
24
+ },
25
+ "createdAt": "2021-01-10T12:06:28+00:00"
26
+ },
27
+ {
28
+ "resource": "balance_transaction",
29
+ "id": "baltr_WhmDwNYR87FPDbiwBhUXCh",
30
+ "type": "payment",
31
+ "resultAmount": {
32
+ "currency": "EUR",
33
+ "value": "9.71"
34
+ },
35
+ "initialAmount": {
36
+ "currency": "EUR",
37
+ "value": "10.00"
38
+ },
39
+ "deductions": {
40
+ "currency": "EUR",
41
+ "value": "-0.29"
42
+ },
43
+ "context": {
44
+ "paymentId": "tr_7UhSN1zuXS"
45
+ },
46
+ "createdAt": "2021-01-10T12:06:28+00:00"
47
+ }
48
+ ]
49
+ },
50
+ "_links": {
51
+ "self": {
52
+ "href": "...",
53
+ "type": "application/hal+json"
54
+ },
55
+ "previous": null,
56
+ "next": {
57
+ "href": "https://api.mollie.com/v2/balances/bal_gVMhHKqSSRYJyPsuoPNFH/transactions?from=baltr_rXeW2yPqqDUyfAqq8fS5Bg&limit=5",
58
+ "type": "application/hal+json"
59
+ },
60
+ "documentation": {
61
+ "href": "...",
62
+ "type": "text/html"
63
+ }
64
+ }
65
+ }