Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
stripe-checkout
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
geant-swd
stripe-checkout
Commits
09f6d9e7
Commit
09f6d9e7
authored
4 months ago
by
Pelle Koster
Browse files
Options
Downloads
Patches
Plain Diff
Limit max invoice due date and set maximum date for allowing bank transfers
parent
5bf17369
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
config-example.json
+3
-1
3 additions, 1 deletion
config-example.json
stripe_checkout/stripe_checkout/stripe_.py
+30
-2
30 additions, 2 deletions
stripe_checkout/stripe_checkout/stripe_.py
test/test_stripe.py
+47
-1
47 additions, 1 deletion
test/test_stripe.py
with
80 additions
and
4 deletions
config-example.json
+
3
−
1
View file @
09f6d9e7
...
...
@@ -5,5 +5,7 @@
"STRIPE_TAX_RATE_ID"
:
"txr_1QeddlDSpyjzuj5pPwUcMwTd"
,
"VISIT_API_KEY"
:
"<visit api key>"
,
"VISIT_EXPO_ID"
:
"18lm2fafttito"
,
"SEND_ERROR_EMAILS_TO"
:
[]
"SEND_ERROR_EMAILS_TO"
:
[],
"MAX_INVOICE_DUE_DATE"
:
"2025-05-23"
,
"MAX_BANK_TRANSFER_ALLOWED_DATE"
:
"2025-05-12"
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
stripe_checkout/stripe_checkout/stripe_.py
+
30
−
2
View file @
09f6d9e7
from
__future__
import
annotations
import
datetime
import
functools
import
logging
import
time
...
...
@@ -72,6 +73,33 @@ def parse_address(visit_address: dict, organization: str):
}
def
get_invoice_days_until_due
(
max_days
=
30
):
max_invoice_due_date
=
getattr
(
settings
,
"
MAX_INVOICE_DUE_DATE
"
,
None
)
if
not
max_invoice_due_date
:
return
max_days
days_until_max_due_date
=
(
datetime
.
date
.
fromisoformat
(
max_invoice_due_date
)
-
datetime
.
date
.
today
()
).
days
return
max
(
min
(
days_until_max_due_date
,
max_days
),
0
)
def
_is_bank_transfer_allowed
():
max_bank_transfer_allowed_date
=
getattr
(
settings
,
"
MAX_BANK_TRANSFER_ALLOWED_DATE
"
,
None
)
if
not
max_bank_transfer_allowed_date
:
return
True
return
datetime
.
date
.
today
()
<=
datetime
.
date
.
fromisoformat
(
max_bank_transfer_allowed_date
)
def
get_allowed_payment_methods
():
if
_is_bank_transfer_allowed
():
return
[
"
card
"
,
"
customer_balance
"
]
return
[
"
card
"
]
def
create_invoice
(
shopping_cart
:
ShoppingCart
,
customer_id
,
...
...
@@ -98,8 +126,8 @@ def create_invoice(
invoice
=
stripe
.
Invoice
.
create
(
customer
=
customer_id
,
collection_method
=
"
send_invoice
"
,
payment_settings
=
{
"
payment_method_types
"
:
[
"
card
"
,
"
customer_balance
"
]
},
days_until_due
=
30
,
payment_settings
=
{
"
payment_method_types
"
:
get_allowed_payment_methods
()
},
days_until_due
=
get_invoice_days_until_due
()
,
custom_fields
=
custom_fields
,
rendering
=
{
"
template
"
:
settings
.
STRIPE_INVOICE_TEMPLATE_ID
},
metadata
=
metadata
,
...
...
This diff is collapsed.
Click to expand it.
test/test_stripe.py
+
47
−
1
View file @
09f6d9e7
import
datetime
import
pytest
import
stripe
from
stripe_checkout.stripe_checkout.stripe_
import
get_or_create_customer
from
stripe_checkout.stripe_checkout.stripe_
import
(
get_allowed_payment_methods
,
get_invoice_days_until_due
,
get_or_create_customer
,
)
@pytest.mark.parametrize
(
...
...
@@ -95,3 +100,44 @@ def test_updates_visitor_with_address(default_visitor, mock_stripe):
new_address
=
stripe
.
Customer
.
modify
.
call_args
.
kwargs
[
"
address
"
]
non_empty
=
{
key
:
val
for
key
,
val
in
new_address
.
items
()
if
val
}
assert
non_empty
==
{
"
country
"
:
"
BE
"
}
@pytest.mark.parametrize
(
"
max_due_date_in_days, expected_days_until_due
"
,
[
(
None
,
30
),
(
31
,
30
),
(
30
,
30
),
(
29
,
29
),
(
1
,
1
),
(
0
,
0
),
(
-
1
,
0
),
],
)
def
test_invoice_due_date
(
max_due_date_in_days
,
expected_days_until_due
,
settings
):
if
max_due_date_in_days
is
not
None
:
max_due_date
=
datetime
.
date
.
today
()
+
datetime
.
timedelta
(
days
=
max_due_date_in_days
)
settings
.
MAX_INVOICE_DUE_DATE
=
max_due_date
.
isoformat
()
assert
get_invoice_days_until_due
()
==
expected_days_until_due
@pytest.mark.parametrize
(
"
days_until_max_bank_transfer_date, expected_payment_methods
"
,
[
(
None
,
[
"
card
"
,
"
customer_balance
"
]),
(
1
,
[
"
card
"
,
"
customer_balance
"
]),
(
0
,
[
"
card
"
,
"
customer_balance
"
]),
(
-
1
,
[
"
card
"
]),
],
)
def
test_get_allowed_payment_methods
(
days_until_max_bank_transfer_date
,
expected_payment_methods
,
settings
):
if
days_until_max_bank_transfer_date
is
not
None
:
max_bank_transfer_date
=
datetime
.
date
.
today
()
+
datetime
.
timedelta
(
days
=
days_until_max_bank_transfer_date
)
settings
.
MAX_BANK_TRANSFER_ALLOWED_DATE
=
max_bank_transfer_date
.
isoformat
()
assert
get_allowed_payment_methods
()
==
expected_payment_methods
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment