starkinfra 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/lib/brcodepreview/brcodepreview.rb +121 -0
  3. data/lib/cardmethod/cardmethod.rb +56 -0
  4. data/lib/creditnote/creditnote.rb +37 -342
  5. data/lib/creditnote/invoice/description.rb +51 -0
  6. data/lib/creditnote/invoice/discount.rb +49 -0
  7. data/lib/creditnote/invoice/invoice.rb +123 -0
  8. data/lib/creditnote/log.rb +2 -2
  9. data/lib/creditnote/transfer.rb +90 -0
  10. data/lib/creditpreview/creditnotepreview.rb +85 -0
  11. data/lib/creditpreview/creditpreview.rb +83 -0
  12. data/lib/creditsigner/creditsigner.rb +57 -0
  13. data/lib/dynamicbrcode/dynamicbrcode.rb +350 -0
  14. data/lib/event/attempt.rb +4 -3
  15. data/lib/event/event.rb +10 -10
  16. data/lib/issuingbalance/issuingbalance.rb +4 -4
  17. data/lib/issuingcard/issuingcard.rb +32 -29
  18. data/lib/issuingcard/log.rb +2 -2
  19. data/lib/issuingholder/issuingholder.rb +13 -8
  20. data/lib/issuingholder/log.rb +2 -2
  21. data/lib/issuinginvoice/issuinginvoice.rb +23 -9
  22. data/lib/issuinginvoice/log.rb +2 -2
  23. data/lib/{issuingbin/issuingbin.rb → issuingproduct/issuingproduct.rb} +27 -30
  24. data/lib/issuingpurchase/issuingpurchase.rb +99 -23
  25. data/lib/issuingpurchase/log.rb +1 -1
  26. data/lib/issuingrule/issuingrule.rb +64 -18
  27. data/lib/issuingtransaction/issuingtransaction.rb +5 -7
  28. data/lib/issuingwithdrawal/issuingwithdrawal.rb +10 -6
  29. data/lib/merchantcategory/merchantcategory.rb +63 -0
  30. data/lib/merchantcountry/merchantcountry.rb +59 -0
  31. data/lib/pixbalance/pixbalance.rb +5 -5
  32. data/lib/pixchargeback/log.rb +3 -3
  33. data/lib/pixchargeback/pixchargeback.rb +32 -20
  34. data/lib/pixclaim/log.rb +8 -11
  35. data/lib/pixclaim/pixclaim.rb +42 -32
  36. data/lib/pixdirector/pixdirector.rb +9 -11
  37. data/lib/pixdomain/certificate.rb +1 -1
  38. data/lib/pixdomain/pixdomain.rb +4 -4
  39. data/lib/pixinfraction/log.rb +2 -2
  40. data/lib/pixinfraction/pixinfraction.rb +21 -13
  41. data/lib/pixkey/log.rb +5 -5
  42. data/lib/pixkey/pixkey.rb +10 -9
  43. data/lib/pixrequest/log.rb +2 -2
  44. data/lib/pixrequest/pixrequest.rb +51 -21
  45. data/lib/pixreversal/log.rb +2 -2
  46. data/lib/pixreversal/pixreversal.rb +48 -21
  47. data/lib/pixstatement/pixstatement.rb +12 -7
  48. data/lib/starkinfra.rb +27 -15
  49. data/lib/staticbrcode/staticbrcode.rb +164 -0
  50. data/lib/user/project.rb +1 -1
  51. data/lib/utils/api.rb +1 -0
  52. data/lib/utils/parse.rb +7 -3
  53. data/lib/utils/request.rb +1 -1
  54. data/lib/utils/resource.rb +1 -1
  55. data/lib/utils/sub_resource.rb +21 -22
  56. data/lib/webhook/webhook.rb +3 -3
  57. metadata +16 -4
  58. data/lib/issuingauthorization/issuingauthorization.rb +0 -141
@@ -1,14 +1,18 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative('../utils/resource')
4
3
  require_relative('../utils/rest')
5
4
  require_relative('../utils/checks')
5
+ require_relative('../utils/resource')
6
6
 
7
7
  module StarkInfra
8
8
  # # IssuingHolder object
9
9
  #
10
10
  # The IssuingHolder describes a card holder that may group several cards.
11
11
  #
12
+ # When you initialize a IssuingHolder, the entity will not be automatically
13
+ # created in the Stark Infra API. The 'create' function sends the objects
14
+ # to the Stark Infra API and returns the created object.
15
+ #
12
16
  # ## Parameters (required):
13
17
  # - name [string]: card holder name.
14
18
  # - tax_id [string]: card holder tax ID
@@ -16,7 +20,7 @@ module StarkInfra
16
20
  #
17
21
  # ## Parameters (optional):
18
22
  # - rules [list of IssuingRule objects, default nil]: [EXPANDABLE] list of holder spending rules.
