当前位置: 首页>>代码示例>>Python>>正文


Python WePay.get_token方法代码示例

本文整理汇总了Python中wepay.WePay.get_token方法的典型用法代码示例。如果您正苦于以下问题:Python WePay.get_token方法的具体用法?Python WePay.get_token怎么用?Python WePay.get_token使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在wepay.WePay的用法示例。


在下文中一共展示了WePay.get_token方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: GET

# 需要导入模块: from wepay import WePay [as 别名]
# 或者: from wepay.WePay import get_token [as 别名]
 def GET(self, query):
     wepay = WePay(IN_PRODUCTION)
     code = web.input(code='')['code']
     try:
         # try to get a token with our code
         wepay.get_token(web.ctx.homedomain + '/callback', CLIENT_ID, CLIENT_SECRET, code)
         
         # make a new account
         create_response = wepay.call('/account/create', { 'name': 'kitty expenses fund', 'description': 'all the money for my kitty' })
         
         # give the account a new picture
         wepay.call('/account/modify', { 'account_id': create_response['account_id'], 'image_uri': 'http://www.placekitten.com/500/500' })
         
         # redirect to the new account
         web.redirect(create_response['account_uri'])
         
     except WePay.WePayError as e:
         return "Received a WePay Error: " + repr(e)
开发者ID:pthrasher,项目名称:Python-SDK,代码行数:20,代码来源:wepay-example.py

示例2: GET

# 需要导入模块: from wepay import WePay [as 别名]
# 或者: from wepay.WePay import get_token [as 别名]
    def GET(self, query):
        wepay = WePay(IN_PRODUCTION)
        code = web.input(code="")["code"]
        try:
            # try to get a token with our code
            wepay.get_token(web.ctx.homedomain + "/callback", CLIENT_ID, CLIENT_SECRET, code)

            # make a new account
            create_response = wepay.call(
                "/account/create", {"name": "kitty expenses fund", "description": "all the money for my kitty"}
            )

            # give the account a new picture
            wepay.call(
                "/account/modify",
                {"account_id": create_response["account_id"], "image_uri": "http://www.placekitten.com/500/500"},
            )

            # redirect to the new account
            web.redirect(create_response["account_uri"])

        except WePay.WePayError as e:
            return "Received a WePay Error: " + repr(e)
开发者ID:brycec,项目名称:Python-SDK,代码行数:25,代码来源:wepay-example.py

示例3: create_wepay_merchant

# 需要导入模块: from wepay import WePay [as 别名]
# 或者: from wepay.WePay import get_token [as 别名]
def create_wepay_merchant(code):
    redirect_uri = settings.WEPAY_REDIRECT_URI
    client_id = settings.WEPAY_CLIENT_ID
    client_secret = settings.WEPAY_CLIENT_SECRET
    production = settings.WEPAY_PRODUCTION
    # set production to True for live environments
    wepay = WePay(production, None)
    # Get a Token to later create an account for a user
    try:
        response = wepay.get_token(redirect_uri, client_id, client_secret, code)
    except:
        response = "Error"
    
    return response
开发者ID:joejean,项目名称:codo_django,代码行数:16,代码来源:payment_utils.py

示例4: authorize

# 需要导入模块: from wepay import WePay [as 别名]
# 或者: from wepay.WePay import get_token [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)
开发者ID:naissa12,项目名称:wefarmdjango,代码行数:41,代码来源:views.py

示例5: WePayPaymentPlatform

# 需要导入模块: from wepay import WePay [as 别名]
# 或者: from wepay.WePay import get_token [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 = {
#.........这里部分代码省略.........
开发者ID:FructusCode,项目名称:website,代码行数:103,代码来源:wepay.py


注:本文中的wepay.WePay.get_token方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。