Skip to content

Commit

Permalink
Merge branch 'hotfix'
Browse files Browse the repository at this point in the history
  • Loading branch information
dti-deploy committed Aug 7, 2019
2 parents 8958f8c + 8cc6140 commit ce23480
Show file tree
Hide file tree
Showing 7 changed files with 177 additions and 14 deletions.
2 changes: 1 addition & 1 deletion gateway_selector/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

__version__ = '1.0.4'
__version__ = '1.0.5'

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"allow_copy": 0,
"allow_guest_to_view": 0,
"allow_import": 0,
"allow_rename": 0,
"beta": 0,
Expand All @@ -12,6 +13,7 @@
"engine": "InnoDB",
"fields": [
{
"allow_bulk_edit": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
Expand All @@ -22,6 +24,7 @@
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Title",
Expand All @@ -40,6 +43,7 @@
"unique": 0
},
{
"allow_bulk_edit": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
Expand All @@ -50,6 +54,7 @@
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Description",
Expand All @@ -68,6 +73,7 @@
"unique": 0
},
{
"allow_bulk_edit": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
Expand All @@ -78,6 +84,7 @@
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Amount",
Expand All @@ -96,6 +103,7 @@
"unique": 0
},
{
"allow_bulk_edit": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
Expand All @@ -106,6 +114,7 @@
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Currency",
Expand All @@ -125,6 +134,7 @@
"unique": 0
},
{
"allow_bulk_edit": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
Expand All @@ -135,6 +145,7 @@
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Reference Type",
Expand All @@ -154,6 +165,7 @@
"unique": 0
},
{
"allow_bulk_edit": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
Expand All @@ -164,6 +176,7 @@
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Reference",
Expand All @@ -183,6 +196,7 @@
"unique": 0
},
{
"allow_bulk_edit": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
Expand All @@ -193,6 +207,7 @@
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Payer Email",
Expand All @@ -211,6 +226,7 @@
"unique": 0
},
{
"allow_bulk_edit": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
Expand All @@ -221,6 +237,7 @@
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Payer Name",
Expand All @@ -239,6 +256,7 @@
"unique": 0
},
{
"allow_bulk_edit": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
Expand All @@ -249,6 +267,7 @@
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Order ID",
Expand All @@ -265,20 +284,50 @@
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_bulk_edit": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "gateway_service",
"fieldtype": "Data",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Gateway Service",
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
}
],
"has_web_view": 0,
"hide_heading": 0,
"hide_toolbar": 0,
"idx": 0,
"image_view": 0,
"in_create": 0,
"in_dialog": 0,
"is_submittable": 0,
"issingle": 0,
"istable": 0,
"max_attachments": 0,
"modified": "2017-03-09 13:23:48.998563",
"modified_by": "Administrator",
"modified": "2019-08-01 00:01:24.314337",
"modified_by": "[email protected]",
"module": "Gateway Selector",
"name": "Gateway Selector Proxy",
"name_case": "",
Expand All @@ -294,7 +343,6 @@
"export": 1,
"if_owner": 0,
"import": 0,
"is_custom": 0,
"permlevel": 0,
"print": 1,
"read": 1,
Expand All @@ -309,8 +357,10 @@
"quick_entry": 0,
"read_only": 0,
"read_only_onload": 0,
"show_name_in_global_search": 0,
"sort_field": "modified",
"sort_order": "DESC",
"title_field": "title",
"track_changes": 1,
"track_seen": 0
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,43 @@
import frappe
from frappe.model.document import Document


def call_hook(hook_name, **kwargs):
hooks = frappe.get_hooks(hook_name) or []
for hook in hooks:
# don't allow hooks to break processing
try:
frappe.call(hook, **kwargs)
except Exception:
# Hook inception, pass exception to hook listening for exception reporting(sentry)
error_hooks = frappe.get_hooks("error_capture_log") or []
if len(error_hooks) > 0:
for error_hook in error_hooks:
frappe.call(error_hook, async=True)
else:
log("Error calling hook method: {}->{}".format(hook_name, hook))
log(frappe.get_traceback())

class GatewaySelectorProxy(Document):

def on_payment_authorized(self, payment_status):
result = frappe.get_doc(

reference_doc = frappe.get_doc(
self.reference_doctype,
self.reference_docname).run_method("on_payment_authorized",
payment_status)
self.reference_docname)

# This may be a quotation, sales order or sales invoice
order_doc = frappe.get_doc(
reference_doc.reference_doctype,
reference_doc.get("reference_docname", reference_doc.get("reference_name"))
)

call_hook("gateway_selector_on_payment_authorized", transaction=self, order=order_doc, pr_result=None)

result = reference_doc.run_method(
"on_payment_authorized",
payment_status)

frappe.db.commit()

return result
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* eslint-disable */
// rename this file from _test_[name] to test_[name] to activate
// and remove above this line

QUnit.test("test: Gateway Selector Proxy", function (assert) {
let done = assert.async();

// number of asserts
assert.expect(1);

frappe.run_serially([
// insert a new Gateway Selector Proxy
() => frappe.tests.make('Gateway Selector Proxy', [
// values to be set
{key: 'value'}
]),
() => {
assert.equal(cur_frm.doc.key, 'value');
},
() => done()
]);

});
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ def build_proxy(self, **kwargs):
"doctype": "Gateway Selector Proxy"
}
data.update(kwargs)

# When a PR request is built system references order_id as the PR itself
# here we are checking if we have a Payment Request to update the proxy's
# order_id field to match the PR doctype's name
if kwargs.get("reference_doctype") == 'Payment Request':
pr = frappe.get_doc("Payment Request", kwargs.get("reference_docname"))
data.update({ "order_id": pr.reference_name })

proxy = frappe.get_doc(data)

proxy.flags.ignore_permissions = 1
Expand Down Expand Up @@ -173,3 +181,8 @@ def build_embed_context(context, is_backend=False):
if gateway.get('embed_form'):
context["gateway_scripts"].append(gateway.get('embed_form').get("script_url"))
context["gateway_styles"].append(gateway.get('embed_form').get("style_url"))

@frappe.whitelist()
def update_proxy_gateway(name, gateway_service):
frappe.db.set_value('Gateway Selector Proxy', name, 'gateway_service', gateway_service)
frappe.db.commit()
Loading

0 comments on commit ce23480

Please sign in to comment.