Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 
 
 

62 wiersze
1.7 KiB

  1. # Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
  2. # License: GNU General Public License v3. See license.txt
  3. from __future__ import unicode_literals
  4. import frappe
  5. from frappe import _
  6. from frappe.utils import flt, cint
  7. import json
  8. from six import string_types
  9. no_cache = 1
  10. no_sitemap = 1
  11. expected_keys = ('amount', 'title', 'description', 'reference_doctype', 'reference_docname',
  12. 'payer_name', 'payer_email', 'order_id')
  13. def get_context(context):
  14. context.no_cache = 1
  15. context.api_key = get_api_key()
  16. try:
  17. doc = frappe.get_doc("Integration Request", frappe.form_dict['token'])
  18. payment_details = json.loads(doc.data)
  19. for key in expected_keys:
  20. context[key] = payment_details[key]
  21. context['token'] = frappe.form_dict['token']
  22. context['amount'] = flt(context['amount'])
  23. except Exception:
  24. frappe.redirect_to_message(_('Invalid Token'),
  25. _('Seems token you are using is invalid!'),
  26. http_status_code=400, indicator_color='red')
  27. frappe.local.flags.redirect_location = frappe.local.response.location
  28. raise frappe.Redirect
  29. def get_api_key():
  30. api_key = frappe.db.get_value("Razorpay Settings", None, "api_key")
  31. if cint(frappe.form_dict.get("use_sandbox")):
  32. api_key = frappe.conf.sandbox_api_key
  33. return api_key
  34. @frappe.whitelist(allow_guest=True)
  35. def make_payment(razorpay_payment_id, options, reference_doctype, reference_docname, token):
  36. data = {}
  37. if isinstance(options, string_types):
  38. data = json.loads(options)
  39. data.update({
  40. "razorpay_payment_id": razorpay_payment_id,
  41. "reference_docname": reference_docname,
  42. "reference_doctype": reference_doctype,
  43. "token": token
  44. })
  45. data = frappe.get_doc("Razorpay Settings").create_request(data)
  46. frappe.db.commit()
  47. return data