Steps to integrate Razorpay
Setting up Razorpay account.
Storing API keys in settings.py
Installing Razorpay library.
Creating order using Razorpay API.
-
Creating order at backend and also creating Razorpay order.
- Show template
- render to payment.html
- Get info of call back URL
- Done with creating an order.
Uploading a File
There are three ways you can upload a file:
From an
Object
instanceFrom a
Bucket
instanceFrom the
client
In each case, you have to provide the Filename
, which is the path of the file you want to upload. You’ll now explore the three alternatives. Feel free to pick whichever you like most to upload the first_file_name
to S3.
from django.urls import path | |
from django.contrib import admin | |
from . import views | |
urlpatterns = [ | |
path("admin/", admin.site.urls), | |
path("", views.home, name="home"), | |
path("payment/", views.order_payment, name="payment"), | |
path("callback/", views.callback, name="callback"), | |
] |
@csrf_exempt | |
def callback(request): | |
def verify_signature(response_data): | |
client = razorpay.Client(auth=(RAZORPAY_KEY_ID, RAZORPAY_KEY_SECRET)) | |
return client.utility.verify_payment_signature(response_data) | |
if "razorpay_signature" in request.POST: | |
payment_id = request.POST.get("razorpay_payment_id", "") | |
provider_order_id = request.POST.get("razorpay_order_id", "") | |
signature_id = request.POST.get("razorpay_signature", "") | |
order = Order.objects.get(provider_order_id=provider_order_id) | |
order.payment_id = payment_id | |
order.signature_id = signature_id | |
order.save() | |
if not verify_signature(request.POST): | |
order.status = PaymentStatus.SUCCESS | |
order.save() | |
return render(request, "callback.html", context={"status": order.status}) | |
else: | |
order.status = PaymentStatus.FAILURE | |
order.save() | |
return render(request, "callback.html", context={"status": order.status}) | |
else: | |
payment_id = json.loads(request.POST.get("error[metadata]")).get("payment_id") | |
provider_order_id = json.loads(request.POST.get("error[metadata]")).get( | |
"order_id" | |
) | |
order = Order.objects.get(provider_order_id=provider_order_id) | |
order.payment_id = payment_id | |
order.status = PaymentStatus.FAILURE | |
order.save() | |
return render(request, "callback.html", context={"status": order.status}) |
@classmethod
def replace_hashnode_gist(cls, markdown):
gist_link_regex = r"\[(https://gist\.github\.com.*?)\]"
gist_urls = re.findall(gist_link_regex, markdown)
new_markdown = markdown
for url in gist_urls:
new_url = "%" + f"[{url}]"
gist_pattern_regex = r"\[" + re.escape(url) + r".*?\)"
gist_to_replace = re.findall(gist_pattern_regex, markdown)[0]
new_markdown = new_markdown.replace(gist_to_replace, new_url)
return new_markdown
Top comments (0)