DEV Community

Cover image for Gists checking
testacc127000
testacc127000

Posted on

3 2

Gists checking

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 instance

  • From a Bucket instance

  • From 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"),
]
view raw urls.py hosted with ❤ by GitHub
@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
Enter fullscreen mode Exit fullscreen mode

Speedy emails, satisfied customers

Postmark Image

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay