예제 #1
0
def check_txn_status(paytmParams):
    environment = os.getenv('FLASK_ENV')
    url = "https://securegw.paytm.in/v3/order/status" if environment == "production" else "https://securegw-stage.paytm.in/v3/order/status"

    # Generate checksum by parameters we have
    checksum = paytmchecksum.generateSignature(json.dumps(paytmParams["body"]),
                                               app.config['MERCHANT_KEY'])

    paytmParams["head"] = {"signature": checksum}

    # prepare JSON string for request
    post_data = json.dumps(paytmParams)

    response = requests.post(url,
                             data=post_data,
                             headers={
                                 "Content-type": "application/json"
                             }).json()

    if response.get("body").get("resultInfo").get(
            "resultStatus") == 'TXN_SUCCESS':
        return True
    else:
        # check_pending_transaction(paytmParams)
        return False
예제 #2
0
def get_paytm_params(payment_details, order_id, paytm_config):

    # initialize a dictionary
    paytm_params = dict()

    redirect_uri = get_request_site_address(
        True
    ) + "/api/method/frappe.integrations.doctype.paytm_settings.paytm_settings.verify_transaction"

    paytm_params.update({
        "MID": paytm_config.merchant_id,
        "WEBSITE": paytm_config.website,
        "INDUSTRY_TYPE_ID": paytm_config.industry_type_id,
        "CHANNEL_ID": "WEB",
        "ORDER_ID": order_id,
        "CUST_ID": payment_details['payer_email'],
        "EMAIL": payment_details['payer_email'],
        "TXN_AMOUNT": cstr(flt(payment_details['amount'], 2)),
        "CALLBACK_URL": redirect_uri,
    })

    checksum = generateSignature(paytm_params, paytm_config.merchant_key)

    paytm_params.update({"CHECKSUMHASH": checksum})

    return paytm_params
예제 #3
0
def LinkGen(linkname, description, amount):
    eot = str(time.time())
    paytmParams = dict()
    paytmParams["body"] = {
        "mid": my.MID,
        "linkType": "GENERIC",
        "linkDescription": "Test Payment",
        "linkName": "Test",
    }
    checksum = paytmchecksum.generateSignature(json.dumps(paytmParams["body"]),
                                               my.KEY)

    paytmParams["head"] = {"tokenType": "AES", "signature": checksum}
    post_data = json.dumps(paytmParams)
    response = requests.post(my.LINK,
                             data=post_data,
                             headers={"Content-type": "application/json"})
    # print (json.dumps(response.json(), indent=4, sort_keys=True))
    json_response = response.json()
    print(json.dumps(json_response, indent=2))
    r2json = json_response["body"]
    if r2json["resultInfo"]["resultStatus"] == "SUCCESS":
        return (r2json["shortUrl"], r2json["expiryDate"], r2json["linkId"])
    else:
        return "Server Unavailable"
예제 #4
0
파일: views.py 프로젝트: NiK73/Payeaze
def pay(request):
    print("pay wala")
    print(request.user.username)
    print(request.user.email)
    paytmParams = dict()
    oid = "ORDERID_"+str(random.randint(100,999999))
    cid = "CUST_005"
    price = "699.00"
    paytmParams["body"] = {
                "requestType"   : "Payment",
                "mid"           : "XSGpNa29724761433350",
                "websiteName"   : "WEBSTAGING",
                "orderId"       : oid,
                "callbackUrl"   : "https://payeaze.in/callback/",
                "txnAmount"     : {
                    "value"     : price,
                    "currency"  : "INR",
                },
                "userInfo"      : {
                    "custId"    : cid,
                    },
            }

                    # Generate checksum by parameters we have in body
                    # Find your Merchant Key in your Paytm Dashboard at https://dashboard.paytm.com/next/apikeys 
    checksum = paytmchecksum.generateSignature(json.dumps(paytmParams["body"]), "UG3N06L_aZji73d@")

    paytmParams["head"] = {
                        "signature" : checksum
                    }

    post_data = json.dumps(paytmParams)

                    # for Staging
    url = "https://securegw-stage.paytm.in/theia/api/v1/initiateTransaction?mid="+paytmParams['body']['mid']+"&orderId="+paytmParams['body']['orderId']

                    # for Production
                    # url = "https://securegw.paytm.in/theia/api/v1/initiateTransaction?mid=YOUR_MID_HERE&orderId=ORDERID_98765"

    response = requests.post(url, data = post_data, headers = {"Content-type": "application/json"}).json()
                    #print(response)
                    # print({'txnToken': response['body']['txnToken'],'CHECKSUMHASH':checksum ,'TXNAMOUNT': paytmParams['body']['txnAmount'],'mid':mid,'orderId':oid})
            
    param_dict = {oid:request.user.username}
    with open('recharge.json','w') as f:
        json.dump(param_dict,f)

    payment_data = {'txnToken': response['body']['txnToken'],'CHECKSUMHASH':checksum ,'txnAmount': paytmParams['body']['txnAmount']['value'],'merchant_id':paytmParams['body']['mid'],'orderId':paytmParams['body']['orderId'],'websiteName':paytmParams['body']['websiteName']}
    print(payment_data)

            #return redirect('../pay/', payment_data)
    return render(request, 'acc/paytm.html', payment_data)
