Пример #1
0
def forward_json(myCharge):
    """
    [email protected]:ark930/charge-forward.git
    :param myCharge:
    :return:
    """
    url = "http://114.215.237.77:3000/forward"
    APIClient._http_call(url, "POST", "json", "json", None, {}, 30, **myCharge)
Пример #2
0
def send(is_private,charge_id, content):
    if is_private==False:
        env_name, root_url, live_key, app_id = datagen.get_current_env()
    else:
        env_name, root_url, live_key, app_id = datagen.get_my_env()

    url = "{0}/notify/charges/{1}".format(root_url, charge_id)
    if isinstance(content, basestring):
        data = {}
        data['value'] = content
        response = APIClient._http_call(url, 'POST', 'text', 'form-urlencoded', None, {}, 30, **data)
    else:
        response = APIClient._http_call(url, 'POST', 'text', 'json', None, {}, 30, **content)
    return response
Пример #3
0
def jdpay_wap():
    env_name, root_url, live_key, app_id = datagen.get_current_env()
    url = "{0}/v1/charges".format(root_url)

    # request body
    charge = Model.ChargeBase.ChargeDict
    charge['order_no'] = random_str(10)
    charge['subject'] = 'TestOrder4jdpay_wap'
    charge['body'] = 'appletest4Pay'
    charge['amount'] = 10
    charge['channel'] = 'jdpay_wap'
    charge['currency'] = 'cny'
    charge['client_ip'] = '127.0.0.1'
    id = [('id', app_id)]
    extra = [("success_url", "http://pingxx.com"), ("fail_url", "htpps://pingxx.com")]
    charge['app'] = dict(id)
    charge['extra'] = dict(extra)

    mycharge = APIClient._http_call(url, "post", "json", "json", None, {"Authorization": "Bearer {0}".format(live_key)},
                                    30, **charge)
    print(mycharge)
    sshCmd.ssh_cmd("114.215.237.77", "56f27c2B", "echo "">/var/www/example/ziteng")
    threading._start_new_thread(sshCmd.ssh_cmd("114.215.237.77", "56f27c2B", "echo "">/var/www/example/ziteng"))
    time.sleep(5)
    Forward.forward_json(mycharge)
    ret = sshCmd.ssh_cmd("114.215.237.77", "56f27c2B", "echo "">/var/www/example/ziteng")

    print ret
    if int(filter(lambda x: x.isdigit(), ret)) > 1:
        print "The charge file had updated on %s" % ctime()
    else:
        print "forward the charge to update file again..."
        threading._start_new_thread(sshCmd.ssh_cmd("114.215.237.77", "56f27c2B", "echo "">/var/www/example/ziteng"))
        time.sleep(2)
        Forward.forward_json(mycharge)
Пример #4
0
def base(is_private,channel, needforward=True, **extra):
    if is_private == False:
        env_name, root_url, live_key, app_id = datagen.get_current_env()
    else:
        env_name, root_url, live_key, app_id = datagen.get_my_env()

    url = "{0}/v1/charges".format(root_url)

    # request body
    charge = Model.ChargeBase.ChargeDict()
    charge['order_no'] = random_str(10)
    charge['subject'] = "Autopay_TestOrder4{0}".format(channel)
    charge['body'] = "appletesting4Pay"
    charge['amount'] = 10
    charge['channel'] = channel
    charge['currency'] = "cny"
    charge['client_ip'] = "127.0.0.1"
    id = [("id", app_id)]
    charge['app'] = dict(id)
    charge['extra'] = extra

    myCharge = APIClient._http_call(url, "POST", "json", "json", None, {"Authorization": "Bearer {0}".format(live_key)},
                                    30, **charge)
    print(myCharge)

    if (needforward):
        time.sleep(5)
        Forward.forward_json(myCharge)
    else:
        return myCharge
