Beispiel #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(DonationPaymentForm, 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"]
            amount = self.cleaned_data["amount"]
            #amount *= 100
            amount_wfee = (float(amount) * float(0.05))
            amount_wfee = (amount_wfee + 2) + amount
            amount_wfee *= 100
            donation = Donation()
            
            # let's charge
            success, instance = donation.charge(int(amount_wfee), 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
Beispiel #2
0
 def make_donations(request):
     user = request.user
     data = request.session['donation_items']
     for item in data:
         type = DonationType.objects.get(pk=item[0])
         amount = item[1]['amount']
         recurrence = item[1]['recurrence']
         Donation(user=user, type=type, monthly_billing=recurrence, amount=amount).save()
Beispiel #3
0
def index(request):
    if request.method == 'POST':
        form = DonationForm(request.POST or None)
        if form.is_valid():
            name = form.cleaned_data['name']
            amount = form.cleaned_data['amount']
            donation = Donation(name=name, amount=amount, is_donated=True)
            donation.save()

            context = {
                'amount': str(amount),
                'id': settings.PAYPAL_RECEIVER_ID
            }
            return render(request, 'paypal.html', context)

    form = DonationForm()

    return render(request, 'checkout.html', {'form': form})
Beispiel #4
0
def donate(request, handle):
    initial_amount = int(request.GET.get("amount", 0))
    initial_user = request.user if not request.user.is_anonymous() else None
    org = Org.objects.get(handle = handle)
    form = StandardDonationForm(initial_amount=initial_amount,initial_user=initial_user)

    if request.POST:
        form = StandardDonationForm(data=request.POST)
        if form.is_valid():
            donation_data = form.to_donation_data(org)
            try:
                donation = Donation.create_and_process(**donation_data)

                try:
                    #Post To Facebook
                    if form.cleaned_data.get("post_to_facebook") and initial_user:
                        fb_helpers.post_donation_to_wall(initial_user, org)
                    #Post To Stream
                    #if form.cleaned_data.get("list_name_publicly") and initial_user:
                        #FeedStream.post_new_donation(actor=initial_user, target=org, donation_id=donation.id)

                except Exception, ex:
                    logging.exception("FAILED TO SEND DONATE NOTIFICATION")
                    send_admins_error_email("FAILED TO SEND DONATE NOTIFICATION", ex.message, sys.exc_info())

                share_url = reverse('donate_share', args=[org.id])
		return HttpResponseRedirect("%s?amount=%s" % (share_url, donation.amount))

            #except NFGException, err:
            #    logging.exception("NFG ERROR PROCESSING STANDARD DONATION")
            #    if err.message.get("error_details"):
            #        form.handle_nfg_errors(err.message["error_details"])
            #    else:
            #        form.handle_unknown_error()
            except Exception, err:
                logging.exception("ERROR PROCESSING STANDARD DONATION")
                form.handle_unknown_error()
Beispiel #5
0
 def run_iteration(self):
     donations_to_retry = Donation.get_retryable_donations()
     for donation in donations_to_retry:
         process_donation.delay(donation.id)
     return self.sleep_interval
Beispiel #6
0
 def run_iteration(self):
     donations_to_retry = Donation.get_retryable_donations()
     for donation in donations_to_retry:
         process_donation.delay(donation.id)
     return self.sleep_interval