我想集成PayTR支付网关与odoo10。我遵循PayTR的开发者指南,在里面找到了一个示例代码php脚本。在将php脚本转换为python脚本之后,我得到了一个错误:
ALPN, server did not agree to a protocol
以下是日志: logs
代码如下:
@http.route('/my/payment', type='http', auth="user", website=True)
def pay_now(self, **kw):
partner = request.env.user.partner_id
res = request.env['account.payment'].sudo().search([('partner_id' , '=', partner.id)])
print res
acquirer = request.env['payment.acquirer'].sudo().search([('provider', '=', 'paytr')])
merchant_id = acquirer.paytr_seller_account
merchant_key = acquirer.paytr_merchant_key
merchant_salt = acquirer.paytr_merchant_salt
email = acquirer.paytr_email_account
payment_amount = 300 #example
merchant_oid = "50" #example
merchant_ok_url = "http://www.example.com/success.php"
merchant_fail_url = "http://www.example.com/error.php"
user_basket = "sample product" #example
user_basket = base64.b64encode(bytes(user_basket).encode('utf-8'))
user_ip = get('https://api.ipify.org').text
print user_ip
timeout_limit = "30"
debug_on = 1
test_mode = 0
no_installment = 0
max_installment = 0
currency = "TL"
hash_str = str(merchant_id) + str(user_ip) + str(merchant_oid) + str(email) + str(payment_amount) + str(user_basket) + str(no_installment) + str(max_installment) + str(currency) + str(test_mode)
print hash_str
str_salt = hash_str + str(merchant_salt)
print str_salt
message = bytes(str_salt).encode('utf-8')
secret = bytes(merchant_key).encode('utf-8')
# paytr_token = base64.b64encode(hmac.new(str(merchant_key), str_salt, digestmod = hashlib.sha256).digest())
paytr_token = base64.b64encode(hmac.new(secret, message, digestmod = hashlib.sha256).digest())
print paytr_token
values = {
'merchant_id' : merchant_id,
'user_ip' : user_ip ,
'merchant_oid' : merchant_oid ,
'email' : str(email) ,
'payment_amount' : int(payment_amount) ,
'currency' : str(currency) ,
'user_basket' : user_basket,
'no_installment' : no_installment,
'max_installment' : max_installment,
'paytr_token' : paytr_token,
'user_name' : str(partner.name),
'user_address' : str(partner.street),
'user_phone' : str(partner.phone),
'merchant_ok_url' : str(merchant_ok_url),
'merchant_fail_url' : str(merchant_fail_url),
'test_mode' : test_mode,
'debug_on' : int(debug_on),
'timeout_limit' : int(timeout_limit),
'lang' : "en",
}
print values
post_data = urlencode(values)
print "postfields : " +post_data
buff = cStringIO.StringIO()
buff = StringIO()
c = pycurl.Curl()
c.setopt(c.URL, 'https://www.paytr.com/odeme/api/get-token')
c.setopt(c.POSTFIELDS, post_data)
c.setopt(c.VERBOSE, True)
c.setopt(c.WRITEDATA, buff)
resp_data = c.perform()
print('Status: %d' % c.getinfo(c.RESPONSE_CODE))
print('Status: %f' % c.getinfo(c.TOTAL_TIME))
c.close()
data = buff.getvalue().decode('utf-8')
buff.close()
resp_data = json.load(resp_data)
if resp_data['status'] =='success':
token = resp_data['token']
else :
print resp_data['reason']
template = 'retailer_payment.pay_now'
return request.render(template, token)
这样,结果不包含任何内容并抛出:
AttributeError: 'NoneType' object has no attribute 'read'
有人能帮我弄明白这里怎么了吗?在
目前没有回答
相关问题 更多 >
编程相关推荐