starkbank 2.5.0 → 2.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '08a72ad1389e8bcaa2f466c4fc6e3f0d299773da12d934449a389a36410b21eb'
4
- data.tar.gz: 128f8bb159e098b3c1013332900e3cc949d05f4c62e4fcadead1c70b2f722581
3
+ metadata.gz: df05543973d4dbbc39842f117e914f0ab892e382637766bae66e58297bbbf639
4
+ data.tar.gz: 56e8433e4d08637c893bf45cf717b798233619782ff6f1874ed01b5b74f4f45e
5
5
  SHA512:
6
- metadata.gz: 5811d6b08b2cd51589aee78ffb3b01193ff8df586af0ae7dcb401b1f0913448a420175090447cc4ace0cdbd318cc800664ea0d997ff2681a30426be0e0716b41
7
- data.tar.gz: 00005b82bf82aaa0a2af6ec6df1b4001e2646848562688e874d8ea8a08d985c7ceacea0b34c4762d93c3fcc3aabc67d63594cb35752a49a71fe865c2f34e12e6
6
+ metadata.gz: 32c50715be122647ff026491515c953818c6d2570157088da4e7d27d5687686d305475c2c3711798f97aad70d1269f181f72f48bdb4e8fc379fff03b8408d88d
7
+ data.tar.gz: b2a9b0d86a9e293c26f75649d0c2f2cf41e373f7503ac5edb59765bb9ab44bdf8f8e6231d236c104d524ecded335fd205bb8188ae822a2bf2572582dee21abae
@@ -35,7 +35,8 @@ module StarkBank
35
35
  @reconciliation_id = reconciliation_id
36
36
  end
37
37
 
38
- # # Retrieve BrcodePreviews
38
+ # # BrcodePreview is DEPRECATED: Please use PaymentPreview instead.
39
+ # Retrieve BrcodePreviews
39
40
  #
40
41
  # Receive a generator of BrcodePreview objects previously created in the Stark Bank API
41
42
  #
@@ -46,6 +47,7 @@ module StarkBank
46
47
  # ## Return:
47
48
  # - generator of BrcodePreview objects with updated attributes
48
49
  def self.query(limit: nil, brcodes: nil, user: nil)
50
+ warn "[DEPRECATION] `BrcodePreview` is deprecated. Please use `PaymentPreview` instead."
49
51
  StarkBank::Utils::Rest.get_stream(
50
52
  user: user,
51
53
  limit: nil,
@@ -10,6 +10,8 @@ module StarkBank
10
10
  # When you initialize an Invoice, the entity will not be automatically
11
11
  # sent to the Stark Bank API. The 'create' function sends the objects
12
12
  # to the Stark Bank API and returns the list of created objects.
13
+ # To create scheduled Invoices, which will display the discount, interest, etc. on the final users banking interface,
14
+ # use dates instead of datetimes on the "due" and "discounts" fields.
13
15
  #
14
16
  # ## Parameters (required):
15
17
  # - amount [integer]: Invoice value in cents. Minimum = 0 (any value will be accepted). ex: 1234 (= R$ 12.34)
@@ -47,13 +49,12 @@ module StarkBank
47
49
  )
48
50
  super(id)
49
51
  @amount = amount
50
- @due = StarkBank::Utils::Checks.check_datetime(due)
52
+ @due = StarkBank::Utils::Checks.check_date_or_datetime(due)
51
53
  @tax_id = tax_id
52
54
  @name = name
53
55
  @expiration = expiration
54
56
  @fine = fine
55
57
  @interest = interest
56
- @discounts = discounts
57
58
  @tags = tags
58
59
  @pdf = pdf
59
60
  @link = link
@@ -68,6 +69,14 @@ module StarkBank
68
69
  @transaction_ids = transaction_ids
69
70
  @updated = StarkBank::Utils::Checks.check_datetime(updated)
70
71
  @created = StarkBank::Utils::Checks.check_datetime(created)
72
+ if !discounts.nil?
73
+ checked_discounts = []
74
+ discounts.each do |discount|
75
+ discount["due"] = StarkBank::Utils::Checks.check_date_or_datetime(discount["due"])
76
+ checked_discounts.push(discount)
77
+ end
78
+ @discounts = checked_discounts
79
+ end
71
80
  end
72
81
 
