44from .refund_info import RefundInfo
55from .buyer_provided_info import BuyerProvidedInfo
66from .supported_transaction_currencies import SupportedTransactionCurrencies
7+ from src .bitpay_sdk .utils .key_utils import change_camel_case_to_snake_case
78
8-
9- def change_camel_case_to_snake_case (string ):
10- return '' .join (['_' + i .lower () if i .isupper ()
11- else i for i in string ]).lstrip ('_' )
12-
13-
14- class Invoice :
9+ class Invoice (object ):
1510 __currency = ""
1611
1712 __guid = ""
@@ -35,7 +30,7 @@ class Invoice:
3530 __payment_display_subtotals = None
3631 __payment_codes = None
3732 __acceptance_window = None
38- __buyer = None
33+ __buyer = Buyer ()
3934 __refund_addresses = None
4035 __close_url = ""
4136 __auto_redirect = False
@@ -53,13 +48,13 @@ class Invoice:
5348 __target_confirmations = None
5449 __refund_address_request_pending = None
5550 __buyer_provided_email = None
56- __buyer_provided_info = None
57- __supported_transaction_currencies = None
58- __miner_fees = None
51+ __buyer_provided_info = BuyerProvidedInfo ()
52+ __supported_transaction_currencies = SupportedTransactionCurrencies ()
53+ __miner_fees = MinerFees ()
5954 __non_paypro_payment_received = None
60- __shopper = None
55+ __shopper = Shopper ()
6156 __bill_id = None
62- __refund_info = None
57+ __refund_info = RefundInfo ()
6358 __extended_notifications = False
6459
6560 __transaction_currency = None
@@ -70,21 +65,18 @@ class Invoice:
7065 __exchange_rates = None
7166
7267 def __init__ (self , price = None , currency = None , ** kwargs ):
68+
7369 self .__price = kwargs .get ('price' , "" ) if not price else price
7470 self .__currency = kwargs .get ('currency' , "" ) if not currency else currency
7571
7672 for key , value in kwargs .items ():
7773 try :
74+ if key in ["buyer" , "buyerProvidedInfo" , "shopper" , "supportedTransactionCurrencies" , "minerFees" , "refundInfo" ]:
75+ klass = globals ()[key [0 ].upper () + key [1 :]]
76+ value = klass (** value )
7877 getattr (self , 'set_%s' % change_camel_case_to_snake_case (key ))(value )
7978 except AttributeError as e :
80- pass
81-
82- self .__buyer = Buyer ()
83- self .__buyer_provided_info = BuyerProvidedInfo ()
84- self .__supported_transaction_currencies = SupportedTransactionCurrencies ()
85- self .__miner_fees = MinerFees ()
86- self .__shopper = Shopper ()
87- self .__refund_info = RefundInfo ()
79+ print (e )
8880
8981 def get_guid (self ):
9082 return self .__guid
0 commit comments