Skip to content
Snippets Groups Projects
Commit 9a606053 authored by Pelle Koster's avatar Pelle Koster
Browse files

update billing address for existings customers

parent 6d5684ab
No related branches found
No related tags found
No related merge requests found
...@@ -37,6 +37,13 @@ def get_or_create_customer(visitor: Visitor) -> Optional[str]: ...@@ -37,6 +37,13 @@ def get_or_create_customer(visitor: Visitor) -> Optional[str]:
address=parse_address(visitor.billing_address), address=parse_address(visitor.billing_address),
) )
return customer["id"] return customer["id"]
customer_id = result[0]["id"]
stripe.Customer.modify(
customer_id,
name=visitor.full_name,
address=parse_address(visitor.billing_address),
)
return result[0]["id"] return result[0]["id"]
......
...@@ -177,6 +177,7 @@ def mock_stripe(item_data): ...@@ -177,6 +177,7 @@ def mock_stripe(item_data):
"stripe.Customer.search", return_value={"data": [{"id": "stripe-cus-id"}]} "stripe.Customer.search", return_value={"data": [{"id": "stripe-cus-id"}]}
), ),
patch("stripe.Customer.create", return_value={"id": "stripe-cus-id"}), patch("stripe.Customer.create", return_value={"id": "stripe-cus-id"}),
patch("stripe.Customer.modify", return_value={"id": "stripe-cus-id"}),
patch("stripe.Invoice.create", return_value={"id": "stripe-inv-id"}), patch("stripe.Invoice.create", return_value={"id": "stripe-inv-id"}),
patch("stripe.InvoiceItem.create", return_value={"id": "stripe-invitem-id"}), patch("stripe.InvoiceItem.create", return_value={"id": "stripe-invitem-id"}),
patch( patch(
......
import pytest
import stripe
from stripe_checkout.stripe_checkout.stripe import get_or_create_customer
@pytest.mark.parametrize(
"visit_addresses, stripe_address",
[
([], {}),
([{"country": "NL", "type": "postal"}], {}),
(
[
{"country": "NL", "type": "postal"},
{"country": "BE", "type": "billing"},
],
{"country": "BE"},
),
(
[
{
"address": "line 1\nline 2",
"city": "cityasdf",
"country": "NL",
"houseNumber": "1234",
"houseNumberSuffix": "A",
"postalCode": "1235AF",
"state": "state-asdf",
"type": "billing",
}
],
{
"line1": "line 1\nline 2 1234 A",
"postal_code": "1235AF",
"city": "cityasdf",
"state": "state-asdf",
"country": "NL",
},
),
],
)
def test_create_customer_with_billing_address(
visit_addresses, stripe_address, default_visitor, mock_stripe
):
default_visitor["contact"]["addresses"] = visit_addresses
stripe.Customer.search.return_value = {"data": []}
get_or_create_customer(default_visitor)
assert stripe.Customer.create.call_count == 1
full_result = stripe.Customer.create.call_args.kwargs["address"]
non_empty = {key: val for key, val in full_result.items() if val}
assert non_empty == stripe_address
def test_updates_visitor_with_address(default_visitor, mock_stripe):
default_visitor["contact"]["addresses"] = [{"country": "BE", "type": "billing"}]
get_or_create_customer(default_visitor)
assert stripe.Customer.modify.call_count == 1
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"}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment