Skip to content

Commit

Permalink
Merge pull request #56 from cassiewang/chore/add-payments-api-to-readme
Browse files Browse the repository at this point in the history
chore: Add payments api to readme
  • Loading branch information
bob-xendit authored Nov 7, 2022
2 parents 758845c + 866c341 commit e1fe71c
Show file tree
Hide file tree
Showing 8 changed files with 1,063 additions and 32 deletions.
1,014 changes: 1,014 additions & 0 deletions README.md

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions xendit/models/_base_model.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
from typing import List
from dataclasses import dataclass


Expand All @@ -12,3 +13,24 @@ def __init__(self, **kwargs):

def __repr__(self):
return json.dumps(vars(self), indent=4)



@dataclass(init=False)
class BaseListModel:
has_more: bool
data: List[any]

"""Abstract class for feature class. Useful for pretty print and automatically set attribute"""

def __init__(self, **kwargs):
for key, value in kwargs.items():
setattr(self, key, value)

def __repr__(self):
return json.dumps({
"has_more": self.has_more,
"data": [
vars(d) for d in self.data
]
}, indent=4)
2 changes: 1 addition & 1 deletion xendit/models/payment/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .payment import Payment
from .payment import Payment
8 changes: 3 additions & 5 deletions xendit/models/payment/payment.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
from typing import List

from xendit._api_requestor import _APIRequestor
from xendit._extract_params import _extract_params
from xendit.models._base_model import BaseModel
from xendit.models._base_model import BaseModel, BaseListModel
from xendit.models.paymentmethod.payment_method import PaymentMethod
from xendit.xendit_error import XenditError


class Payment(BaseModel):
id: str
Expand All @@ -24,6 +22,6 @@ class Payment(BaseModel):
metadata: dict


class PaymentList(BaseModel):
class PaymentList(BaseListModel):
has_more: bool
data: List[Payment]
22 changes: 10 additions & 12 deletions xendit/models/paymentmethod/payment_method.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import List
from xendit._api_requestor import _APIRequestor
from xendit._extract_params import _extract_params
from xendit.models._base_model import BaseModel
from xendit.models._base_model import BaseModel, BaseListModel
from xendit.models._base_query import BaseQuery
from xendit.models.paymentmethod.billing_information import BillingInformation
from xendit.models.paymentmethod.card.card import Card
Expand Down Expand Up @@ -172,8 +172,8 @@ def update(
status: str = None,
reusability: str = None,
reference_id: str = None,
over_the_counter=OverTheCounter.Query,
virtual_account=VirtualAccount.Query,
over_the_counter: OverTheCounter.Query = None,
virtual_account: VirtualAccount.Query = None,
for_user_id=None,
x_api_version=None,
**kwargs,
Expand Down Expand Up @@ -358,8 +358,8 @@ def list_payments(
before_id: str = None,
channel_code: str = None,
customer_id: str = None,
payment_request_id: str=None,
reference_id: str=None,
payment_request_id: str = None,
reference_id: str = None,
status: str = None,
limit: int = None,
for_user_id=None,
Expand Down Expand Up @@ -392,16 +392,16 @@ def list_payments(

from xendit.models.payment.payment import Payment, PaymentList

url = "/v2/payment_methods"
url = f"/v2/payment_methods/{payment_method_id}/payments"
headers, params = _extract_params(
locals(),
func_object=PaymentMethod.list_payments,
headers_params=["for_user_id", "x_idempotency_key", "x_api_version"],
ignore_params=[],
ignore_params=["payment_method_id"],
)
kwargs["headers"] = headers
kwargs["params"] = params

resp = _APIRequestor.get(url, **kwargs)
if resp.status_code >= 200 and resp.status_code < 300:
has_more = resp.body["has_more"]
Expand All @@ -410,7 +410,6 @@ def list_payments(
else:
raise XenditError(resp)


class Query(BaseQuery):
type: str
reusability: str
Expand All @@ -428,6 +427,5 @@ class Query(BaseQuery):
billing_information: BillingInformation


class PaymentMethodList(BaseModel):
has_more: bool
data: List[PaymentMethod]
class PaymentMethodList(BaseListModel):
pass
13 changes: 6 additions & 7 deletions xendit/models/paymentrequest/payment_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from xendit._api_requestor import _APIRequestor
from xendit._extract_params import _extract_params
from xendit.models._base_model import BaseModel
from xendit.models._base_model import BaseModel, BaseListModel
from xendit.models.paymentmethod.payment_method import PaymentMethod
from xendit.xendit_error import XenditError

Expand Down Expand Up @@ -91,7 +91,7 @@ def create(
Raises:
XenditError
"""

url = "/payment_requests"
headers, body = _extract_params(
locals(),
Expand Down Expand Up @@ -210,10 +210,10 @@ def resend_auth(
XenditError
"""
url = f"/payment_requests/{payment_request_id}/resend"
url = f"/payment_requests/{payment_request_id}/auth/resend"
headers, _ = _extract_params(
locals(),
func_object=PaymentRequest.confirm,
func_object=PaymentRequest.resend_auth,
headers_params=["for_user_id", "x_idempotency_key", "x_api_version"],
ignore_params=["payment_request_id"],
)
Expand Down Expand Up @@ -284,6 +284,5 @@ def list(
raise XenditError(resp)


class PaymentRequestList(BaseModel):
has_more: bool
data: List[PaymentRequest]
class PaymentRequestList(BaseListModel):
pass
2 changes: 1 addition & 1 deletion xendit/models/refund/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .refund import Refund
from .refund import Refund
12 changes: 6 additions & 6 deletions xendit/models/refund/refund.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

from xendit._api_requestor import _APIRequestor
from xendit._extract_params import _extract_params
from xendit.models._base_model import BaseModel
from xendit.models._base_model import BaseModel, BaseListModel
from xendit.xendit_error import XenditError


class Refund(BaseModel):
"""Refund class (API Reference: Payment Method)
Expand All @@ -27,7 +28,7 @@ class Refund(BaseModel):
status: str
channel_code: str
reason: str
failure_code:str
failure_code: str
refund_fee_amount: float
created: str
updated: str
Expand All @@ -42,7 +43,7 @@ def create(
currency: str = None,
amount: float = None,
reason: str = None,
metadata: dict=None,
metadata: dict = None,
for_user_id=None,
x_api_version=None,
**kwargs,
Expand Down Expand Up @@ -175,6 +176,5 @@ def list(
raise XenditError(resp)


class RefundList(BaseModel):
has_more: bool
data: List[Refund]
class RefundList(BaseListModel):
pass

0 comments on commit e1fe71c

Please sign in to comment.