19
- # - tags [list of strings, default []]: list of strings for tagging. ex: ['travel', 'food']
23
+ # - tags [list of strings, default nil]: list of strings for tagging. ex: ['travel', 'food']
20
24
  #
21
25
  # ## Attributes (return-only):
22
26
  # - id [string]: unique id returned when IssuingHolder is created. ex: '5656565656565656'
@@ -24,17 +28,17 @@ module StarkInfra
24
28
  # - updated [DateTime]: latest update datetime for the IssuingHolder. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
25
29
  # - created [DateTime]: creation datetime for the log. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
26
30
  class IssuingHolder < StarkInfra::Utils::Resource
27
- attr_reader :id, :name, :tax_id, :external_id, :status, :rules, :tags, :updated, :created
31
+ attr_reader :id, :name, :tax_id, :external_id, :rules, :tags, :status, :updated, :created
28
32
  def initialize(
29
- name:, tax_id:, external_id:, id: nil, status: nil, rules: nil, tags: nil, updated: nil, created: nil
33
+ name:, tax_id:, external_id:, rules: nil, tags: nil, id: nil, status: nil, updated: nil, created: nil
30
34
  )
31
35
  super(id)
32
36
  @name = name
33
37
  @tax_id = tax_id
34
38
  @external_id = external_id
35
- @status = status
36
39
  @rules = StarkInfra::IssuingRule.parse_rules(rules)
37
40
  @tags = tags
41
+ @status = status
38
42
  @created = StarkInfra::Utils::Checks.check_datetime(created)
39
43
  @updated = StarkInfra::Utils::Checks.check_datetime(updated)
40
44
  end
@@ -47,12 +51,13 @@ module StarkInfra
47
51
  # - holders [list of IssuingHolder objects]: list of IssuingHolder objects to be created in the API
48
52
  #
49
53
  # ## Parameters (optional):
54
+ # - expand [list of strings, default nil]: fields to expand information. Options: ['rules']
50
55
  # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
51
56
  #
52
57
  # ## Return:
53
58
  # - list of IssuingHolder objects with updated attributes
54
- def self.create(holders:, user: nil)
55
- StarkInfra::Utils::Rest.post(entities: holders, user: user, **resource)
59
+ def self.create(holders:, expand: nil, user: nil)
60
+ StarkInfra::Utils::Rest.post(entities: holders, expand: expand, user: user, **resource)
56
61
  end
57
62
 
58
63
  # # Retrieve a specific IssuingHolder
@@ -193,9 +198,9 @@ module StarkInfra
193
198
  name: json['name'],
194
199
  tax_id: json['tax_id'],
195
200
  external_id: json['external_id'],
196
- status: json['status'],
197
201
  rules: json['rules'],
198
202
  tags: json['tags'],
203
+ status: json['status'],
199
204
  updated: json['updated'],
200
205
  created: json['created']
201
206
  )
@@ -1,9 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative('../utils/resource')
3
+ require_relative('issuingholder')
4
4
  require_relative('../utils/rest')
5
5
  require_relative('../utils/checks')
6
- require_relative('issuingholder')
6
+ require_relative('../utils/resource')
7
7
 
8
8
  module StarkInfra
9
9
  class IssuingHolder
@@ -1,42 +1,53 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative('../utils/resource')
4
3
  require_relative('../utils/rest')
5
4
  require_relative('../utils/checks')
5
+ require_relative('../utils/resource')
6
6
 
7
7
  module StarkInfra
8
8
  # # IssuingInvoice object
9
9
  #
10
10
  # The IssuingInvoice objects created in your Workspace load your Issuing balance when paid.
11
11
  #
12
+ # When you initialize a IssuingInvoice, the entity will not be automatically
13
+ # created in the Stark Infra API. The 'create' function sends the objects
14
+ # to the Stark Infra API and returns the created object.
15
+ #
12
16
  # ## Parameters (required):
13
17
  # - amount [integer]: IssuingInvoice value in cents. ex: 1234 (= R$ 12.34)
14
18
  #
15
19
  # ## Parameters (optional):
16
20
  # - tax_id [string, default sub-issuer tax ID]: payer tax ID (CPF or CNPJ) with or without formatting. ex: '01234567890' or '20.018.183/0001-80'
17
21
  # - name [string, default sub-issuer name]: payer name. ex: 'Iron Bank S.A.'
18
- # - tags [list of strings, default []]: list of strings for tagging. ex: ['travel', 'food']
22
+ # - tags [list of strings, default nil]: list of strings for tagging. ex: ['travel', 'food']
19
23
  #
20
24
  # ## Attributes (return-only):
21
25
  # - id [string]: unique id returned when IssuingInvoice is created. ex: '5656565656565656'
