Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow blank billing address #467

Closed
wants to merge 2 commits into from
Closed
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
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ universal = true

[project]
name = "django-vendor"
version = "0.4.20"
version = "0.4.21"

authors = [
{ name="Grant Viklund", email="[email protected]" },
Expand Down
25 changes: 13 additions & 12 deletions src/vendor/processors/authorizenet.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,18 +275,19 @@ def create_billing_address(self, api_address_type):
billing_address = api_address_type
billing_address.firstName = " ".join(self.payment_info.cleaned_data.get('full_name', "").split(" ")[:-1])[:50]
billing_address.lastName = (self.payment_info.cleaned_data.get('full_name', "").split(" ")[-1])[:50]
billing_address.company = self.billing_address.cleaned_data.get('company', "")[:50]
address_lines = self.billing_address.cleaned_data.get('address_1', "")

if self.billing_address.cleaned_data.get('address_2'):
address_lines += f", {self.billing_address.cleaned_data['address_2']}"

billing_address.address = address_lines
billing_address.city = self.billing_address.cleaned_data.get("locality", "")[:40]
billing_address.state = self.billing_address.cleaned_data.get("state", "")[:40]
billing_address.zip = self.billing_address.cleaned_data.get("postal_code")[:20]
country = Country(int(self.billing_address.cleaned_data.get("country")))
billing_address.country = str(country.name)
if self.billing_address:
billing_address.company = self.billing_address.cleaned_data.get('company', "")[:50]
address_lines = self.billing_address.cleaned_data.get('address_1', "")

if self.billing_address.cleaned_data.get('address_2'):
address_lines += f", {self.billing_address.cleaned_data['address_2']}"

billing_address.address = address_lines
billing_address.city = self.billing_address.cleaned_data.get("locality", "")[:40]
billing_address.state = self.billing_address.cleaned_data.get("state", "")[:40]
billing_address.zip = self.billing_address.cleaned_data.get("postal_code")[:20]
country = Country(int(self.billing_address.cleaned_data.get("country")))
billing_address.country = str(country.name)

return billing_address

Expand Down
22 changes: 14 additions & 8 deletions src/vendor/processors/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,18 +108,21 @@ def create_payment_model(self, amount=None):
'full_name': self.payment_info.cleaned_data.get('full_name')
}
self.payment.payee_full_name = self.payment_info.cleaned_data.get('full_name')
self.payment.payee_company = self.billing_address.cleaned_data.get('company')
if self.billing_address:
self.payment.payee_company = self.billing_address.cleaned_data.get('company')
self.payment.status = PurchaseStatus.QUEUED
self.payment.submitted_date = timezone.now()

billing_address = self.billing_address.save(commit=False)
billing_address, created = self.invoice.profile.get_or_create_address(billing_address)
if self.billing_address:
billing_address = self.billing_address.save(commit=False)
billing_address, created = self.invoice.profile.get_or_create_address(billing_address)

if created:
billing_address.profile = self.invoice.profile
billing_address.save()
if created:
billing_address.profile = self.invoice.profile
billing_address.save()

self.payment.billing_address = billing_address

self.payment.billing_address = billing_address
self.payment.save()

def save_payment_transaction_result(self):
Expand Down Expand Up @@ -317,7 +320,10 @@ def set_payment_info_form_data(self, form_data, form_class):
self.payment_info = form_class(form_data)

def is_data_valid(self):
if not (self.billing_address.is_valid() and self.payment_info.is_valid() and self.invoice and self.invoice.order_items.count()):
# allow billing_address to be blank
if self.billing_address and not self.billing_address.is_valid():
return False
if not (self.payment_info.is_valid() and self.invoice and self.invoice.order_items.count()):
return False
return True

Expand Down
23 changes: 14 additions & 9 deletions src/vendor/processors/stripe.py
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ def build_coupon(self, offer, currency):
return coupon_data

def build_payment_method(self):
return {
payment_method = {
'type': 'card',
'card': {
'number': self.payment_info.cleaned_data.get('card_number'),
Expand All @@ -642,19 +642,24 @@ def build_payment_method(self):
'cvc': self.payment_info.cleaned_data.get('cvv_number'),
},
'billing_details': {
'address': {
'line1': self.billing_address.cleaned_data.get('address_1', None),
'line2': self.billing_address.cleaned_data.get('address_2', None),
'city': self.billing_address.cleaned_data.get("locality", ""),
'state': self.billing_address.cleaned_data.get("state", ""),
'country': Country.names[Country.values.index(int(self.billing_address.cleaned_data.get("country")))],
'postal_code': self.billing_address.cleaned_data.get("postal_code")
},
'name': self.payment_info.cleaned_data.get('full_name', None),
'email': self.invoice.profile.user.email
}
}

if self.billing_address:
address = {
'line1': self.billing_address.cleaned_data.get('address_1', None),
'line2': self.billing_address.cleaned_data.get('address_2', None),
'city': self.billing_address.cleaned_data.get("locality", ""),
'state': self.billing_address.cleaned_data.get("state", ""),
'country': Country.names[Country.values.index(int(self.billing_address.cleaned_data.get("country")))],
'postal_code': self.billing_address.cleaned_data.get("postal_code")
}
payment_method.billing_details["address"] = address

return payment_method

def build_payment_intent(self, amount, payment_method_id, currency=DEFAULT_CURRENCY):
stripe_base_fee = self.get_stripe_base_fee_amount(amount)
application_fee = self.get_application_fee_amount(amount)
Expand Down
Loading