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


Python PayPalIPN.host_email方法代码示例

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


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

示例1: ipn

# 需要导入模块: from paypal.standard.ipn.models import PayPalIPN [as 别名]
# 或者: from paypal.standard.ipn.models.PayPalIPN import host_email [as 别名]
def ipn(request, item_check_callable=None, host_id=None, trans_id=None):
    """
    PayPal IPN endpoint (notify_url).
    Used by both PayPal Payments Pro and Payments Standard to confirm transactions.
    http://tinyurl.com/d9vu9d
    
    PayPal IPN Simulator:
    https://developer.paypal.com/cgi-bin/devscr?cmd=_ipn-link-session
    
    #what triggers this view?
    """
    #TODO: Clean up code so that we don't need to set None here and have a lot
    #      of if checks just to determine if flag is set.
    flag = None
    ipn_obj = None
    
    # Clean up the data as PayPal sends some weird values such as "N/A"
    # Also, need to cope with custom encoding, which is stored in the body (!).
    # Assuming the tolerant parsing of QueryDict and an ASCII-like encoding,
    # such as windows-1252, latin1 or UTF8, the following will work:

    encoding = request.POST.get('charset', None)

    if encoding is None:
        flag = "Invalid form - no charset passed, can't decode"
        data = None
    else:
        try:
            data = QueryDict(request.body, encoding=encoding).copy()
        except LookupError:
            data = None
            flag = "Invalid form - invalid charset"

    if data is not None:
        date_fields = ('time_created', 'payment_date', 'next_payment_date',
                       'subscr_date', 'subscr_effective')
        for date_field in date_fields:
            if data.get(date_field) == 'N/A':
                del data[date_field]

        form = PayPalIPNForm(data) #from paypal.standard.ipn.forms import PayPalIPNForm
        if form.is_valid():
            try:
                #When commit = False, object is returned without saving to DB.
                ipn_obj = form.save(commit=False)
            except Exception as e:
                flag = "Exception while processing. (%s)" % e
        else:
            flag = "Invalid form. (%s)" % form.errors
		    
    if ipn_obj is None:
        ipn_obj = PayPalIPN() #from paypal.standard.ipn.models import PayPalIPN
        
    #Set query params and sender's IP address
    ipn_obj.initialize(request)
    
    #Store the invoice value so i can use it to update the transactions model
    invoice_sent = ipn_obj.invoice
    
    #Add other host characteristicsto the model
    #Eventually add transaction_id to the ipn_obj model
    if host_id:
        host = get_object_or_404(UserInfo, pk=host_id)
        ipn_obj.host_email = host.email
        ipn_obj.host_fname = host.first_name
        ipn_obj.host_lname = host.last_name
        ipn_obj.host_st_address1 = host.st_address1
        ipn_obj.host_st_address2 = host.st_address2
    if trans_id:
        trans = Transaction.objects.get(pk=trans_id) 
        ipn_obj.trans_table_id = trans.id	
    #the following set_flag is defined in paypal.standard.modle.spy, flat var is passed as the "info" parameter
    if flag is not None:
        #We save errors in the flag field
        ipn_obj.set_flag(flag)
    else:
        # Secrets should only be used over SSL.
        if request.is_secure() and 'secret' in request.GET:
            ipn_obj.verify_secret(form, request.GET['secret'])
        else:
            ipn_obj.verify(item_check_callable)

    ipn_obj.save()
    ipn_obj.send_signals()
    
    #JMY ADDED: Update the Transaction Table to confirm we need to transation ID but only have invoice on the paypal IPN
    if trans_id:
        trans.payment_processed = True
        trans_table_id = trans.id
        trans.payment_method = "Paypal"
        trans.save()
        #update the userinfo table to add an account balance
        new_balance = trans.balance_created_packages
        userinfo = UserInfo.objects.get(pk=trans.enduser.id)
        if new_balance:
    		    userinfo.account_balance_packages = new_balance
    		    userinfo.save()
        #send emails
        notify_host_shipment_paid(request,trans_table_id)
        notify_enduser_shipment_paid(request, trans_table_id) 
#.........这里部分代码省略.........
开发者ID:JessAtBlocBoxCo,项目名称:blocbox,代码行数:103,代码来源:views.py


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