本文整理汇总了Python中wepay.WePay.get_authorization_url方法的典型用法代码示例。如果您正苦于以下问题:Python WePay.get_authorization_url方法的具体用法?Python WePay.get_authorization_url怎么用?Python WePay.get_authorization_url使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类wepay.WePay
的用法示例。
在下文中一共展示了WePay.get_authorization_url方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: profile
# 需要导入模块: from wepay import WePay [as 别名]
# 或者: from wepay.WePay import get_authorization_url [as 别名]
def profile(request, pk):
user = get_object_or_404(User, pk=pk)
farmer = get_object_or_404(Farmer, user=user)
production = settings.WEPAY['in_production']
wepay = WePay(production)
redirect_uri = settings.WEPAY['authorize_url']
auth_url = None
show_edit = False
if farmer.user.pk == request.user.pk:
show_edit = True
if not farmer.has_access_token:
auth_url = wepay.get_authorization_url(
redirect_uri, settings.WEPAY['client_id'])
context = {
'farmer': farmer,
'auth_url': auth_url,
'show_edit': show_edit
}
return render(request, 'profile.html', context)
示例2: authorize
# 需要导入模块: from wepay import WePay [as 别名]
# 或者: from wepay.WePay import get_authorization_url [as 别名]
def authorize(request):
user = request.user
farmer = get_object_or_404(Farmer, user=user)
production = settings.WEPAY['in_production']
wepay = WePay(production)
redirect_uri = settings.WEPAY['authorize_url']
try:
if 'code' in request.GET:
code = request.GET['code']
token = wepay.get_token(
redirect_uri,
settings.WEPAY['client_id'],
settings.WEPAY['client_secret'],
code)
if token:
farmer.save_access_token(token['access_token'])
created = farmer.create_account()
if not created[0]:
return HttpResponse(
"WePay error on update. %s" % error, status=500)
# redirect back to profile
return HttpResponseRedirect(reverse('profile', args=[user.pk]))
else:
url = wepay.get_authorization_url(
redirect_uri, settings.WEPAY['client_id'])
# redirect to authorization url
return redirect(url)
except WePayError as error:
return HttpResponse("WePay error on update. %s" % error, status=500)
示例3: GET
# 需要导入模块: from wepay import WePay [as 别名]
# 或者: from wepay.WePay import get_authorization_url [as 别名]
def GET(self):
wepay = WePay(IN_PRODUCTION)
# redirect to wepay for authorization
web.redirect(wepay.get_authorization_url(web.ctx.homedomain + '/callback', CLIENT_ID))
示例4: WePayPaymentPlatform
# 需要导入模块: from wepay import WePay [as 别名]
# 或者: from wepay.WePay import get_authorization_url [as 别名]
class WePayPaymentPlatform(PaymentPlatform):
class Meta(PaymentPlatformMeta):
key = Service.SERVICE_WEPAY
title = "WePay"
thumbnail = "/img/media/wepay.png"
description = """Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Vivamus placerat venenatis libero vel pellentesque."""
authorization_type = AUTHORIZATION_OAUTH
donation_type = DONATION_REDIRECT
country = "United States"
country_class = "label-info"
DEFAULT_AUTH_SCOPE = "manage_accounts,collect_payments,view_user"
def __init__(self):
PaymentPlatform.__init__(self)
self.wepay = WePay(
production=settings.FRUCTUS_KEYS.WEPAY_PRODUCTION,
store_token=False
)
def get_oauth_url(self, redirect_uri, **kwargs):
_scope = self.DEFAULT_AUTH_SCOPE
if 'scope' in kwargs:
_scope = kwargs['scope']
return self.wepay.get_authorization_url(
redirect_uri, settings.FRUCTUS_KEYS.WEPAY_CLIENT_ID, scope=_scope
)
def service_create(self, owner, **kwargs):
if 'code' not in kwargs:
raise TypeError()
if 'redirect_uri' not in kwargs:
raise TypeError()
# Get the OAuth token
token_result = self.wepay.get_token(
kwargs['redirect_uri'], settings.FRUCTUS_KEYS.WEPAY_CLIENT_ID,
settings.FRUCTUS_KEYS.WEPAY_CLIENT_SECRET, kwargs['code']
)
if 'error' in token_result:
return False, None
# Get User Info
user_result = self.wepay.call(
'/user',
token=token_result['access_token']
)
if 'error' in user_result:
return False, None
if user_result['state'] != 'registered':
return False, None
# Store details in database
return self.db_service_create(
owner, Service.SERVICE_WEPAY, token_result['user_id'],
link_type=Service.LINK_TYPE_OAUTH, data={
'access_token': token_result['access_token'],
'token_type': token_result['token_type'],
'email': user_result['email'],
'name': user_result['user_name'],
'first_name': user_result['first_name'],
'last_name': user_result['last_name']
}
)
def account_find(self, payee, **kwargs):
if not payee or not payee.userservice or not payee.userservice.valid():
return None
params = {}
if 'name' in kwargs:
params['name'] = kwargs['name']
if 'reference_id' in kwargs:
params['reference_id'] = kwargs['reference_id']
return self.wepay.call(
'/account/find', params,
token=payee.userservice.data['access_token']
)
def donation_create(self, entity, recipient, payee,
amount, tip=0.0, **kwargs):
amount = float(amount)
tip = float(tip)
if payee is None or payee.userservice is None:
return None, None
donation = self.db_donation_create(entity, recipient, payee,
amount, tip=tip)
# Create donation descriptions
short_description = self.short_description(recipient, tip)
long_description = self.long_description(recipient, amount, tip)
params = {
#.........这里部分代码省略.........