Skip to content

Commit a84d0f9

Browse files
Add merchant purchase, merchant session, merchant card and merchant installment
1 parent d21c221 commit a84d0f9

36 files changed

+1369
-7
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

+194
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+
- [MerchantCard](#query-merchantcard): The Merchant Card resource stores information about cards used in approved purchases. These cards can be used in new purchases without the need to create a new session.
53+
- [MerchantSession](#create-a-merchantsession): 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.
54+
- [MerchantPurchase](#create-a-merchantpurchase): The Merchant Purchase resource can be used to charge customers with credit or debit cards. If a card hasn't been used before, a Merchant Session Purchase must be created and approved with that specific card before it can be used directly in a Merchant Purchase.
55+
- [MerchantInstallment](#query-merchantinstallment): Merchant Installments are created for every installment in a purchase. These resources will track its own due payment date and settlement lifecycle.
5256
- [Split](#query-splits): Split received Invoice payments between different receivers
5357
- [SplitReceiver](#create-splitreceivers): Receiver of an Invoice split
5458
- [Webhooks](#create-a-webhook-subscription): Configure your webhook endpoints and subscriptions
@@ -2333,6 +2337,196 @@ log = starkbank.splitreceiver.log.get("5155165527080960")
23332337
print(log)
23342338
```
23352339

2340+
## Merchant Card
2341+
2342+
The Merchant Card resource stores information about cards used in approved purchases.
2343+
These cards can be used in new purchases without the need to create a new session.
2344+
2345+
## Query MerchantCard
2346+
2347+
```python
2348+
import starkbank
2349+
2350+
merchant_cards = starkbank.merchantcard.query(limit=3)
2351+
for merchant_card in merchant_cards:
2352+
print(merchant_card)
2353+
```
2354+
2355+
## Get a MerchantCard
2356+
2357+
```python
2358+
import starkbank
2359+
2360+
merchantcard = starkbank.merchantcard.get('5950134772826112')
2361+
print(merchantcard)
2362+
```
2363+
2364+
## Create a MerchantSession
2365+
2366+
The Merchant Session allows you to create a session prior to a purchase.
2367+
Sessions are essential for defining the parameters of a purchase, including funding type, expiration, 3DS, and more.
2368+
2369+
```python
2370+
import starkbank
2371+
2372+
merchant_session = starkbank.merchantsession.create({
2373+
"allowedFundingTypes": [
2374+
"debit",
2375+
"credit"
2376+
],
2377+
"allowedInstallments": [
2378+
{
2379+
"totalAmount": 0,
2380+
"count": 1
2381+
},
2382+
{
2383+
"totalAmount": 12000,
2384+
"count": 2
2385+
},
2386+
{
2387+
"totalAmount": 18000,
2388+
"count": 12
2389+
}
2390+
],
2391+
"expiration": 3600,
2392+
"challengeMode": "disabled",
2393+
"tags": [
2394+
"your-tags"
2395+
]
2396+
})
2397+
2398+
print(merchant_session)
2399+
```
2400+
2401+
You can create a MerchantPurchase through a MerchantSession by passing its UUID.
2402+
**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.
2403+
2404+
## Create a MerchantSession Purchase
2405+
2406+
```python
2407+
import starkbank
2408+
2409+
merchant_session_purchase = starkbank.merchantsession.purchase(
2410+
uuid="0bb894a2697d41d99fe02cad2c00c9bc",
2411+
amount=18000,
2412+
installment_count=12,
2413+
card_expiration="2035-01",
2414+
card_number="5448280000000007",
2415+
card_security_code="123",
2416+
holder_name="Margaery Tyrell",
2417+
holder_email="[email protected]",
2418+
holder_phone="11998663456",
2419+
funding_type="credit",
2420+
billing_country_code="BRA",
2421+
billing_city="São Paulo",
2422+
billing_state_code="SP",
2423+
billing_street_line1="Rua do Jardim de cima, 123",
2424+
billing_street_line2="1 andar",
2425+
billing_zip_code="11111-111",
2426+
metadata={
2427+
"extraData": "extraData",
2428+
"language": "pt-BR",
2429+
"timezoneOffset": 3,
2430+
"userAgent": "Mozilla",
2431+
"userIp": "255.255.255.255"
2432+
}
2433+
)
2434+
2435+
print(merchant_session_purchase)
2436+
```
2437+
2438+
## Query MerchantSessions
2439+
2440+
```python
2441+
import starkbank
2442+
2443+
merchant_sessions = starkbank.merchantsession.query(limit=3)
2444+
for merchant_session in merchant_sessions:
2445+
print(merchant_session)
2446+
```
2447+
2448+
## Get a MerchantSession
2449+
2450+
```python
2451+
import starkbank
2452+
2453+
merchant_session = starkbank.merchantsession.get('5950134772826112')
2454+
print(merchant_session)
2455+
```
2456+
2457+
## Create a MerchantPurchase
2458+
2459+
The Merchant Purchase resource can be used to charge customers with credit or debit cards.
2460+
If a card hasn't been used before, a Merchant Session Purchase must be created and approved with that specific card before it can be used directly in a Merchant Purchase.
2461+
2462+
```python
2463+
import starkbank
2464+
2465+
merchant_purchase = starkbank.merchantpurchase.create(
2466+
starkbank.MerchantPurchase(
2467+
amount=10000,
2468+
installment_count=5,
2469+
card_id="6295415968235520",
2470+
funding_type="credit",
2471+
challenge_mode="disabled",
2472+
billing_city="Sao Paulo",
2473+
billing_country_code="BRA",
2474+
billing_state_code="SP",
2475+
billing_street_line_1="Rua Casterly Rock, 2000",
2476+
billing_street_line_2="1 andar",
2477+
billing_zip_code="11111-111",
2478+
holder_email="[email protected]",
2479+
holder_phone="11985923451",
2480+
metadata={
2481+
"userAgent": "userAgent",
2482+
"userIp": "255.255.255.255",
2483+
"language": "pt-BR",
2484+
"timezoneOffset": 3,
2485+
"extraData": "extraData"
2486+
},
2487+
tags=["teste"]
2488+
)
2489+
)
2490+
```
2491+
2492+
## Query MerchantPurchases
2493+
2494+
```python
2495+
import starkbank
2496+
2497+
merchant_purchases = starkbank.merchantpurchase.query(limit=3)
2498+
for merchant_purchase in merchant_purchases:
2499+
print(merchant_purchase)
2500+
```
2501+
2502+
## Get a MerchantPurchase
2503+
2504+
```python
2505+
import starkbank
2506+
2507+
merchant_purchase = starkbank.merchantpurchase.get('5950134772826112')
2508+
print(merchant_purchase)
2509+
```
2510+
2511+
## Query MerchantInstallment
2512+
2513+
```python
2514+
import starkbank
2515+
2516+
merchant_installments = starkbank.merchantinstallment.query(limit=3)
2517+
for merchant_installment in merchant_installments:
2518+
print(merchant_installment)
2519+
```
2520+
2521+
## Get a MerchantInstallment
2522+
2523+
```python
2524+
import starkbank
2525+
2526+
merchant_installment = starkbank.merchantinstallment.get('5950134772826112')
2527+
print(merchant_installment)
2528+
```
2529+
23362530
## Create a webhook subscription
23372531

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

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
+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
from ..utils import rest
2+
from starkcore.utils.resource import Resource
3+
from starkcore.utils.checks import check_date, check_datetime, check_datetime_or_date
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,
11+
expiration=None, created=None, updated=None):
12+
Resource.__init__(self, id=id)
13+
self.ending = ending
14+
self.funding_type = funding_type
15+
self.holder_name = holder_name
16+
self.network = network
17+
self.status = status
18+
self.tags = tags
19+
self.expiration = check_datetime_or_date(expiration)
20+
self.created = check_datetime(created)
21+
self.updated = check_datetime(updated)
22+
23+
24+
_resource = {"class": MerchantCard, "name": "MerchantCard"}
25+
26+
27+
def get(id, user=None):
28+
return rest.get_id(resource=_resource, id=id, user=user)
29+
30+
31+
def query(limit=None, after=None, before=None, status=None, tags=None, ids=None, user=None):
32+
return rest.get_stream(
33+
resource=_resource,
34+
limit=limit,
35+
after=check_date(after),
36+
before=check_date(before),
37+
status=status,
38+
tags=tags,
39+
ids=ids,
40+
user=user,
41+
)
42+
43+
44+
def page(cursor=None, limit=None, after=None, before=None, status=None, tags=None, ids=None, user=None):
45+
return rest.get_page(
46+
resource=_resource,
47+
cursor=cursor,
48+
limit=limit,
49+
after=check_date(after),
50+
before=check_date(before),
51+
status=status,
52+
tags=tags,
53+
ids=ids,
54+
user=user,
55+
)
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .__log import query, page, get

starkbank/merchantcard/log/__log.py

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

0 commit comments

Comments
 (0)