73
82
  # # Create Invoices
@@ -0,0 +1,75 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative('../utils/sub_resource')
4
+ require_relative('../utils/rest')
5
+ require_relative('../utils/checks')
6
+
7
+ module StarkBank
8
+ class PaymentPreview
9
+ # # BoletoPreview object
10
+ #
11
+ # A BoletoPreview is used to get information from a Boleto payment you received before confirming the payment.
12
+ #
13
+ # ## Attributes (return-only):
14
+ # - status [string]: current boleto status. ex: 'active', 'expired' or 'inactive'
15
+ # - amount [int]: final amount to be paid. ex: 23456 (= R$ 234.56)
16
+ # - discount_amount [int]: discount amount to be paid. ex: 23456 (= R$ 234.56)
17
+ # - fine_amount [int]: fine amount to be paid. ex: 23456 (= R$ 234.56)
18
+ # - interest_amount [int]: interest amount to be paid. ex: 23456 (= R$ 234.56)
19
+ # - due [DateTime or string]: Boleto due date. ex: '2020-04-30'
20
+ # - expiration [DateTime or string]: Boleto expiration date. ex: '2020-04-30'
21
+ # - name [string]: beneficiary full name. ex: 'Anthony Edward Stark'
22
+ # - tax_id [string]: beneficiary tax ID (CPF or CNPJ). ex: '20.018.183/0001-80'
23
+ # - receiver_name [string]: receiver (Sacador Avalista) full name. ex: 'Anthony Edward Stark'
24
+ # - receiver_tax_id [string]: receiver (Sacador Avalista) tax ID (CPF or CNPJ). ex: '20.018.183/0001-80'
25
+ # - payer_name [string]: payer full name. ex: 'Anthony Edward Stark'
26
+ # - payer_tax_id [string]: payer tax ID (CPF or CNPJ). ex: '20.018.183/0001-80'
27
+ # - line [string]: Number sequence that identifies the payment. ex: '34191.09008 63571.277308 71444.640008 5 81960000000062'
28
+ # - bar_code [string]: Bar code number that identifies the payment. ex: '34195819600000000621090063571277307144464000'
29
+ class BoletoPreview < StarkBank::Utils::SubResource
30
+ attr_reader :status, :amount, :discount_amount, :fine_amount, :interest_amount, :due, :expiration, :name, :tax_id, :receiver_name, :receiver_tax_id, :payer_name, :payer_tax_id, :line, :bar_code
31
+ def initialize(status:, amount:, discount_amount:, fine_amount:, interest_amount:, due:, expiration:, name:, tax_id:, receiver_name:, receiver_tax_id:, payer_name:, payer_tax_id:, line:, bar_code:)
32
+ @status = status
33
+ @amount = amount
34
+ @discount_amount = discount_amount
35
+ @fine_amount = fine_amount
36
+ @interest_amount = interest_amount
37
+ @due = StarkBank::Utils::Checks.check_datetime(due)
38
+ @expiration = StarkBank::Utils::Checks.check_datetime(expiration)
39
+ @name = name
40
+ @tax_id = tax_id
41
+ @receiver_name = receiver_name
42
+ @receiver_tax_id = receiver_tax_id
43
+ @payer_name = payer_name
44
+ @payer_tax_id = payer_tax_id
45
+ @line = line
46
+ @bar_code = bar_code
47
+ end
48
+
49
+ def self.resource
50
+ {
51
+ resource_name: 'BoletoPreview',
52
+ resource_maker: proc { |json|
53
+ BoletoPreview.new(
54
+ status: json['status'],
55
+ amount: json['amount'],
56
+ discount_amount: json['discount_amount'],
57
+ fine_amount: json['fine_amount'],
58
+ interest_amount: json['interest_amount'],
59
+ due: json['due'],
60
+ expiration: json['expiration'],
61
+ name: json['name'],
62
+ tax_id: json['tax_id'],
63
+ receiver_name: json['receiver_name'],
64
+ receiver_tax_id: json['receiver_tax_id'],
65
+ payer_name: json['payer_name'],
66
+ payer_tax_id: json['payer_tax_id'],
67
+ line: json['line'],
68
+ bar_code: json['bar_code'],
69
+ )
70
+ }
71
+ }
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,75 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative('../utils/sub_resource')
4
+ require_relative('../utils/rest')
5
+ require_relative('../utils/checks')
6
+
7
+ module StarkBank
8
+ class PaymentPreview
9
+ # # BrcodePreview object
10
+ #
11
+ # A BrcodePreview is used to get information from a BR Code you received before confirming the payment.
12
+ #
13
+ # ## Attributes (return-only):
14
+ # - status [string]: Payment status. ex: 'active', 'paid', 'canceled' or 'unknown'
15
+ # - name [string]: Payment receiver name. ex: 'Tony Stark'
16
+ # - tax_id [string]: Payment receiver tax ID. ex: '012.345.678-90'
17
+ # - bank_code [string]: Payment receiver bank code. ex: '20018183'
18
+ # - branch_code [string]: Payment receiver branch code. ex: '0001'
19
+ # - account_number [string]: Payment receiver account number. ex: '1234567'
20
+ # - account_type [string]: Payment receiver account type. ex: 'checking'
21
+ # - allow_change [bool]: If True, the payment is able to receive amounts that are different from the nominal one. ex: True or False
22
+ # - amount [integer]: Value in cents that this payment is expecting to receive. If 0, any value is accepted. ex: 123 (= R$1,23)
23
+ # - nominal_amount [integer]: Original value in cents that this payment was expecting to receive without the discounts, fines, etc.. If 0, any value is accepted. ex: 123 (= R$1,23)
24
+ # - interest_amount [integer]: Current interest value in cents that this payment is charging. If 0, any value is accepted. ex: 123 (= R$1,23)
25
+ # - fine_amount [integer]: Current fine value in cents that this payment is charging. ex: 123 (= R$1,23)
26
+ # - reduction_amount [integer]: Current value reduction value in cents that this payment is expecting. ex: 123 (= R$1,23)
27
+ # - discount_amount [integer]: Current discount value in cents that this payment is expecting. ex: 123 (= R$1,23)
28
+ # - reconciliation_id [string]: Reconciliation ID linked to this payment. ex: 'txId', 'payment-123'
29
+ class BrcodePreview < StarkBank::Utils::SubResource
30
+ attr_reader :status, :name, :tax_id, :bank_code, :branch_code, :account_number, :account_type, :allow_change, :amount, :nominal_amount, :interest_amount, :fine_amount, :reduction_amount, :discount_amount, :reconciliation_id
31
+ def initialize(status:, name:, tax_id:, bank_code:, branch_code:, account_number:, account_type:, allow_change:, amount:, nominal_amount:, interest_amount:, fine_amount:, reduction_amount:, discount_amount:, reconciliation_id:)
32
+ @status = status
33
+ @name = name
34
+ @tax_id = tax_id
35
+ @bank_code = bank_code
36
+ @branch_code = branch_code
37
+ @account_number = account_number
38
+ @account_type = account_type
39
+ @allow_change = allow_change
40
+ @amount = amount
41
+ @nominal_amount = nominal_amount
42
+ @interest_amount = interest_amount
43
+ @fine_amount = fine_amount
44
+ @reduction_amount = reduction_amount
45
+ @discount_amount = discount_amount
46
+ @reconciliation_id = reconciliation_id
47
+ end
48
+
49
+ def self.resource
50
+ {
51
+ resource_name: 'BrcodePreview',
52
+ resource_maker: proc { |json|
53
+ BrcodePreview.new(
54
+ status: json['status'],
55
+ name: json['name'],
56
+ tax_id: json['tax_id'],
57
+ bank_code: json['bank_code'],
58
+ branch_code: json['branch_code'],
59
+ account_number: json['account_number'],
60
+ account_type: json['account_type'],
61
+ allow_change: json['allow_change'],
62
+ amount: json['amount'],
63
+ nominal_amount: json['nominal_amount'],
64
+ interest_amount: json['interest_amount'],
65
+ fine_amount: json['fine_amount'],
66
+ reduction_amount: json['reduction_amount'],
67
+ discount_amount: json['discount_amount'],
68
+ reconciliation_id: json['reconciliation_id']
69
+ )
70
+ }
71
+ }
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative('../utils/resource')
4
+ require_relative('../utils/rest')
5
+ require_relative('../utils/checks')
6
+
7
+ module StarkBank
8
+ # # PaymentPreview object
9
+ #
10
+ # A PaymentPreview is used to get information from a payment code before confirming the payment.
11
+ # This resource can be used to preview BR Codes and bar codes of boleto, tax and utility payments
12
+ #
13
+ # ## Attributes (return-only):
14
+ # - id [string]: Main identification of the payment. This should be the BR Code for Pix payments and lines or bar codes for payment slips. ex: '34191.09008 63571.277308 71444.640008 5 81960000000062', '00020126580014br.gov.bcb.pix0136a629532e-7693-4846-852d-1bbff817b5a8520400005303986540510.005802BR5908T'Challa6009Sao Paulo62090505123456304B14A'
15
+ # - scheduled [DateTime or string]: intended payment date. Right now, this parameter only has effect on BrcodePreviews. ex: '2020-04-30'
16
+ # - type [string]: Payment type. ex: 'brcode-payment', 'boleto-payment', 'utility-payment' or 'tax-payment'
17
+ # - payment [BrcodePreview, BoletoPreview, UtilityPreview or TaxPreview]: Information preview of the informed payment.
18
+ class PaymentPreview < StarkBank::Utils::Resource
19
+ attr_reader :id, :scheduled, :type, :payment
20
+ def initialize(id: nil, scheduled: nil, type: nil, payment: nil)
21
+ super(id)
22
+ @scheduled = StarkBank::Utils::Checks.check_date(scheduled)
23
+ @type = type
24
+ @payment = payment
25
+ return if type.nil?
26
+
27
+ resource = {
28
+ 'brcode-payment': StarkBank::PaymentPreview::BrcodePreview.resource,
29
+ 'boleto-payment': StarkBank::PaymentPreview::BoletoPreview.resource,
30
+ 'tax-payment': StarkBank::PaymentPreview::TaxPreview.resource,
31
+ 'utility-payment': StarkBank::PaymentPreview::UtilityPreview.resource
32
+ }[type.to_sym]
33
+
34
+ @payment = StarkBank::Utils::API.from_api_json(resource[:resource_maker], payment) unless resource.nil?
35
+ end
36
+
37
+ # # Create PaymentPreviews
38
+ #
39
+ # Send a list of PaymentPreviews objects for processing in the Stark Bank API
40
+ #
41
+ # ## Parameters (required):
42
+ # - previews [list of PaymentPreviews objects]: list of PaymentPreviews objects to be created in the API
43
+ #
44
+ # ## Parameters (optional):
45
+ # - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
46
+ #
47
+ # ## Return:
48
+ # - list of PaymentPreviews objects with updated attributes
49
+ def self.create(previews, user: nil)
50
+ StarkBank::Utils::Rest.post(entities: previews, user: user, **resource)
51
+ end
52
+
53
+ def self.resource
54
+ {
55
+ resource_name: 'PaymentPreview',
56
+ resource_maker: proc { |json|
57
+ PaymentPreview.new(
58
+ id: json['id'],
59
+ scheduled: json['scheduled'],
60
+ type: json['type'],
61
+ payment: json['payment']
62
+ )
63
+ }
64
+ }
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative('../utils/sub_resource')
4
+ require_relative('../utils/rest')
5
+ require_relative('../utils/checks')
6
+
7
+ module StarkBank
8
+ class PaymentPreview
9
+ # # TaxPreview object
10
+ #
11
+ # A TaxPreview is used to get information from a Tax Payment you received before confirming the payment.
12
+ #
13
+ # ## Attributes (return-only):
14
+ # - amount [int]: final amount to be paid. ex: 23456 (= R$ 234.56)
15
+ # - name [string]: beneficiary full name. ex: "Iron Throne"
16
+ # - description [string]: tax payment description. ex: "ISS Payment - Iron Throne"
17
+ # - line [string]: Number sequence that identifies the payment. ex: "85660000006 6 67940064007 5 41190025511 7 00010601813 8"
18
+ # - bar_code [string]: Bar code number that identifies the payment. ex: "85660000006679400640074119002551100010601813"
19
+ class TaxPreview < StarkBank::Utils::SubResource
20
+ attr_reader :amount, :name, :description, :line, :bar_code
21
+ def initialize(amount:, name:, description:, line:, bar_code:)
22
+ @amount = amount
23
+ @name = name
24
+ @description = description
25
+ @line = line
26
+ @bar_code = bar_code
27
+ end
28
+
29
+ def self.resource
30
+ {
31
+ resource_name: 'TaxPreview',
32
+ resource_maker: proc { |json|
33
+ TaxPreview.new(
34
+ amount: json['amount'],
35
+ name: json['name'],
36
+ description: json['description'],
37
+ line: json['line'],
38
+ bar_code: json['bar_code']
39
+ )
40
+ }
41
+ }
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative('../utils/sub_resource')
4
+ require_relative('../utils/rest')
5
+ require_relative('../utils/checks')
6
+
7
+ module StarkBank
8
+ class PaymentPreview
9
+ # # UtilityPreview object
10
+ #
11
+ # A UtilityPreview is used to get information from a Utility Payment you received before confirming the payment.
12
+ #
13
+ # ## Attributes (return-only):
14
+ # - amount [int]: final amount to be paid. ex: 23456 (= R$ 234.56)
15
+ # - name [string]: beneficiary full name. ex: "Light Company"
16
+ # - description [string]: utility payment description. ex: "Utility Payment - Light Company"
17
+ # - line [string]: Number sequence that identifies the payment. ex: "82660000002 8 44361143007 7 41190025511 7 00010601813 8"
18
+ # - bar_code [string]: Bar code number that identifies the payment. ex: "82660000002443611430074119002551100010601813"
19
+ class UtilityPreview < StarkBank::Utils::SubResource
20
+ attr_reader :amount, :name, :description, :line, :bar_code
21
+ def initialize(amount:, name:, description:, line:, bar_code:)
22
+ @amount = amount
23
+ @name = name
24
+ @description = description
25
+ @line = line
26
+ @bar_code = bar_code
27
+ end
28
+
29
+ def self.resource
30
+ {
31
+ resource_name: 'UtilityPreview',
32
+ resource_maker: proc { |json|
33
+ UtilityPreview.new(
34
+ amount: json['amount'],
35
+ name: json['name'],
36
+ description: json['description'],
37
+ line: json['line'],
38
+ bar_code: json['bar_code']
39
+ )
40
+ }
41
+ }
42
+ end
43
+ end
44
+ end
45
+ end
data/lib/starkbank.rb CHANGED
@@ -33,6 +33,11 @@ require_relative('webhook/webhook')
33
33
  require_relative('event/event')
34
34
  require_relative('event/attempt')
35
35
  require_relative('payment_request/payment_request')
36
+ require_relative('payment_preview/payment_preview')
37
+ require_relative('payment_preview/brcode_preview')
38
+ require_relative('payment_preview/boleto_preview')
39
+ require_relative('payment_preview/tax_preview')
40
+ require_relative('payment_preview/utility_preview')
36
41
  require_relative('institution/institution')
37
42
 
38
43
  # SDK to facilitate Ruby integrations with Stark Bank
data/lib/utils/request.rb CHANGED
@@ -61,7 +61,7 @@ module StarkBank
61
61
  req['Access-Time'] = access_time
62
62
  req['Access-Signature'] = signature
63
63
  req['Content-Type'] = 'application/json'
64
- req['User-Agent'] = "Ruby-#{RUBY_VERSION}-SDK-2.5.0"
64
+ req['User-Agent'] = "Ruby-#{RUBY_VERSION}-SDK-2.6.0"
65
65
  req['Accept-Language'] = language
66
66
 
67
67
  request = Net::HTTP.start(uri.hostname, use_ssl: true) { |http| http.request(req) }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: starkbank
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.0
4
+ version: 2.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - starkbank
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-30 00:00:00.000000000 Z
11
+ date: 2021-09-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: starkbank-ecdsa
@@ -95,6 +95,11 @@ files:
95
95
  - lib/invoice/log.rb
96
96
  - lib/invoice/payment.rb
97
97
  - lib/key.rb
98
+ - lib/payment_preview/boleto_preview.rb
99
+ - lib/payment_preview/brcode_preview.rb
100
+ - lib/payment_preview/payment_preview.rb
101
+ - lib/payment_preview/tax_preview.rb
102
+ - lib/payment_preview/utility_preview.rb
98
103
  - lib/payment_request/payment_request.rb
99
104
  - lib/starkbank.rb
100
105
  - lib/tax_payment/log.rb