Django.fun

'dict' object has no attribute 'META' redirect error

sorry for typos, I'm using translation

I want to integrate virtual pos for payment method, but the error I got is as follows

Error; 'dict' object has no attribute 'META'

views.py:

@login_required(login_url="/user/login")
def payment(request):
options = {
    'api_key': 'api_key',
    'secret_key': 'secret_key',
    'base_url': 'sandbox-api.iyzipay.com'
}


payment_card = {
    'cardHolderName': 'John Doe',
    'cardNumber': '5528790000000008',
    'expireMonth': '12',
    'expireYear': '2030',
    'cvc': '123',
    'registerCard': '0'
}

buyer = {
    'id': 'BY789',
    'name': 'John',
    'surname': 'Doe',
    'gsmNumber': '+905350000000',
    'email': 'email@email.com',
    'identityNumber': '74300864791',
    'lastLoginDate': '2015-10-05 12:43:35',
    'registrationDate': '2013-04-21 15:12:09',
    'registrationAddress': 'Nidakule Göztepe, Merdivenköy Mah. Bora Sok. No:1',
    'ip': '85.34.78.112',
    'city': 'Istanbul',
    'country': 'Turkey',
    'zipCode': '34732'
}

address = {
    'contactName': 'Jane Doe',
    'city': 'Istanbul',
    'country': 'Turkey',
    'address': 'Nidakule Göztepe, Merdivenköy Mah. Bora Sok. No:1',
    'zipCode': '34732'
}

basket_items = [
    {
        'id': 'BI101',
        'name': 'Binocular',
        'category1': 'Collectibles',
        'category2': 'Accessories',
        'itemType': 'PHYSICAL',
        'price': '0.3'
    },
    {
        'id': 'BI102',
        'name': 'Game code',
        'category1': 'Game',
        'category2': 'Online Game Items',
        'itemType': 'VIRTUAL',
        'price': '0.5'
    },
    {
        'id': 'BI103',
        'name': 'Usb',
        'category1': 'Electronics',
        'category2': 'Usb / Cable',
        'itemType': 'PHYSICAL',
        'price': '0.2'
    }
]

request = {
    'locale': 'tr',
    'conversationId': '123456789',
    'price': '1',
    'paidPrice': '1.2',
    'currency': 'TRY',
    'installment': '1',
    'basketId': 'B67832',
    'paymentChannel': 'WEB',
    'paymentGroup': 'PRODUCT',
    'paymentCard': payment_card,
    'buyer': buyer,
    'shippingAddress': address,
    'billingAddress': address,
    'basketItems': basket_items
}

payment = iyzipay.Payment().create(request, options)
return render(request, "cart/payment.html")

brokerage firm codes; https://github.com/iyzico/iyzipay-python

Maybe you can condemn me for attempting such a job without knowing the basics :)

Answers: 2

Answered by Marcus Aldrey, Oct. 13, 2021, 5:23 a.m.

You change the value of request in your code in line

request = {'locale': 'tr',...

This causes the line

return render(request, "cart/payment.html")

to use the modified value of request, instead of the value in

def payment(request):

Try to change the name of your request variable to something different

ex:

request_api = {'locale': 'tr',...
payment = iyzipay.Payment().create(request_api, options)
Answered by Shreeyansh Jain, Oct. 13, 2021, 5:53 a.m.

You override the request variable with your custom dict, due to which you are getting the meta data error.

Change the dict variable name request to something request_payload such as :

request_payload = {
    'locale': 'tr',
    'conversationId': '123456789',
    'price': '1',
    'paidPrice': '1.2',
    'currency': 'TRY',
    'installment': '1',
    'basketId': 'B67832',
    'paymentChannel': 'WEB',
    'paymentGroup': 'PRODUCT',
    'paymentCard': payment_card,
    'buyer': buyer,
    'shippingAddress': address,
    'billingAddress': address,
    'basketItems': basket_items
}
payment = iyzipay.Payment().create(request_payload, options)
return render(request, "cart/payment.html")

Thats it.