本文整理汇总了Python中paypal.standard.ipn.forms.PayPalIPNForm.is_valid方法的典型用法代码示例。如果您正苦于以下问题:Python PayPalIPNForm.is_valid方法的具体用法?Python PayPalIPNForm.is_valid怎么用?Python PayPalIPNForm.is_valid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类paypal.standard.ipn.forms.PayPalIPNForm
的用法示例。
在下文中一共展示了PayPalIPNForm.is_valid方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ipn
# 需要导入模块: from paypal.standard.ipn.forms import PayPalIPNForm [as 别名]
# 或者: from paypal.standard.ipn.forms.PayPalIPNForm import is_valid [as 别名]
def ipn(request, item_check_callable=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
"""
logging.info(request)
form = PayPalIPNForm(request.POST)
logging.info(form)
logging.info(form.is_valid())
if form.is_valid():
try:
ipn_obj = form.save(commit=False)
logging.info(ipn_obj)
except Exception, e:
logging.error(e)
ipn_obj = PayPalIPN()
ipn_obj.set_flag("Exception while processing. (%s)" % form.errors)
logging.info(ipn_obj)
示例2: create_ipn
# 需要导入模块: from paypal.standard.ipn.forms import PayPalIPNForm [as 别名]
# 或者: from paypal.standard.ipn.forms.PayPalIPNForm import is_valid [as 别名]
def create_ipn(request):
flag = None
ipnObj = None
form = PayPalIPNForm(request.POST)
if form.is_valid():
try:
ipnObj = form.save(commit=False)
except Exception as e:
flag = "Exception while processing. (%s)" % e
else:
flag = "Invalid form. (%s)" % form.errors
if ipnObj is None:
ipnObj = PayPalIPN()
ipnObj.initialize(request)
if flag is not None:
ipnObj.set_flag(flag)
else:
# Secrets should only be used over SSL.
if request.is_secure() and 'secret' in request.GET:
ipnObj.verify_secret(form, request.GET['secret'])
else:
donation = get_ipn_donation(ipnObj)
if not donation:
raise Exception('No donation associated with this IPN')
verify_ipn_recipient_email(ipnObj, donation.event.paypalemail)
ipnObj.verify(None)
ipnObj.save()
return ipnObj
示例3: ipn
# 需要导入模块: from paypal.standard.ipn.forms import PayPalIPNForm [as 别名]
# 或者: from paypal.standard.ipn.forms.PayPalIPNForm import is_valid [as 别名]
def ipn(request, item_check_callable=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
"""
flag = None
ipn_obj = None
# Clean up the data as PayPal sends some weird values such as "N/A"
data = request.POST.copy()
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)
if form.is_valid():
try:
ipn_obj = form.save(commit=False)
except Exception, e:
flag = "Exception while processing. (%s)" % e
示例4: ipn
# 需要导入模块: from paypal.standard.ipn.forms import PayPalIPNForm [as 别名]
# 或者: from paypal.standard.ipn.forms.PayPalIPNForm import is_valid [as 别名]
def ipn(request, item_check_callable=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
"""
# 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"
data = request.POST.copy()
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)
if form.is_valid():
try:
# When commit = False, object is returned without saving to DB.
ipn_obj = form.save(commit=False)
except Exception, e:
flag = "Exception while processing. (%s)" % e
示例5: ipn
# 需要导入模块: from paypal.standard.ipn.forms import PayPalIPNForm [as 别名]
# 或者: from paypal.standard.ipn.forms.PayPalIPNForm import is_valid [as 别名]
def ipn(request, item_check_callable=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
"""
#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
#set the encoding of the request, so that request.POST can be correctly decoded.
#see https://github.com/johnboxall/django-paypal/issues/32
#https://code.djangoproject.com/ticket/14035, worth noting, but this doesn't
# affect this ipn view as there won't be uploaded files.
encoding = request.POST.get('charset', '')
try:
codecs.getdecoder(encoding) # check if the codec exists
request.encoding = encoding
except:
pass
# 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 tolerate 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)
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)
if form.is_valid():
try:
#When commit = False, object is returned without saving to DB.
ipn_obj = form.save(commit=False)
except Exception, e:
flag = "Exception while processing. (%s)" % e
else:
flag = "Invalid form. (%s)" % form.errors
示例6: initialize_ipn_object
# 需要导入模块: from paypal.standard.ipn.forms import PayPalIPNForm [as 别名]
# 或者: from paypal.standard.ipn.forms.PayPalIPNForm import is_valid [as 别名]
def initialize_ipn_object(request):
flag = None
ipn_obj = None
form = PayPalIPNForm(request.POST)
if form.is_valid():
try:
ipn_obj = form.save(commit=False)
except Exception, e:
flag = "Exception while processing. (%s)" % e
示例7: ipn
# 需要导入模块: from paypal.standard.ipn.forms import PayPalIPNForm [as 别名]
# 或者: from paypal.standard.ipn.forms.PayPalIPNForm import is_valid [as 别名]
def ipn(request, item_check_callable=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
"""
#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"
data = request.POST.copy()
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)
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()
#Set query params and sender's IP address
ipn_obj.initialize(request)
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()
return HttpResponse("OKAY")
示例8: ipn
# 需要导入模块: from paypal.standard.ipn.forms import PayPalIPNForm [as 别名]
# 或者: from paypal.standard.ipn.forms.PayPalIPNForm import is_valid [as 别名]
def ipn(request, item_check_callable=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
"""
#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
# Also, need to cope with custom encoding, which is stored in the body (!).
# Assuming the tolerate 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.raw_post_data, encoding=encoding).dict()
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':
data[date_field] = None
del data[date_field]
form = PayPalIPNForm(data)
if form.is_valid():
try:
#When commit = False, object is returned without saving to DB.
ipn_obj = form.save(commit = False)
except Exception, e:
flag = "Exception while processing. (%s)" % e
else:
flag = "Invalid form. (%s)" % form.errors
示例9: ipn
# 需要导入模块: from paypal.standard.ipn.forms import PayPalIPNForm [as 别名]
# 或者: from paypal.standard.ipn.forms.PayPalIPNForm import is_valid [as 别名]
def ipn(request, item_check_callable=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
"""
params = request.POST
invoice_id = params["invoice"]
payer_email = params["payer_email"]
payment_obj = Payment.objects.get(pk=int(invoice_id))
payment_obj.paypal_txn_key = params["txn_id"]
payment_obj.is_active = True
payment_obj.save()
photo = payment_obj.photo
message = render_to_string("flickrpayments/photo_purchase_mail.txt", {"photo": photo})
send_mail("Photo purchase order", message, "[email protected]", [payer_email])
# from the paypal invoice get
# payment obj (inovice number == payment obj pk)
# get the buyer email
# save the amount and paypal_txn_key to
# payment object and activate the
# payment obj
# from payment obj get photo
# mail the photo originla url to buyer
flag = None
ipn_obj = None
form = PayPalIPNForm(request.POST)
if form.is_valid():
try:
ipn_obj = form.save(commit=False)
except Exception, e:
flag = "Exception while processing. (%s)" % e
示例10: test_invalid_date_format
# 需要导入模块: from paypal.standard.ipn.forms import PayPalIPNForm [as 别名]
# 或者: from paypal.standard.ipn.forms.PayPalIPNForm import is_valid [as 别名]
def test_invalid_date_format(self):
data = {'payment_date': "2015-10-25 01:21:32"}
form = PayPalIPNForm(data)
self.assertFalse(form.is_valid())
self.assertIn(
form.errors,
[
{
'payment_date': ['Invalid date format '
'2015-10-25 01:21:32: '
'need more than 2 values to unpack']
},
{
'payment_date': ['Invalid date format '
'2015-10-25 01:21:32: '
'not enough values to unpack '
'(expected 5, got 2)']
}
]
)
示例11: ipn
# 需要导入模块: from paypal.standard.ipn.forms import PayPalIPNForm [as 别名]
# 或者: from paypal.standard.ipn.forms.PayPalIPNForm import is_valid [as 别名]
def ipn(request, item_check_callable=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
"""
#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
#set the encoding of the request, so that request.POST can be correctly decoded.
#see https://github.com/johnboxall/django-paypal/issues/32
#https://code.djangoproject.com/ticket/14035, worth noting, but this doesn't
# affect this ipn view as there won't be uploaded files.
encoding = request.POST.get('charset', '')
try:
codecs.getdecoder(encoding) # check if the codec exists
request.encoding = encoding
except:
pass
# Clean up the data as PayPal sends some weird values such as "N/A"
data = request.POST.copy()
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)
if form.is_valid():
try:
#When commit = False, object is returned without saving to DB.
ipn_obj = form.save(commit = False)
except Exception, e:
flag = "Exception while processing. (%s)" % e
示例12: paypal_ipn
# 需要导入模块: from paypal.standard.ipn.forms import PayPalIPNForm [as 别名]
# 或者: from paypal.standard.ipn.forms.PayPalIPNForm import is_valid [as 别名]
def paypal_ipn(self) -> PayPalIPN or None:
data = dict(
txn_id=self.txn_id,
buisness='square email',
custom=self.custom,
txn_type=self.TXN_TYPE,
payment_gross=self.payment_gross,
payment_status=self.payment_status,
payment_type=self.payment_type,
mc_currency=self.mc_currency,
mc_fee=self.mc_fee,
mc_gross=self.mc_gross,
mc_handling=self.mc_handling,
mc_shipping=self.mc_shipping,
from_view='square',
)
ipn_form = PayPalIPNForm(
data=data
)
if ipn_form.is_valid():
ipn_form.clean()
return ipn_form.save()
示例13: ipn
# 需要导入模块: from paypal.standard.ipn.forms import PayPalIPNForm [as 别名]
# 或者: from paypal.standard.ipn.forms.PayPalIPNForm import is_valid [as 别名]
def ipn(request, item_check_callable=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
"""
#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"
data = request.POST.copy()
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]
data['payer_id'] = int(data['custom'])
if data.get('txn_type') in ['web_accept','cart']:
user = User.objects.get(pk=data['custom'])
user.first_name = data['first_name']
user.last_name = data['last_name']
user.save()
if data.get('txn_type') == 'web_accept':
accessRecord = Access(user=user,lecture=Lecture.objects.get(pk=data['item_number']),
activation_date=datetime.now(pytz.utc),active=True)
accessRecord.save()
touch_user.send_robust(sender=data)
elif data.get('txn_type') == 'cart':
xname = []
xnumber = []
for x in xrange(int(data['num_cart_items'])):
name = 'item_name' + str(x+1)
xname.append(data[name])
number = 'item_number' + str(x+1)
xnumber.append(data[number])
accessRecord = Access(user=User.objects.get(pk=data['custom']),lecture=Lecture.objects.get(pk=data[number]),activation_date=datetime.now(pytz.utc),active=True)
accessRecord.save()
data['item_name'] = ", ".join(xname)[:125]
data['item_number'] = ", ".join(xnumber)
elif data.get('txn_type') in ['subscr_signup']:
license_user.send_robust(sender=data)
elif data.get('txn_type') in ['subscr_payment']:
pass
form = PayPalIPNForm(data)
if form.is_valid():
try:
#When commit = False, object is returned without saving to DB.
ipn_obj = form.save(commit = False)
except Exception, e:
flag = "Exception while processing. (%s)" % e
示例14: ipn
# 需要导入模块: from paypal.standard.ipn.forms import PayPalIPNForm [as 别名]
# 或者: from paypal.standard.ipn.forms.PayPalIPNForm import is_valid [as 别名]
def ipn(request, item_check_callable=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
"""
# 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)
encoding_missing = encoding is None
if encoding_missing:
encoding = DEFAULT_ENCODING
try:
data = QueryDict(request.body, encoding=encoding).copy()
except LookupError:
data = None
flag = "Invalid form - invalid charset"
if data is not None:
if hasattr(PayPalIPN._meta, 'get_fields'):
date_fields = [f.attname for f in PayPalIPN._meta.get_fields() if f.__class__.__name__ == 'DateTimeField']
else:
date_fields = [f.attname for f, m in PayPalIPN._meta.get_fields_with_model()
if f.__class__.__name__ == 'DateTimeField']
for date_field in date_fields:
if data.get(date_field) == 'N/A':
del data[date_field]
form = PayPalIPNForm(data)
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:
formatted_form_errors = ["{0}: {1}".format(k, ", ".join(v)) for k, v in form.errors.items()]
flag = "Invalid form. ({0})".format(", ".join(formatted_form_errors))
if ipn_obj is None:
ipn_obj = PayPalIPN()
# Set query params and sender's IP address
ipn_obj.initialize(request)
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()
if encoding_missing:
# Wait until we have an ID to log warning
log.warning("No charset passed with PayPalIPN: %s. Guessing %s", ipn_obj.id, encoding)
return HttpResponse("OKAY")
示例15: ipn
# 需要导入模块: from paypal.standard.ipn.forms import PayPalIPNForm [as 别名]
# 或者: from paypal.standard.ipn.forms.PayPalIPNForm import is_valid [as 别名]
def ipn(request, item_check_callable=None):
"""
The response from Paypal Payment
{u'protection_eligibility': [u'Eligible'],
u'last_name': [u'R'],
u'txn_id': [u'1B883441C5191701K'],
u'receiver_email': [u'[email protected]'],
u'payment_status': [u'Completed'],
u'payment_gross': [u'100.00'],
u'tax': [u'0.00'],
u'residence_country': [u'US'],
u'invoice': [u'1461'],
u'address_state': [u'CA'],
u'payer_status': [u'verified'],
u'txn_type': [u'web_accept'],
u'address_country': [u'United States'],
u'handling_amount': [u'0.00'],
u'payment_date': [u'01:23:03 Jul 04, 2014 PDT'],
u'first_name': [u'XXXXXXXXX'], u'item_name': [u''],
u'address_street': [u'1 Main St'],
u'charset': [u'windows-1252'],
u'custom': [u''],
u'notify_version': [u'3.8'],
u'address_name': [u'XXXXXXXXX'],
u'test_ipn': [u'1'],
u'item_number': [u''],
u'receiver_id': [u'7EEGW6KXU7H3G'],
u'transaction_subject': [u''],
u'business': [u'[email protected]'],
u'payer_id': [u'YQG53MRMSMVT8'],
u'verify_sign': [u'AMIsJErLWFh1ByQ-Pn.oseCWp0SBAOA1.0fCwFL.qfIIq6GQoS36n5i8'],
u'address_zip': [u'95131'],
u'payment_fee': [u'3.20'],
u'address_country_code': [u'US'],
u'address_city': [u'San Jose'],
u'address_status': [u'confirmed'],
u'mc_fee': [u'3.20'],
u'mc_currency': [u'USD'],
u'shipping': [u'0.00'],
u'payer_email': [u'[email protected]'],
u'payment_type': [u'instant'],
u'mc_gross': [u'100.00'],
u'ipn_track_id': [u'59b0e84327236'],
u'quantity': [u'1']
}
"""
"""
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
"""
#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 tolerate 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)
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()
#.........这里部分代码省略.........