Arsh Ergon
Arsh Ergon

Reputation: 160

Razorpay payment button connection in django

Hey I'm trying to make donation web app in django I have never work in gateway application.

views.py

def payment_page(request):
    form = PaymentForm(request.POST or None)
    donation = request.POST.get('donation')
        try:
          donation = int(donation) * 100  # Note 1 Rs == 100 ps
          donation = str(donation)
        except TypeError: 
                donation = 100     
        #   If delete this you will TypeError Razorpay money should be greater than 1 ps 
    return render(request, 'mysite/payment_page.html', {'form':form, 'donation':donation})

What I done in try block? 1 rs is equal to 100ps so I multiple it with 100. If I don't use the try it give me typeError

payment_page.html

<div class="container">
    <div class="jumbotron">
        <form method="post">{% csrf_token %}
            {{ form.as_p }}
            <button type="submit" class="btn btn-danger">Donate</button>
        </form>     
    </div>
</div>


<form action="/purchase" method="POST">

     <!-- Note that the amount is in paise = 50 INR -->

<script
    src="https://checkout.razorpay.com/v1/checkout.js"
    data-key="rzp_test_VKwzQnRYkTmxEW"
    data-amount="{{ donation }}"
    data-buttontext="Pay"
    data-name="Merchant Name"
    data-description="Purchase Description"
    data-image=""
    data-prefill.email=" email "
    data-theme.color="blue"
></script>
<input type="hidden" value="Hidden Element" name="hidden">
</form>

How it working right now I enter name, donation amount, email in form click donate the amount it save in database and after that I press pay it display the amount, but I want only one button which can do the both work at the same time or I'm doing something wrong?

Upvotes: 0

Views: 1221

Answers (2)

VICTOR VICKIE
VICTOR VICKIE

Reputation: 31

I know i'm too late but will help someone Razorpay's script tag by default will include a button we cant remove that but can be modified by css for .razorpay-payment-button

Upvotes: 0

Yugandhar Chaudhari
Yugandhar Chaudhari

Reputation: 3964

Dont use "{{ donation }}" it is String by type do {{ donation }} so it will be of type Integer

Upvotes: 1

Related Questions