Пример #5
0
def GetChargeList100_Refund_ByChannel(channel, mode):
    if mode == 0:
        env_name, root_url, live_key, app_id = datagen.get_my_env()
    else:
        env_name, root_url, live_key, app_id = datagen.get_test_env()

    url = "{0}/v1/charges/".format(root_url)
    params = {}
    params["channel"] = channel
    params["limit"] = 100
    params["paid"] = True
    if channel == "alipay":
        params["refunded"] = True
    else:
        params["refunded"] = False
    params["app[id]"] = app_id
    response = APIClient._http_call(
        url, 1, "json", None, {}, {"Authorization": "Bearer {0}".format(live_key)}, 30, **params
    )
    if response["data"] is None or len(response["data"]) == 0:
        logging.info("GetCharge_NoRefund_ByChannel: " + channel + " No charge returned")
        print "GetCharge_NoRefund_ByChannel: " + channel + " No charge returned"
        return
    charge = response["data"]
    return charge
Пример #6
0
def GetCharge(chargeid):
    env_name, root_url, test_key,app_id = datagen.get_my_test_env()
    url = "{0}/v1/charges/{1}".format(root_url,chargeid)
    params ={}
    response = APIClient._http_call(url, 1, 'json', None, {}, {"Authorization": "Bearer {0}".format(test_key)}, 30,
                                    **params)
    print response
Пример #7
0
def forward_alipay(myCharge):

    # JUST FORWARD THE CHARGE INFO TO DEMO APP FOR PAY
    # NO NEED SOCKET HERE
    # try:
    #     s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
    #     remoteIP = "114.215.237.77"
    #     port = 8880
    #     s.connect((remoteIP, port))
    # except socket.error:
    #     sys.exit()
    #
    # print('Socket Created')

    url = "http://114.215.237.77:3000/forward"
    APIClient._http_call(url, "POST", "json", "json", None, {}, 30, id=myCharge['id'].encode('utf-8')
                             , object=myCharge['object'].encode('utf-8')
                             , created=myCharge['created']
                             , livemode=myCharge['livemode']
                             , paid=myCharge['paid']
                             , refunded=myCharge['refunded']
                             , app=myCharge['app'].encode('utf-8')
                             , channel=myCharge['channel'].encode('utf-8')
                             , order_no=myCharge['order_no'].encode('utf-8')
                             , client_ip=myCharge['client_ip'].encode('utf-8')
                             , amount=myCharge['amount']
                             , amount_settle=myCharge['amount_settle']
                             , currency=myCharge['currency'].encode('utf-8')
                             , subject=myCharge['subject'].encode('utf-8')
                             , body=myCharge['body'].encode('utf-8')
                             , extra=myCharge['extra']
                             , time_paid=myCharge['time_paid']
                             , time_expire=myCharge['time_expire']
                             , time_settle=myCharge['time_settle']
                             , transaction_no=myCharge['transaction_no']
                             , refunds={"object": myCharge['refunds']['object'].encode('utf-8'),
                                         "url": myCharge['refunds']['url'].encode('utf-8'),
                                         "has_more":myCharge['refunds']['has_more'],
                                         "data":[]}
                             , credential={"object": myCharge['credential']['object'].encode('utf-8'),
                                            "alipay": myCharge['credential']['alipay']}
                             , amount_refunded=myCharge['amount_refunded']
                             , failure_code=myCharge['failure_code']
                             , failure_msg=myCharge['failure_msg']
                             , metadata=myCharge['metadata']
                             , description=myCharge['description']
                             )
Пример #8
0
def GetCharge(is_private,chargeid):
    if is_private==False:
        env_name, root_url, live_key,app_id = datagen.get_current_env()
    else:
        env_name, root_url, live_key,app_id = datagen.get_my_env()

    url = "{0}/v1/charges/{1}".format(root_url,chargeid)
    params ={}
    response = APIClient._http_call(url, 1, 'json', None, {}, {"Authorization": "Bearer {0}".format(live_key)}, 30,
                                    **params)
    print response
Пример #9
0
def bfb():
    env_name, root_url, test_key, app_id = datagen.get_my_test_env()
    url = "{0}/v1/charges".format(root_url)

    # request body
    charge = Model.ChargeBase.Charge()
    charge.order_no = random_str(10)
    charge.channel = "bfb"
    myCharge = APIClient._http_call(url, "POST", "json", "json", None, {"Authorization": "Bearer {0}".format(test_key)},
                                    30, subject=charge.subject, body=charge.body, app={"id": charge.app.id},
                                    amount=charge.amount, channel=charge.channel, client_ip=charge.client_ip,
                                    currency=charge.currency, order_no=charge.order_no)
    return myCharge["id"]
Пример #10
0
def base(channel):
    env_name, root_url, live_key, app_id = datagen.get_current_env()

    url = "{0}/v1/charges/".format(root_url)
    params = {}
    params["channel"] = channel
    params["limit"] = 1
    params["paid"] = False
    params["app[id]"] = app_id
    response = APIClient._http_call(
        url, 1, "json", None, {}, {"Authorization": "Bearer {0}".format(live_key)}, 30, **params
    )
    charge = response["data"][0]
    return charge
Пример #11
0
def bfb():
    env_name, root_url, live_key, app_id = datagen.get_current_env()
    url = "{0}/v1/charges".format(root_url)

    # request body
    charge = Model.ChargeBase.Charge()
    charge.order_no = random_str(10)
    charge.channel = "bfb"
    myCharge = APIClient._http_call(url, "POST", "json", "json", None, {"Authorization": "Bearer {0}".format(live_key)},
                                    30, subject=charge.subject, body=charge.body, app={"id": charge.app.id},
                                    amount=charge.amount, channel=charge.channel, client_ip=charge.client_ip,
                                    currency=charge.currency, order_no=charge.order_no)

    # Get the charge info(json) and send to another API for forward
    #And the demo app will receive the charge Info for pay
    #print(myCharge)

    Forward.forward_json(myCharge)
Пример #12
0
def GetTransfer_received(mode):
    if mode == 0:
        env_name, root_url, live_key, app_id = datagen.get_current_env()
    else:
        env_name, root_url, live_key, app_id = datagen.get_test_env()

    url = "{0}/v1/transfers/".format(root_url)
    params = {}
    params["limit"] = 1
    params["app[id]"] = app_id
    response = APIClient._http_call(
        url, 1, "json", None, {}, {"Authorization": "Bearer {0}".format(live_key)}, 30, **params
    )
    if response["data"] == None or len(response["data"]) == 0:
        logging.info("GetOrder_NoRefund_ByChannel: " + " No charge returned")
        print "GetCharge_NoRefund_ByChannel: " + " No charge returned"
        return
    transfer = response["data"][0]
    return transfer["id"]
Пример #13
0
def yeepay_wap():
    env_name, root_url, live_key, app_id = datagen.get_current_env()
    url = "{0}/v1/charges".format(root_url)

    # request body
    charge = Model.ChargeBase.ChargeDict()
    charge['order_no'] = random_str(10)
    charge['subject'] = "TestOrder4YeepayWap"
    charge['body'] = "appletesting4Pay"
    charge['amount'] = 10
    charge['channel'] = "yeepay_wap"
    charge['currency'] = "cny"
    charge['client_ip'] = "127.0.0.1"
    id = [("id", app_id)]
    extra = [("product_category", "1"), ("identity_id", "d2:bf:11:78:09:69"), ("identity_type", "0"),
             ("terminal_type", "1"), ("terminal_id", "d2:bf:11:78:09:69"),
             ("user_ua", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:36.0) Gecko/20100101 Firefox/36.0"),
             ("result_url", "https://pingxx.com")]
    charge['extra'] = dict(extra)
    charge['app'] = dict(id)

    myCharge = APIClient._http_call(url, "post", "json", "json", None, {"Authorization": "Bearer {0}".format(live_key)},
                                    30, **charge)
    print(myCharge)
    sshCmd.ssh_cmd("114.215.237.77", "56f27c2B", "echo "">/var/www/example/ziteng.php")
    threading._start_new_thread(sshCmd.ssh_cmd,
                                ("114.215.237.77", "56f27c2B", "php /var/www/example/client4ziteng.php"))
    time.sleep(5)
    Forward.forward_json(myCharge)
    ret = sshCmd.ssh_cmd("114.215.237.77", "56f27c2B", "echo $(stat -c %s /var/www/example/ziteng.php)")

    print ret

    if int(filter(lambda x: x.isdigit(), ret)) > 1:
        print "The charge file had updated on %s" % ctime()
    else:
        print "forward the charge to update the file again..."
        threading._start_new_thread(sshCmd.ssh_cmd,
                                    ("114.215.237.77", "56f27c2B", "php /var/www/example/client4ziteng.php"))
        time.sleep(2)
        Forward.forward_json(myCharge)
