如何使用Djangopaypal更新用户帐户balan

2024-09-26 17:46:49 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用的是标准的django paypal模块: https://github.com/spookylukey/django-paypal

我试图实现的是一个人可以添加资金到他们的帐户在我的网站上,而不要求他们有一个贝宝帐户档案(解释如下)。目前我的系统是

def paypal_payment_successful(sender, **kwargs):
    #Called when the payment is sucessful
    ipn_obj = sender


    if ipn_obj.payment_status == "Completed":
        try:
            user_profile = models.UserProfile.objects.get(paypal_account=sender.payer_email)
            user_profile.account_balance += float(ipn_obj.mc_gross)
            user_profile.save()

        except models.UserProfile.DoesNotExist:
            pass # TODO email admin

paypal_signals.payment_was_successful.connect(paypal_payment_successful)

@csrf_exempt
def account_paypal_return(request):
    if request.REQUEST.get('payment_status') == 'Completed':
        messages.add_message(request, messages.INFO,
                message=_('The amount of %(amount)s was successfully deposited to your account.') % {
                        'amount': utils.format_currency(float(request.REQUEST['mc_gross']))})

        notifications.notify_paypal_payment(request.user, int(float(request.REQUEST['mc_gross'])))

    return HttpResponseRedirect('/account/')

如果你看一下paypal_payment_successful函数,你可以看到目前我通过ipn提供的paypal帐户和用户配置文件中的paypal帐户获取关联的用户。有没有其他方法可以让我知道如何更新用户的帐户配置文件,而不要求他们在其配置文件中保存一个。在

如果我能以某种方式结合贝宝支付成功和帐户贝宝返回(这是从贝宝网站返回调用)我可以使用请求.user.id确定用户。在


Tags: 用户objrequest帐户accountpaymentmcfloat
1条回答
网友
1楼 · 发布于 2024-09-26 17:46:49

明白了。在页面的查看功能中,您可以添加我修改了paypal字典的资金

 paypal_info = {
        'business': settings.PAYPAL_RECEIVER_EMAIL,
        'currency_code': settings.CURRENCY_CODE,
        'amount': 20,
        'item_name':Funds,
        'custom':str(request.user.id),
        'notify_url': url + reverse('paypal-ipn'),
        'return_url': url + '/account/paypal/return/',
        'cancel_return': url + '/account/paypal/return/'
    }

我把成功的函数调用改为

^{pr2}$

相关问题 更多 >

    热门问题