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.
 
 
 
 

49 líneas
1.5 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. no_cache = 1
  9. no_sitemap = 1
  10. expected_keys = ('amount', 'title', 'description', 'reference_doctype', 'reference_docname',
  11. 'payer_name', 'payer_email', 'order_id', 'currency')
  12. def get_context(context):
  13. context.no_cache = 1
  14. context.publishable_key = get_api_key()
  15. # all these keys exist in form_dict
  16. if not (set(expected_keys) - set(list(frappe.form_dict))):
  17. for key in expected_keys:
  18. context[key] = frappe.form_dict[key]
  19. context['amount'] = flt(context['amount'])
  20. else:
  21. frappe.redirect_to_message(_('Some information is missing'),
  22. _('Looks like someone sent you to an incomplete URL. Please ask them to look into it.'))
  23. frappe.local.flags.redirect_location = frappe.local.response.location
  24. raise frappe.Redirect
  25. def get_api_key():
  26. publishable_key = frappe.db.get_value("Stripe Settings", None, "publishable_key")
  27. if cint(frappe.form_dict.get("use_sandbox")):
  28. publishable_key = frappe.conf.sandbox_publishable_key
  29. return publishable_key
  30. @frappe.whitelist(allow_guest=True)
  31. def make_payment(stripe_token_id, data, reference_doctype=None, reference_docname=None):
  32. data = json.loads(data)
  33. data.update({
  34. "stripe_token_id": stripe_token_id
  35. })
  36. data = frappe.get_doc("Stripe Settings").create_request(data)
  37. frappe.db.commit()
  38. return data