class PaymentForm(forms.Form): """Form used to process direct payments.""" firstname = forms.CharField(255, label="First Name") lastname = forms.CharField(255, label="Last Name") street = forms.CharField(255, label="Street Address") city = forms.CharField(255, label="City") state = forms.CharField(255, label="State") countrycode = CountryField(label="Country", initial="US") zip = forms.CharField(32, label="Postal / Zip Code") acct = CreditCardField(label="Credit Card Number") expdate = CreditCardExpiryField(label="Expiration Date") cvv2 = CreditCardCVV2Field(label="Card Security Code") currencycode = forms.CharField(widget=forms.HiddenInput(), initial="USD") def process(self, request, item): """Process a PayPal direct payment.""" from paypal.pro.helpers import PayPalWPP wpp = PayPalWPP(request) params = self.cleaned_data params['creditcardtype'] = self.fields['acct'].card_type params['expdate'] = self.cleaned_data['expdate'].strftime("%m%Y") params['ipaddress'] = request.META.get("REMOTE_ADDR", "") params.update(item) try: # Create single payment: if 'billingperiod' not in params: nvp_obj = wpp.doDirectPayment(params) # Create recurring payment: else: nvp_obj = wpp.createRecurringPaymentsProfile(params, direct=True) except PayPalFailure: return False return True
class PaymentForm(forms.Form): """Form used to process direct payments.""" firstname = forms.CharField(255, label=_("First Name")) lastname = forms.CharField(255, label=_("Last Name")) street = forms.CharField(255, label=_("Street Address")) street2 = forms.CharField(255, label="", required=False) city = forms.CharField(255, label=_("City")) state = forms.CharField(255, label=_("State / Province")) countrycode = CountryField(label=_("Country"), initial="US") zip = forms.CharField(32, label=_("Postal / Zip Code")) acct = CreditCardField(label=_("Credit Card Number")) expdate = CreditCardExpiryField(label=_("Expiration Date")) cvv2 = CreditCardCVV2Field(label=_("Card Security Code"), help_text=_("You can find the 3-digit code on the back of your Visa/MasterCard/Discover card, next to your signature, or a small 4-digit number printed on the front of your American Express card.")) def process(self, ipaddress, user, item): """Process a PayPal direct payment.""" from paypal.pro.helpers import PayPalWPP wpp = PayPalWPP(ipaddress, user) params = self.cleaned_data params['creditcardtype'] = self.fields['acct'].card_type params['expdate'] = self.cleaned_data['expdate'].strftime("%m%Y") params['ipaddress'] = ipaddress params.update(item) try: # Create single payment: if 'billingperiod' not in params: nvp_obj = wpp.doDirectPayment(params) # Create recurring payment: else: nvp_obj = wpp.createRecurringPaymentsProfile(params, direct=True) except PayPalFailure: return None return nvp_obj