Esempio n. 1
0
 def clean(self):
     """
     The clean method will effectively charge the card and create a new
     Sale instance. If it fails, it simply raises the error given from
     Stripe's library as a standard ValidationError for proper feedback.
     """
     cleaned = super(SalePaymentForm, self).clean()
     
     if not self.errors:
         number = self.cleaned_data["number"]
         exp_month = self.cleaned_data["expiration"].month
         exp_year = self.cleaned_data["expiration"].year
         cvc = self.cleaned_data["cvc"]
         
         sale = Sale()
         
         # let's charge $10.00 for this particular item
         success, instance = sale.charge(1000, number, exp_month, 
                                             exp_year, cvc)
         
         if not success:
             raise forms.ValidationError("Error: %s" % instance.message)
         else:
                 #instance.save()
             # we were successful! do whatever you will here... 
             # perhaps you'd like to send an email...
             pass
     
     return cleaned
Esempio n. 2
0
 def clean(self):
     """
     The clean method will effectively charge the card and create a new
     Sale instance. If it fails, it simply raises the error given from
     Stripe's library as a standard ValidationError for proper feedback.
     """
     cleaned = super(SalePaymentForm, self).clean()
     
     if not self.errors:
         number = self.cleaned_data["number"]
         exp_month = self.cleaned_data["expiration"].month
         exp_year = self.cleaned_data["expiration"].year
         cvc = self.cleaned_data["cvc"]
         
         sale = Sale()
         
         # let's charge $10.00 for this particular item
         success, instance = sale.charge(1000, number, exp_month, 
                                             exp_year, cvc)
         
         if not success:
             raise forms.ValidationError("Error: %s" % instance.message)
         else:
             instance.save()
             # we were successful! do whatever you will here... 
             # perhaps you'd like to send an email...
             pass
     
     return cleaned
Esempio n. 3
0
def charge(request, amount):
    if request.method == 'POST':
        if amount == '0':
            return redirect('sales:checkout')
        u = User.objects.get(username=request.user)
        sale = Sale()
        #stripe charge
        success, instance = sale.charge(amount, request.POST['stripeToken'],
                                        u.email)
        if not success:
            print(instance)
            return HttpResponse("Error reading card.")
        else:
            try:
                billing = Billing.objects.get(user=u)
            except Billing.DoesNotExist:
                billing = Billing(user=u)
            billing.address = request.POST['args[billing_address_line1]']
            billing.city = request.POST['args[billing_address_city]']
            billing.state = request.POST['args[billing_address_state]']
            billing.zipcode = request.POST['args[billing_address_zip]']
            billing.country = request.POST['args[billing_address_country]']
            billing.save()

            try:
                shipping = Shipping.objects.get(user=u)
            except Shipping.DoesNotExist:
                shipping = Shipping(user=u)

            shipping.address = request.POST['args[shipping_address_line1]']
            shipping.city = request.POST['args[shipping_address_city]']
            shipping.state = request.POST['args[shipping_address_state]']
            shipping.zipcode = request.POST['args[shipping_address_zip]']
            shipping.country = request.POST['args[shipping_address_country]']
            shipping.save()

            sale.date = timezone.now()
            sale.amount = amount
            sale.user = u
            sale.save()
            request.session['sale_id'] = sale.id

            #Send Confirmation email.
            subject = "Master Faster Confirmation Email."
            message = "Thank you for shopping with Master Faster. \
Your payment successfully went through.\n\nConfirmation number: %s\n\n\
Shipping Address is:\n\n%s\n%s, %s\n%s %s\n\nBilling Address:\n\n%s\n%s, %s\n%s %s\n\n\
You will be receiving your receipt shortly.\n\n\
Please email us at %s to correct any order detail errors." % (
                sale.charge_id, shipping.address, shipping.city,
                shipping.state, shipping.zipcode, shipping.country,
                billing.address, billing.city, billing.state, billing.zipcode,
                billing.country, settings.EMAIL_HOST_USER)
            from_email = settings.EMAIL_HOST_USER
            to_email = request.POST.get('emailAddress', '')
            send_email(subject, message, from_email, to_email)
            return HttpResponse('Successful Charge.')
    return HttpResponse("Invalid match.")
Esempio n. 4
0
    def clean(self):
        """
        The clean method will effectively charge the card and create a new
        Sale instance. If it fails, it simply raises the error given from
        Stripe's library as a standard ValidationError for proper feedback.
        """
        cleaned = super(SalePaymentForm, self).clean()

        if not self.errors:
            number = self.cleaned_data["number"]
            amount = self.cleaned_data["amount"]
            exp_month = self.cleaned_data["expiration"].month
            exp_year = self.cleaned_data["expiration"].year
            cvc = self.cleaned_data["cvc"]
            username = self.user
            user_data = User.objects.filter(username=self.user).values('email')
            user_email = user_data.values()[0]['email']
            sale = Sale()
            # let's charge $10.00 for this particular item
            success, instance = sale.charge(amount * 100, number, exp_month,
                                            exp_year, username, user_email,
                                            cvc)

            instance.save()
            if not success:
                raise forms.ValidationError("Error: %s" % instance.message)
            else:
                print self.user

                trans = sale.save()
                # transaction_data = PayTransactions(user_name=self.user, email_id=user_email, amount=amount,
                #                                    date_time=datetime.now())
                # transaction_data.save()

                # try:
                #     trans = sale.save()
                #     customer = stripe.Customer.create(email = user_email, plan='MPL01',card=trans.stripe_id )
                #     trans.stripe_id = customer.id
                #     trans.plan = 'MPL01'
                #     trans.save()
                # except stripe.CardError , e:
                #     forms.ValidationError("Error: %s" % instance.message)

                print "SSSSSSSSSSSSSSSSSSSSSSSSsssssssssssssssssssssssssssssssssss"
                return "Payment Successfull"
                # we were successful! do whatever you will here...
                # perhaps you'd like to send an email...
                # pass

        return cleaned