-
Notifications
You must be signed in to change notification settings - Fork 224
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'frappe:develop' into develop
- Loading branch information
Showing
31 changed files
with
2,083 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
5 changes: 5 additions & 0 deletions
5
payments/payment_gateways/doctype/gocardless_mandate/gocardless_mandate.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// Copyright (c) 2018, Frappe Technologies and contributors | ||
// For license information, please see license.txt | ||
|
||
frappe.ui.form.on('GoCardless Mandate', { | ||
}); |
63 changes: 63 additions & 0 deletions
63
payments/payment_gateways/doctype/gocardless_mandate/gocardless_mandate.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
{ | ||
"actions": [], | ||
"autoname": "field:mandate", | ||
"creation": "2018-02-08 11:33:15.721919", | ||
"doctype": "DocType", | ||
"editable_grid": 1, | ||
"engine": "InnoDB", | ||
"field_order": [ | ||
"disabled", | ||
"mandate", | ||
"gocardless_customer" | ||
], | ||
"fields": [ | ||
{ | ||
"default": "0", | ||
"fieldname": "disabled", | ||
"fieldtype": "Check", | ||
"label": "Disabled" | ||
}, | ||
{ | ||
"fieldname": "mandate", | ||
"fieldtype": "Data", | ||
"label": "Mandate", | ||
"read_only": 1, | ||
"reqd": 1, | ||
"unique": 1 | ||
}, | ||
{ | ||
"fieldname": "gocardless_customer", | ||
"fieldtype": "Data", | ||
"in_list_view": 1, | ||
"label": "GoCardless Customer", | ||
"read_only": 1, | ||
"reqd": 1 | ||
} | ||
], | ||
"links": [], | ||
"modified": "2023-09-27 10:33:44.453462", | ||
"modified_by": "Administrator", | ||
"module": "Payment Gateways", | ||
"name": "GoCardless Mandate", | ||
"naming_rule": "By fieldname", | ||
"owner": "Administrator", | ||
"permissions": [ | ||
{ | ||
"create": 1, | ||
"delete": 1, | ||
"email": 1, | ||
"export": 1, | ||
"print": 1, | ||
"read": 1, | ||
"report": 1, | ||
"role": "System Manager", | ||
"share": 1, | ||
"write": 1 | ||
} | ||
], | ||
"quick_entry": 1, | ||
"sort_field": "modified", | ||
"sort_order": "DESC", | ||
"states": [], | ||
"track_changes": 1 | ||
} |
9 changes: 9 additions & 0 deletions
9
payments/payment_gateways/doctype/gocardless_mandate/gocardless_mandate.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Copyright (c) 2018, Frappe Technologies and contributors | ||
# For license information, please see license.txt | ||
|
||
|
||
from frappe.model.document import Document | ||
|
||
|
||
class GoCardlessMandate(Document): | ||
pass |
8 changes: 8 additions & 0 deletions
8
payments/payment_gateways/doctype/gocardless_mandate/test_gocardless_mandate.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Copyright (c) 2018, Frappe Technologies and Contributors | ||
# See license.txt | ||
|
||
import unittest | ||
|
||
|
||
class TestGoCardlessMandate(unittest.TestCase): | ||
pass |
89 changes: 89 additions & 0 deletions
89
payments/payment_gateways/doctype/gocardless_settings/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
# Copyright (c) 2018, Frappe Technologies and contributors | ||
# For license information, please see license.txt | ||
|
||
|
||
import hashlib | ||
import hmac | ||
import json | ||
|
||
import frappe | ||
|
||
|
||
@frappe.whitelist(allow_guest=True) | ||
def webhooks(): | ||
r = frappe.request | ||
if not r: | ||
return | ||
|
||
if not authenticate_signature(r): | ||
raise frappe.AuthenticationError | ||
|
||
gocardless_events = json.loads(r.get_data()) or [] | ||
for event in gocardless_events["events"]: | ||
set_status(event) | ||
|
||
return 200 | ||
|
||
|
||
def set_status(event): | ||
resource_type = event.get("resource_type", {}) | ||
|
||
if resource_type == "mandates": | ||
set_mandate_status(event) | ||
|
||
|
||
def set_mandate_status(event): | ||
mandates = [] | ||
if isinstance(event["links"], (list,)): | ||
for link in event["links"]: | ||
mandates.append(link["mandate"]) | ||
else: | ||
mandates.append(event["links"]["mandate"]) | ||
|
||
if ( | ||
event["action"] == "pending_customer_approval" | ||
or event["action"] == "pending_submission" | ||
or event["action"] == "submitted" | ||
or event["action"] == "active" | ||
): | ||
disabled = 0 | ||
else: | ||
disabled = 1 | ||
|
||
for mandate in mandates: | ||
frappe.db.set_value("GoCardless Mandate", mandate, "disabled", disabled) | ||
|
||
|
||
def authenticate_signature(r): | ||
"""Returns True if the received signature matches the generated signature""" | ||
received_signature = frappe.get_request_header("Webhook-Signature") | ||
|
||
if not received_signature: | ||
return False | ||
|
||
for key in get_webhook_keys(): | ||
computed_signature = hmac.new(key.encode("utf-8"), r.get_data(), hashlib.sha256).hexdigest() | ||
if hmac.compare_digest(str(received_signature), computed_signature): | ||
return True | ||
|
||
return False | ||
|
||
|
||
def get_webhook_keys(): | ||
def _get_webhook_keys(): | ||
webhook_keys = [ | ||
d.webhooks_secret | ||
for d in frappe.get_all( | ||
"GoCardless Settings", | ||
fields=["webhooks_secret"], | ||
) | ||
if d.webhooks_secret | ||
] | ||
|
||
return webhook_keys | ||
|
||
return frappe.cache().get_value("gocardless_webhooks_secret", _get_webhook_keys) | ||
|
||
|
||
def clear_cache(): | ||
frappe.cache().delete_value("gocardless_webhooks_secret") |
8 changes: 8 additions & 0 deletions
8
payments/payment_gateways/doctype/gocardless_settings/gocardless_settings.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// Copyright (c) 2018, Frappe Technologies and contributors | ||
// For license information, please see license.txt | ||
|
||
// frappe.ui.form.on('GoCardless Settings', { | ||
// refresh(frm) { | ||
|
||
// }, | ||
// }); |
72 changes: 72 additions & 0 deletions
72
payments/payment_gateways/doctype/gocardless_settings/gocardless_settings.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
{ | ||
"actions": [], | ||
"autoname": "field:gateway_name", | ||
"creation": "2018-02-06 16:11:10.028249", | ||
"doctype": "DocType", | ||
"editable_grid": 1, | ||
"engine": "InnoDB", | ||
"field_order": [ | ||
"gateway_name", | ||
"section_break_2", | ||
"access_token", | ||
"webhooks_secret", | ||
"use_sandbox" | ||
], | ||
"fields": [ | ||
{ | ||
"fieldname": "gateway_name", | ||
"fieldtype": "Data", | ||
"in_list_view": 1, | ||
"label": "Payment Gateway Name", | ||
"reqd": 1, | ||
"unique": 1 | ||
}, | ||
{ | ||
"fieldname": "section_break_2", | ||
"fieldtype": "Section Break" | ||
}, | ||
{ | ||
"fieldname": "access_token", | ||
"fieldtype": "Data", | ||
"in_list_view": 1, | ||
"label": "Access Token", | ||
"reqd": 1 | ||
}, | ||
{ | ||
"fieldname": "webhooks_secret", | ||
"fieldtype": "Data", | ||
"label": "Webhooks Secret" | ||
}, | ||
{ | ||
"default": "0", | ||
"fieldname": "use_sandbox", | ||
"fieldtype": "Check", | ||
"label": "Use Sandbox" | ||
} | ||
], | ||
"links": [], | ||
"modified": "2023-09-22 13:33:42.225243", | ||
"modified_by": "Administrator", | ||
"module": "Payment Gateways", | ||
"name": "GoCardless Settings", | ||
"naming_rule": "By fieldname", | ||
"owner": "Administrator", | ||
"permissions": [ | ||
{ | ||
"create": 1, | ||
"delete": 1, | ||
"email": 1, | ||
"export": 1, | ||
"print": 1, | ||
"read": 1, | ||
"report": 1, | ||
"role": "System Manager", | ||
"share": 1, | ||
"write": 1 | ||
} | ||
], | ||
"sort_field": "modified", | ||
"sort_order": "DESC", | ||
"states": [], | ||
"track_changes": 1 | ||
} |
Oops, something went wrong.