Skip to content

Commit faa8601

Browse files
jonasborges-starkluistarkbank
authored andcommitted
Add merchant purchase, merchant session, merchant card and merchant installment
1 parent d21c221 commit faa8601

33 files changed

+1239
-0
lines changed

CHANGELOG.md

+2
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 and merchantSessionPurchase resources
1618

1719
## [2.26.1] - 2025-02-18
1820
### Fixed

README.md

+109
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ 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+
- [MerchantPurchase](#merchant-purchase): The Merchant Purchase section allows users to retrieve detailed information of the purchases.
5254
- [Split](#query-splits): Split received Invoice payments between different receivers
5355
- [SplitReceiver](#create-splitreceivers): Receiver of an Invoice split
5456
- [Webhooks](#create-a-webhook-subscription): Configure your webhook endpoints and subscriptions
@@ -2332,6 +2334,113 @@ log = starkbank.splitreceiver.log.get("5155165527080960")
23322334

23332335
print(log)
23342336
```
2337+
## Merchant Session
2338+
2339+
The Merchant Session allows you to create a session prior to a purchase.
2340+
Sessions are essential for defining the parameters of a purchase, including funding type, expiration, 3DS, and more.
2341+
2342+
## Create a MerchantSession
2343+
2344+
```python
2345+
import starkbank
2346+
2347+
merchant_session = starkbank.merchantsession.create({
2348+
"allowedFundingTypes": [
2349+
"debit",
2350+
"credit"
2351+
],
2352+
"allowedInstallments": [
2353+
{
2354+
"totalAmount": 0,
2355+
"count": 1
2356+
},
2357+
{
2358+
"totalAmount": 120,
2359+
"count": 2
2360+
},
2361+
{
2362+
"totalAmount": 180,
2363+
"count": 12
2364+
}
2365+
],
2366+
"expiration": 3600,
2367+
"challengeMode": "disabled",
2368+
"tags": [
2369+
"yourTags"
2370+
]
2371+
})
2372+
2373+
print(merchant_session)
2374+
```
2375+
2376+
You can create a MerchantPurchase through a MerchantSession by passing its UUID.
2377+
**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.
2378+
2379+
### Create a MerchantSession Purchase
2380+
2381+
```python
2382+
import starkbank
2383+
2384+
merchant_session_purchase = starkbank.merchantsession.purchase(
2385+
uuid="0bb894a2697d41d99fe02cad2c00c9bc",
2386+
amount=180,
2387+
installment_count=12,
2388+
card_expiration="2035-01",
2389+
card_number="5448280000000007",
2390+
card_security_code="123",
2391+
holder_name="Holder Name",
2392+
holder_email="[email protected]",
2393+
holder_phone="11111111111",
2394+
funding_type="credit",
2395+
billing_country_code="BRA",
2396+
billing_city="São Paulo",
2397+
billing_state_code="SP",
2398+
billing_street_line1="Rua do Holder Name, 123",
2399+
billing_street_line2="",
2400+
billing_zip_code="11111-111",
2401+
metadata={
2402+
"extraData": "extraData",
2403+
"language": "pt-BR",
2404+
"timezoneOffset": 3,
2405+
"userAgent": "Postman",
2406+
"userIp": "255.255.255.255"
2407+
}
2408+
)
2409+
2410+
print(merchant_session_purchase)
2411+
```
2412+
### Query MerchantSessions
2413+
```python
2414+
import starkbank
2415+
2416+
merchant_sessions = starkbank.merchantsession.query(limit=3)
2417+
for merchant_session in merchant_sessions:
2418+
print(merchant_session)
2419+
```
2420+
### Get a MerchantSession
2421+
```python
2422+
import starkbank
2423+
2424+
merchant_session = starkbank.merchantsession.get('5950134772826112')
2425+
print(merchant_session)
2426+
```
2427+
## Merchant Purchase
2428+
The Merchant Purchase section allows users to retrieve detailed information of the purchases.
2429+
### Query MerchantPurchases
2430+
```python
2431+
import starkbank
2432+
2433+
merchant_purchases = starkbank.merchantpurchase.query(limit=3)
2434+
for merchant_purchase in merchant_purchases:
2435+
print(merchant_purchase)
2436+
```
2437+
### Get a MerchantPurchase
2438+
```python
2439+
import starkbank
2440+
2441+
merchant_purchase = starkbank.merchantpurchase.get('5950134772826112')
2442+
print(merchant_purchase)
2443+
```
23352444

23362445
## Create a webhook subscription
23372446

starkbank/__init__.py

+12
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,24 @@
5858
from . import corporaterule
5959
from .corporaterule.__corporaterule import CorporateRule
6060

61+
from . import merchantcard
62+
from .merchantcard.__merchantcard import MerchantCard
63+
6164
from . import merchantcategory
6265
from .merchantcategory.__merchantcategory import MerchantCategory
6366

6467
from . import merchantcountry
6568
from .merchantcountry.__merchantcountry import MerchantCountry
6669

70+
from . import merchantinstallment
71+
from .merchantinstallment.__merchantinstallment import MerchantInstallment
72+
73+
from . import merchantpurchase
74+
from .merchantpurchase.__merchantpurchase import MerchantPurchase
75+
76+
from . import merchantsession
77+
from .merchantsession.__merchantsession import MerchantSession
78+
6779
from . import cardmethod
6880
from .cardmethod.__cardmethod import CardMethod
6981

starkbank/merchantcard/__init__.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from .__merchantcard import get, query, page
2+
from .log.__log import Log
3+
from . import log
+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
from starkcore.utils.resource import Resource
2+
from ..utils import rest
3+
from starkcore.utils.checks import check_date, check_datetime
4+
5+
class MerchantCard(Resource):
6+
"""# MerchantCard object
7+
Check out our API Documentation at https://starkbank.com/docs/api#merchant-card
8+
"""
9+
10+
def __init__(self, id=None, ending=None , funding_type=None, holder_name=None, network=None, status=None, tags=None, expiration=None, created=None, updated=None):
11+
Resource.__init__(self, id=id)
12+
self.ending = ending
13+
self.funding_type = funding_type
14+
self.holder_name = holder_name
15+
self.network = network
16+
self.status = status
17+
self.tags = tags
18+
self.expiration = expiration
19+
self.created = check_datetime(created)
20+
self.updated = check_datetime(updated)
21+
22+
_resource = {"class": MerchantCard, "name": "MerchantCard"}
23+
24+
def get(id, user=None):
25+
return rest.get_id(resource=_resource, id=id, user=user)
26+
27+
28+
def query(limit=None, after=None, before=None, status=None, tags=None, ids=None, user=None):
29+
return rest.get_stream(
30+
resource=_resource,
31+
limit=limit,
32+
after=check_date(after),
33+
before=check_date(before),
34+
status=status,
35+
tags=tags,
36+
ids=ids,
37+
user=user,
38+
)
39+
40+
41+
def page(cursor=None, limit=None, after=None, before=None, status=None, tags=None, ids=None, user=None):
42+
return rest.get_page(
43+
resource=_resource,
44+
cursor=cursor,
45+
limit=limit,
46+
after=check_date(after),
47+
before=check_date(before),
48+
status=status,
49+
tags=tags,
50+
ids=ids,
51+
user=user,
52+
)
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .__log import query, page, get

starkbank/merchantcard/log/__log.py

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
from starkcore.utils.resource import Resource
2+
from ...utils import rest
3+
from starkcore.utils.checks import check_date
4+
5+
6+
class Log(Resource):
7+
"""# MerchantCard object
8+
Check out our API Documentation at https://starkbank.com/docs/api#merchant-card
9+
"""
10+
11+
def __init__(self, id, created, updated, type, errors, card):
12+
Resource.__init__(self, id=id)
13+
self.created = check_date(created)
14+
self.updated = check_date(updated)
15+
self.type = type
16+
self.errors = errors
17+
self.card = card
18+
19+
_resource = {"class": Log, "name": "MerchantCardLog"}
20+
21+
22+
def get(id, user=None):
23+
return rest.get_id(resource=_resource, id=id, user=user)
24+
25+
26+
def query(limit=None, after=None, before=None, user=None):
27+
return rest.get_stream(
28+
resource=_resource,
29+
limit=limit,
30+
after=check_date(after),
31+
before=check_date(before),
32+
user=user,
33+
)
34+
35+
36+
def page(cursor=None, limit=None, after=None, before=None, types=None, ids=None, user=None):
37+
return rest.get_page(
38+
resource=_resource,
39+
cursor=cursor,
40+
limit=limit,
41+
after=check_date(after),
42+
before=check_date(before),
43+
types=types,
44+
ids=ids,
45+
user=user,
46+
)
47+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from .__merchantinstallment import get, query, page
2+
from .log.__log import Log
3+
from . import log
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
from starkcore.utils.resource import Resource
2+
from ..utils import rest
3+
from starkcore.utils.checks import check_date, check_datetime, check_datetime_or_date
4+
5+
6+
class MerchantInstallment(Resource):
7+
"""# MerchantInstallment object
8+
Check out our API Documentation at https://starkbank.com/docs/api#merchant-installment
9+
"""
10+
11+
def __init__(self, id=None, amount=None, created=None, due=None, fee=None, funding_type=None, network=None, purchase_id=None, status=None, tags=None, transaction_ids=None, updated=None):
12+
Resource.__init__(self, id=id)
13+
14+
self.amount = amount
15+
self.due = check_datetime_or_date(due)
16+
self.fee = fee
17+
self.funding_type = funding_type
18+
self.network = network
19+
self.purchase_id = purchase_id
20+
self.status = status
21+
self.tags = tags
22+
self.transaction_ids = transaction_ids
23+
self.created = check_datetime(created)
24+
self.updated = check_datetime(updated)
25+
26+
_resource = {"class": MerchantInstallment, "name": "MerchantInstallment"}
27+
28+
def get(id, user=None):
29+
return rest.get_id(resource=_resource, id=id, user=user)
30+
31+
32+
def query(limit=None, after=None, before=None, status=None, tags=None, ids=None, user=None):
33+
return rest.get_stream(
34+
resource=_resource,
35+
limit=limit,
36+
after=check_date(after),
37+
before=check_date(before),
38+
status=status,
39+
tags=tags,
40+
ids=ids,
41+
user=user,
42+
)
43+
44+
45+
def page(cursor=None, limit=None, after=None, before=None, status=None, tags=None, ids=None, user=None):
46+
return rest.get_page(
47+
resource=_resource,
48+
cursor=cursor,
49+
limit=limit,
50+
after=check_date(after),
51+
before=check_date(before),
52+
status=status,
53+
tags=tags,
54+
ids=ids,
55+
user=user,
56+
)
57+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .__log import query, page, get
+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
from starkcore.utils.resource import Resource
2+
from ...utils import rest
3+
from starkcore.utils.checks import check_date
4+
5+
6+
class Log(Resource):
7+
"""# MerchantInstallment object
8+
Check out our API Documentation at https://starkbank.com/docs/api#merchant-installment
9+
"""
10+
11+
def __init__(self, id, created, updated, type, errors, installment):
12+
Resource.__init__(self, id=id)
13+
self.created = check_date(created)
14+
self.updated = check_date(updated)
15+
self.type = type
16+
self.errors = errors
17+
self.installment = installment
18+
19+
_resource = {"class": Log, "name": "MerchantInstallmentLog"}
20+
21+
22+
def get(id, user=None):
23+
return rest.get_id(resource=_resource, id=id, user=user)
24+
25+
26+
def query(limit=None, after=None, before=None, user=None):
27+
return rest.get_stream(
28+
resource=_resource,
29+
limit=limit,
30+
after=check_date(after),
31+
before=check_date(before),
32+
user=user,
33+
)
34+
35+
36+
def page(cursor=None, limit=None, after=None, before=None, types=None, ids=None, user=None):
37+
return rest.get_page(
38+
resource=_resource,
39+
cursor=cursor,
40+
limit=limit,
41+
after=check_date(after),
42+
before=check_date(before),
43+
types=types,
44+
ids=ids,
45+
user=user,
46+
)
47+
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from .__merchantpurchase import get, query, page, create, update
2+
from .log.__log import Log
3+
from . import log

0 commit comments

Comments
 (0)