예제 #5
0
def deletelink(linkid):
    paytmParams = dict()
    paytmParams["body"] = {
        "mid": my.MID,
        "linkId": linkid,
    }
    checksum = paytmchecksum.generateSignature(json.dumps(paytmParams["body"]),
                                               my.KEY)

    paytmParams["head"] = {"tokenType": "AES", "signature": checksum}
    post_data = json.dumps(paytmParams)
    requests.post(my.LINK,
                  data=post_data,
                  headers={"Content-type": "application/json"})
예제 #6
0
def verify_transaction_status(paytm_config, order_id):
    '''Verify transaction completion after checksum has been verified'''
    paytm_params = dict(MID=paytm_config.merchant_id, ORDERID=order_id)

    checksum = generateSignature(paytm_params, paytm_config.merchant_key)
    paytm_params["CHECKSUMHASH"] = checksum

    post_data = json.dumps(paytm_params)
    url = paytm_config.transaction_status_url

    response = requests.post(url,
                             data=post_data,
                             headers={
                                 "Content-type": "application/json"
                             }).json()
    finalize_request(order_id, response)
예제 #7
0
def ham(update, context):
    user = str(update.effective_user.id)
    data = json.load(open('users.json','r'))
    try:
        msg=update.message.text
        paytmParams = dict()
        orderID="20201224130531688029"
        amb=float(cvb)
        amb=str(amb)
        number = str(random.randint(0000,9999))
        orderID+=number
        paytmParams["subwalletGuid"]      = "242f7e06-c860-4a14-8eba-5b6d18c4e6e2"
        paytmParams["orderId"]            = orderID
        paytmParams["beneficiaryPhoneNo"] = msg
        paytmParams["amount"]             = amb
        post_data = json.dumps(paytmParams)
        checksum = paytmchecksum.generateSignature(post_data, "cX2gDSq!&ajo4kgN")
        x_mid      = "KJTRIC10516333500679"
        x_checksum = checksum
        url = "https://dashboard.paytm.com/bpay/api/v1/disburse/order/wallet/gratification"
        response = requests.post(url, data = post_data, headers = {"Content-type": "application/json", "x-mid": x_mid, "x-checksum": x_checksum}).json()
        asd=response['status']
        if asd=="ACCEPTED":
            i = str(data["id"][user])
            am=data['referred'][i]
            am=int(am)
            fg=am-cvb
            fg=str(fg)
            data['referred'][i]=fg
            data['withd'][user] = "1"
            json.dump(data,open('users.json','w'))
            reply_markup = ReplyKeyboardMarkup(dash_key,resize_keyboard=True)
            update.message.reply_text("Withdrawl initiated successfully!",reply_markup=reply_markup)
            context.job_queue.run_once(callb, 86400,context=user)
            return BAS
        else:
            reply_markup = ReplyKeyboardMarkup(dash_key,resize_keyboard=True)
            update.message.reply_text("Something Goes wrong please check your wallet is correct and then come back later.",reply_markup=reply_markup)
            return BAS
            
    except:
        reply_markup = ReplyKeyboardMarkup(dash_key,resize_keyboard=True)
        update.message.reply_text("Something Goes wrong please come back later.",reply_markup=reply_markup)
        return BAS
예제 #8
0
def paytm_transaction_status(order_id, customer_id, total_price):

    # import checksum generation utility
    # You can get this utility from https://developer.paytm.com/docs/checksum/
    # import PaytmChecksum

    # initialize a dictionary
    paytmParams = dict()

    # body parameters
    paytmParams["body"] = {

        # Find your MID in your Paytm Dashboard at https://dashboard.paytm.com/next/apikeys
        "mid": settings.M_ID,

        # Enter your order id which needs to be check status for
        "orderId": order_id,
    }

    # Generate checksum by parameters we have in body
    # Find your Merchant Key in your Paytm Dashboard at https://dashboard.paytm.com/next/apikeys
    checksum = paytmchecksum.generateSignature(json.dumps(paytmParams["body"]),
                                               settings.M_KEY)
    # head parameters
    paytmParams["head"] = {

        # put generated checksum value here
        "signature": checksum
    }

    # prepare JSON string for request
    post_data = json.dumps(paytmParams)

    # for Staging
    # url = "https://securegw-stage.paytm.in/v3/order/status"
    url = settings.PAYTM_STATUS_TRANSACTION
    # for Production
    # url = "https://securegw.paytm.in/v3/order/status"
    response = requests.post(url,
                             data=post_data,
                             headers={
                                 "Content-type": "application/json"
                             }).json()
    return response
예제 #9
0
def checker(linkid, ):
    paytmParams = dict()
    paytmParams["body"] = {
        "mid": my.MID,
        "linkId": linkid,
    }
    checksum = paytmchecksum.generateSignature(json.dumps(paytmParams["body"]),
                                               my.KEY)
    paytmParams["head"] = {"tokenType": "AES", "signature": checksum}
    post_data = json.dumps(paytmParams)
    response = requests.post(my.LINK,
                             data=post_data,
                             headers={"Content-type": "application/json"})
    json_response = response.json()
    r2d2 = json_response["body"]
    if r2d2["orders"]["orderStatus"] == "SUCCESS":
        return True
    else:
        return False
예제 #10
0
def paytm(order_id, customer_id, price):

    # import checksum generation utility
    # You can get this utility from https://developer.paytm.com/docs/checksum/
    paytmParams = dict()

    paytmParams["body"] = {
        "requestType": "Payment",
        "mid": settings.M_ID,
        "websiteName": settings.PAYTM_WEBSITE,
        "orderId": order_id,
        "callbackUrl": settings.PAYTM_CALL_BACK,
        "txnAmount": {
            "value": price,
            "currency": "INR",
        },
        "userInfo": {
            "custId": customer_id,
        },
    }

    # Generate checksum by parameters we have in body
    # Find your Merchant Key in your Paytm Dashboard at https://dashboard.paytm.com/next/apikeys
    checksum = paytmchecksum.generateSignature(json.dumps(paytmParams["body"]),
                                               settings.M_KEY)

    paytmParams["head"] = {"signature": checksum}

    post_data = json.dumps(paytmParams)

    # for Staging
    # url = "https://securegw-stage.paytm.in/theia/api/v1/initiateTransaction?mid=BapaHR15076620391870&orderId="+str(order_id)
    url = settings.PAYTM_INITIATE_TRANSACTION + str(order_id)

    # for Production
    # url = "https://securegw.paytm.in/theia/api/v1/initiateTransaction?mid=YOUR_MID_HERE&orderId="+str(order_id)
    response = requests.post(url,
                             data=post_data,
                             headers={
                                 "Content-type": "application/json"
                             }).json()
    print(response)
    return response
예제 #11
0
def payment_make():
    paytmParams = {
        "MID": environ.get('PAYTM_MERCHANT_ID'),
        "WEBSITE": "WEBSTAGING",
        "ORDER_ID": str(secrets.token_hex(16)),  # change this everytime
        "CUST_ID": "1",
        "MOBILE_NO": "1234567890",
        "EMAIL": "*****@*****.**",
        "INDUSTRY_TYPE_ID": "Retail",
        'CHANNEL_ID': 'WAP',
        # 'CHANNEL_ID':'WEB',
        "TXN_AMOUNT": "200",
        "CALLBACK_URL": "http://127.0.0.1:5000/payment/callback",
    }
    merchant_key = environ.get('PAYTM_MERCHANT_KEY')
    paytmParams['CHECKSUMHASH'] = str(
        paytmchecksum.generateSignature(paytmParams, merchant_key))
    # for Staging
    url = "https://securegw-stage.paytm.in/order/process"
    # for Production
    # url = "https://securegw.paytm.in/order/process"
    return render_template('paytm_view.html', paytmParams=paytmParams, url=url)
