Skip to content

Commit

Permalink
[DE-801] Fix invoice events structure (#40)
Browse files Browse the repository at this point in the history
- Remove default collection method value
- Reorganize `Invoice Event` structure:
  - Invoice Event is now union type
  - Invoice Event Data is no longer union type. Each Invoice Event has it's own invoice_data with a concrete type
- Remove some redundant models
  • Loading branch information
maciej-nedza authored Jun 4, 2024
1 parent 5a03c89 commit 18f20f0
Show file tree
Hide file tree
Showing 151 changed files with 3,921 additions and 4,161 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ client = AdvancedBillingClient(
basic_auth_credentials=BasicAuthCredentials(
username='BasicAuthUserName',
password='BasicAuthPassword'
)
),
subdomain='subdomain',
domain='chargify.com'
)
```

Expand Down
30 changes: 16 additions & 14 deletions advancedbilling/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
__all__ = [
'invoice_event_payment',
'payment_method_apple_pay',
'payment_method_bank_account',
'payment_method_credit_card',
'payment_method_external',
'payment_method_paypal',
'apply_credit_note_event',
'apply_debit_note_event',
'apply_payment_event',
'backport_invoice_event',
'change_chargeback_status_event',
'change_invoice_collection_method_event',
'change_invoice_status_event',
'create_credit_note_event',
'create_debit_note_event',
'failed_payment_event',
'issue_invoice_event',
'refund_invoice_event',
'remove_payment_event',
'void_invoice_event',
'void_remainder_event',
'list_invoice_events_response',
'account_balance',
'account_balances',
'ach_agreement',
Expand Down Expand Up @@ -40,7 +55,6 @@
'billing_manifest',
'billing_manifest_item',
'billing_schedule',
'billing_address',
'breakouts',
'bulk_components_price_point_assignment',
'bulk_create_product_price_points_request',
Expand Down Expand Up @@ -153,7 +167,6 @@
'credit_note',
'credit_note_application',
'credit_note_line_item',
'credit_note_1',
'credit_scheme_request',
'currency_price',
'currency_prices_response',
Expand All @@ -166,7 +179,6 @@
'customer_error',
'customer_payer_change',
'customer_response',
'customer_1',
'debit_note',
'deduct_service_credit',
'deduct_service_credit_request',
Expand Down Expand Up @@ -202,15 +214,11 @@
'invoice_discount',
'invoice_discount_breakout',
'invoice_display_settings',
'invoice_event',
'invoice_event_data',
'invoice_event_payment_1',
'invoice_issued',
'invoice_line_item',
'invoice_line_item_component_cost_data',
'invoice_line_item_event_data',
'invoice_line_item_pricing_detail',
'invoice_line_item_1',
'invoice_payer',
'invoice_payer_change',
'invoice_payment',
Expand All @@ -235,7 +243,6 @@
'list_components_price_points_response',
'list_coupons_filter',
'list_credit_notes_response',
'list_invoice_events_response',
'list_invoices_response',
'list_metafields_response',
'list_mrr_filter',
Expand Down Expand Up @@ -313,7 +320,6 @@
'prepayments_response',
'preview_allocations_request',
'price',
'price_point',
'product',
'product_family',
'product_family_response',
Expand Down Expand Up @@ -343,7 +349,6 @@
'record_payment_response',
'referral_code',
'referral_validation_response',
'refund',
'refund_consolidated_invoice',
'refund_invoice',
'refund_invoice_event_data',
Expand All @@ -370,11 +375,9 @@
'segment',
'segment_price',
'segment_response',
'seller',
'send_invoice_request',
'service_credit',
'service_credit_response',
'shipping_address',
'signup_proforma_preview',
'signup_proforma_preview_response',
'site',
Expand Down Expand Up @@ -521,7 +524,6 @@
'invoice_payment_method_type',
'invoice_payment_type',
'invoice_role',
'invoice_role_1',
'invoice_sort_field',
'invoice_status',
'item_category',
Expand Down
137 changes: 137 additions & 0 deletions advancedbilling/models/apply_credit_note_event.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
# -*- coding: utf-8 -*-

"""
advanced_billing
This file was automatically generated for Maxio by APIMATIC v3.0 (
https://www.apimatic.io ).
"""
from advancedbilling.api_helper import APIHelper
from advancedbilling.models.apply_credit_note_event_data import ApplyCreditNoteEventData
from advancedbilling.models.invoice import Invoice
from advancedbilling.models.invoice_event_type import InvoiceEventType


class ApplyCreditNoteEvent(object):

"""Implementation of the 'Apply Credit Note Event' model.
TODO: type model description here.
Attributes:
id (long|int): TODO: type description here.
timestamp (datetime): TODO: type description here.
invoice (Invoice): TODO: type description here.
event_type (InvoiceEventType): TODO: type description here.
event_data (ApplyCreditNoteEventData): Example schema for an
`apply_credit_note` event
"""

# Create a mapping from Model property names to API property names
_names = {
"id": 'id',
"timestamp": 'timestamp',
"invoice": 'invoice',
"event_type": 'event_type',
"event_data": 'event_data'
}

def __init__(self,
id=None,
timestamp=None,
invoice=None,
event_type='apply_credit_note',
event_data=None,
additional_properties={}):
"""Constructor for the ApplyCreditNoteEvent class"""

# Initialize members of the class
self.id = id
self.timestamp = APIHelper.apply_datetime_converter(timestamp, APIHelper.RFC3339DateTime) if timestamp else None
self.invoice = invoice
self.event_type = event_type
self.event_data = event_data

# Add additional model properties to the instance
self.additional_properties = additional_properties

@classmethod
def from_dictionary(cls,
dictionary):
"""Creates an instance of this model from a dictionary
Args:
dictionary (dictionary): A dictionary representation of the object
as obtained from the deserialization of the server's response. The
keys MUST match property names in the API description.
Returns:
object: An instance of this structure class.
"""

if dictionary is None:
return None

# Extract variables from the dictionary
id = dictionary.get("id") if dictionary.get("id") else None
timestamp = APIHelper.RFC3339DateTime.from_value(dictionary.get("timestamp")).datetime if dictionary.get("timestamp") else None
invoice = Invoice.from_dictionary(dictionary.get('invoice')) if dictionary.get('invoice') else None
event_type = dictionary.get("event_type") if dictionary.get("event_type") else 'apply_credit_note'
event_data = ApplyCreditNoteEventData.from_dictionary(dictionary.get('event_data')) if dictionary.get('event_data') else None
# Clean out expected properties from dictionary
for key in cls._names.values():
if key in dictionary:
del dictionary[key]
# Return an object of this model
return cls(id,
timestamp,
invoice,
event_type,
event_data,
dictionary)

@classmethod
def validate(cls, dictionary):
"""Validates dictionary against class required properties
Args:
dictionary (dictionary): A dictionary representation of the object
as obtained from the deserialization of the server's response. The
keys MUST match property names in the API description.
Returns:
boolean : if dictionary is valid contains required properties.
"""

if isinstance(dictionary, cls):
return APIHelper.is_valid_type(value=dictionary.id,
type_callable=lambda value: isinstance(value, int)) \
and APIHelper.is_valid_type(value=dictionary.timestamp,
type_callable=lambda value: isinstance(value, APIHelper.RFC3339DateTime)) \
and APIHelper.is_valid_type(value=dictionary.invoice,
type_callable=lambda value: Invoice.validate(value),
is_model_dict=True) \
and APIHelper.is_valid_type(value=dictionary.event_type,
type_callable=lambda value: InvoiceEventType.validate(value)) \
and APIHelper.is_valid_type(value=dictionary.event_data,
type_callable=lambda value: ApplyCreditNoteEventData.validate(value),
is_model_dict=True)

if not isinstance(dictionary, dict):
return False

return APIHelper.is_valid_type(value=dictionary.get('id'),
type_callable=lambda value: isinstance(value, int)) \
and APIHelper.is_valid_type(value=dictionary.get('timestamp'),
type_callable=lambda value: isinstance(value, str)) \
and APIHelper.is_valid_type(value=dictionary.get('invoice'),
type_callable=lambda value: Invoice.validate(value),
is_model_dict=True) \
and APIHelper.is_valid_type(value=dictionary.get('event_type'),
type_callable=lambda value: InvoiceEventType.validate(value)) \
and APIHelper.is_valid_type(value=dictionary.get('event_data'),
type_callable=lambda value: ApplyCreditNoteEventData.validate(value),
is_model_dict=True)
30 changes: 20 additions & 10 deletions advancedbilling/models/apply_credit_note_event_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,17 +164,27 @@ def validate(cls, dictionary):
"""

if isinstance(dictionary, cls):
return APIHelper.is_valid_type(value=dictionary.uid, type_callable=lambda value: isinstance(value, str)) \
and APIHelper.is_valid_type(value=dictionary.credit_note_number, type_callable=lambda value: isinstance(value, str)) \
and APIHelper.is_valid_type(value=dictionary.credit_note_uid, type_callable=lambda value: isinstance(value, str)) \
and APIHelper.is_valid_type(value=dictionary.original_amount, type_callable=lambda value: isinstance(value, str)) \
and APIHelper.is_valid_type(value=dictionary.applied_amount, type_callable=lambda value: isinstance(value, str))
return APIHelper.is_valid_type(value=dictionary.uid,
type_callable=lambda value: isinstance(value, str)) \
and APIHelper.is_valid_type(value=dictionary.credit_note_number,
type_callable=lambda value: isinstance(value, str)) \
and APIHelper.is_valid_type(value=dictionary.credit_note_uid,
type_callable=lambda value: isinstance(value, str)) \
and APIHelper.is_valid_type(value=dictionary.original_amount,
type_callable=lambda value: isinstance(value, str)) \
and APIHelper.is_valid_type(value=dictionary.applied_amount,
type_callable=lambda value: isinstance(value, str))

if not isinstance(dictionary, dict):
return False

return APIHelper.is_valid_type(value=dictionary.get('uid'), type_callable=lambda value: isinstance(value, str)) \
and APIHelper.is_valid_type(value=dictionary.get('credit_note_number'), type_callable=lambda value: isinstance(value, str)) \
and APIHelper.is_valid_type(value=dictionary.get('credit_note_uid'), type_callable=lambda value: isinstance(value, str)) \
and APIHelper.is_valid_type(value=dictionary.get('original_amount'), type_callable=lambda value: isinstance(value, str)) \
and APIHelper.is_valid_type(value=dictionary.get('applied_amount'), type_callable=lambda value: isinstance(value, str))
return APIHelper.is_valid_type(value=dictionary.get('uid'),
type_callable=lambda value: isinstance(value, str)) \
and APIHelper.is_valid_type(value=dictionary.get('credit_note_number'),
type_callable=lambda value: isinstance(value, str)) \
and APIHelper.is_valid_type(value=dictionary.get('credit_note_uid'),
type_callable=lambda value: isinstance(value, str)) \
and APIHelper.is_valid_type(value=dictionary.get('original_amount'),
type_callable=lambda value: isinstance(value, str)) \
and APIHelper.is_valid_type(value=dictionary.get('applied_amount'),
type_callable=lambda value: isinstance(value, str))
Loading

0 comments on commit 18f20f0

Please sign in to comment.