@@ -21,14 +21,20 @@ def filter(self, record):
2121 else :
2222 return 0
2323
24+
2425# Patch pyxb date class; https://github.com/pabigot/pyxb/issues/12
2526from pyxb .binding .datatypes import date as pyxb_date
27+
2628orig_new = pyxb_date .__new__
29+
30+
2731def date_new (cls , * args , ** kw ):
2832 if len (args ) == 8 :
2933 if args [3 ] == 12 and all (not bool (x ) for x in args [- 4 :]):
3034 args = args [:3 ]
3135 return orig_new (cls , * args , ** kw )
36+
37+
3238pyxb_date .__new__ = date_new
3339
3440
@@ -57,21 +63,21 @@ def enhanced_authnet_logging():
5763def _getMerchantAuth ():
5864 merchantAuth = apicontractsv1 .merchantAuthenticationType ()
5965 if config .IN_PRODUCTION :
60- merchantAuth .name = get_setting (' authorizenet_api_login_id_production' )
66+ merchantAuth .name = get_setting (" authorizenet_api_login_id_production" )
6167 merchantAuth .transactionKey = get_setting (
62- 'authorizenet_transaction_key_production' )
68+ "authorizenet_transaction_key_production"
69+ )
6370 else :
64- merchantAuth .name = get_setting ('authorizenet_api_login_id_dev' )
65- merchantAuth .transactionKey = get_setting (
66- 'authorizenet_transaction_key_dev' )
71+ merchantAuth .name = get_setting ("authorizenet_api_login_id_dev" )
72+ merchantAuth .transactionKey = get_setting ("authorizenet_transaction_key_dev" )
6773 return merchantAuth
6874
6975
7076def _getPayment (opaque_data ):
7177 # Create the payment object for a payment nonce
7278 opaqueData = apicontractsv1 .opaqueDataType ()
73- opaqueData .dataDescriptor = opaque_data [' dataDescriptor' ]
74- opaqueData .dataValue = opaque_data [' dataValue' ]
79+ opaqueData .dataDescriptor = opaque_data [" dataDescriptor" ]
80+ opaqueData .dataValue = opaque_data [" dataValue" ]
7581
7682 # Add the payment data to a paymentType object
7783 payment = apicontractsv1 .paymentType ()
@@ -93,8 +99,8 @@ def _getLineItems(cart):
9399
94100
95101def createTransactionRequest (
96- cart , refId , opaque_data , contact_info ,
97- transactionType = 'authCaptureTransaction' ):
102+ cart , refId , opaque_data , contact_info , transactionType = "authCaptureTransaction"
103+ ):
98104
99105 # Get Authorize.net API credentials
100106 merchantAuth = _getMerchantAuth ()
@@ -109,19 +115,20 @@ def createTransactionRequest(
109115 # Set the customer's Bill To address
110116 customerAddress = apicontractsv1 .customerAddressType ()
111117 customerAddress .firstName = contact_info .get (
112- 'first_name' , contact_info .get ('name_on_card' , '' ))
113- customerAddress .lastName = contact_info .get ('last_name' , '' )
114- customerAddress .address = contact_info ['address' ]
115- customerAddress .city = contact_info ['city' ]
116- customerAddress .state = contact_info ['state' ]
117- customerAddress .zip = contact_info ['zip' ]
118- customerAddress .country = contact_info ['country' ]
119- customerAddress .phoneNumber = contact_info ['phone' ]
118+ "first_name" , contact_info .get ("name_on_card" , "" )
119+ )
120+ customerAddress .lastName = contact_info .get ("last_name" , "" )
121+ customerAddress .address = contact_info ["address" ]
122+ customerAddress .city = contact_info ["city" ]
123+ customerAddress .state = contact_info ["state" ]
124+ customerAddress .zip = contact_info ["zip" ]
125+ customerAddress .country = contact_info ["country" ]
126+ customerAddress .phoneNumber = contact_info ["phone" ]
120127
121128 # Set the customer's identifying information
122129 customerData = apicontractsv1 .customerDataType ()
123130 customerData .type = "individual"
124- customerData .email = contact_info [' email' ]
131+ customerData .email = contact_info [" email" ]
125132
126133 # @@@ shipping
127134
@@ -155,23 +162,21 @@ def createTransactionRequest(
155162 controller .execute ()
156163 response = controller .getresponse ()
157164
158- logger .info (
159- 'createTransactionController response: {}' .format (response .__repr__ ())
160- )
161- defaultMsg = 'Your card could not be processed.'
165+ logger .info ("createTransactionController response: {}" .format (response .__repr__ ()))
166+ defaultMsg = "Your card could not be processed."
162167 if controller ._httpResponse :
163- logger .info (' Authorize.net response: {}' .format (controller ._httpResponse ))
164- if response .messages .resultCode == 'Ok' :
168+ logger .info (" Authorize.net response: {}" .format (controller ._httpResponse ))
169+ if response .messages .resultCode == "Ok" :
165170 if response .transactionResponse .responseCode != 1 : # Approved
166171 raise PaymentProcessingException (defaultMsg )
167172 return response
168173 else :
169174 raise PaymentProcessingException (
170- response .messages .message [0 ].text or defaultMsg )
175+ response .messages .message [0 ].text or defaultMsg
176+ )
171177
172178
173- def ARBCreateSubscriptionRequest (
174- cart , refId , opaque_data , contact_info , months ):
179+ def ARBCreateSubscriptionRequest (cart , refId , opaque_data , contact_info , months ):
175180
176181 # Get Authorize.net API credentials
177182 merchantAuth = _getMerchantAuth ()
@@ -193,20 +198,20 @@ def ARBCreateSubscriptionRequest(
193198
194199 # Setting billing information
195200 billto = apicontractsv1 .nameAndAddressType ()
196- billto .firstName = contact_info [' first_name' ]
197- billto .lastName = contact_info [' last_name' ]
198- billto .address = contact_info [' address' ]
199- billto .city = contact_info [' city' ]
200- billto .state = contact_info [' state' ]
201- billto .zip = contact_info [' zip' ]
202- billto .country = contact_info [' country' ]
203- billto .phoneNumber = contact_info [' phone' ]
201+ billto .firstName = contact_info [" first_name" ]
202+ billto .lastName = contact_info [" last_name" ]
203+ billto .address = contact_info [" address" ]
204+ billto .city = contact_info [" city" ]
205+ billto .state = contact_info [" state" ]
206+ billto .zip = contact_info [" zip" ]
207+ billto .country = contact_info [" country" ]
208+ billto .phoneNumber = contact_info [" phone" ]
204209
205210 # Set the customer's identifying information
206211 customerData = apicontractsv1 .customerType ()
207212 customerData .type = "individual"
208- customerData .email = contact_info [' email' ]
209- customerData .phoneNumber = contact_info [' phone' ]
213+ customerData .email = contact_info [" email" ]
214+ customerData .phoneNumber = contact_info [" phone" ]
210215
211216 # Setting subscription details
212217 subscription = apicontractsv1 .ARBSubscriptionType ()
@@ -230,9 +235,9 @@ def ARBCreateSubscriptionRequest(
230235 response = controller .getresponse ()
231236
232237 logger .info (
233- ' ARBCreateSubscriptionController response: {}' .format (response .__repr__ ())
238+ " ARBCreateSubscriptionController response: {}" .format (response .__repr__ ())
234239 )
235- if response .messages .resultCode == 'Ok' :
240+ if response .messages .resultCode == "Ok" :
236241 return response
237242 else :
238- raise PaymentProcessingException (response .messages .message [0 ]. text )
243+ raise PaymentProcessingException (response .messages .message [0 ][ " text" ] )
0 commit comments