From 734227d5c08912fa597f604bb72dad3536b86d2e Mon Sep 17 00:00:00 2001 From: donatello Date: Thu, 18 Jul 2019 10:37:48 +0430 Subject: [PATCH] Added staticfile option for provision --- wolf/application.py | 3 +++ wolf/helpers.py | 13 +++++++++++++ wolf/iso8583.py | 7 ++----- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/wolf/application.py b/wolf/application.py index a6ec092..dccb6e7 100644 --- a/wolf/application.py +++ b/wolf/application.py @@ -118,6 +118,9 @@ class Wolf(Application): iso8583: mackey: 1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C pinkey: 1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C + provision: + delivery: maskansmsprovider + filename: %(data_dir)s/provision-strings.csv ''' diff --git a/wolf/helpers.py b/wolf/helpers.py index 8a580f6..545874c 100644 --- a/wolf/helpers.py +++ b/wolf/helpers.py @@ -9,6 +9,19 @@ def create_soap_client(wsdl): return zeep.Client(wsdl) +def deliver_provisioning(phone, provisionstring): + config = settings.iso8583.provision + + if config.delivery == 'staticfile': + with open(config.filename, 'a') as codes_file: + codes_file.write(f'{phone}, {provisionstring}\n') + + elif config.delivery == 'maskansmsprovider': + sms_response = MaskanSmsProvider().send( + phone, + provisionstring[:120] + ) + class MaskanSmsProvider: def __init__(self): diff --git a/wolf/iso8583.py b/wolf/iso8583.py index 6262189..f7ed3ae 100644 --- a/wolf/iso8583.py +++ b/wolf/iso8583.py @@ -19,7 +19,7 @@ from .models import Token, MiniToken, Cryptomodule, Person from wolf.authentication import MaskanAuthenticator from wolf.backends import MaskanClient -from wolf.helpers import MaskanSmsProvider +from wolf.helpers import MaskanSmsProvider, deliver_provisioning logger = get_logger('ISO8583') @@ -342,10 +342,7 @@ def zero_padding_datetime(value): try: provision = token.provision(f'98{phone[-10:]}').split('/')[-1] - sms_response = MaskanSmsProvider().send( - phone, - provision[:120] - ) + sms_response = deliver_provisioning(phone, provision) except HTTPKnownStatus: logger.exception(traceback.format_exc())