Commit 35442adc by Solo Group

senin 3:25

1 parent 36f9fc8f
Generic single-database configuration.
\ No newline at end of file
from __future__ import with_statement
from logging.config import fileConfig
from sqlalchemy import engine_from_config
from sqlalchemy import pool
from alembic import context
# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
config = context.config
# Interpret the config file for Python logging.
# This line sets up loggers basically.
fileConfig(config.config_file_name)
# add your model's MetaData object here
# for 'autogenerate' support
# from myapp import mymodel
# target_metadata = mymodel.Base.metadata
target_metadata = None
# other values from the config, defined by the needs of env.py,
# can be acquired:
# my_important_option = config.get_main_option("my_important_option")
# ... etc.
def run_migrations_offline():
"""Run migrations in 'offline' mode.
This configures the context with just a URL
and not an Engine, though an Engine is acceptable
here as well. By skipping the Engine creation
we don't even need a DBAPI to be available.
Calls to context.execute() here emit the given string to the
script output.
"""
url = config.get_main_option("sqlalchemy.url")
context.configure(
url=url, target_metadata=target_metadata, literal_binds=True
)
with context.begin_transaction():
context.run_migrations()
def run_migrations_online():
"""Run migrations in 'online' mode.
In this scenario we need to create an Engine
and associate a connection with the context.
"""
connectable = engine_from_config(
config.get_section(config.config_ini_section),
prefix="sqlalchemy.",
poolclass=pool.NullPool,
)
with connectable.connect() as connection:
context.configure(
connection=connection, target_metadata=target_metadata
)
with context.begin_transaction():
context.run_migrations()
if context.is_offline_mode():
run_migrations_offline()
else:
run_migrations_online()
"""${message}
Revision ID: ${up_revision}
Revises: ${down_revision | comma,n}
Create Date: ${create_date}
"""
from alembic import op
import sqlalchemy as sa
${imports if imports else ""}
# revision identifiers, used by Alembic.
revision = ${repr(up_revision)}
down_revision = ${repr(down_revision)}
branch_labels = ${repr(branch_labels)}
depends_on = ${repr(depends_on)}
def upgrade():
${upgrades if upgrades else "pass"}
def downgrade():
${downgrades if downgrades else "pass"}
......@@ -64,4 +64,9 @@ api-partner-act,/api/partner/{act}/act,Api Act partner,1,0
api-partner-view,/api/partner/{id}/view,Api View partner,1,0
api-partner-add,/api/partner/add,Api Add partner,1,0
api-partner-edit,/api/partner/{id}/edit,Api Edit partner,1,0
api-partner-delete,/api/partner/{id}/delete,Api Delete partner,1,0
\ No newline at end of file
api-partner-delete,/api/partner/{id}/delete,Api Delete partner,1,0
odeo-purchase,/api/odeo/prepaid/purchase,'API TEST ODEO PURCHASE,1,0
odeo-prepaid-inquiry-pln,/api/odeo/prepaid/pln/inquiry,'API TEST ODEO PLN PRE INQUIRY,1,0
odeo-postpaid-inquiry,/api/odeo/postpaid/inquiry,'API TEST ODEO INQUIRY POSTPAUD,1,0
api-vsi,/api/vsi,'API VSI,1,0
\ No newline at end of file
......@@ -98,7 +98,7 @@ def callback_merchant(order):
url = customer.website
users = customer.users
status = order.status == 1 and "SUCCESS" \
or order.status > -2 and "FAILED" \
or order.status < -2 and "FAILED" \
or "PENDING"
key = invoice.cust_inv_no + users.user_name + users.api_key + status
signature = sha256(key)
......@@ -123,8 +123,7 @@ def callback_merchant(order):
js = get_jsonrpc(method="notify", params=dict(data=data))
log.info("Notify: %s %s" %(url, js))
try:
with requests.session():
requests.post(url, data=data, timeout=10)
requests.post(url, data=js, timeout=10)
except:
pass
......
......@@ -61,7 +61,7 @@ class AddSchema(colander.Schema):
oid="satuan_id", widget=deferred_satuan)
volume = colander.SchemaNode(
colander.Integer(),
oid="volume "
oid="volume"
)
......
Penggunaan Alembic
==================
1. Masuk ke folder module yang akan diinstall
Jalankan perintah berikut ini pada terminal:
```bash
$ alembic init alembic
$ cd alembic
```
2. Edit file `env.py`
Ubah baris 23
```python
# target_metadata = None
from opensipkd.base.models import Base
target_metadata = Base.metadata
version_table = "alembic_pasar_version" # gunakan sesuai dengan dama module biar gak tumpang tindih
```
3. copy alembic.ini.tpl ke folder alembic menjadi alembic.ini:
```commandline
cp ../alembic.ini.tpl alembic.ini
```
4. edit alembic.ini
```ini
sqlalchemy.url = {{db_url}}
sqlalchemy.url = dengan url yang akan digunakan
```
5. Untuk membuat file revisi:
```commandline
alembic -c alembic\alembic.ini revision -m "add modules in produk_category"
```
Output:
```commandline
Generating C:\project\apps3\pasar\models\alembic\versions\dee47015bc2e_add_modules_in_produk_category.py ... done
```
6. Edit file revisi tersebut
ubah pada bagian upgrade
```python
def upgrade():
op.add_column('produk_kategori', sa.Column('moduels', sa.String(64)))
def downgrade():
op.drop_column('produk_kategori', sa.Column('moduels', sa.String(64)))
```
7. Run migrastion
```commandline
alembic -c alembic\alembic.ini upgrade head
```
Catatan:
Jenis operasi standard
```python
def upgrade():
op.create_table(
'account',
sa.Column('id', sa.Integer, primary_key=True),
sa.Column('name', sa.String(50), nullable=False),
sa.Column('description', sa.Unicode(200)),
)
def downgrade():
op.drop_table('account')
```
\ No newline at end of file
......@@ -9,65 +9,68 @@ from opensipkd.base import get_settings
from opensipkd.pasar.models import Partner, PartnerProduk, Produk
from pyramid_rpc.jsonrpc import JsonRpcError
from ..vendor import VendorClass
vsi_status = {
"11": {"message": "ERROR NEED TO SIGN ON", "status": -1},
"12": {"message": "ERROR Tidak bisa dibatalkan", "status": -1},
"13": {"message": "ERROR Nilai Transaksi tidak valid", "status": -3},
"14": {"message": "ERROR ID Tidak Terdaftar", "status": -3},
"15": {"message": "ERROR No Meter Tidak Terdaftar", "status": -3},
"16": {"message": "ERROR PRR SUBSCRIBER", "status": -3},
"17": {"message": "ERROR ID Punya Tunggakan", "status": -3},
"18": {"message": "ERROR Permintaan Sedang diproses", "status": -1},
"26": {"message": "Quota Transaksi Agen Tidak Mencukupi. Silahkan Kontak Agen.", "status": -2},
"29": {"message": "ERROR Kode Hash tidak valid", "status": -2},
"30": {"message": "ERROR Pesan tidak valid", "status": -2},
"31": {"message": "ERROR Kode Bank tidak terdaftar", "status": -2},
"32": {"message": "ERROR Sentral tidak terdaftar", "status": -2},
"33": {"message": "ERROR Produk tidak terdaftar", "status": -2},
"34": {"message": "ERROR PPID Tidak terdaftar", "status": -2},
"35": {"message": "ERROR Akun Tidak Terdaftar", "status": -2},
"41": {"message": "ERROR Nilai Transaksi dibawah Nilai Minimum", "status": -2},
"42": {"message": "ERROR Nilai Transaksi diatas Nilai Maximum", "status": -2},
"43": {"message": "ERROR Daya Baru Lebih Kecil dari Daya Sekarang", "status": -3},
"44": {"message": "ERROR Nilai Daya Tidak Valid", "status": -3},
"45": {"message": "ERROR Nilai Biaya Administrasi Tidak Valid", "status": -3},
"46": {"message": "ERROR Deposit Tidak Mencukupi", "status": -2},
"47": {"message": "ERROR Diluar Batas KWH", "status": -3},
"48": {"message": "ERROR Permintaan sudah kadaluarsa", "status": -3},
"51": {"message": "ERROR Transaksi Gagal dari Mesin Vending", "status": -3},
"52": {"message": "ERROR Transaksi dipending dari Mesin Vending", "status": -1},
"53": {"message": "ERROR Produk tidak ditemukan", "status": -1},
"54": {"message": "ERROR Jawaban dari Biller Tidak ditemukan", "status": -3},
"55": {"message": "ERROR Lainnya Mesin Vending", "status": -2},
"56": {"message": "ERROR Nomor Telpon Tidak diketahui", "status": -3},
"63": {"message": "ERROR Tidak ada Pembayaran", "status": -1},
"60": {"message": "ERROR Akun sudah didaftarkan", "status": -3},
"67": {"message": "ERROR CANNOT CONNECT", "status": -3},
"68": {"message": "ERROR Timeout", "status": -2},
"69": {"message": "ERROR Sertifikat tidak dikenal", "status": -2},
"70": {"message": "ERROR Timeout tidak refund", "status": -1},
"72": {"message": "ERROR Permintaan tidak mungkin dilayani", "status": -2},
"73": {"message": "ERROR Request dipending di Biller", "status": -1},
"77": {"message": "ERROR Id di suspend", "status": -2},
"88": {"message": "ERROR Tagihan sudah dibayar", "status": -3},
"89": {"message": "ERROR Tagihan tidak tersedia", "status": -3},
"90": {"message": "ERROR sedang proses CUT OFF", "status": -1},
"91": {"message": "ERROR Database", "status": -1},
"92": {"message": "ERROR Nomor Referensi Switching tidak ditemukan", "status": -2},
"93": {"message": "ERROR Nomor Referensi Switching tidak valid", "status": -2},
"94": {"message": "ERROR Pembatalan sudah dilakukan", "status": -3},
"95": {"message": "ERROR Kode Merchant tidak terdaftar", "status": -2},
"96": {"message": "ERROR Transaksi tidak ditemukan", "status": -3},
"97": {"message": "ERROR SW BANK Tidak identik", "status": -2},
"98": {"message": "ERROR Nomor Referensi Switching tidak valid", "status": -2},
"146": {"message": "ERROR di servis deposit", "status": -1},
"500": {"message": "ERROR Other Error", "status": -1},
"400": {"message": "ERROR Other Error", "status": -1},
"999": {"message": "ERROR Other Error", "status": -1},
}
"11": {"message": "ERROR NEED TO SIGN ON", "status": -3, "code": 99},
"12": {"message": "ERROR Tidak bisa dibatalkan", "status": -1, "code": 68},
"13": {"message": "ERROR Nilai Transaksi tidak valid", "status": -3, "code": 99},
"17": {"message": "ERROR ID Punya Tunggakan", "status": -3, "code": 99},
"88": {"message": "ERROR Tagihan sudah dibayar", "status": -3, "code": 54},
"89": {"message": "ERROR Tagihan tidak tersedia", "status": -3, "code": 55},
"14": {"message": "ERROR ID Tidak Terdaftar", "status": -3, "code": 55},
"15": {"message": "ERROR No Meter Tidak Terdaftar", "status": -3, "code": 55},
"33": {"message": "ERROR Produk tidak terdaftar", "status": -3, "code": 55},
"31": {"message": "ERROR Kode Bank tidak terdaftar", "status": -3, "code": 55},
"32": {"message": "ERROR Sentral tidak terdaftar", "status": -3, "code": 55},
"16": {"message": "ERROR PRR SUBSCRIBER", "status": -3, "code": 55},
"34": {"message": "ERROR PPID Tidak terdaftar", "status": -3, "code": 55},
"35": {"message": "ERROR Akun Tidak Terdaftar", "status": -3, "code": 55},
"53": {"message": "ERROR Produk tidak ditemukan", "status": -3, "code": 55},
"56": {"message": "ERROR Nomor Telpon Tidak diketahui", "status": -3, "code": 55},
"18": {"message": "ERROR Permintaan Sedang diproses", "status": -1, "code": 68},
"26": {"message": "Quota Transaksi Agen Tidak Mencukupi. Silahkan Kontak Agen.", "status": 0, "code": 68},
"29": {"message": "ERROR Kode Hash tidak valid", "status": -2, "code": 68},
"30": {"message": "ERROR Pesan tidak valid", "status": -2, "code": 68},
"46": {"message": "ERROR Deposit Tidak Mencukupi", "status": -2, "code": 68},
"52": {"message": "ERROR Transaksi dipending dari Mesin Vending", "status": -1, "code": 68 },
"68": {"message": "ERROR Timeout", "status": -1, "code": 68 },
"70": {"message": "ERROR Timeout tidak refund", "status": -1, "code": 68},
"73": {"message": "ERROR Request dipending di Biller", "status": -1, "code": 68},
"51": {"message": "ERROR Transaksi Gagal dari Mesin Vending", "status": -3, "code": 99},
"41": {"message": "ERROR Nilai Transaksi dibawah Nilai Minimum", "status": -3, "code": 99},
"42": {"message": "ERROR Nilai Transaksi diatas Nilai Maximum", "status": -3, "code": 99},
"43": {"message": "ERROR Daya Baru Lebih Kecil dari Daya Sekarang", "status": -3, "code": 99},
"44": {"message": "ERROR Nilai Daya Tidak Valid", "status": -3, "code": 99},
"45": {"message": "ERROR Nilai Biaya Administrasi Tidak Valid", "status": -3, "code": 99},
"47": {"message": "ERROR Diluar Batas KWH", "status": -3, "code": 99},
"48": {"message": "ERROR Permintaan sudah kadaluarsa", "status": -3, "code": 99},
"54": {"message": "ERROR Jawaban dari Biller Tidak ditemukan", "status": -3, "code": 99},
"55": {"message": "ERROR Lainnya Mesin Vending", "status": -3, "code": 99},
"63": {"message": "ERROR Tidak ada Pembayaran", "status": -3, "code": 99},
"60": {"message": "ERROR Akun sudah didaftarkan", "status": -3, "code": 99},
"67": {"message": "ERROR CANNOT CONNECT", "status": -3, "code": 99},
"69": {"message": "ERROR Sertifikat tidak dikenal", "status": -3, "code": 99},
"72": {"message": "ERROR Permintaan tidak mungkin dilayani", "status": -3, "code": 99},
"77": {"message": "ERROR Id di suspend", "status": -2, "code": 68},
"90": {"message": "ERROR sedang proses CUT OFF", "status": -3, "code": 99},
"91": {"message": "ERROR Database", "status": -3, "code": 99},
"92": {"message": "ERROR Nomor Referensi Switching tidak ditemukan", "status": -3, "code": 99},
"93": {"message": "ERROR Nomor Referensi Switching tidak valid", "status": -3, "code": 99},
"94": {"message": "ERROR Pembatalan sudah dilakukan", "status": -3, "code": 99},
"95": {"message": "ERROR Kode Merchant tidak terdaftar", "status": -3, "code": 99},
"96": {"message": "ERROR Transaksi tidak ditemukan", "status": -3, "code": 99},
"97": {"message": "ERROR SW BANK Tidak identik", "status": -3, "code": 99},
"98": {"message": "ERROR Nomor Referensi Switching tidak valid", "status": -3, "code": 99},
"146": {"message": "ERROR di servis deposit", "status": -3, "code": 99},
"500": {"message": "ERROR Other Error", "status": -2, "code": 68},
"400": {"message": "ERROR Other Error", "status": -2, "code": 68},
"999": {"message": "ERROR Other Error", "status": -2, "code": 68},
}
from ..vendor import VendorClass
class Vendor(VendorClass):
def __init__(self, vendor_produk, invoice_det, **kwargs):
......
......@@ -6,7 +6,6 @@ from opensipkd.base.tools import log
class Vendor(VendorClass):
def pars_data(self, data):
product_id = self.invoice_det.produk.id
partner_id = self.invoice_det.h2h_ar_invoice.customer_id
......@@ -38,49 +37,7 @@ class Vendor(VendorClass):
else:
message = "PENDING"
meter = "startend" in data and data["startend"] or ""
"""
<?xml version="1.0"?>
<root>
<status>SUCCESS</status>
<rc>0000</rc>
<rcm>[0] Cek Tagihan Sukses ke:51110000100 refnum:BE1D2979288141D595C19C2A2A8ADAA4</rcm>
<text>51110000100
Dmmy'Smltor.Name-511
1 BLN
AGU17
RP TAG PDAM RP 270.100
ADM RP 1.600
TOTAL RP 271.700
</text>
<refnum>BE1D2979288141D595C19C2A2A8ADAA4</refnum>
<idpel>51110000100</idpel>
<name>Dmmy'Smltor.Name51110000100</name>
<totalperiod>1 BLN</totalperiod>
<billperiod>AGU17</billperiod>
<admincharge>1600</admincharge>
<transamount>271700</transamount>
</root>
"""
"""
{
"data": [{
"nopel": "636289",
"nama": "SUBCRIBER NAME",
"refno": "25641544",
"rincian":{
"pokok": 68000,
"denda": 0,
"admin": 2500,
"period": "2016-07",
"jml_bulan": 1,
"meter": "140-162"
},
"subtotal": 70500,
"discount": 600,
"total": 69900
}]
"""
return {
"code": code,
"status": message,
......@@ -92,7 +49,7 @@ class Vendor(VendorClass):
"pokok": pokok,
"denda": 0,
"admin": admin,
"periode": "billperiod" in data and data["billperiod"] or "",
"period": "billperiod" in data and data["billperiod"] or "",
"jml_bulan": bulan,
# "tarif": "tarifdaya" in data and data["tarifdaya"] or "",
# "no_meter": "msn" in data and data["msn"] or "",
......@@ -114,35 +71,26 @@ class Vendor(VendorClass):
params = self.get_params(cmd='INQ', modul='PDAM')
params["idpel"] = self.id_pel
params["biller"] = self.vendor_produk.kode
params['trxid'] = self.invoice_det.id
self.request = params
self.save_log('inquiry')
params['trxid'] = self.invoice_det.id
log.info("Request: %s", params)
log.info("Inquiry Request: %s", params)
try:
resp = requests.get(self.url, params=params, timeout=15)
except requests.exceptions.RequestException as e:
data = dict(message = e.strerror,
code = e.errno)
return self.save_response(data)
if resp and resp.ok:
data = dict(xmltodict.parse(resp.text)["root"])
log.info("Response: %s", data)
data = self.pars_data(data)
elif resp:
data = dict(message=resp.text,
code=resp.status_code)
else:
data = dict(message="No Response From Biller ",
code=500)
return self.save_response(data)
if resp and resp.ok:
data = dict(xmltodict.parse(resp.text)["root"])
self.response = data
log.info("Inquiry Response: %s", data)
data = self.pars_data(data)
if data:
self.set_success(data, typ="inquiry")
except:
return self.set_failed(typ="inquiry")
return self.save_response(data)
return self.set_failed(typ="inquiry")
def payment(self):
params = self.get_params(cmd='PAY', modul='PDAM')
params["idpel"] = self.id_pel
self.request = params
self.save_log('payment')
......@@ -150,6 +98,9 @@ class Vendor(VendorClass):
resp = requests.get(self.url, params=params, timeout=15)
if resp.ok:
data = dict(xmltodict.parse(resp.text)["root"])
self.response = data
data = self.pars_data(data)
return self.set_success(data)
else:
data = dict(code=resp.status_code,
message=resp.text)
......@@ -157,11 +108,7 @@ class Vendor(VendorClass):
data = dict(code=500,
message="No Response From Biller")
self.response = data
data = self.pars_data(data)
self.save_log('payment')
return data
return self.set_failed(data)
def advice(self):
params = self.get_params(cmd='ADV', modul='pln')
......
......@@ -2,112 +2,29 @@ from opensipkd.pasar.models import PartnerProduk
import requests
import xmltodict
from . import Vendor as VendorClass, vsi_status
from opensipkd.base.tools import log
import logging
log = logging.getLogger(__name__)
class Vendor(VendorClass):
def pars_data(self, data):
"""
<?xml version="1.0"?>
<root>
<status>SUCCESS</status>
<rc>0000</rc>
<rcm>[0] CEK TAGIHAN SUKSES ke:532110000060 refnum:33ECE3543E62474AA0C6C3147D94A31D</rcm>
<text>532110000060
DU'MMY-VSI-532110000
1 BLN
JUN16
RP TAG PLN RP 887.817
ADM RP 1.600
TOTAL RP 890.929
</text>
<refnum>33ECE3543E62474AA0C6C3147D94A31D</refnum>
<idpel>532110000060</idpel>
<nama>DU'MMY-VSI-532110000060</nama>
<bulan>1 BLN</bulan>
<blntagihan>JUN16</blntagihan>
<admin>1600</admin>
<tagihan>889329</tagihan>
<total>890929</total>
</root>
"""
"""
<?xml version="1.0"?>
<root>
<status>SUCCESS</status>
<rc>0000</rc>
<rcm>[0] PEMBAYARAN SUKSES ke:532110000060 refnum:0506213515100D3399B27293E3DBC535</rcm>
<text>22/06/16 14:29
0506213515100D3399B27293E3DBC535
532110000060
3
DU'MMY-VSI-532110000
R1/450
BLN JUN16
RP 887.729
ADM RP 1.600
TOTAL RP 890.929
SUKSES</text>
<date>2016-06-22 14:29:25</date>
<refnum>0506213515100D3399B27293E3DBC535</refnum>
<idpel>532110000060</idpel>
<nama>DU'MMY-VSI-532110000060</nama>
<segmenpower>R1/450</segmenpower>
<startend>888800-889900</startend>
<blntagihan>JUN16</blntagihan>
<ppn>0</ppn>
<denda>0</denda>
<totaltagihanpln>887729</totaltagihanpln>
<admin>1600</admin>
<total>890929</total>
<info1>Informasi Hubungi Call Center: 123 Atau Hub. PLN Terdekat:</info1>
<info2>Terima Kasih</info2>
</root>
"""
power = "segmenpower" in data and data["segmenpower"].split("/") or [""]
power = len(power)>1 and power[-1:][0] or power[0]
pokok = int(data["tagihan"])
self.amt_buy = int(data["total"])
tarif = "tarif" in data and data["tarif"] or ""
p = tarif.split("/")
power = len(p)>1 and p[1] or ""
product_id = self.invoice_det.produk.id
if hasattr(self.invoice_det,'customer_id'):
customer_id = self.invoice_det.customer_id
else:
customer_id = self.invoice_det.h2h_ar_invoice.customer_id
discount = PartnerProduk.get_discount(customer_id, product_id)
admin = self.vendor_produk.produk.harga
harga = "nominal" in data and data["nominal"] or 0
subtotal = harga + admin
token = "token" in data and data["token"] or ""
if "status" in data and data["status"] and data["status"] == "SUCCESS":
self.status = 1
elif "status" in data and data["status"] and data["status"] == "ERROR":
self.status = -1
meter = "startend" in data and data["startend"] or ""
"""
{
"data": [{
"nopel": "530678910024",
"nama": "SUBCRIBER NAME",
"refno": "25641544",
"rincian":{
"pokok": 300000,
"denda": 0,
"admin": 2500,
"period": "2016-08",
"jml_bulan": 1,
"tarif": "R1\/1300VA",
"no_meter": "530678910012",
"meter": "567-756"
},
"subtotal": 302500,
"discount": 800,
"total": 301700
}]
"""
bulan = "bulan" in data and data["bulan"].split(" ")
bulan = bulan and bulan[0] or 0
bulan = "bulan" in data and data["bulan"].split()[0] or 1
bulan = bulan and int(bulan) or 1
discount = int(PartnerProduk.get_discount(customer_id, product_id) * bulan)
admin = int(self.vendor_produk.produk.harga * bulan)
subtotal = pokok + admin
meter = "standmeter" in data and data["standmeter"] or ""
if "rc" in data:
if data['rc']=='0000':
code = 0
......@@ -118,8 +35,27 @@ class Vendor(VendorClass):
# code = "rc" in data and data['rc']=='0000' and 0 or int(data["rc"]) or 500
if code == 0:
self.status = 1
message = "SUCCESS"
return {
"code": 0,
"status": "SUCCESS",
"message": "rcm" in data and "Transaksi berhasil",
"nama": "nama" in data and data["nama"] or "NO-NAME",
"rincian": {
"pokok": pokok,
"denda": 0,
"admin": admin,
"total": subtotal,
"period": "blth" in data and data["blth"] or "",
"jml_bulan": bulan,
"tarif": tarif,
"no_meter": data["subid"] or "",
"power": power,
"meter": meter,
},
"subtotal": subtotal,
"discount": discount,
"total": subtotal - discount,
}
else:
self.status = vsi_status[str(code)]["status"]
if self.status == -3:
......@@ -141,6 +77,7 @@ class Vendor(VendorClass):
"pokok": "tagihan" in data and int(data["tagihan"]) or 0,
"denda": "denda" in data and int(data["denda"]) or 0,
"admin": admin,
"total": subtotal,
"periode": "blntagihan" in data and data["blntagihan"] or "",
"jml_bulan": bulan,
"tarif": "tarifdaya" in data and data["tarifdaya"] or "",
......@@ -171,7 +108,7 @@ class Vendor(VendorClass):
except requests.exceptions.RequestException as e:
data = dict(message = e.strerror,
code = e.errno)
return self.set_pending(data)
return self.set_failed(data)
if resp and resp.ok:
data = dict(xmltodict.parse(resp.text)["root"])
......@@ -181,6 +118,7 @@ class Vendor(VendorClass):
return self.set_failed()
self.result = data
log.info(data)
return self.set_success(data)
elif resp:
......@@ -204,15 +142,15 @@ class Vendor(VendorClass):
# todo: apakah harus di cek dulu data inquirynya
self.save_log('payment')
params['trxid'] = self.invoice_det.id
resp = requests.get(self.url, params=params, timeout=15)
try:
resp = requests.get(self.url, params=params, timeout=15)
if resp.ok:
data = dict(xmltodict.parse(resp.text)["root"])
else:
data = dict(code=resp.status_code,
message=resp.text)
self.response = data
log.info("VSI Payment Result: {}".format(self.response))
# except requests.exceptions.Timeout as errt:
# message = "Biller Timeout Transaksi will be retry"
# self.status = -1
......@@ -228,8 +166,8 @@ class Vendor(VendorClass):
log.info("Payment Response: %s" % (self.response))
return self.set_pending()
self.amt_buy = "harga" in data and data["harga"] or self.amt_buy
self.vend_inv_no = "ref_num" in data and data["ref_num"] or self.vend_inv_no
#self.amt_buy = "harga" in data and data["harga"] or self.amt_buy
self.vend_inv_no = str(self.invoice_det.id)
data = self.pars_data(self.response)
return self.set_success(data)
......
import re
from opensipkd.pasar.models import PartnerProduk
import requests
import xmltodict
from . import Vendor as VendorClass, vsi_status
from opensipkd.base.tools import log
import logging
log = logging.getLogger(__name__)
class Vendor(VendorClass):
def pars_data(self, data):
"""
<status>SUCCESS</status>
<rc>0000</rc>
<rcm>[0] CEK TAGIHAN SUKSES ke:88888888888 refnum:D0EE65CAB0C04601878612867541EEA5</rcm>
<text>88888888888
TestDu''mmyP
R2/7000 VA
Token Unsold: 0
Adm 1.600,00
*Denom Belum Termasuk
Admin</text>
<refnum>D0EE65CAB0C04601878612867541EEA5</refnum>
<msn>88888888888</msn>
<idpel>885555555555</idpel>
<nama>TestDu''mmyPanjang8855555</nama>
<tarifdaya>R2/7000</tarifdaya>
<adm>1600</adm>
<jmltokenunsold>0</jmltokenunsold>
"""
"""
<status>SUCCESS</status>
<rc>0000</rc>
<rcm>[0] PEMBAYARAN SUKSES ke:88888888888 refnum:05062135116139A54A95CCC549DDA94C</rcm>
<text>08/06/16 11:50
05062135116139A54A95CCC549DDA94C
TestDu''mmyP
88888888888
881111111111
R2/6600 VA
RP 201.600
KWH352,0
STROOM/TOKEN 2593 0960 8106 1072 1376
ADM 1.600,00</text>
<tanggal>2016-06-08 11:50:22</tanggal>
<nama>TestDu''mmyPanjang8811111</nama>
<msn>88888888888</msn>
<idpel>881111111111</idpel>
<tarifdaya>R2/6600</tarifdaya>
<nominal>201600</nominal>
<jmlkwh>352</jmlkwh>
<token>2593-0960-8106-1072-51376</token>
<ppn>0</ppn>
<ppj>0</ppj>
<adm>1600</adm>
<angsuran>24000</angsuran>
<materai>0</materai>
"""
power = "tarifdaya" in data and data["tarifdaya"].split("/") or [""]
""""""
tarif = "tarif" in data and data["tarif"] or ""
tarif = "tarifdaya" in data and data["tarifdaya"] or tarif
power = tarif.split("/") or [""]
power = len(power)>1 and power[-1:][0] or power[0]
product_id = self.invoice_det.produk.id
if hasattr(self.invoice_det,"customer_id"):
......@@ -65,9 +23,9 @@ class Vendor(VendorClass):
discount = PartnerProduk.get_discount(partner_id, product_id)
admin = int(self.vendor_produk.produk.harga)
harga = int(self.v_produk_kd)
nominal = "nominal" in data and data["nominal"] and int(data["nominal"]) or 0
harga = nominal and int(re.sub("\D","",self.v_produk_kd))*1000 or 0
subtotal = harga + admin
token = "token" in data and data["token"] or ""
if "status" in data and data["status"] and data["status"] == "SUCCESS":
self.status = 1
......@@ -82,8 +40,6 @@ class Vendor(VendorClass):
else:
code = 500
# code = "rc" in data and data['rc']=='0000' and 0 or int(data["rc"]) or 500
log.info("VSI Result Code: {} {}".format(code, data))
if code == 0:
self.status = 1
message="SUCCESS"
......@@ -95,29 +51,30 @@ class Vendor(VendorClass):
message = "PENDING"
return dict(code=code,
message=message)
return {
self.vend_inv_no = str(self.invoice_det.id)
result = {
"code": code,
"status": message,
"message": "rcm" in data and "Transaksi %s" % message or "No Response From Biller",
"refno": "refnum" in data and data["refnum"] or "",
"nopel": "idpel" in data and data["idpel"] or self.id_pel,
"nama": "nama" in data and data["nama"] or "NO-NAME",
"rincian":{
"pokok": int(self.v_produk_kd),
"rincian": {
"pokok": harga,
"denda": "denda" in data and int(data["denda"]) or 0,
"admin": admin,
"tarif": "tarifdaya" in data and data["tarifdaya"] or "",
"tarif": tarif,
# "ppn": "ppn" in data and data["ppn"] or 0,
# "ref_no": "refnum" in data and data["refnum"] or "",
"no_meter": "msn" in data and data["msn"] or "",
"power": power,
"token": token,
"total": subtotal,
"token": "token" in data and data["token"] or ""
},
"subtotal": subtotal,
"discount": discount,
"total": subtotal-discount,
}
return result
def save_result(self, data, typ="inquiry"):
self.result = data
......@@ -128,7 +85,8 @@ class Vendor(VendorClass):
def inquiry(self):
params = self.get_params(cmd='INQ', modul='PRE')
params["msn"] = self.id_pel
params["nominal"] = self.v_produk_kd
nominal = int(re.sub("\D","",self.v_produk_kd))*1000
params["nominal"] = nominal
self.request = params
self.save_log('inquiry')
params['trxid'] = self.invoice_det.id
......@@ -136,6 +94,7 @@ class Vendor(VendorClass):
try:
resp = requests.get(self.url, params=params, timeout=15)
if resp and resp.ok:
log.info("XML Response: %s" % resp.text)
data = dict(xmltodict.parse(resp.text)["root"])
self.response = data
......@@ -143,7 +102,7 @@ class Vendor(VendorClass):
data = dict(message=resp.text,
code=resp.status_code)
self.response = data
log.info("Response: %s" % data )
log.info("Response as JSON: %s" % data )
except requests.exceptions.RequestException as e:
data = dict(message = e.strerror,
code = e.errno)
......@@ -159,7 +118,8 @@ class Vendor(VendorClass):
def payment(self):
params = self.get_params(cmd='PAY', modul='PRE')
params["msn"] = self.id_pel
params["nominal"] = self.v_produk_kd
nominal = int(re.sub("\D", "", self.v_produk_kd)) * 1000
params["nominal"] = nominal
self.request = params
# todo: apakah harus di cek dulu data inquirynya
self.save_log('payment')
......@@ -188,7 +148,8 @@ class Vendor(VendorClass):
def advice(self):
params = self.get_params(cmd='ADV', modul='PRE')
params["msn"] = self.id_pel
params["nominal"] = self.v_produk_kd
nominal = int(re.sub("\D", "", self.v_produk_kd)) * 1000
params["nominal"] = nominal
self.request = params
# todo: apakah harus di cek dulu data inquirynya
......
......@@ -10,81 +10,60 @@ log = logging.getLogger(__name__)
# todo: result harus distandarisasi
class Vendor(VendorClass):
def pars_data(self, data):
"""
<status>SUCCESS</status>
<rc>0000</rc>
<rcm>0000</rcm>
<text>[0] Pembayaran Sukses</text>
<date>Isi pulsa TN10 berhasil untuk nomor 628527778889 sebesar 10.000, refnum F148919BB5F4093A0F40000000000000 pada tgl 17/04/17 15:32</date>
<refnum>2017-04-17 15:40:28</refnum>
<voucherid>4A61D574138A2D6B4B6 </voucherid>
<destnum>TN10</destnum>
<nominal>10000</nominal>
<serial>4A61D574138A2D6B4B6 </serial>
:return:
"""
code = "rc" in data and int(data["rc"]) or 0
self.status = code and vsi_status[str(code)]["status"] or 1
status = self.status == -3 and "FAILED" or "PENDING"
if status == "PENDING":
code = 68
if self.status>-3:
if "rc" in data:
if data["rc"]=="0000":
code = 0
else:
code = int(data["rc"])
else:
code = -1
if code == 0: # sukses
product_id = self.invoice_det.produk.id
partner_id = self.invoice_det.h2h_ar_invoice.customer_id
discount = PartnerProduk.get_discount(partner_id, product_id)
harga = self.vendor_produk.produk.harga
self.status = 1
status = "status" in data and data["status"] or ""
if not harga:
raise JsonRpcError()
self.discount = int(PartnerProduk.get_discount(partner_id, product_id))
harga = int(self.vendor_produk.produk.harga)
self.amt_buy = data["harga"]
self.amt_sell = harga - self.discount
result = dict(
serial_number="serialnumber" in data and data["serialnumber"] or "",
subtotal=self.amt_sell,
discount=self.discount,
total=self.amt_sell)
return result
else:
discount = 0
harga = 0
self.status = code and vsi_status[str(code)]["status"] or 1
status = self.status == -3 and "FAILED" or "PENDING"
if status == "PENDING":
code = 68
if self.status>-3:
harga = self.vendor_produk.produk.harga
self.status = 1
status = "status" in data and data["status"] or ""
if not harga:
raise JsonRpcError()
else:
discount = 0
harga = 0
result = dict(
status=status,
code=code,
message="rcm" in data \
and (data["rcm"] == "00000" and "SUCCESS" or data["rcm"]) \
message="rcm" in data\
and (data["rcm"] == "00000" and "SUCCESS" or data["rcm"])\
or status,
serial_number="serialnumber" in data and data["serialnumber"] or "",
subtotal=int(harga),
discount=int(discount),
total = int(harga-discount)
total=int(harga-discount)
)
return result
# def inquiry(self):
# params = self.get_params(cmd='INQ', modul='ISI')
# params["tujuan"] = self.id_pel
# params["voucherid"] = self.vendor_produk.kode
# self.request = params
# self.save_log('inquiry')
# log.info("Request: %s %s" % (self.url, self.request))
# try:
# result = requests.get(self.url, params=params, timeout=15)
# if result.ok:
# data = dict(xmltodict.parse(result.text)["root"])
# else:
# data = dict(code=result.status_code,
# message=result.text)
# self.response = data
# log.info("Response: %s" % (data))
#
# except requests.exceptions.RequestException as e:
# data = dict(code=e.errno,
# message=e.strerror)
#
# self.result = self.pars_data(data)
# log.info("Result: %s" % (self.result))
# self.save_log('inquiry')
# return self.result
#
def payment(self):
params = self.get_params(cmd='PAY', modul='ISI')
params["tujuan"] = self.id_pel
params["voucherid"] = self.vendor_produk.kode
self.request = params
log.info("Payment Request: %s" % (params))
data = self.get_price()
......@@ -98,16 +77,7 @@ class Vendor(VendorClass):
self.response = dict(code=result.status_code, message=result.text)
log.info("Payment Response: %s" % (self.response))
return self.set_pending(data, message=result.text)
# except requests.exceptions.HTTPError as errh:
# message = "Http Error:"
# self.status = -2
# return self.set_pending(data, message=message)
#
# except requests.exceptions.ConnectionError as errc:
# message = "Error Connecting:"
# self.status = -2
# return self.set_pending(data, message=message)
#
except requests.exceptions.Timeout as errt:
message = "Biller Timeout Transaksi will be retry"
self.status = -1
......@@ -117,8 +87,8 @@ class Vendor(VendorClass):
self.status = -2
return self.set_pending(data, message=message)
self.amt_buy = "harga" in data and data["harga"] or self.amt_buy
self.vend_inv_no = "ref_num" in data and data["ref_num"] or self.vend_inv_no
# self.amt_buy = "harga" in data and data["harga"] or self.amt_buy
self.vend_inv_no = str(self.invoice_det.id)
data = self.pars_data(self.response)
return self.set_success(data)
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!