No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 

82 líneas
1.8 KiB

  1. # Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and Contributors
  2. # License: MIT. See LICENSE
  3. import json
  4. import frappe
  5. from frappe import _
  6. from frappe.utils import cint, flt
  7. no_cache = 1
  8. expected_keys = (
  9. "amount",
  10. "title",
  11. "description",
  12. "reference_doctype",
  13. "reference_docname",
  14. "payer_name",
  15. "payer_email",
  16. "order_id",
  17. "currency",
  18. )
  19. def get_context(context):
  20. context.no_cache = 1
  21. context.api_key = get_api_key()
  22. try:
  23. doc = frappe.get_doc("Integration Request", frappe.form_dict["token"])
  24. payment_details = json.loads(doc.data)
  25. for key in expected_keys:
  26. context[key] = payment_details[key]
  27. context["token"] = frappe.form_dict["token"]
  28. context["amount"] = flt(context["amount"])
  29. context["subscription_id"] = (
  30. payment_details["subscription_id"] if payment_details.get("subscription_id") else ""
  31. )
  32. except Exception as e:
  33. frappe.redirect_to_message(
  34. _("Invalid Token"),
  35. _("Seems token you are using is invalid!"),
  36. http_status_code=400,
  37. indicator_color="red",
  38. )
  39. frappe.local.flags.redirect_location = frappe.local.response.location
  40. raise frappe.Redirect
  41. def get_api_key():
  42. api_key = frappe.db.get_single_value("Razorpay Settings", "api_key")
  43. if cint(frappe.form_dict.get("use_sandbox")):
  44. api_key = frappe.conf.sandbox_api_key
  45. return api_key
  46. @frappe.whitelist(allow_guest=True)
  47. def make_payment(
  48. razorpay_payment_id, options, reference_doctype, reference_docname, token
  49. ):
  50. data = {}
  51. if isinstance(options, str):
  52. data = json.loads(options)
  53. data.update(
  54. {
  55. "razorpay_payment_id": razorpay_payment_id,
  56. "reference_docname": reference_docname,
  57. "reference_doctype": reference_doctype,
  58. "token": token,
  59. }
  60. )
  61. data = frappe.get_doc("Razorpay Settings").create_request(data)
  62. frappe.db.commit()
  63. return data