Home>

Interesting problem. I am making a payment in Django using the payment processor Fondy

I do a paid vote, that is, in order to vote -the user must pay by clicking on the button that takes him to the payment page here in views.py:

def black (request):
if request.user.is_authenticated:
    value, created= Choose.objects.get_or_create (voter= request.user)
    if request.method== 'POST':
        select_action= request.POST ['choose']
        if select_action== 'black':
            value.count_black += 1
            value.save ()
        # return redirect ("home")
    api= Api (merchant_id=, secret_key= '') # I deleted this data in the question
    checkout= Checkout (api= api)
    data= {
        "currency": "RUB",
        "amount": 100,
        "order_desc": "Payment description", # Payment description
        "order_id": str (time.time ())
    }
    url= checkout.url (data) .get ('checkout_url')

html:

<
a href= "{{url}}" >
    <
form method= "post" >
    {% csrf_token%}
        <
button class= "button_b" name= "choose" value= "black" >
            <
h1 style= "color: white" >
                <
strong >
Choose <
/strong >
            <
/h1 >
        <
/button >
    <
/form >
<
/a >

In my code, if a user clicks on a button, then in the results page this value is increased by + 1. To do this, the button must have tupe= "submit" (because of this, the link does not work), but for the link to work the button must have type= "button" (because of this, the vote is not read (no data is sent)).

It turns out that either I can read the voice or redirect the user, but I need both of these actions. What should I do? Please, help.

add an onsubmit event to the form and redirect to the link you need there

entithat2022-01-02 12:47:44

it won't work, the link on the checkout page changes, or can the "url" variable be passed to js?

tammalako2022-01-02 13:19:48

turns out to be possible, but how? on youtube people use wordpress, and I have django.

tammalako2022-01-02 15:28:40