DEV Community

Cover image for Gists checking Final
testacc127000
testacc127000

Posted on

3 2

Gists checking Final

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

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

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

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay