class PayPalPDTAdmin(admin.ModelAdmin): date_hierarchy = 'payment_date' fieldsets = ( (None, { "fields": L("flag txn_id txn_type payment_status payment_date transaction_entity reason_code pending_reason mc_gross mc_fee auth_status auth_amount auth_exp auth_id" ) }), ("Address", { "description": "The address of the Buyer.", 'classes': ('collapse', ), "fields": L("address_city address_country address_country_code address_name address_state address_status address_street address_zip" ) }), ("Buyer", { "description": "The information about the Buyer.", 'classes': ('collapse', ), "fields": L("first_name last_name payer_business_name payer_email payer_id payer_status contact_phone residence_country" ) }), ("Seller", { "description": "The information about the Seller.", 'classes': ('collapse', ), "fields": L("business item_name item_number quantity receiver_email receiver_id custom invoice memo" ) }), ("Subscriber", { "description": "The information about the Subscription.", 'classes': ('collapse', ), "fields": L("subscr_id subscr_date subscr_effective") }), ("Recurring", { "description": "Information about recurring Payments.", "classes": ("collapse", ), "fields": L("profile_status initial_payment_amount amount_per_cycle outstanding_balance period_type product_name product_type recurring_payment_id receipt_id next_payment_date" ) }), ("Admin", { "description": "Additional Info.", "classes": ('collapse', ), "fields": L("test_ipn ipaddress query flag_code flag_info") }), ) list_display = L( "__unicode__ flag invoice custom payment_status created_at") search_fields = L("txn_id recurring_payment_id")
class PayPalNVP(models.Model): """Record of a NVP interaction with PayPal.""" TIMESTAMP_FORMAT = "%Y-%m-%dT%H:%M:%SZ" # 2009-02-03T17:47:41Z RESTRICTED_FIELDS = L("expdate cvv2 acct") ADMIN_FIELDS = L( "id user flag flag_code flag_info query response created_at updated_at " ) ITEM_FIELDS = L("amt custom invnum") DIRECT_FIELDS = L("firstname lastname street city state countrycode zip") # Response fields method = models.CharField(max_length=64, blank=True) ack = models.CharField(max_length=32, blank=True) profilestatus = models.CharField(max_length=32, blank=True) timestamp = models.DateTimeField(blank=True, null=True) profileid = models.CharField(max_length=32, blank=True) # I-E596DFUSD882 profilereference = models.CharField(max_length=128, blank=True) # PROFILEREFERENCE correlationid = models.CharField(max_length=32, blank=True) # 25b380cda7a21 token = models.CharField(max_length=64, blank=True) payerid = models.CharField(max_length=64, blank=True) # Transaction Fields firstname = models.CharField("First Name", max_length=255, blank=True) lastname = models.CharField("Last Name", max_length=255, blank=True) street = models.CharField("Street Address", max_length=255, blank=True) city = models.CharField("City", max_length=255, blank=True) state = models.CharField("State", max_length=255, blank=True) countrycode = models.CharField("Country", max_length=2, blank=True) zip = models.CharField("Postal / Zip Code", max_length=32, blank=True) # Custom fields invnum = models.CharField(max_length=255, blank=True) custom = models.CharField(max_length=255, blank=True) # Admin fields user = models.ForeignKey(User, blank=True, null=True) flag = models.BooleanField(default=False, blank=True) flag_code = models.CharField(max_length=32, blank=True) flag_info = models.TextField(blank=True) ipaddress = models.IPAddressField(blank=True) query = models.TextField(blank=True) response = models.TextField(blank=True) created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True) class Meta: db_table = "paypal_nvp" verbose_name = "PayPal NVP" def init(self, request, paypal_request, paypal_response): """Initialize a PayPalNVP instance from a HttpRequest.""" self.ipaddress = request.META.get('REMOTE_ADDR', '') if hasattr(request, "user") and request.user.is_authenticated(): self.user = request.user # No storing credit card info. query_data = dict((k, v) for k, v in paypal_request.iteritems() if k not in self.RESTRICTED_FIELDS) self.query = urlencode(query_data) self.response = urlencode(paypal_response) # Was there a flag on the play? ack = paypal_response.get('ack', False) if ack != "Success": if ack == "SuccessWithWarning": self.flag_info = paypal_response.get('l_longmessage0', '') else: self.set_flag(paypal_response.get('l_longmessage0', ''), paypal_response.get('l_errorcode', '')) def set_flag(self, info, code=None): """Flag this instance for investigation.""" self.flag = True self.flag_info += info if code is not None: self.flag_code = code def process(self, request, item): """Do a direct payment.""" from vendor.paypal.pro.helpers import PayPalWPP wpp = PayPalWPP(request) # Change the model information into a dict that PayPal can understand. params = model_to_dict(self, exclude=self.ADMIN_FIELDS) params['acct'] = self.acct params['creditcardtype'] = self.creditcardtype params['expdate'] = self.expdate params['cvv2'] = self.cvv2 params.update(item) # Create recurring payment: if 'billingperiod' in params: return wpp.createRecurringPaymentsProfile(params, direct=True) # Create single payment: else: return wpp.doDirectPayment(params)
class PayPalNVPAdmin(admin.ModelAdmin): list_display = L("user method flag flag_code created_at")
# http://www.djangosnippets.org/snippets/764/ # http://www.satchmoproject.com/ # http://tinyurl.com/shoppify-credit-cards # Well known card regular expressions. CARDS = { 'Visa': re.compile(r"^4\d{12}(\d{3})?$"), 'Mastercard': re.compile(r"(5[1-5]\d{4}|677189)\d{10}$"), 'Dinersclub': re.compile(r"^3(0[0-5]|[68]\d)\d{11}"), 'Amex': re.compile("^3[47]\d{13}$"), 'Discover': re.compile("^(6011|65\d{2})\d{12}$"), } # Well known test numbers TEST_NUMBERS = L("378282246310005 371449635398431 378734493671000" "30569309025904 38520000023237 6011111111111117" "6011000990139424 555555555554444 5105105105105100" "4111111111111111 4012888888881881 4222222222222") def verify_credit_card(number, allow_test=False): """Returns the card type for given card number or None if invalid.""" return CreditCard(number).verify(allow_test) class CreditCard(object): def __init__(self, number): self.number = number def is_number(self): """Returns True if there is at least one digit in number.""" if isinstance(self.number, basestring):
from django.utils.hashcompat import md5_constructor # Set these badboys in your settings file. PUBLISHER_ID = getattr(settings, 'ADMOB_PUBLISHER_ID') ANALYTICS_ID = getattr(settings, 'ADMOB_ANALYTICS_ID') COOKIE_PATH = getattr(settings, 'ADMOB_COOKIE_PATH', '/') COOKIE_DOMAIN = getattr(settings, 'ADMOB_COOKIE_DOMAIN', settings.SESSION_COOKIE_DOMAIN) ENCODING = getattr(settings, 'ADMOB_ENCODING', settings.DEFAULT_CHARSET) TEST = getattr(settings, 'ADMOB_TEST', True) ENDPOINT = "http://r.admob.com/ad_source.php" TIMEOUT = 1 # Timeout in seconds. PUBCODE_VERSION = "20090601-DJANGO" IGNORE = L( "HTTP_PRAGMA HTTP_CACHE_CONTROL HTTP_CONNECTION HTTP_USER_AGENT HTTP_COOKIE" ) class AdMobError(Exception): "Base class for AdMob exceptions." class AdMob(object): """ Handles requests for ads/analytics from AdMob. """ def __init__(self, request, params=None, fail_silently=False): """ * request - HttpRequest object * params - dict of parameters to pass to AdMob