Пример #14
0
def GetOrderList_NotRefund(mode):
    if mode == 0:
        env_name, root_url, live_key, app_id = datagen.get_my_env()
    else:
        env_name, root_url, live_key, app_id = datagen.get_test_env()

    url = "{0}/v1/charges/".format(root_url)
    params = {}
    params["limit"] = 2
    params["paid"] = True
    params["refunded"] = False
    params["app[id]"] = app_id
    response = APIClient._http_call(
        url, 1, "json", None, {}, {"Authorization": "Bearer {0}".format(live_key)}, 30, **params
    )
    if response["data"] == None or len(response["data"]) == 0:
        logging.info("GetOrder_NoRefund_ByChannel: " + " No charge returned")
        print "GetCharge_NoRefund_ByChannel: " + " No charge returned"
        return
    charge = response["data"]
    return charge[0]["order_no"], charge[1]["order_no"]
Пример #15
0
def bfb_wap():
    env_name, root_url, live_key, app_id = datagen.get_current_env()
    url = "{0}/v1/charges".format(root_url)

    # request body
    charge = Model.ChargeBase.ChargeDict()
    charge['order_no'] = random_str(10)
    charge['subject'] = "TestOrder4bfbWap"
    charge['body'] = "appletesting4Pay"
    charge['amount'] = 10
    charge['channel'] = "bfb_wap"
    charge['currency'] = "cny"
    charge['client_ip'] = "127.0.0.1"
    id = [("id", app_id)]
    extra = [("result_url", "http://pingxx.com"), ("bfb_login", "false")]
    charge['extra'] = dict(extra)
    charge['app'] = dict(id)

    myCharge = APIClient._http_call(url, "POST", "json", "json", None, {"Authorization": "Bearer {0}".format(live_key)},
                                    30, **charge)
    print(myCharge)

    sshCmd.ssh_cmd("114.215.237.77", "56f27c2B", "echo "">/var/www/example/ziteng.php")

    threading._start_new_thread(sshCmd.ssh_cmd,
                                ("114.215.237.77", "56f27c2B", "php /var/www/example/client4ziteng.php"))
    time.sleep(5)
    Forward.forward_json(myCharge)
    ret = sshCmd.ssh_cmd("114.215.237.77", "56f27c2B", "echo $(stat -c %s /var/www/example/ziteng.php)")

    print ret
    if int(filter(lambda x: x.isdigit(), ret)) > 1:
        print "The charge file had updated on %s" % ctime()
    else:
        print "forward the charge to update the file again..."
        threading._start_new_thread(sshCmd.ssh_cmd,
                                    ("114.215.237.77", "56f27c2B", "php /var/www/example/client4ziteng.php"))
        time.sleep(2)
        Forward.forward_json(myCharge)
Пример #16
0
def alipay():
    """
        1- Generate the charge via API
        2- Forward the charge so that the demoapp will reflush
    """

    env_name, root_url, live_key, app_id = datagen.get_current_env()
    url = "{0}/v1/charges".format(root_url)

    # request body
    charge = Model.ChargeBase.Charge()
    charge.order_no = random_str(10)
    # myCharge = APIClient._http_call(url,"POST","json","json",None,{"Authorization":"Bearer sk_live_vjfr90jj1q985KuPO84iP8KO"},30,charge.__dict__)
    myCharge = APIClient._http_call(url, "POST", "json", "json", None, {"Authorization": "Bearer {0}".format(live_key)},
                                    30, subject=charge.subject, body=charge.body, app={"id": charge.app.id},
                                    amount=charge.amount, channel=charge.channel, client_ip=charge.client_ip,
                                    currency=charge.currency, order_no=charge.order_no)

    #Get the charge info(json) and send to another API for forward
    #And the demo app will receive the charge Info for pay
    print(myCharge)

    Forward.forward_alipay(myCharge)