def handle_donation(request): if request.method == 'POST': amount = request.POST.get('amount', "") campaign_id = request.POST.get('campaign') campaign = get_object_or_404(Campaign, pk=campaign_id) access_token = campaign.organizer.get_wepay_access_token() account_id = campaign.organizer.get_wepay_account_id() redirect_uri = request.build_absolute_uri('/')[:-1]+campaign.get_absolute_url() print redirect_uri response = wepay_checkout(access_token, account_id, amount, campaign.title,redirect_uri) print response if wepay_returns_error(response): return process_wepay_error(request, response) else: response = response.get('hosted_checkout') return render(request, 'payments/payment.html',\ {'checkout_uri':response.get('checkout_uri'), 'campaign':campaign, 'amount': amount})
def direct_donation(request): if request.session.get('campaign_id',""): campaign_id = request.session['campaign_id'] campaign = get_object_or_404(Campaign, pk=campaign_id) access_token = campaign.organizer.get_wepay_access_token() account_id = campaign.organizer.get_wepay_account_id() else: return Http404("Campaign does not exist") if request.method == 'GET': direct_donation_form = DirectDonationForm() return render(request, 'payments/direct_donation.html',\ {'campaign_title':campaign.title,'form':direct_donation_form}) if request.method == 'POST': amount = request.POST.get('amount', "") response = wepay_checkout(access_token, account_id, amount, campaign.title) if wepay_returns_error(response): return process_wepay_error(request, response) else: response = response.get('hosted_checkout') return render(request, 'payments/direct_donation.html',\ {'checkout_uri':response.get('checkout_uri')} )