26
+ # - brcode [string]: BR Code for the Invoice payment. ex: '00020101021226930014br.gov.bcb.pix2571brcode-h.development.starkinfra.com/v2/d7f6546e194d4c64a153e8f79f1c41ac5204000053039865802BR5925Stark Bank S.A. - Institu6009Sao Paulo62070503***63042109'
27
+ # - due [DateTime, Date or string]: Invoice due and expiration date in UTC ISO format. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0), Date.new(2020, 3, 10) or '2020-03-10T10:30:00.000000+00:00'
28
+ # - link [string]: public Invoice webpage URL. ex: 'https://starkbank-card-issuer.development.starkbank.com/invoicelink/d7f6546e194d4c64a153e8f79f1c41ac'
22
29
  # - status [string]: current IssuingInvoice status. ex: 'created', 'expired', 'overdue', 'paid'
23
30
  # - issuing_transaction_id [string]: ledger transaction ids linked to this IssuingInvoice. ex: 'issuing-invoice/5656565656565656'
24
31
  # - updated [DateTime]: latest update datetime for the IssuingInvoice. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
25
32
  # - created [DateTime]: creation datetime for the IssuingInvoice. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
26
33
  class IssuingInvoice < StarkInfra::Utils::Resource
27
- attr_reader :amount, :id, :name, :tax_id, :status, :issuing_transaction_id, :tags, :updated, :created
34
+ attr_reader :id, :amount, :tax_id, :name, :tags, :brcode, :due, :link, :status, :issuing_transaction_id, :updated, :created
28
35
  def initialize(
29
- amount:, id: nil, name: nil, tax_id: nil, status: nil, issuing_transaction_id: nil, tags: nil, updated: nil, created: nil
36
+ amount:, id: nil, tax_id: nil, name: nil, tags: nil, brcode: nil, due: nil, link: nil, status: nil, issuing_transaction_id: nil,
37
+ updated: nil, created: nil
30
38
  )
31
39
  super(id)
32
40
  @amount = amount
33
- @name = name
34
41
  @tax_id = tax_id
42
+ @name = name
43
+ @tags = tags
44
+ @brcode = brcode
45
+ @due = due
46
+ @link = link
35
47
  @status = status
36
48
  @issuing_transaction_id = issuing_transaction_id
37
- @tags = tags
38
- @created = StarkInfra::Utils::Checks.check_datetime(created)
39
49
  @updated = StarkInfra::Utils::Checks.check_datetime(updated)
50
+ @created = StarkInfra::Utils::Checks.check_datetime(created)
40
51
  end
41
52
 
42
53
  # # Create an IssuingInvoice
@@ -137,11 +148,14 @@ module StarkInfra
137
148
  IssuingInvoice.new(
138
149
  id: json['id'],
139
150
  amount: json['amount'],
140
- name: json['name'],
141
151
  tax_id: json['tax_id'],
152
+ name: json['name'],
153
+ tags: json['tags'],
154
+ brcode: json['brcode'],
155
+ due: json['due'],
156
+ link: json['link'],
142
157
  status: json['status'],
143
158
  issuing_transaction_id: json['issuing_transaction_id'],
144
- tags: json['tags'],
145
159
  updated: json['updated'],
146
160
  created: json['created']
147
161
  )
@@ -1,9 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative('../utils/resource')
4
3
  require_relative('../utils/rest')
5
- require_relative('../utils/checks')
6
4
  require_relative('issuinginvoice')
5
+ require_relative('../utils/checks')
6
+ require_relative('../utils/resource')
7
7
 
8
8
  module StarkInfra
9
9
  class IssuingInvoice
@@ -1,45 +1,43 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative('../utils/resource')
4
3
  require_relative('../utils/rest')
5
4
  require_relative('../utils/checks')
5
+ require_relative('../utils/resource')
6
6
 
7
7
  module StarkInfra
8
- # # IssuingBin object
8
+ # # IssuingProduct object
9
9
  #
10
- # The IssuingBin object displays information of BINs registered to your Workspace.
11
- # They represent a group of cards that begin with the same numbers (BIN) and offer the same product to end customers.
10
+ # The IssuingProduct object displays information of avaliable card products registered to your Workspace.
11
+ # They represent a group of cards that begin with the same numbers (id) and offer the same product to end customers.
12
12
  #
13
13
  # ## Attributes (return-only):
14
- # - id [string]: unique BIN number registered within the card network. ex: '53810200'
14
+ # - id [string]: unique card product number (BIN) registered within the card network. ex: '53810200'
15
15
  # - network [string]: card network flag. ex: 'mastercard'
