Created
May 20, 2022 14:50
-
-
Save guhkun13/f5b4b7d37c21a123aa5037ffb0d0e37c to your computer and use it in GitHub Desktop.
Test
This file contains hidden or 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
import zeep | |
import simplejson | |
import os | |
# import jsonify | |
from flask import Flask | |
from zeep.transports import Transport | |
app_env = os.getenv('APP_ENV') | |
app = Flask(__name__) | |
app.run(debug=True) | |
@app.route("/") | |
def hello_world(): | |
return "Halo Dunia" | |
@app.route("/inquiry/<kode_biller>/<no_bayar>") | |
def inquiry(kode_biller, no_bayar): | |
url = get_url_switching(kode_biller) | |
data_request = { | |
"kodeBank": "BSM", | |
"kodeChannel": "ATM", | |
"kodeTerminal": "FLAGGING", | |
"nomorPembayaran": no_bayar, | |
"tanggalTransaksi": "0519092813", | |
"idTransaksi": "checkIdTrx" | |
} | |
return hit_wsdl(url, data_request) | |
# private func | |
def get_url_switching(kode_biller): | |
host = os.getenv('HOST_SWITCHING_DEV') or "localhost" | |
if app_env == "prod": | |
host = os.getenv('HOST_SWITCHING_PROD') | |
return host+"/services/switching-"+app_env+"/"+kode_biller+"/wsdl" | |
def hit_wsdl(url, data) : | |
print(url, data) | |
transport = Transport(timeout=10) | |
try: | |
client = zeep.Client(wsdl=url, transport=transport) | |
ret = client.service.inquiry(data) | |
mydict = zeep.helpers.serialize_object(ret) | |
fret = simplejson.loads(simplejson.dumps(mydict), use_decimal=True) | |
print(fret, type(fret)) | |
# retjson = jsonify(fret) | |
return fret | |
except Exception as e: | |
print("Exception:", e) | |
return simplejson.loads({"status":False, "message":str(e)}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment