-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
payments: relocate shared EPC QR generation code
- Loading branch information
1 parent
81c15e6
commit 177ad55
Showing
3 changed files
with
39 additions
and
37 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from io import BytesIO | ||
|
||
from markupsafe import Markup | ||
from segno import helpers | ||
|
||
|
||
def make_epc_qrfile(payment, **kwargs): | ||
qrfile = BytesIO() | ||
# TODO: this isn't currently used. Need to fetch IBAN from payment.recommended_destination | ||
# and name from somewhere - maybe config rather than hard-coding. | ||
qr = helpers.make_epc_qr( | ||
name="EMF Festivals Ltd", | ||
iban=payment.recommended_destination.iban, | ||
amount=payment.amount, | ||
reference=payment.bankref, | ||
encoding=1, | ||
) | ||
qr.save(qrfile, **kwargs) | ||
qrfile.seek(0) | ||
return qrfile | ||
|
||
|
||
def qrfile_to_svg(qrfile): | ||
return Markup(qrfile.getvalue().decode("utf-8")) | ||
|
||
|
||
def format_inline_epc_qr(payment): | ||
qrfile = make_epc_qrfile( | ||
payment, | ||
kind="svg", | ||
svgclass=None, | ||
omitsize=True, | ||
xmldecl=False, | ||
svgns=False, | ||
nl=False, | ||
) | ||
return qrfile_to_svg(qrfile) |
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