Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions barte/client.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import Dict, Any, Optional
from typing import Dict, Any, Optional, Union
from dataclasses import asdict
import requests
from dacite import from_dict
from .models import (
Expand All @@ -11,6 +12,7 @@
BuyerList,
Order,
ChargeList,
OrderPayload,
)


Expand Down Expand Up @@ -51,9 +53,13 @@ def get_instance(cls) -> "BarteClient":
)
return cls._instance

def create_order(self, data: Dict[str, Any]) -> Order:
def create_order(self, data: Union[Dict[str, Any], OrderPayload]) -> Order:
"""Create a new order"""
endpoint = f"{self.base_url}/v2/orders"

if isinstance(data, OrderPayload):
data = asdict(data)

response = requests.post(endpoint, headers=self.headers, json=data)
response.raise_for_status()
return from_dict(data_class=Order, data=response.json(), config=DACITE_CONFIG)
Expand Down
95 changes: 94 additions & 1 deletion barte/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from dataclasses import dataclass
from datetime import datetime
from typing import Optional, List
from typing import Optional, List, Literal
from dacite import Config
from dateutil.parser import parse as parse_date

Expand Down Expand Up @@ -199,3 +199,96 @@ class BuyerList(BaseListReponse):
@dataclass
class ChargeList(BaseListReponse):
content: List[Charge]


@dataclass
class Card:
holderName: str
number: str
expiration: str
cvv: str


@dataclass
class InternationalDocument:
documentNumber: str
documentType: str
documentNation: str


@dataclass
class BillingAddress:
country: str
state: str
city: str
district: str
street: str
zipCode: str
number: Optional[str]
complement: Optional[str]


@dataclass
class FraudData:
name: str
email: str
phone: str
billingAddress: BillingAddress
internationalDocument: Optional[InternationalDocument]
document: Optional[str]


@dataclass
class Payment:
method: Literal[
"PIX",
"BANK_SLIP",
"CREDIT_CARD",
"CREDIT_CARD_EARLY_BUYER",
"CREDIT_CARD_EARLY_SELLER",
"DEBIT_CARD",
"CREDIT_CARD_EARLY_MIXED",
"GOOGLE_PAY",
"APPLE_PAY",
"INVALID",
]
brand: Optional[str]
cardToken: Optional[str]
capture: Optional[bool]
integrationOrderId: Optional[str]
card: Optional[Card]
fraudData: Optional[FraudData]


@dataclass
class SubSellerPayment:
idSubSeller: int
amount: int
paymentValue: int
paymentType: str


@dataclass
class SubSellerPaymentRequest:
subSellerPayment: List[SubSellerPayment]


@dataclass
class Metadata:
key: str
value: str


@dataclass
class OrderPayload:
title: str
uuidBuyer: str
startDate: str
value: int
installments: int
payment: Payment
attemptReference: Optional[str]
urlCallBack: Optional[str]
description: Optional[str]
subSellerPaymentRequest: Optional[SubSellerPaymentRequest]
metadata: Optional[List[Metadata]]