Skip to content

Commit

Permalink
Add darf-payment and tax-payment options to payment-requests
Browse files Browse the repository at this point in the history
  • Loading branch information
leoKagohara-Stark committed Feb 21, 2024
1 parent 68bc9d8 commit febf705
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Given a version number MAJOR.MINOR.PATCH, increment:
## [Unreleased]
### Added
- function to deposit.log resource get Deposit reversal receipt
- TaxPayment and DarfPayment as PaymentRequest options
### Fixed
- README import on setup file

Expand Down
19 changes: 13 additions & 6 deletions starkbank/paymentrequest/__paymentrequest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
from ..brcodepayment.__brcodepayment import BrcodePayment
from ..boletopayment.__boletopayment import BoletoPayment
from ..utilitypayment.__utilitypayment import UtilityPayment
from ..darfpayment.__darfpayment import DarfPayment
from ..taxpayment.__taxpayment import TaxPayment
from ..transfer.__transfer import _resource as _transfer_resource
from ..transaction.__transaction import _resource as _transaction_resource
from ..boletopayment.__boletopayment import _resource as _boleto_payment_resource
from ..brcodepayment.__brcodepayment import _resource as _brcode_payment_resource
from ..utilitypayment.__utilitypayment import _resource as _utility_payment_resource


from ..darfpayment.__darfpayment import _resource as _darf_payment_resource
from ..taxpayment.__taxpayment import _resource as _tax_payment_resource
class PaymentRequest(Resource):
"""# PaymentRequest object
A PaymentRequest is an indirect request to access a specific cash-out service
Expand All @@ -23,7 +25,7 @@ class PaymentRequest(Resource):
cost center page.
## Parameters (required):
- center_id [string]: target cost center ID. ex: "5656565656565656"
- payment [Transfer, BoletoPayment, UtilityPayment, BrcodePayment, Transaction or dictionary]: payment entity that should be approved and executed.
- payment [Transfer, BoletoPayment, UtilityPayment, BrcodePayment, Transaction, DarfPayment, TaxPayment or dictionary]: payment entity that should be approved and executed.
## Parameters (conditionally required):
- type [string]: payment type, inferred from the payment parameter if it is not a dictionary. ex: "transfer", "boleto-payment"
## Parameters (optional):
Expand Down Expand Up @@ -65,6 +67,8 @@ def _parse_payment(payment, type):
"boleto-payment": _boleto_payment_resource,
"brcode-payment": _brcode_payment_resource,
"utility-payment": _utility_payment_resource,
"darf-payment": _darf_payment_resource,
"tax-payment": _tax_payment_resource,
}[type], payment)), type
except KeyError:
return payment, type
Expand All @@ -82,8 +86,10 @@ def _parse_payment(payment, type):
return payment, "boleto-payment"
if isinstance(payment, UtilityPayment):
return payment, "utility-payment"
if isinstance(payment, BrcodePayment):
return payment, "brcode-payment"
if isinstance(payment, DarfPayment):
return payment, "darf-payment"
if isinstance(payment, TaxPayment):
return payment, "tax-payment"

raise Exception(
"payment must be either "
Expand All @@ -93,7 +99,8 @@ def _parse_payment(payment, type):
", a starkbank.BrcodePayment"
", a starkbank.BoletoPayment"
", a starkbank.UtilityPayment"
" or a starkbank.BrcodePayment"
", a starkbank.TaxPayment"
" or a starkbank.DarfPayment"
", but not a {}".format(type(payment))
)

Expand Down
4 changes: 2 additions & 2 deletions tests/sdk/test_payment_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
class TestPaymentRequestPost(TestCase):

def test_success(self):
requests = generateExamplePaymentRequestsJson(n=5)
requests = generateExamplePaymentRequestsJson(n=7)
requests = starkbank.paymentrequest.create(requests)
self.assertEqual(len(requests), 5)
self.assertEqual(len(requests), 7)
for request in requests:
print(request)

Expand Down
7 changes: 7 additions & 0 deletions tests/utils/paymentRequest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
from .transfer import generateExampleTransfersJson
from .utilityPayment import generateExampleUtilityPaymentsJson
from .brcodePayment import generateExampleBrcodePaymentsJson
from .taxPayment import generateExampleDarfPaymentsJson, generateExampleTaxPaymentsJson


import os

center_id = os.environ["SANDBOX_CENTER_ID"]
Expand All @@ -22,6 +25,8 @@ def generateExamplePaymentRequestsJson(n=1):
"utility-payment",
"brcode-payment",
"transaction",
"darf-payment",
"tax-payment",
])
for _ in range(n)
]
Expand All @@ -34,6 +39,8 @@ def generateExamplePaymentRequestsJson(n=1):
"utility-payment": generateExampleUtilityPaymentsJson,
"brcode-payment": generateExampleBrcodePaymentsJson,
"transaction": generateExampleTransactionsJson,
"darf-payment": generateExampleDarfPaymentsJson,
"tax-payment": generateExampleTaxPaymentsJson,
}[type](n=types.count(type)))

for payment in payments:
Expand Down

0 comments on commit febf705

Please sign in to comment.