passing dictionay as argument

marco.nawijn at colosso.nl marco.nawijn at colosso.nl
Mon Jun 13 07:36:57 EDT 2016


On Monday, June 13, 2016 at 12:54:45 PM UTC+2, Arshpreet Singh wrote:
> I have to pass dictionary as function argument for following code:
> 
> </code>
> import authorize
> 
> authorize.Configuration.configure(
>     authorize.Environment.TEST,
>     'api_login_id',
>     'api_transaction_key',
> )
> 
> result = authorize.Transaction.sale({
>     'amount': 40.00,
> 
>     'credit_card': {
>         'card_number': '4111111111111111',
>         'expiration_date': '04/2014',
>         'card_code': '343',
>     }
> 
> })
> 
> result.transaction_response.trans_id
> 
> </code>
> 
> I want to define 'credit-card' dictionary as argument in the function as follows but it returns syntax error:
> 
> </code>
> 
> # define dictionary outside the function call: 
> credit_card={
>         'card_number': '4111111111111111',
>         'expiration_date': '04/2014',
>         'card_code': '343',
>     }
> 
> import authorize
> 
> authorize.Configuration.configure(
>     authorize.Environment.TEST,
>     'api_login_id',
>     'api_transaction_key',
> )
> 
> result = authorize.Transaction.sale({'amount': 40.00,credit_card})
> 
> result.transaction_response.trans_id
> 
> it returns following error:
> 
> result = authorize.Transaction.sale({40.00,credit_card})
> TypeError: unhashable type: 'dict'
> 
> Do I need to make changes in authorize.Transaction.sale() source code?

You explicitly need to specify the key for credit_card in the
call to sale(..). I have not run the code myself, but I believe it
will work like this:

result = authorize.Transaction.sale({'amount': 40.00,'credit_card': credit_card}) 


More information about the Python-list mailing list