16
- # - settlement [string]: settlement type. ex: 'credit'
17
- # - category [string]: purchase category. ex: 'prepaid'
18
- # - client [string]: client type. ex: 'business'
19
- # - created [DateTime]: creation datetime for the IssuingBin. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
20
- # - updated [DateTime]: latest update datetime for the IssuingBin. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
21
- class IssuingBin < StarkInfra::Utils::Resource
22
- attr_reader :id, :network, :settlement, :category, :client, :updated, :created
23
- def initialize(id: nil, network: nil, settlement: nil, category: nil, client: nil, updated: nil, created: nil)
16
+ # - funding_type [string]: type of funding used for payment. ex: 'credit', 'debit'
17
+ # - holder_type [string]: holder type. ex: 'business', 'individual'
18
+ # - code [string]: internal code from card flag informing the product. ex: 'MRW', 'MCO', 'MWB', 'MCS'
19
+ # - created [DateTime]: creation datetime for the IssuingProduct. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
20
+ class IssuingProduct < StarkInfra::Utils::Resource
21
+ attr_reader :id, :network, :funding_type, :holder_type, :code, :created
22
+ def initialize(id: nil, network: nil, funding_type: nil, holder_type: nil, code: nil, created: nil)
24
23
  super(id)
25
24
  @network = network
26
- @settlement = settlement
27
- @category = category
28
- @client = client
29
- @updated = StarkInfra::Utils::Checks.check_datetime(updated)
25
+ @funding_type = funding_type
26
+ @holder_type = holder_type
27
+ @code = code
30
28
  @created = StarkInfra::Utils::Checks.check_datetime(created)
31
29
  end
32
30
 
33
- # # Retrieve the IssuingBin object
31
+ # # Retrieve IssuingProducts
34
32
  #
35
- # Receive a generator of IssuingBin objects previously registered in the Stark Infra API
33
+ # Receive a generator of available IssuingProduct objects previously registered to your workspace
36
34
  #
37
35
  # ## Parameters (optional):
38
36
  # - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
39
37
  # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
40
38
  #
41
39
  # ## Return:
42
- # - generator of IssuingBin objects with updated attributes
40
+ # - generator of IssuingProduct objects with updated attributes
43
41
  def self.query(limit: nil, user: nil)
44
42
  StarkInfra::Utils::Rest.get_stream(
45
43
  limit: limit,
@@ -48,9 +46,9 @@ module StarkInfra
48
46
  )
49
47
  end
50
48
 
51
- # # Retrieve paged IssuingBins
49
+ # # Retrieve paged IssuingProducts
52
50
  #
53
- # Receive a list of up to 100 IssuingBin objects previously registered in the Stark Infra API and the cursor to the next page.
51
+ # Receive a list of up to 100 IssuingProduct objects previously registered to your workspace and the cursor to the next page.
54
52
  #
55
53
  # ## Parameters (optional):
56
54
  # - cursor [string, default nil]: cursor returned on the previous page function call.
@@ -58,8 +56,8 @@ module StarkInfra
58
56
  # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
59
57
  #
60
58
  # ## Return:
61
- # - list of IssuingBin objects with updated attributes
62
- # - cursor to retrieve the next page of IssuingBin objects
59
+ # - list of IssuingProduct objects with updated attributes
60
+ # - cursor to retrieve the next page of IssuingProduct objects
63
61
  def self.page(cursor: nil, limit: nil, user: nil)
