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
14 changes: 14 additions & 0 deletions checkout_sdk/accounts/accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,18 +520,24 @@ def __init__(self, frequency_p: ScheduleFrequency):


class ScheduleFrequencyDailyRequest(ScheduleRequest):
# For ISV (SaaS seller) sub-entities, a daily schedule runs on working days only
# (Monday to Friday); payouts do not take place on weekends.
def __init__(self):
super().__init__(ScheduleFrequency.DAILY)


class ScheduleFrequencyMonthlyRequest(ScheduleRequest):
# For ISV (SaaS seller) sub-entities, by_month_day accepts only the combinations
# [1], [15], [1, 15] or [1, 16], in any order.
by_month_day: list # int

def __init__(self):
super().__init__(ScheduleFrequency.MONTHLY)


class ScheduleFrequencyWeeklyRequest(ScheduleRequest):
# For ISV (SaaS seller) sub-entities, by_day accepts working days only
# (Monday to Friday); payouts set to take place on weekends are rejected.
by_day: list # DaySchedule

def __init__(self):
Expand All @@ -541,6 +547,14 @@ def __init__(self):
class UpdateScheduleRequest:
enabled: bool
threshold: int
# The amount, in the minor units of the schedule's currency, to retain in the
# sub-entity's available balance. ISV (SaaS seller) sub-entities only. Min 0.
balance_minimum: int
# Indicates whether to carry forward any balance below the configured minimum
# to the next payout. ISV (SaaS seller) sub-entities only.
carry_forward_enabled: bool
# The ID of the platforms payment instrument used as the payout destination.
payment_instrument_id: str
recurrence: ScheduleRequest


Expand Down
47 changes: 47 additions & 0 deletions tests/accounts/update_schedule_request_serialization_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import json

from checkout_sdk.json_serializer import JsonSerializer
from checkout_sdk.accounts.accounts import (
DaySchedule, ScheduleFrequencyWeeklyRequest, UpdateScheduleRequest,
)


def _serialize(obj):
return json.loads(json.dumps(obj, cls=JsonSerializer))


class TestUpdateScheduleRequestSerialization:

def test_serializes_isv_fields_when_set(self):
recurrence = ScheduleFrequencyWeeklyRequest()
recurrence.by_day = [DaySchedule.MONDAY]

request = UpdateScheduleRequest()
request.enabled = True
request.threshold = 100
request.balance_minimum = 500
request.carry_forward_enabled = True
request.payment_instrument_id = 'ppi_w4jelhppmfiufdnatam37wrfc4'
request.recurrence = recurrence

assert _serialize(request) == {
'enabled': True,
'threshold': 100,
'balance_minimum': 500,
'carry_forward_enabled': True,
'payment_instrument_id': 'ppi_w4jelhppmfiufdnatam37wrfc4',
'recurrence': {
'frequency': 'weekly',
'by_day': ['monday'],
},
}

def test_omits_isv_fields_when_unset(self):
request = UpdateScheduleRequest()
request.enabled = False

serialized = _serialize(request)
assert serialized == {'enabled': False}
assert 'balance_minimum' not in serialized
assert 'carry_forward_enabled' not in serialized
assert 'payment_instrument_id' not in serialized
Loading