0

我正在使用在这里找到的标准 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 帐户获取关联的用户。有没有办法我可以做其他事情来弄清楚如何更新用户帐户配置文件,而不需要他们将一个保存在他们的配置文件中。

如果我能以某种方式结合 paypal_payment_successful 和 account_paypal_return (从贝宝网站返回时调用),我可以使用 request.user.id 来确定用户。

4

1 回答 1

0

弄清楚了。在可以添加资金的页面的查看功能中,我将贝宝字典修改为

 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/'
    }

我将成功的函数调用更改为

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

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

        except models.UserProfile.DoesNotExist:
            pass # TODO email admin
于 2014-10-04T17:53:17.450 回答