64
62
  StarkInfra::Utils::Rest.get_page(
65
63
  cursor: cursor,
@@ -71,15 +69,14 @@ module StarkInfra
71
69
 
72
70
  def self.resource
73
71
  {
74
- resource_name: 'IssuingBin',
72
+ resource_name: 'IssuingProduct',
75
73
  resource_maker: proc { |json|
76
- IssuingBin.new(
74
+ IssuingProduct.new(
77
75
  id: json['id'],
78
76
  network: json['network'],
79
- settlement: json['settlement'],
80
- category: json['category'],
81
- client: json['client'],
82
- updated: json['updated'],
77
+ funding_type: json['funding_type'],
78
+ holder_type: json['holder_type'],
79
+ code: json['code'],
83
80
  created: json['created']
84
81
  )
85
82
  }
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative('../utils/resource')
4
3
  require_relative('../utils/rest')
5
4
  require_relative('../utils/checks')
5
+ require_relative('../utils/resource')
6
6
 
7
7
  module StarkInfra
8
8
  # # IssuingPurchase object
@@ -14,6 +14,7 @@ module StarkInfra
14
14
  # - holder_name [string]: card holder name. ex: 'Tony Stark'
15
15
  # - card_id [string]: unique id returned when IssuingCard is created. ex: '5656565656565656'
16
16
  # - card_ending [string]: last 4 digits of the card number. ex: '1234'
17
+ # - purpose [string]: purchase purpose. ex: 'purchase'
17
18
  # - amount [integer]: IssuingPurchase value in cents. Minimum = 0. ex: 1234 (= R$ 12.34)
18
19
  # - tax [integer]: IOF amount taxed for international purchases. ex: 1234 (= R$ 12.34)
19
20
  # - issuer_amount [integer]: issuer amount. ex: 1234 (= R$ 12.34)
@@ -29,32 +30,42 @@ module StarkInfra
29
30
  # - merchant_name [string]: merchant name. ex: 'Google Cloud Platform'
30
31
  # - merchant_fee [integer]: fee charged by the merchant to cover specific costs, such as ATM withdrawal logistics, etc. ex: 200 (= R$ 2.00)
31
32
  # - wallet_id [string]: virtual wallet ID. ex: '5656565656565656'
32
- # - method_code [string]: method code. ex: 'chip', 'token', 'server', 'manual', 'magstripe' or 'contactless'
33
+ # - method_code [string]: method code. Options: 'chip', 'token', 'server', 'manual', 'magstripe' or 'contactless'
33
34
  # - score [float]: internal score calculated for the authenticity of the purchase. nil in case of insufficient data. ex: 7.6
34
- # - issuing_transaction_ids [string]: ledger transaction ids linked to this Purchase
35
- # - end_to_end_id [string]: Unique id used to identify the transaction through all of its life cycle, even before the purchase is denied or accepted and gets its usual id. Example: endToEndId='679cd385-642b-49d0-96b7-89491e1249a5'
36
- # - status [string]: current IssuingCard status. ex: 'approved', 'canceled', 'denied', 'confirmed', 'voided'
35
+ # - end_to_end_id [string]: Unique id used to identify the transaction through all of its life cycle, even before the purchase is denied or approved and gets its usual id. ex: '679cd385-642b-49d0-96b7-89491e1249a5'
37
36
  # - tags [string]: list of strings for tagging returned by the sub-issuer during the authorization. ex: ['travel', 'food']
38
- # - created [DateTime]: creation datetime for the IssuingPurchase. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
37
+ # - zip_code [string]: zip code of the merchant location. ex: '02101234'
38
+ #
39
+ # ## Attributes (IssuingPurchase only):
40
+ # - issuing_transaction_ids [string]: ledger transaction ids linked to this Purchase
41
+ # - status [string]: current IssuingCard status. Options: 'approved', 'canceled', 'denied', 'confirmed', 'voided'
39
42
  # - updated [DateTime]: latest update datetime for the IssuingPurchase. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
43
+ # - created [DateTime]: creation datetime for the IssuingPurchase. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
44
+ #
45
+ # ## Attributes (authorization request only):
46
+ # - is_partial_allowed [bool]: true if the merchant allows partial purchases. ex: False
47
+ # - card_tags [list of strings]: tags of the IssuingCard responsible for this purchase. ex: ['travel', 'food']
48
+ # - holder_tags [list of strings]: tags of the IssuingHolder responsible for this purchase. ex: ['technology', 'john snow']
40
49
  class IssuingPurchase < StarkInfra::Utils::Resource
41
- attr_reader :id, :holder_name, :card_id, :card_ending, :amount, :tax, :issuer_amount, :issuer_currency_code,
50
+ attr_reader :id, :holder_name, :card_id, :card_ending, :purpose, :amount, :tax, :issuer_amount, :issuer_currency_code,
42
51
  :issuer_currency_symbol, :merchant_amount, :merchant_currency_code, :merchant_currency_symbol,
43
52
  :merchant_category_code, :merchant_country_code, :acquirer_id, :merchant_id, :merchant_name,
44
- :merchant_fee, :wallet_id, :method_code, :score, :issuing_transaction_ids, :end_to_end_id, :status,
45
- :tags, :updated, :created
53
+ :merchant_fee, :wallet_id, :method_code, :score, :end_to_end_id, :tags, :zip_code,
54
+ :issuing_transaction_ids, :status, :updated, :created, :is_partial_allowed, :card_tags, :holder_tags
46
55
 
47
56
  def initialize(
48
- id: nil, holder_name: nil, card_id: nil, card_ending: nil, amount: nil, tax: nil, issuer_amount: nil,
57
+ id: nil, holder_name: nil, card_id: nil, card_ending: nil, purpose: nil, amount: nil, tax: nil, issuer_amount: nil,
49
58
  issuer_currency_code: nil, issuer_currency_symbol: nil, merchant_amount: nil, merchant_currency_code: nil,
50
59
  merchant_currency_symbol: nil, merchant_category_code: nil, merchant_country_code: nil, acquirer_id: nil,
51
60
  merchant_id: nil, merchant_name: nil, merchant_fee: nil, wallet_id: nil, method_code: nil, score: nil,
52
- issuing_transaction_ids: nil, end_to_end_id: nil, status: nil, tags: nil, updated: nil, created: nil
61
+ end_to_end_id: nil, tags: nil, zip_code: nil, issuing_transaction_ids: nil, status: nil, updated: nil, created: nil,
62
+ is_partial_allowed: nil, card_tags:nil, holder_tags:nil
53
63
  )
54
64
  super(id)
55
65
  @holder_name = holder_name
56
66
  @card_id = card_id
57
67
  @card_ending = card_ending
68
+ @purpose = purpose
58
69
  @amount = amount
59
70
  @tax = tax
60
71
  @issuer_amount = issuer_amount
@@ -72,12 +83,17 @@ module StarkInfra
72
83
  @wallet_id = wallet_id
73
84
  @method_code = method_code
74
85
  @score = score
75
- @issuing_transaction_ids = issuing_transaction_ids
76
86
  @end_to_end_id = end_to_end_id
77
- @status = status
78
87
  @tags = tags
79
- @created = StarkInfra::Utils::Checks.check_datetime(created)
88
+ @zip_code = zip_code
89
+ @issuing_transaction_ids = issuing_transaction_ids
90
+ @status = status
80
91
  @updated = StarkInfra::Utils::Checks.check_datetime(updated)
92
+ @created = StarkInfra::Utils::Checks.check_datetime(created)
93
+ @is_partial_allowed = is_partial_allowed
94
+ @card_tags = card_tags
95
+ @holder_tags = holder_tags
96
+
81
97
  end
82
98
 
83
99
  # # Retrieve a specific IssuingPurchase
@@ -105,9 +121,9 @@ module StarkInfra
105
121
  # - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
106
122
  # - after [Date or string, default nil] date filter for objects created only after specified date. ex: Date.new(2020, 3, 09)
107
123
  # - before [Date or string, default nil] date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
108
- # - end_to_end_ids [list of strings, default []]: central bank's unique transaction ID. ex: 'E79457883202101262140HHX553UPqeq'
109
- # - holder_ids [list of strings, default []]: card holder IDs. ex: ['5656565656565656', '4545454545454545']
110
- # - card_ids [list of strings, default []]: card IDs. ex: ['5656565656565656', '4545454545454545']
124
+ # - end_to_end_ids [list of strings, default nil]: central bank's unique transaction ID. ex: 'E79457883202101262140HHX553UPqeq'
125
+ # - holder_ids [list of strings, default nil]: card holder IDs. ex: ['5656565656565656', '4545454545454545']
126
+ # - card_ids [list of strings, default nil]: card IDs. ex: ['5656565656565656', '4545454545454545']
111
127
  # - status [list of strings, default nil]: filter for status of retrieved objects. ex: ['approved', 'canceled', 'denied', 'confirmed', 'voided']
112
128
  # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if starkinfra.user was set before function call
113
129
  #
@@ -141,9 +157,9 @@ module StarkInfra
141
157
  # - limit [integer, default 100]: maximum number of objects to be retrieved. Max = 100. ex: 35
142
158
  # - after [Date or string, default nil] date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
143
159
  # - before [Date or string, default nil] date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
144
- # - end_to_end_ids [list of strings, default []]: central bank's unique transaction ID. ex: 'E79457883202101262140HHX553UPqeq'
145
- # - holder_ids [list of strings, default []]: card holder IDs. ex: ['5656565656565656', '4545454545454545']
146
- # - card_ids [list of strings, default []]: card IDs. ex: ['5656565656565656', '4545454545454545']
160
+ # - end_to_end_ids [list of strings, default nil]: central bank's unique transaction ID. ex: 'E79457883202101262140HHX553UPqeq'
161
+ # - holder_ids [list of strings, default nil]: card holder IDs. ex: ['5656565656565656', '4545454545454545']
162
+ # - card_ids [list of strings, default nil]: card IDs. ex: ['5656565656565656', '4545454545454545']
147
163
  # - status [list of strings, default nil]: filter for status of retrieved objects. ex: ['approved', 'canceled', 'denied', 'confirmed', 'voided']
148
164
  # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if starkinfra.user was set before function call
149
165
  #
@@ -169,6 +185,61 @@ module StarkInfra
169
185
  )
170
186
  end
171
187
 
188
+ # # Create a single verified IssuingPurchase authorization request from a content string
189
+ #
190
+ # Use this method to parse and verify the authenticity of the authorization request received at the informed endpoint.
191
+ # Authorization requests are posted to your registered endpoint whenever IssuingPurchases are received.
192
+ # They present IssuingPurchase data that must be analyzed and answered with approval or declination.
193
+ # If the provided digital signature does not check out with the StarkInfra public key, a stark.exception.InvalidSignatureException will be raised.
194
+ # If the authorization request is not answered within 2 seconds or is not answered with an HTTP status code 200 the
195
+ # IssuingPurchase will go through the pre-configured stand-in validation.
196
+ #
197
+ # ## Parameters (required):
198
+ # - content [string]: response content from request received at user endpoint (not parsed)
199
+ # - signature [string]: base-64 digital signature received at response header 'Digital-Signature'
200
+ #
201
+ # # ## Parameters (optional):
202
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if starkinfra.user was set before function call
203
+ #
204
+ # ## Return:
205
+ # - Parsed IssuingPurchase object
206
+ def self.parse(content:, signature:, user: nil)
207
+ StarkInfra::Utils::Parse.parse_and_verify(
208
+ content: content,
209
+ signature: signature,
210
+ user: user,
211
+ key: nil,
212
+ **resource
213
+ )
214
+ end
215
+
216
+ # # Helps you respond to a IssuingPurchase authorization request
217
+ #
218
+ # ## Parameters (required):
219
+ # - status [string]: sub-issuer response to the authorization. ex: 'approved' or 'denied'
220
+ #
221
+ # ## Parameters (conditionally required):
222
+ # - reason [string]: denial reason. Options: 'other', 'blocked', 'lostCard', 'stolenCard', 'invalidPin', 'invalidCard', 'cardExpired', 'issuerError', 'concurrency', 'standInDenial', 'subIssuerError', 'invalidPurpose', 'invalidZipCode', 'invalidWalletId', 'inconsistentCard', 'settlementFailed', 'cardRuleMismatch', 'invalidExpiration', 'prepaidInstallment', 'holderRuleMismatch', 'insufficientBalance', 'tooManyTransactions', 'invalidSecurityCode', 'invalidPaymentMethod', 'confirmationDeadline', 'withdrawalAmountLimit', 'insufficientCardLimit', 'insufficientHolderLimit'
223
+ #
224
+ # # ## Parameters (optional):
225
+ # - amount [integer, default nil]: amount in cents that was authorized. ex: 1234 (= R$ 12.34)
226
+ # - tags [list of strings, default nil]: tags to filter retrieved object. ex: ['tony', 'stark']
227
+ #
228
+ # ## Return:
229
+ # - Dumped JSON string that must be returned to us on the IssuingPurchase request
230
+ def self.response(
231
+ status:, reason:, amount:, tags:
232
+ )
233
+ params = {
234
+ 'status': status,
235
+ 'reason': reason,
236
+ 'amount': amount,
237
+ 'tags': tags
238
+ }
239
+
240
+ params.to_json
241
+ end
242
+
172
243
  def self.resource
173
244
  {
174
245
  resource_name: 'IssuingPurchase',
@@ -178,6 +249,7 @@ module StarkInfra
178
249
  holder_name: json['holder_name'],
179
250
  card_id: json['card_id'],
180
251
  card_ending: json['card_ending'],
252
+ purpose: json['purpose'],
181
253
  amount: json['amount'],
182
254
  tax: json['tax'],
183
255
  issuer_amount: json['issuer_amount'],
@@ -195,12 +267,16 @@ module StarkInfra
195
267
  wallet_id: json['wallet_id'],
196
268
  method_code: json['method_code'],
197
269
  score: json['score'],
198
- issuing_transaction_ids: json['issuing_transaction_ids'],
199
270
  end_to_end_id: json['end_to_end_id'],
200
- status: json['status'],
201
271
  tags: json['tags'],
272
+ zip_code: json['zip_code'],
273
+ issuing_transaction_ids: json['issuing_transaction_ids'],
274
+ status: json['status'],
202
275
  updated: json['updated'],
203
- created: json['created']
276
+ created: json['created'],
277
+ is_partial_allowed: json['is_partial_allowed'],
278
+ card_tags: json['card_tags'],
279
+ holder_tags: json['holder_tags']
204
280
  )
205
281
  }
206
282
  }
