Skip to content

Commit 39df548

Browse files
committed
Add merchant resources
1 parent 642e510 commit 39df548

24 files changed

+1319
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ Given a version number MAJOR.MINOR.PATCH, increment:
1313

1414

1515
## [Unreleased]
16+
### Added
17+
- merchantSession, merchantPurchase, merchantCard, merchantInstallment
1618

1719
## [2.12.0] - 2024-07-20
1820
### Added

README.md

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ is as easy as sending a text message to your client!
4949
- [CorporateBalance](#get-your-corporatebalance): View your corporate balance
5050
- [CorporateTransactions](#query-corporatetransactions): View the transactions that have affected your corporate balance
5151
- [CorporateEnums](#corporate-enums): Query enums related to the corporate purchases, such as merchant categories, countries and card purchase methods
52+
- [MerchantSession](#merchant-session): The Merchant Session allows you to create a session prior to a purchase. Sessions are essential for defining the parameters of a purchase, including funding type, expiration, 3DS, and more.
53+
- [MerchantCard](#merchant-card): The Merchant Card resource stores information about cards used in approved purchases.
54+
- [MerchantInstallment](#merchant-installment): Merchant Installments are created for every installment in a purchase.
55+
- [MerchantPurchase](#merchant-purchase): The Merchant Purchase section allows users to retrieve detailed information of the purchases.
5256
- [Webhooks](#create-a-webhook-subscription): Configure your webhook endpoints and subscriptions
5357
- [WebhookEvents](#process-webhook-events): Manage webhook events
5458
- [WebhookEventAttempts](#query-failed-webhook-event-delivery-attempts-information): Query failed webhook event deliveries
@@ -2221,6 +2225,157 @@ methods.each do |method|
22212225
end
22222226
```
22232227

2228+
## Merchant Session
2229+
2230+
The Merchant Session allows you to create a session prior to a purchase.
2231+
Sessions are essential for defining the parameters of a purchase, including funding type, expiration, 3DS, and more.
2232+
2233+
## Create a MerchantSession
2234+
2235+
```ruby
2236+
require('starkbank')
2237+
2238+
session = {
2239+
allowed_funding_types: ['debit', 'credit'],
2240+
allowed_installments: [
2241+
{ total_amount: 0, count: 1 },
2242+
{ total_amount: 120, count: 2 },
2243+
{ total_amount: 180, count: 12 }
2244+
],
2245+
expiration: 3600,
2246+
challenge_mode: challenge_mode,
2247+
tags: ['yourTags']
2248+
}
2249+
2250+
merchant_session = StarkBank::MerchantSession.create(session)
2251+
2252+
puts merchant_session
2253+
```
2254+
2255+
You can create a MerchantPurchase through a MerchantSession by passing its UUID.
2256+
**Note**: This method must be implemented in your front-end to ensure that sensitive card data does not pass through the back-end of the integration.
2257+
2258+
### Create a MerchantSession Purchase
2259+
2260+
```ruby
2261+
require('starkbank')
2262+
2263+
session_purchase = {
2264+
amount: 180,
2265+
installment_count: 12,
2266+
card_expiration: '2035-01',
2267+
card_number: '5277696455399733',
2268+
card_security_code: '123',
2269+
holder_name: 'Holder Name',
2270+
holder_email: '[email protected]',
2271+
holder_phone: '11111111111',
2272+
funding_type: 'credit',
2273+
billing_country_code: 'BRA',
2274+
billing_city: 'São Paulo',
2275+
billing_state_code: 'SP',
2276+
billing_street_line_1: 'Rua do Holder Name, 123',
2277+
billing_street_line_2: '',
2278+
billing_zip_code: '11111-111',
2279+
metadata: {
2280+
user_agent: 'Postman',
2281+
user_ip: '255.255.255.255',
2282+
language: 'pt-BR',
2283+
timezone_offset: 3,
2284+
extra_data: 'extraData'
2285+
}
2286+
}
2287+
2288+
purchase = StarkBank::MerchantSession.purchase(
2289+
uuid: "c32f9d2385974957a777f8351921afd7",
2290+
payload: session_purchase
2291+
)
2292+
2293+
puts purchase
2294+
```
2295+
2296+
### Query MerchantSessions
2297+
```ruby
2298+
require('starkbank')
2299+
2300+
merchant_sessions = StarkBank::MerchantSession.query(limit: 3).to_a
2301+
merchant_sessions.each do |merchant_session|
2302+
puts merchant_session
2303+
end
2304+
```
2305+
2306+
### Get a MerchantSession
2307+
```ruby
2308+
require('starkbank')
2309+
2310+
merchant_session = StarkBank::MerchantSession.get("5130086357401600")
2311+
puts merchant_session
2312+
```
2313+
## Merchant Purchase
2314+
The Merchant Purchase section allows users to retrieve detailed information of the purchases.
2315+
2316+
### Query MerchantPurchases
2317+
```ruby
2318+
require('starkbank')
2319+
2320+
merchant_purchases = StarkBank::MerchantPurchase.query(limit: 3).to_a
2321+
merchant_purchases.each do |session|
2322+
puts session
2323+
end
2324+
```
2325+
### Get a MerchantPurchase
2326+
```ruby
2327+
require('starkbank')
2328+
2329+
merchant_purchase = StarkBank::MerchantPurchase.get("5130086357401600")
2330+
puts merchant_purchase
2331+
```
2332+
2333+
## Merchant Card
2334+
2335+
The Merchant Card resource stores information about cards used in approved purchases.
2336+
These cards can be used in new purchases without the need to create a new session.
2337+
2338+
### Query MerchantCards
2339+
```ruby
2340+
require('starkbank')
2341+
2342+
merchant_cards = StarkBank::MerchantCard.query(limit: 3).to_a
2343+
merchant_cards.each do |card|
2344+
puts card
2345+
end
2346+
```
2347+
2348+
### Get a MerchantCard
2349+
```ruby
2350+
require('starkbank')
2351+
2352+
merchant_card = StarkBank::MerchantCard.get("5130086357401600")
2353+
puts merchant_card
2354+
```
2355+
2356+
## Merchant Installment
2357+
2358+
Merchant Installments are created for every installment in a purchase.
2359+
These resources will track its own due payment date and settlement lifecycle.
2360+
2361+
### Query MerchantInstallments
2362+
```ruby
2363+
require('starkbank')
2364+
2365+
merchant_installments = StarkBank::MerchantInstallment.query(limit: 3).to_a
2366+
merchant_installments.each do |installment|
2367+
puts installment
2368+
end
2369+
```
2370+
2371+
### Get a MerchantInstallment
2372+
```ruby
2373+
require('starkbank')
2374+
2375+
merchant_installment = StarkBank::MerchantCard.get("5130086357401600")
2376+
puts merchant_installment
2377+
```
2378+
22242379
## Create a webhook subscription
22252380

22262381
To create a webhook subscription and be notified whenever an event occurs, run:

lib/merchant_card/log.rb

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
require('starkcore')
2+
require_relative('../utils/rest')
3+
require_relative('merchant_card')
4+
5+
6+
module StarkBank
7+
class MerchantCard
8+
class Log < StarkCore::Utils::Resource
9+
attr_reader :id, :created, :type, :errors, :card
10+
def initialize(id:, created:, type:, errors:, card:)
11+
super(id)
12+
@created = StarkCore::Utils::Checks.check_datetime(created)
13+
@type = type
14+
@errors = errors
15+
@card = card
16+
end
17+
18+
def self.get(id, user: nil)
19+
StarkBank::Utils::Rest.get_id(id: id, user: user, **resource)
20+
end
21+
22+
def self.query(limit: nil, after: nil, before: nil, types: nil, card_ids: nil, user: nil)
23+
after = StarkCore::Utils::Checks.check_date(after)
24+
before = StarkCore::Utils::Checks.check_date(before)
25+
StarkBank::Utils::Rest.get_stream(
26+
limit: limit,
27+
after: after,
28+
before: before,
29+
types: types,
30+
card_ids: card_ids,
31+
user: user,
32+
**resource
33+
)
34+
end
35+
36+
def self.page(cursor: nil, limit: nil, after: nil, before: nil, types: nil, card_ids: nil, user: nil)
37+
after = StarkCore::Utils::Checks.check_date(after)
38+
before = StarkCore::Utils::Checks.check_date(before)
39+
return StarkBank::Utils::Rest.get_page(
40+
cursor: cursor,
41+
limit: limit,
42+
after: after,
43+
before: before,
44+
types: types,
45+
card_ids: card_ids,
46+
user: user,
47+
**resource
48+
)
49+
end
50+
51+
def self.resource
52+
card_maker = StarkBank::MerchantCard.resource[:resource_maker]
53+
{
54+
resource_name: 'MerchantCardLog',
55+
resource_maker: proc { |json|
56+
Log.new(
57+
id: json['id'],
58+
created: json['created'],
59+
type: json['type'],
60+
errors: json['errors'],
61+
card: StarkCore::Utils::API.from_api_json(card_maker, json['card'])
62+
)
63+
}
64+
}
65+
end
66+
end
67+
end
68+
end

lib/merchant_card/merchant_card.rb

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
require 'starkcore'
2+
require_relative '../utils/rest'
3+
4+
5+
module StarkBank
6+
class MerchantCard < StarkCore::Utils::Resource
7+
attr_reader :created, :ending, :expiration, :fundingType, :holderName, :id, :network, :status, :tags, :updated
8+
9+
def initialize(ending:, expiration:, fundingType:, holderName:, id: nil, created: nil, network: nil, status: nil, tags: nil, updated: nil)
10+
super(id)
11+
@ending = ending
12+
@expiration = expiration
13+
@fundingType = fundingType
14+
@holderName = holderName
15+
@created = StarkCore::Utils::Checks.check_datetime(created)
16+
@network = network
17+
@status = status
18+
@tags = tags
19+
@updated = StarkCore::Utils::Checks.check_datetime(updated)
20+
end
21+
22+
def self.resource
23+
{
24+
resource_name: 'MerchantCard',
25+
resource_maker: proc { |json|
26+
MerchantCard.new(
27+
ending: json['ending'],
28+
expiration: json['expiration'],
29+
fundingType: json['fundingType'],
30+
holderName: json['holderName'],
31+
id: json['id'],
32+
created: json['created'],
33+
network: json['network'],
34+
status: json['status'],
35+
tags: json['tags'],
36+
updated: json['updated']
37+
)
38+
}
39+
}
40+
end
41+
42+
def self.get(id, user: nil)
43+
StarkBank::Utils::Rest.get_id(id: id, user: user, **resource)
44+
end
45+
46+
def self.query(limit: nil, status: nil, tags: nil, ids: nil, after: nil, before: nil, user: nil)
47+
StarkBank::Utils::Rest.get_stream(
48+
limit: limit,
49+
after: after,
50+
before: before,
51+
status: status,
52+
tags: tags,
53+
ids: ids,
54+
user: user,
55+
**resource
56+
)
57+
end
58+
59+
def self.page(limit: nil, cursor: nil, status: nil, tags: nil, ids: nil, user: nil)
60+
StarkBank::Utils::Rest.get_page(
61+
limit: limit,
62+
cursor: cursor,
63+
status: status,
64+
tags: tags,
65+
ids: ids,
66+
user: user,
67+
**resource
68+
)
69+
end
70+
end
71+
end

lib/merchant_installment/log.rb

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
require('starkcore')
2+
require_relative('../utils/rest')
3+
require_relative('merchant_installment')
4+
5+
6+
module StarkBank
7+
class MerchantInstallment
8+
class Log < StarkCore::Utils::Resource
9+
attr_reader :id, :created, :type, :errors, :installment
10+
def initialize(id:, created:, type:, errors:, installment:)
11+
super(id)
12+
@created = StarkCore::Utils::Checks.check_datetime(created)
13+
@type = type
14+
@errors = errors
15+
@installment = installment
16+
end
17+
18+
def self.get(id, user: nil)
19+
StarkBank::Utils::Rest.get_id(id: id, user: user, **resource)
20+
end
21+
22+
def self.query(limit: nil, after: nil, before: nil, types: nil, installment_ids: nil, user: nil)
23+
after = StarkCore::Utils::Checks.check_date(after)
24+
before = StarkCore::Utils::Checks.check_date(before)
25+
StarkBank::Utils::Rest.get_stream(
26+
limit: limit,
27+
after: after,
28+
before: before,
29+
types: types,
30+
installment_ids: installment_ids,
31+
user: user,
32+
**resource
33+
)
34+
end
35+
36+
def self.page(cursor: nil, limit: nil, after: nil, before: nil, types: nil, installment_ids: nil, user: nil)
37+
after = StarkCore::Utils::Checks.check_date(after)
38+
before = StarkCore::Utils::Checks.check_date(before)
39+
return StarkBank::Utils::Rest.get_page(
40+
cursor: cursor,
41+
limit: limit,
42+
after: after,
43+
before: before,
44+
types: types,
45+
installment_ids: installment_ids,
46+
user: user,
47+
**resource
48+
)
49+
end
50+
51+
def self.resource
52+
installment_maker = StarkBank::MerchantInstallment.resource[:resource_maker]
53+
{
54+
resource_name: 'MerchantInstallmentLog',
55+
resource_maker: proc { |json|
56+
Log.new(
57+
id: json['id'],
58+
created: json['created'],
59+
type: json['type'],
60+
errors: json['errors'],
61+
installment: StarkCore::Utils::API.from_api_json(installment_maker, json['installment'])
62+
)
63+
}
64+
}
65+
end
66+
end
67+
end
68+
end

0 commit comments

Comments
 (0)