async def get_new_postal_data(session, remittance): apikey = '5c91a4239f54889de26a9a4a29698f16' request_url = "https://api.novaposhta.ua/v2.0/json/" json_req = { "apiKey": "{}".format(apikey), "modelName": "TrackingDocument", "calledMethod": "getStatusDocuments", "methodProperties": { "Documents":[ { "DocumentNumber": "{}".format(remittance.postal_code), }] } } async with session.get(request_url, data=json.dumps(json_req)) as response: data = await response.read() data = json.loads(data) if time.time() - float(remittance.date_payed) > 1874880: if data['data'][0]['StatusCode'] == '9' or data['data'][0]['StatusCode'] == '3': liqpay = LiqPay(public_key, private_key) res = liqpay.api("request", { "action" : "hold_completion", "version" : "3", "order_id" : remittance.liqpay_order_id, "amount" : str(float(remittance.amount * 0.01)), }) res = liqpay.api("request", { "action" : "p2p", "version" : "3", "phone" : remittance.remittance_customer.usercard.phone_number, "amount" : remittance.amount, "currency" : "UAH", "description" : remittance.payment_desciption, "order_id" : str(gen_link()), "receiver_card" : remittance.remittance_seller.usercard.card_number, "card" : remittance.remittance_customer.usercard.card_number, "card_exp_month" : remittance.remittance_customer.usercard.month_card, "card_exp_year" : remittance.remittance_customer.usercard.year_card, "card_cvv" : remittance.remittance_customer.usercard.cvv_card })
def lipay_send(self, remittance, res='yes'): if res == 'yes': liqpay = LiqPay(public_key, private_key) res = liqpay.api( "request", { "action": "hold_completion", "version": "3", "order_id": remittance.liqpay_order_id, "amount": str(float(remittance.amount * 0.01)), }) res = liqpay.api( "request", { "action": "p2p", "version": "3", "phone": '38' + remittance.remittance_customer.usercard.phone_number, "amount": remittance.amount, "currency": "UAH", "description": remittance.payment_desciption, "order_id": str(gen_link()), "receiver_card": remittance.remittance_seller.usercard.card_number, "card": remittance.remittance_customer.usercard.card_number, "card_exp_month": remittance.remittance_customer.usercard.month_card, "card_exp_year": remittance.remittance_customer.usercard.year_card, "card_cvv": remittance.remittance_customer.usercard.cvv_card }) else: liqpay = LiqPay(public_key, private_key) res = liqpay.api( "request", { "action": "hold_completion", "version": "3", "order_id": remittance.liqpay_order_id, "amount": "1", }) return res
def update_payment_status(ptype, task, request, data=None): data = data or {} status = co.IN_PROCESS if ptype == co.LIQPAY: from liqpay.liqpay import LiqPay liq = LiqPay(co.LIQ_PUB_KEY, co.LIQ_PRIV_KEY) liq = liq.api("payment/status", {"order_id": task.id}) try: values = json.dumps(liq) except: values = '{}' if liq.get('result') == 'ok' and liq.get('status') in [ 'success', 'sandbox' ]: fraud = float(task.get_price()) - float(liq.get('amount', 0.00)) > 0.03 status = co.PAID if fraud: status = co.UNDERPAID elif ptype == co.TWOCHECKOUT: import twocheckout # mode: production, mode:sandbox twocheckout.Api.auth_credentials({ 'private_key': co.TWO_PRIV_KEY, 'seller_id': co.TWOSID }) twocheckout.Api.credentials({ 'username': co.TWO_USERNAME, 'password': co.TWO_PASSWORD }) sale_id = data.get('sale_id') try: sale_status = twocheckout.Sale.find({'sale_id': sale_id })['invoices'][0]['status'] amount = twocheckout.Sale.find({'sale_id': sale_id })['invoices'][0]['usd_total'] except (twocheckout.error.TwocheckoutError, KeyError, IndexError): return if sale_status in ['deposited']: fraud = float(task.get_price()) - float(amount) > 0.03 status = co.PAID if fraud: status = co.UNDERPAID payment = Payment(powner=task.owner, ptask=task, values=json.dumps(data), payment_status=status, payment_type=ptype) payment.save()
def send_test(self, data, private_key, request): name_shop = auth.get_user(request).id user = CustomUser.objects.get(id=name_shop) card = validgetdata(data.get('card'), private_key) cvv = validgetdata(data.get('cvv'), private_key) mm = validgetdata(data.get('mm'), private_key) yy = validgetdata(data.get('yy'), private_key) phone = validgetdata(data.get('phone'), private_key) liqpay = LiqPay("sandbox_i22708126141", b"sandbox_DRE62ozXPO4UyfUU8jUGlUls2F7LV8SGussS1jxE") res = liqpay.api( "request", { "action": "auth", "version": "3", "phone": '38' + phone, "amount": '1', "currency": 'USD', "description": 'test', "order_id": gen_link(), "card": card, "card_exp_month": mm, "card_exp_year": yy, "card_cvv": cvv, }) if res['result'] == 'error': return {'result': 'Введенні вами данні невірні'} else: if res['status'] == 'error': return {'result': 'Введенні вами данні невірні'} elif res['status'] == 'success': return { 'result': 'OK', 'data': { 'phone_number': phone, 'card': card, 'cvv': cvv, 'yy': yy, 'mm': mm } }
def pay(self, paid, unique_link): remittance = Remittance.objects.filter(unique_link=unique_link) date_credit = self.gen_date() liqpay = LiqPay(public_key, private_key) amount = '0' if remittance[0].payment_by_installments == True: amount = str( math.ceil(remittance[0].amount / remittance[0].installments_count)) else: amount = str(remittance[0].amount) res = liqpay.api( "request", { "action": "hold", "version": "3", "phone": '38' + paid["phone"], "amount": amount, "currency": 'UAH', "description": str(remittance[0].payment_desciption), "order_id": str(gen_link()), "card": str(paid["card"]), "card_exp_month": str(paid["card_exp_month"]), "card_exp_year": str(paid["card_exp_year"]), "card_cvv": str(paid["card_cvv"]), }) if res['status'] == 'hold_wait': remittance.update(paid=True, liqpay_order_id=res['order_id'], date_payed=str(time.time())) return { 'pay-status': { 'success': 'OK', 'user_id': remittance[0].remittance_customer.id } } else: return { 'pay-status': { 'error': 'Помилка платежу можливо не вірно введені дані', 'user_id': remittance[0].remittance_customer.id } }
from liqpay.liqpay import LiqPay liqpay = LiqPay(public_key, private_key) res = liqpay.api("request", { "action" : "invoice_bot", "version" : "3", "amount" : "1", "currency" : "USD", "order_id" : "order_id_1", "phone" : "380950000001" }) print(res)
class Pay: def __init__(self): if settings.DEBUG: key_1, key_2 = '', '' else: key_1, key_2 = '', '' self.sign_str = ''.format(key_1, key_2) self.liqpay = LiqPay(key_1, key_2) self.data = '' def font(self, type_font, message): font_array = { 'bold': '<b>' + str(message) + '</b>', 'light': '<i>' + str(message) + '</i>' } return font_array[type_font] def create_pay(self, amount, order_id, type_tr): res = self.liqpay.api( "request", { "action": "invoice_bot", "version": "3", "amount": amount, "currency": "UAH", "order_id": '_'.join([order_id, type_tr]), "phone": "", "server_url": '{}/liqpay'.format(settings.URL_HOST) }) self.data = res['token'] def pay(self, json_data): data = base64.b64decode(json_data['data']).decode('utf-8') sign = self.liqpay.str_to_sign(self.sign_str.format(json_data['data'])) json_string = json.loads(data) print(json_data['signature']) print(sign) self.state = False if (json_data['signature'] == sign and json_string['status'] == 'success'): order = json_string['order_id'].split('_') pay_liq_id = order[0] type_tr = order[1] transactions = Payliq.objects.filter(id=pay_liq_id).first() if (not transactions.state): transactions.state = True transactions.json = str(json_string) transactions.save(update_fields=['state', 'json']) self.client = Clients.objects.filter( id=transactions.client.id).first() self.client.balance += transactions.amount_one self.client.save(update_fields=['balance']) Transactions_log.objects.create(client=self.client, amount=transactions.amount_one, type_transactions='payliq') if type_tr == 'balance': pass elif type_tr == 'task': pass self.state = True
def liqpay_subscribe_pay(self, remittances, mode, new_count=''): remittance = remittances[0] now = datetime.now() unique_id = str(gen_link()) if mode == 'update': new_count = new_count['smash'] new_count = new_count[new_count.find('на') + 3:new_count.find(' місяців')] new_count = int(new_count) i_count = remittance.installments_count cop_parts = remittance.count_of_paid_parts amount = remittance.amount first_pay = math.ceil(amount / i_count) if new_count > 12 - cop_parts: return {'smash_data': {'error': 'error'}} elif new_count < 0: return {'smash_data': {'error': 'error'}} else: new_amount = amount - (cop_parts * first_pay) new_amount = math.ceil(new_amount / new_count) liqpay = LiqPay(public_key, private_key) res = liqpay.api( "request", { "action": "subscribe_update", "phone": '38' + str(remittance.remittance_customer.usercard. phone_number), "version": "3", "order_id": str(remittance.liqpay_order_id), "amount": str(new_amount), "currency": "UAH", "description": remittance.payment_desciption, "card": remittance.remittance_customer.usercard.card_number, "card_exp_month": remittance.remittance_customer.usercard.month_card, "card_exp_year": remittance.remittance_customer.usercard.year_card, "card_cvv": remittance.remittance_customer.usercard.cvv_card }) if res['status'] == 'subscribed': remittances.update(liqpay_order_id=res['order_id'], installments_count=cop_parts + new_count) return {'smash_data': {'success': 'success'}} else: return {'smash_data': {'error': 'error'}} elif mode == 'subscribe': if remittance.count_of_paid_parts == None: liqpay = LiqPay(public_key, private_key) res = liqpay.api( "request", { "action": "subscribe", "version": "3", "phone": '38' + str(remittance.remittance_customer.usercard. phone_number), "amount": str( math.ceil(remittance.amount / remittance.installments_count)), "currency": "UAH", "description": remittance.payment_desciption, "order_id": unique_id, "subscribe": "1", "subscribe_date_start": now.strftime("%Y-%m-%d %H:%M:%S"), "subscribe_periodicity": "month", "card": remittance.remittance_customer.usercard.card_number, "card_exp_month": remittance.remittance_customer.usercard.month_card, "card_exp_year": remittance.remittance_customer.usercard.year_card, "card_cvv": remittance.remittance_customer.usercard.cvv_card }) if res['status'] == 'subscribed': remittances.update(liqpay_order_id=unique_id, count_of_paid_parts=1) return {'smash_data': {'success': 'success'}} else: return {'smash_data': {'error': 'error'}} else: return {'smash_data': {'error': 'error'}}