@@ -1,9 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative('../utils/resource')
4
3
  require_relative('../utils/rest')
5
4
  require_relative('../utils/checks')
6
5
  require_relative('issuingpurchase')
6
+ require_relative('../utils/resource')
7
7
 
8
8
  module StarkInfra
9
9
  class IssuingPurchase
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative('../utils/resource')
4
3
  require_relative('../utils/rest')
5
4
  require_relative('../utils/checks')
5
+ require_relative('../utils/resource')
6
6
 
7
7
  module StarkInfra
8
8
  # # IssuingRule object
@@ -12,33 +12,79 @@ module StarkInfra
12
12
  # ## Parameters (required):
13
13
  # - name [string]: rule name. ex: 'Travel' or 'Food'
14
14
  # - amount [integer]: maximum amount that can be spent in the informed interval. ex: 200000 (= R$ 2000.00)
15
+ #
15
16
  # ## Parameters (optional):
16
- # - id [string, default nil]: unique id returned when Rule is created. ex: '5656565656565656'
17
+ # - id [string, default nil]: unique id returned when an IssuingRule is created, used to update a specific IssuingRule. ex: '5656565656565656'
17
18
  # - interval [string, default 'lifetime']: interval after which the rule amount counter will be reset to 0. ex: 'instant', 'day', 'week', 'month', 'year' or 'lifetime'