예제 #12
0
    def save(self, *args, **kwargs):
        try:
            order_update = Order.objects.get(order_id=self.order_id)
            if self.update_description == "Delivered":
                order_update.order_status = "Delivered"
                order_update.is_amount_paid = True
                order_update.save()
            elif self.update_description == "Returned":
                if order_update.payment_mode == "paytm":
                    paytmParams = dict()
                    paytmParams["body"] = {
                        "mid": settings.MERCHANT_ID,
                        "txnType": "REFUND",
                        "orderId": order_update.order_id,
                        "txnId": order_update.transaction_id,
                        "refId": order_update.reference_id,
                        "refundAmount": str(order_update.final_total),
                    }
                    checksum = paytmchecksum.generateSignature(
                        json.dumps(paytmParams["body"]), settings.MERCHANT_KEY)
                    paytmParams["head"] = {"signature": checksum}
                    post_data = json.dumps(paytmParams)
                    # for Staging
                    url = settings.REFUND_INITIATE_URL
                    # for Production
                    # url = "https://securegw.paytm.in/refund/apply"
                    response = requests.post(
                        url,
                        data=post_data,
                        headers={"Content-type": "application/json"})
                    r = response.json()
                    # if r['body']['resultInfo']['resultCode'] == "601" or r['body']['resultInfo']['resultCode'] == "617":
                    order_update.status = "Abandoned"
                    order_update.save()

                elif order_update.payment_mode == "credits":
                    order_update.status = "Abandoned"
                    order_update.save()
                    user.profile.credit = float(order_update.credits_used)
                    user.save()
                    request.session['total_credits'] = user.profile.credit

                elif order_update.payment_mode == "cod":
                    order_update.status = "Abandoned"
                    order_update.save()

                elif order_update.payment_mode == "credits + paytm":
                    remaining_amount = 0.0
                    user = User.objects.get(pk=order_update.user.id)
                    user.profile.credit = float(order_update.credits_used)
                    remaining_amount = float(order_update.final_total) - float(
                        order_update.credits_used)
                    paytmParams = dict()
                    paytmParams["body"] = {
                        "mid": settings.MERCHANT_ID,
                        "txnType": "REFUND",
                        "orderId": order_update.order_id,
                        "txnId": order_update.transaction_id,
                        "refId": order_update.reference_id,
                        "refundAmount": str(remaining_amount),
                    }
                    checksum = paytmchecksum.generateSignature(
                        json.dumps(paytmParams["body"]), settings.MERCHANT_KEY)
                    paytmParams["head"] = {"signature": checksum}
                    post_data = json.dumps(paytmParams)
                    # for Staging
                    url = settings.REFUND_INITIATE_URL
                    # for Production
                    # url = "https://securegw.paytm.in/refund/apply"
                    response = requests.post(
                        url,
                        data=post_data,
                        headers={"Content-type": "application/json"})
                    r = response.json()
                    # if r['body']['resultInfo']['resultCode'] == "601" or r['body']['resultInfo']['resultCode'] == "617":
                    order_update.status = "Abandoned"
                    order_update.save()
                    user.save()
        except Exception as e:
            print(e)
        super(OrdersUpdate, self).save(*args, **kwargs)
예제 #13
0
import paytmchecksum
from typing import Dict
# initialize an Hash/Array
paytmParams = {}

paytmParams["MID"] = "123456789"
paytmParams["ORDERID"] = "054300"

# Generate checksum by parameters we have
# Find your Merchant Key in your Paytm Dashboard at https://dashboard.paytm.com/next/apikeys
paytmChecksum = paytmchecksum.generateSignature(paytmParams, "YOUR_MERCHANT_KEY")
print("generateSignature Returns:" + str(paytmChecksum))


def create_paytm_checksum(params: Dict, merchant_key):
    return paytmChecksum.generatesSignature(params, merchant_key)


def validate_checksum(params: Dict, merchant_key, check_sum):
    return paytmChecksum.verifySignature(params, merchant_key, check_sum)

print(create_paytm_checksum(paytmParams, 123456789))
예제 #14
0
def register():

    evlist = event_list().evlist
    list = [(str(event["event_id"]), event["event_name"]) for event in evlist]
    set_evlist(list)
    session['evlist'] = evlist
    form = RegistrationForm()

    if form.validate_on_submit():
        if current_user.is_authenticated:
            user = current_user.username
        else:
            user = "******"
        salt = '8f1e39a21c9d4661b24a06356e5fe4d1'
        ORDER_ID = str(uuid.uuid4())
        CUST_ID = str(
            hashlib.md5(salt.encode() + form.phno.data.encode()).hexdigest())

        ev_selected = int(form.event.data)
        selectedEvent = next(
            (item for item in evlist if item["event_id"] == ev_selected), None)

        if (selectedEvent is None):
            flash("An error occured")
            return redirect(url_for('.register'))
        TXN_AMOUNT = int(selectedEvent["amt"])

        registration = registrations(name=form.name.data,
                                     phno=form.phno.data,
                                     email=form.email.data,
                                     clgname=form.clgname.data,
                                     grpname=form.GrpName.data,
                                     team=form.radio_team.data,
                                     event_id=ev_selected,
                                     user=user,
                                     order_id=ORDER_ID,
                                     cust_id=CUST_ID,
                                     amt=str(TXN_AMOUNT),
                                     paymentmode='ONLINE')
        registration_dict = vars(registration)
        registration_dict.pop('_sa_instance_state', None)
        session['reg_info'] = registration_dict
        registration = registrations(**registration_dict)

        try:
            if request.form.get('submit_ofc',
                                False) == "REGISTER ( Pay via Cash )":
                try:
                    registration.paid = True
                    registration.paymentmode = 'Cash'

                    db.session.add(registration)
                    db.session.commit()

                    flash('Registration Successful')
                    print('Offline Registration Done')
                    try:
                        # send_email(registration_dict,evlist)
                        flash(
                            'An Email consisting of Registration Details has been sent to the specified email address'
                        )
                    except Exception as error:
                        print(error)
                        traceback.print_exc()
                except Exception as error:
                    db.session.rollback()
                    flash('Registration Failed')
                    print(error)
                    traceback.print_exc()

                return redirect(
                    url_for('.success',
                            order_id=registration_dict['order_id'],
                            user_id=registration_dict['cust_id']))

            else:
                environment = os.getenv('FLASK_ENV')
                # initialize a dictionary
                paytmParams = dict()
                paytmParams["body"] = {
                    "requestType":
                    "Payment",
                    "mid":
                    app.config['MID'],
                    "websiteName":
                    app.config['WEBSITE']
                    if environment == "production" else "WEBSTAGING",
                    "orderId":
                    ORDER_ID,
                    "callbackUrl":
                    request.host_url + "payment",
                    "txnAmount": {
                        "value": str(TXN_AMOUNT),
                        "currency": "INR",
                    },
                    "userInfo": {
                        "custId": CUST_ID,
                        "mobile": str(form.phno.data),
                        "email": form.email.data,
                    },
                }

                # Generate checksum by parameters we have
                # Find your Merchant Key in your Paytm Dashboard at https://dashboard.paytm.com/next/apikeys

                checksum = paytmchecksum.generateSignature(
                    json.dumps(paytmParams["body"]),
                    app.config['MERCHANT_KEY'])

                paytmParams["head"] = {
                    "signature": checksum,
                    "channelId": app.config['CHANNEL_ID']
                }

                postData = json.dumps(paytmParams)

                initiateTxnUrl = app.config["PAYMENT_URL" if environment == "production" else "PAYMENT_URL_STAGING"] + "initiateTransaction?mid=" + \
                    app.config["MID"] + "&orderId=" + ORDER_ID

                paytmResponse = requests.post(initiateTxnUrl,
                                              data=postData,
                                              headers={
                                                  "Content-type":
                                                  "application/json"
                                              }).json()

                paymentPageUrl = app.config["PAYMENT_URL" if environment == "production" else "PAYMENT_URL_STAGING"] + "showPaymentPage?mid=" + \
                    app.config["MID"] + "&orderId=" + ORDER_ID

                return render_template(
                    '/paymentform.html',
                    mid=paytmParams.get("body").get("mid"),
                    orderId=paytmParams.get("body").get("orderId"),
                    url=paymentPageUrl,
                    txnToken=paytmResponse.get("body").get("txnToken"))
        except Exception as error:
            print(error)
            traceback.print_exc()

    return render_template('/Main.HTML', form=form, evlist=evlist)