Skip to content

Commit

Permalink
adding payrexx integration
Browse files Browse the repository at this point in the history
  • Loading branch information
lasalesi committed Jun 8, 2023
1 parent cada28c commit 3493294
Show file tree
Hide file tree
Showing 9 changed files with 167 additions and 6 deletions.
2 changes: 1 addition & 1 deletion erpnextswiss/__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.21.0'
__version__ = '1.22.0'

16 changes: 11 additions & 5 deletions erpnextswiss/config/erpnextswiss.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,19 +222,25 @@ def get_data():
"name": "Datatrans Settings",
"label": _("Datatrans Settings"),
"description": _("Datatrans Settings")
},
{
},
{
"type": "doctype",
"name": "Payrexx Settings",
"label": _("Payrexx Settings"),
"description": _("Payrexx Settings")
},
{
"type": "doctype",
"name": "Abacus Export File",
"label": _("Abacus Export File"),
"description": _("Abacus Export File")
},
{
},
{
"type": "page",
"name": "abacus_export",
"label": _("Abacus Export"),
"description": _("Abacus Export")
}
}
]
},
{
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Copyright (c) 2023, libracore (https://www.libracore.com) and contributors
// For license information, please see license.txt

frappe.ui.form.on('Payrexx Settings', {
// refresh: function(frm) {

// }
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"creation": "2023-06-08 22:05:50.215665",
"doctype": "DocType",
"editable_grid": 1,
"engine": "InnoDB",
"field_order": [
"payrexx_instance",
"payrexx_api_key",
"col_main",
"success_url"
],
"fields": [
{
"fieldname": "payrexx_api_key",
"fieldtype": "Data",
"label": "Payrexx API Key"
},
{
"fieldname": "col_main",
"fieldtype": "Column Break"
},
{
"fieldname": "success_url",
"fieldtype": "Data",
"label": "Success URL"
},
{
"fieldname": "payrexx_instance",
"fieldtype": "Data",
"label": "Payrexx Instance"
}
],
"issingle": 1,
"modified": "2023-06-08 22:19:41.458200",
"modified_by": "Administrator",
"module": "ERPNextSwiss",
"name": "Payrexx Settings",
"owner": "Administrator",
"permissions": [
{
"create": 1,
"delete": 1,
"email": 1,
"print": 1,
"read": 1,
"role": "System Manager",
"share": 1,
"write": 1
},
{
"email": 1,
"print": 1,
"read": 1,
"role": "Sales User",
"share": 1
}
],
"quick_entry": 1,
"sort_field": "modified",
"sort_order": "DESC",
"track_changes": 1
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2023, libracore (https://www.libracore.com) and contributors
# For license information, please see license.txt

from __future__ import unicode_literals
# import frappe
from frappe.model.document import Document

class PayrexxSettings(Document):
pass
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2023, libracore (https://www.libracore.com) and Contributors
# See license.txt
from __future__ import unicode_literals

# import frappe
import unittest

class TestPayrexxSettings(unittest.TestCase):
pass
60 changes: 60 additions & 0 deletions erpnextswiss/erpnextswiss/payrexx.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2021-2023, libracore and contributors
# For license information, please see license.txt

from __future__ import unicode_literals
import frappe
from frappe import _
import urllib.request
import requests
import hmac
import hashlib
import base64
import json
from datetime import date, timedelta

API_BASE = "https://api.payrexx.com/v1.0/"

@frappe.whitelist()
def create_payment(title, description, reference, purpose, amount,
vat_rate, sku, currency, success_url):
post_data = {
"title": title,
"description": description,
"psp": 1,
"referenceId": reference,
"purpose": purpose,
"amount": amount,
"vatRate": vat_rate,
"currency": currency,
"sku": sku,
"preAuthorization": 0,
"reservation": 0,
"successRedirectUrl": success_url
}
data = urllib.parse.urlencode(post_data).encode('utf-8')
settings = frappe.get_doc("Payrexx Settings", "Payrexx Settings")
if not settings.payrexx_api_key:
frappe.throw( _("Please set payrexx API key in the Payrexx settings.") )
dig = hmac.new(settings.payrexx_api_key.encode('utf-8'), msg=data, digestmod=hashlib.sha256).digest()
post_data['ApiSignature'] = base64.b64encode(dig).decode()
data = urllib.parse.urlencode(post_data, quote_via=urllib.parse.quote).encode('utf-8')
r = requests.post("{0}Invoice/?instance={1}".format(API_BASE, settings.payrexx_instance), data=data)
response = json.loads(r.content.decode('utf-8'))
invoice = response['data'][0]
return invoice

@frappe.whitelist()
def get_payment_status(payrexx_id):
post_data = {}
data = urllib.parse.urlencode(post_data).encode('utf-8')
settings = frappe.get_doc("Payrexx Settings", "Payrexx Settings")
if not settings.payrexx_api_key:
frappe.throw( _("Please set payrexx API key in the Payrexx settings.") )
dig = hmac.new(settings.payrexx_api_key.encode('utf-8'), msg=data, digestmod=hashlib.sha256).digest()
post_data['ApiSignature'] = base64.b64encode(dig).decode()
data = urllib.parse.urlencode(post_data, quote_via=urllib.parse.quote).encode('utf-8')
r = requests.get("{0}Invoice/{2}/?instance={1}".format(API_BASE, settings.payrexx_instance, payrexx_id), data=data)
response = json.loads(r.content.decode('utf-8'))
invoice = response['data'][0]
return invoice
5 changes: 5 additions & 0 deletions erpnextswiss/translations/de.csv
Original file line number Diff line number Diff line change
Expand Up @@ -404,3 +404,8 @@ DocType: Salary Certificate Settings,Salary Certificate Settings,Lohnausweis Ein
DocType: Payment Reminder,Final reminder,Letzte Mahnung
DocType: Payment Reminder,First reminder,Erste Mahnung
DocType: Payment Reminder,Second reminder,Zweite Mahnung
DocType: Payrexx Settings,Payrexx Settings,Payrexx-Einstellungen
DocType: Payrexx Settings,Please set payrexx API key in the Payrexx settings.,Bitte den Payrexx API Key in den Payrexx-Einstellungen eintragen.
DocType: Payrexx Settings,Payrexx Instance,Payrexx-Instanz
DocType: Payrexx Settings,Payrexx API Key,Payrexx API-Schlüssel
DocType: Payrexx Settings,Success URL,Erfolgs-URL

0 comments on commit 3493294

Please sign in to comment.