18
19
  # - currency_code [string, default 'BRL']: code of the currency that the rule amount refers to. ex: 'BRL' or 'USD'
19
- # - categories [list of strings, default []]: merchant categories accepted by the rule. ex: ['eatingPlacesRestaurants', 'travelAgenciesTourOperators']
20
- # - countries [list of strings, default []]: countries accepted by the rule. ex: ['BRA', 'USA']
21
- # - methods [list of strings, default []]: card purchase methods accepted by the rule. ex: ['chip', 'token', 'server', 'manual', 'magstripe', 'contactless']
20
+ # - categories [list of MerchantCategories, default nil]: merchant categories accepted by the rule. ex: [MerchantCategory(code='fastFoodRestaurants')]
21
+ # - countries [list of MerchantCountries, default nil]: countries accepted by the rule. ex: [MerchantCountry(code='BRA')]
22
+ # - methods [list of CardMethods, default nil]: card purchase methods accepted by the rule. ex: [CardMethod(code='magstripe')]
23
+ #
22
24
  # ## Attributes (expanded return-only):
23
25
  # - counter_amount [integer]: current rule spent amount. ex: 1000
24
26
  # - currency_symbol [string]: currency symbol. ex: 'R$'
25
27
  # - currency_name [string]: currency name. ex: 'Brazilian Real'
26
28
  class IssuingRule < StarkInfra::Utils::Resource
27
- attr_reader :name, :interval, :amount, :currency_code, :counter_amount, :currency_name, :currency_symbol, :categories, :countries, :methods
28
- def initialize(name:, amount:, id: nil, interval: nil, currency_code: nil, counter_amount: nil, currency_name: nil,
29
- currency_symbol: nil, categories: nil, countries: nil, methods: nil
29
+ attr_reader :name, :interval, :amount, :currency_code, :counter_amount, :currency_name, :currency_symbol,
30
+ :categories, :countries, :methods
31
+ def initialize(
32
+ name:, amount:, id: nil, interval: nil, currency_code: nil, categories: nil, countries: nil, methods: nil,
33
+ counter_amount: nil, currency_symbol: nil, currency_name: nil
30
34
  )
31
35
  super(id)
32
36
  @name = name
33
- @interval = interval
34
37
  @amount = amount
38
+ @interval = interval
35
39
  @currency_code = currency_code
40
+ @categories = IssuingRule.parse_categories(categories)
41
+ @countries = IssuingRule.parse_categories(countries)
42
+ @methods = IssuingRule.parse_categories(methods)
36
43
  @counter_amount = counter_amount
37
- @currency_name = currency_name
38
44
  @currency_symbol = currency_symbol
39
- @categories = categories
40
- @countries = countries
41
- @methods = methods
45
+ @currency_name = currency_name
46
+ end
47
+
48
+ def self.parse_categories(categories)
49
+ resource_maker = StarkInfra::MerchantCategory.resource[:resource_maker]
50
+ return categories if categories.nil?
51
+
52
+ parsed_categories = []
53
+ categories.each do |category|
54
+ unless category.is_a? MerchantCategory
55
+ category = StarkInfra::Utils::API.from_api_json(resource_maker, category)
56
+ end
57
+ parsed_categories << category
58
+ end
59
+ parsed_categories
60
+ end
61
+
62
+ def self.parse_countries(countries)
63
+ resource_maker = StarkInfra::MerchantCountry.resource[:resource_maker]
64
+ return countries if countries.nil?
65
+
66
+ parsed_countries = []
67
+ countries.each do |country|
68
+ unless country.is_a? MerchantCountry
69
+ country = StarkInfra::Utils::API.from_api_json(resource_maker, country)
70
+ end
71
+ parsed_countries << country
72
+ end
73
+ parsed_countries
74
+ end
75
+
76
+ def self.parse_methods(methods)
77
+ resource_maker = StarkInfra::CardMethod.resource[:resource_maker]
78
+ return methods if methods.nil?
79
+
80
+ parsed_methods = []
81
+ methods.each do |method|
82
+ unless method.is_a? CardMethod
83
+ method = StarkInfra::Utils::API.from_api_json(resource_maker, method)
84
+ end
85
+ parsed_methods << method
86
+ end
87
+ parsed_methods
42
88
  end
43
89
 
44
90
  def self.parse_rules(rules)
@@ -61,15 +107,15 @@ module StarkInfra
61
107
  resource_maker: proc { |json|
62
108
  IssuingRule.new(
63
109
  name: json['name'],
64
- interval: json['interval'],
65
110
  amount: json['amount'],
111
+ interval: json['interval'],
66
112
  currency_code: json['currency_code'],
67
- counter_amount: json['counter_amount'],
68
- currency_name: json['currency_name'],
69
- currency_symbol: json['currency_symbol'],
70
113
  categories: json['categories'],
71
114
  countries: json['countries'],
72
- methods: json['methods']
115
+ methods: json['methods'],
116
+ counter_amount: json['counter_amount'],
117
+ currency_symbol: json['currency_symbol'],
118
+ currency_name: json['currency_name']
73
119
  )
74
120
  }
75
121
  }