You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

70 lines
1.6 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 flt
  7. from payments.payment_gateways.doctype.braintree_settings.braintree_settings import (
  8. get_client_token,
  9. get_gateway_controller,
  10. )
  11. no_cache = 1
  12. expected_keys = (
  13. "amount",
  14. "title",
  15. "description",
  16. "reference_doctype",
  17. "reference_docname",
  18. "payer_name",
  19. "payer_email",
  20. "order_id",
  21. "currency",
  22. )
  23. def get_context(context):
  24. context.no_cache = 1
  25. # all these keys exist in form_dict
  26. if not (set(expected_keys) - set(list(frappe.form_dict))):
  27. for key in expected_keys:
  28. context[key] = frappe.form_dict[key]
  29. context.client_token = get_client_token(context.reference_docname)
  30. context["amount"] = flt(context["amount"])
  31. gateway_controller = get_gateway_controller(context.reference_docname)
  32. context["header_img"] = frappe.db.get_value(
  33. "Braintree Settings", gateway_controller, "header_img"
  34. )
  35. else:
  36. frappe.redirect_to_message(
  37. _("Some information is missing"),
  38. _(
  39. "Looks like someone sent you to an incomplete URL. Please ask them to look into it."
  40. ),
  41. )
  42. frappe.local.flags.redirect_location = frappe.local.response.location
  43. raise frappe.Redirect
  44. @frappe.whitelist(allow_guest=True)
  45. def make_payment(payload_nonce, data, reference_doctype, reference_docname):
  46. data = json.loads(data)
  47. data.update({"payload_nonce": payload_nonce})
  48. gateway_controller = get_gateway_controller(reference_docname)
  49. data = frappe.get_doc("Braintree Settings", gateway_controller).create_payment_request(
  50. data
  51. )
  52. frappe.db.commit()
  53. return data