import razorpay
from django.conf import settings


class RazorpayAccessor:
    def __init__(self):
        self.client = razorpay.Client(auth=(settings.RAZORPAY_KEY, settings.RAZORPAY_SECRET))

    def create_order(self, amount, order_receipt_id):
        data = {"amount": amount, "currency": "INR", "receipt": order_receipt_id}
        response = self.client.order.create(data=data)
        if response and response.get('status') == 'created':
            return response.get('id')

        return None

    @classmethod
    def get_payment_context(cls, name, email, phone, order_id, amount, description, redirect_url):
        return {
            'razorpay_key': settings.RAZORPAY_KEY,
            'amount': amount * 100,
            'app_name': settings.APP_NAME,
            'transaction_description': description,
            'app_logo_url': settings.APP_LOGO_URL,
            'order_id': order_id,
            'callback_url': redirect_url,
            'user_name': name,
            'user_email': email,
            'user_phone': phone,
        }
