def test_form_render(self): return_url = 'https://example.com/return_url' f = PayPalPaymentsForm(initial={'business': '*****@*****.**', 'amount': '10.50', 'shipping': '2.00', 'return_url': return_url, }) rendered = f.render() self.assertIn('''action="https://www.sandbox.paypal.com/cgi-bin/webscr"''', rendered) self.assertIn('''value="*****@*****.**"''', rendered) self.assertIn('''value="2.00"''', rendered) self.assertIn('''value="10.50"''', rendered) self.assertIn('''buynowCC''', rendered) self.assertIn('''value="''' + return_url + '''"''', rendered) f = PayPalPaymentsForm(initial={'business': '*****@*****.**', 'amount': '10.50', 'shipping': '2.00', 'return': return_url, }) rendered = f.render() self.assertIn('''action="https://www.sandbox.paypal.com/cgi-bin/webscr"''', rendered) self.assertIn('''value="*****@*****.**"''', rendered) self.assertIn('''value="2.00"''', rendered) self.assertIn('''value="10.50"''', rendered) self.assertIn('''buynowCC''', rendered) self.assertIn('''value="''' + return_url + '''"''', rendered)
def checkout(request): # 订单号 out_trade_no = baseutil.time_hash() cart = Cart(request) # 关闭cart购物车,防止付款之前购物车内内容改变 cart.cart.checked_out=True cart.cart.save() # 记录transaction now = datetime.datetime.now() Transaction.objects.create(out_trade_no=out_trade_no,user=request.user,\ cart=cart.cart,payed_fee=0,trade_time=now) # What you want the button to do. paypal_dict = { "business": settings.PAYPAL_RECEIVER_EMAIL, "amount": (cart.total_fee)/5, # exchange rate is 5 "item_name": "Bluessh ssh+vpn fee", "invoice": out_trade_no, # 本站订单号 "notify_url": "%s%s" % (settings.SITE_URL, '/paypal/ipn_pengzhao/'), "return_url": "%s/usercenter/" % settings.SITE_URL, "currency_code":"USD", # 人民币CNY,美元USD "charset":"utf-8", } paypal_form = PayPalPaymentsForm(initial=paypal_dict) submit_js = "<script>document.forms['paypalsubmit'].submit()</script>" return render(request,'usercenter/checkout.html', {'content':paypal_form.render(),'submit_js':submit_js})
def scientist_research_payment_paypal(request, research_id, template='scientist/research_payment_paypal.html', extra_context=None): research = get_object_or_404(Research, id=research_id, scientistresearch__scientist=request.user) # What you want the button to do. paypal_dict = { 'business': settings.PAYPAL_RECEIVER_EMAIL, 'amount': research.total_credit - request.user.userprofile.available_balance, 'item_name': research.name, 'invoice': '%s-%d' % (research.name, research.id), 'notify_url': '%s%s' % (settings.SITE_NAME, reverse_lazy('paypal-ipn')), 'return_url': '%s%s' % (settings.SITE_NAME, reverse_lazy('research_paypal_complete', args=[research.id, ])), 'cancel_return': 'http://www.example.com/your-cancel-location/', 'custom': research.id, } # Create the instance. form = PayPalPaymentsForm(initial=paypal_dict) if settings.PAYPAL_API_ENVIRONMENT == 'SANDBOX': paypal_form = form.sandbox() else: paypal_form = form.render() context = { 'form': paypal_form, 'research': research, } if extra_context: context.update(extra_context) return render_to_response(template, context, context_instance=RequestContext(request))
def paypal(request): # What you want the button to do. paypal_dict = { "cmd": "_xclick-subscriptions", "a1": "0", # trial price "p1": 1, # trial duration, duration of unit defaults to month "a3": "1", # yearly price "p3": 1, # duration of each unit (depends on unit) "t3": "Y", # duration unit ("M for Month") "src": "1", # make payments recur "sra": "1", # reattempt payment on payment error "no_note": "1", # remove extra notes (optional) "business": settings.PAYPAL_RECEIVER_EMAIL, #"amount": "1.00", "item_name": "one Bondiz", "invoice": "99", "notify_url": "%s%s" % (settings.SITE_NAME, reverse('paypal-ipn')), "return_url": "http://www.bondiz.com/success/", "cancel_return": "http://www.bondiz.com/cancel/", } # Create the instance. form = PayPalPaymentsForm(initial=paypal_dict, button_type="subscribe") context = {"form": form.render()} # form.render() for real case return render_to_response("paypal.html", context)
def paypal_form(order): # res = {} paypal = { "business": settings.PAYPAL_RECEIVER_EMAIL, "amount": order.total(), "item_name": settings.PAYPAL_SUBJECT_LINE, #'item_number': 1, #'quantity':1, # PayPal wants a unique invoice ID "invoice": order.uid, # It'll be a good idea to setup a SITE_DOMAIN inside settings # so you don't need to hardcode these values. "currency_code": "EUR", "lc": "es_ES", #'notify_url': settings.SITE_DOMAIN + "/tienda/checkout/paypal/ipn", "notify_url": settings.SITE_DOMAIN + reverse("paypal-ipn"), "return_url": settings.SITE_DOMAIN + reverse("return_url"), "cancel_return": settings.SITE_DOMAIN + reverse("cancel_url"), } form = PayPalPaymentsForm(initial=paypal) if settings.DEBUG: rendered_form = form.sandbox() else: rendered_form = form.render() return rendered_form
def pay_item(request,idItem): idIt = idItem _item = get_object_or_404(item,id=idIt) _purch = get_object_or_404(purchases,item=_item) if _purch.user == request.user: paypal = { 'amount':_purch.item.price, 'item_name': _purch.item.title, 'item_number': _purch.item.id, # PayPal wants a unique invoice ID 'invoice': str(uuid.uuid1()), # It'll be a good idea to setup a SITE_DOMAIN inside settings # so you don't need to hardcode these values. 'return_url': settings.SITE_DOMAIN + reverse('return_url'), 'cancel_return': settings.SITE_DOMAIN + reverse('cancel_url'), } form = PayPalPaymentsForm(initial=paypal) if settings.DEBUG: rendered_form = form.sandbox() else: rendered_form = form.render() ctx = {'item' : _item,'form' : rendered_form,} return render_to_response('store/purchase_thanks.html',ctx,context_instance=RequestContext(request)) else: return HttpResponseRedirect('/profile/purchased/images/')
def paypal_form(request): domain = Site.objects.get_current().domain paypal_dict = { "cmd": "_xclick-subscriptions", "business": "*****@*****.**", # "business": "*****@*****.**", "a3": "12.00", # price "p3": 1, # duration of each unit (depends on unit) "t3": "Y", # duration unit ("M for Month") "src": "1", # make payments recur "sra": "1", # reattempt payment on payment error "no_note": "1", # remove extra notes (optional) "item_name": "NewsBlur Premium Account", "notify_url": "http://%s%s" % (domain, reverse('paypal-ipn')), "return_url": "http://%s%s" % (domain, reverse('paypal-return')), "cancel_return": "http://%s%s" % (domain, reverse('index')), "custom": request.user.username, } # Create the instance. form = PayPalPaymentsForm(initial=paypal_dict, button_type="subscribe") # Output the button. return HttpResponse(form.render(), mimetype='text/html')
def product_detail(request, slug): ''' It is a smaple funcation that could be used to send only one item to Paypal. it will send the information of the select product to be paied in Paypal. ''' product = get_object_or_404(Product, pk=slug) paypal = { 'amount': product.price, 'item_name': product.name, 'item_number': product.slug, # PayPal wants a unique invoice ID 'invoice': str(uuid.uuid1()), # It'll be a good idea to setup a SITE_DOMAIN inside settings # so you don't need to hardcode these values. 'return_url': settings.SITE_DOMAIN + 'return_url', #reverse('return_url'), 'cancel_return': settings.SITE_DOMAIN + 'cancel_url', #reverse('cancel_url'), } form = PayPalPaymentsForm(initial=paypal) if settings.DEBUG: rendered_form = form.sandbox() else: rendered_form = form.render() return render_to_response('products/product_detail.html', { 'product' : product, 'form' : rendered_form, }, RequestContext(request))
def process(self,request,cart=None): for k,v in request.REQUEST.iteritems(): if 'product' in k: product = v elif 'value' in k: value = float(v) elif 'qty' in k: qty = int(v) host = 'http://%s' % request.get_host() paypal = { 'business': settings.PAYPAL_RECEIVER_EMAIL, 'notify_url': '%s%s'%(host,settings.PAYPAL_NOTIFY_URL), 'return_url': '%s%s'%(host,settings.PAYPAL_RETURN_URL), 'cancel_return': '%s%s'%(host,settings.PAYPAL_CANCEL_RETURN), 'currency_code': 'BRL', } option = '_cart'; count = 0 form_paypal = PayPalPaymentsForm(initial=paypal) if cart is not None: for p in cart: count += 1 form_paypal.fields['amount_%i'%count] = forms.IntegerField(widget=ValueHiddenInput(),initial=p['value']) form_paypal.fields['item_name_%i'%count] = forms.CharField(widget=ValueHiddenInput(),initial=p['product']) form_paypal.fields['quantity_%i'%count] = forms.CharField(widget=ValueHiddenInput(),initial=p['qty']) else: form_paypal.fields['amount_1'] = forms.IntegerField(widget=ValueHiddenInput(),initial=value) form_paypal.fields['item_name_1'] = forms.CharField(widget=ValueHiddenInput(),initial=product) form_paypal.fields['quantity_1'] = forms.CharField(widget=ValueHiddenInput(),initial=str(qty)) form_paypal.fields['cmd'] = forms.CharField(widget=ValueHiddenInput(),initial=option) form_paypal.fields['upload'] = forms.CharField(widget=ValueHiddenInput(),initial='1') return render(request,'form.jade',{'form':form_paypal.render()})
def purchase_item(request): if request.method == "POST": item_purchase = int(request.POST['item']) _item = get_object_or_404(item, id=item_purchase) if _item.user == request.user: ctx = {'title':'This item belongs to you.','message':'This item belongs to you, you can not buy'} return render_to_response('message/message.html',ctx,context_instance=RequestContext(request)) frmPurchase = purchases(item=_item,user=request.user) frmPurchase.save() paypal = { 'amount':frmPurchase.item.price, 'item_name': frmPurchase.item.title, 'item_number': frmPurchase.item.id, # PayPal wants a unique invoice ID 'invoice': str(uuid.uuid1()), # It'll be a good idea to setup a SITE_DOMAIN inside settings # so you don't need to hardcode these values. 'return_url': settings.SITE_DOMAIN + reverse('return_url'), 'cancel_return': settings.SITE_DOMAIN + reverse('cancel_url'), } form = PayPalPaymentsForm(initial=paypal) if settings.DEBUG: rendered_form = form.sandbox() else: rendered_form = form.render() ctx = {'item' : _item,'form' : rendered_form,} return render_to_response('store/purchase_thanks.html',ctx,context_instance=RequestContext(request)) else: return HttpResponseRedirect('/store/')
def test_form_render_deprecated_paypal_receiver_email(self): f = PayPalPaymentsForm(initial={'amount': '10.50', 'shipping': '2.00', }) rendered = f.render() self.assertIn('''action="https://www.sandbox.paypal.com/cgi-bin/webscr"''', rendered) self.assertIn('''value="*****@*****.**"''', rendered) self.assertIn('''value="2.00"''', rendered) self.assertIn('''value="10.50"''', rendered) self.assertIn('''buynowCC''', rendered)
def ServicesPayment(request, serviceId, csrf, payStatus, date_created): import datetime import time service = Service.objects.all().get(id=int(serviceId)) user = request.user if date_created == "0": date_created = str(time.time()) invoice_number = date_created + '-service-' + str(serviceId) + "-" \ + str(user.id) paypal_dict = { "business": settings.PAYPAL_RECEIVER_EMAIL, "amount": service.service_cost, "item_name": service.name, "invoice": invoice_number, "notify_url": "%s%s" % (settings.SITE_NAME, reverse('paypal-ipn')), "return_url": settings.SITE_NAME + "/paypal/payment/service/" + serviceId + "/1/" + csrf + "/" + date_created + "/", "cancel_return": settings.SITE_NAME + "/paypal/payment/service/" + serviceId + "/0/" + csrf + "/" + date_created + "/", } if payStatus == "2": if len(Invoice.objects.all().filter(number=invoice_number)) > 0: payStatus = "3" else: dateTime = datetime.datetime.\ fromtimestamp(float(date_created)/1000) i = Invoice.objects.create(date_created=dateTime, service=service, buyer=user, amount=1, is_paid=False, number=invoice_number) i.save() if payStatus == "1": if len(Invoice.objects.all().filter(number=invoice_number)) == 0: payStatus = "3" else: i = Invoice.objects.all().get(number=invoice_number) i.is_paid = True i.save() if payStatus == "0": if len(Invoice.objects.all().filter(number=invoice_number)) == 0: payStatus = "3" else: i = Invoice.objects.all().get(number=invoice_number) i.is_paid = False i.save() form = PayPalPaymentsForm(initial=paypal_dict) context = {"form": form.sandbox(), "service": service, "payStatus": payStatus, "invoice_number": invoice_number, "date_created": date_created, "serviceId": serviceId, } return render_with_user(request, "paypal/payment.html", context)
def test_form_render(self): f = PayPalPaymentsForm(initial={'business': '*****@*****.**', 'amount': '10.50', 'shipping': '2.00', }) rendered = f.render() self.assertIn('''action="https://www.sandbox.paypal.com/cgi-bin/webscr"''', rendered) self.assertIn('''value="*****@*****.**"''', rendered) self.assertIn('''value="2.00"''', rendered) self.assertIn('''value="10.50"''', rendered) self.assertIn('''buynowCC''', rendered)
def donation_form(self, request): context = self.get_context(request) single_donation_amounts = [ '50.00', '100.00', '250.00', '500.00', '1000.00', '5000.00' ] recurring_donation_amounts = [ '10.00', '15.00', '25.00', '50.00', '100.00', '125.00' ] paypal_dict_single = { "cmd": "_donations", "business": settings.PAYPAL_ACCT_EMAIL, "amount": "", "no_note": "1", "no_shipping": "2", "item_name": "Single donation for The Chelsea Symphony", "notify_url": request.build_absolute_uri(reverse('paypal-ipn')), "return": self.full_url + 'thank-you/', "cancel_return": self.full_url, "custom": "", "rm": "1" } paypal_dict_recurring = { "cmd": "_xclick-subscriptions", "business": settings.PAYPAL_ACCT_EMAIL, "src": "1", "srt": "24", "p3": "1", "t3": "M", "no_note": "1", "no_shipping": "2", "a3": "", "item_name": "Recurring donation for The Chelsea Symphony", "notify_url": request.build_absolute_uri(reverse('paypal-ipn')), "return": self.full_url + 'thank-you/', "cancel_return": self.full_url, "custom": "", "rm": "1" } form_single = PayPalPaymentsForm(initial=paypal_dict_single, button_type='donate') form_recurring = PayPalPaymentsForm(initial=paypal_dict_recurring, button_type='donate') context = { "page": self, "single": form_single, "recurring": form_recurring, "single_donation_amounts": single_donation_amounts, "recurring_donation_amounts": recurring_donation_amounts, } return render(request, "main/donate.html", context)
def render_page(request, order, selectdiscountform=None, claimdiscountform=None, dropforms=None): context = {} if float(order.get_full_price()) < 0.01: # Free service. Don't show discount forms. Clear coupons so they are not wasted. context['show_discounts'] = False order.reset_discount_claims() order.save() else: context['show_discounts'] = True # Define forms for managing discounts on order if not dropforms: dropforms = []; for claim in order.get_discount_claims(): dropforms.append({ 'label': claim.discount.display_text, 'form': coupons.forms.RemoveDiscountForm(initial={u'discount': claim.pk}) }) context['dropforms'] = dropforms if not selectdiscountform: available_claims = order.get_unused_discount_claims() if available_claims: selectdiscountform = coupons.forms.SelectDiscountForm(request.user, available_claims=available_claims) else: selectdiscountform = None context['selectdiscountform'] = selectdiscountform if not claimdiscountform: claimdiscountform = coupons.forms.ClaimOrSelectDiscountForm(request.user) context['claimdiscountform'] = claimdiscountform # Define invoice data invoice = order.calculate_price() order.save() context['invoice'] = invoice if float(order.get_amount_to_pay()) < 0.01: # No payment due. Free service or 100% covered with discounts context['paid_service'] = False return render_to_response("order/submit_payment.html", RequestContext(request, context)) else: context['paid_service'] = True # paypal button paypal_dict = { "business": settings.PAYPAL_RECEIVER_EMAIL, "amount": invoice['amount_due'], "item_name": order.get_service_description(), "invoice": order.invoice_id, "notify_url": "%s%s" % (settings.ROOT_URL, reverse('paypal-ipn')), "return_url": "%s%s" % (settings.ROOT_URL, 'paymentreceived/'), "cancel_return": "%s%s" % (settings.ROOT_URL, 'paymentcanceled/'), } form = PayPalPaymentsForm(initial=paypal_dict) if settings.RACK_ENV=='production': context["pay_button"] = form.render() else: context["pay_button"] = form.sandbox() context["pay_button_message"] = mark_safe(_('Clicking the "Buy Now" button will submit your order and take you away from this site.')+'<br/>'+_('Please complete your secure payment with PayPal.')) return render_to_response("order/submit_payment.html", RequestContext(request, context))
def paypal(request): # What you want the button to do. paypal_dict = { "business": settings.PAYPAL_RECEIVER_EMAIL, "amount": "1.00", "item_name": "name of the item", "invoice": "unique-invoice-id", "notify_url": "%s%s" % (settings.SITE_NAME, reverse('paypal-ipn')), "return_url": "http://www.example.com/your-return-location/", "cancel_return": "http://www.example.com/your-cancel-location/",} # Create the instance. form = PayPalPaymentsForm(initial=paypal_dict) context = {"form": form.sandbox()} return render_to_response("paypal.html", context)
def checkout(request, pk): ad = get_object_or_404(Ad, pk=pk) form = CheckoutForm(request.POST or None) if form.is_valid(): total = 0 pricing = form.cleaned_data["pricing"] total += pricing.price pricing_options = [] for option in form.cleaned_data["pricing_options"]: pricing_options.append(option) total += option.price # create Payment object payment = Payment.objects.create(ad=ad, pricing=pricing, amount=total) for option in pricing_options: payment.options.add(option) payment.save() # send email when done # 1. render context to email template email_template = loader.get_template('classifieds/email/posting.txt') context = Context({'ad': ad}) email_contents = email_template.render(context) # 2. send email send_mail(_('Your ad will be posted shortly.'), email_contents, app_settings.FROM_EMAIL, [ad.user.email], fail_silently=False) item_name = _('Your ad on ') + Site.objects.get_current().name paypal_values = {'amount': total, 'item_name': item_name, 'item_number': payment.pk, 'quantity': 1} if settings.DEBUG: paypal_form = PayPalPaymentsForm(initial=paypal_values).sandbox() else: paypal_form = PayPalPaymentsForm(initial=paypal_values).render() return render_to_response('classifieds/paypal.html', {'form': paypal_form}, context_instance=RequestContext(request)) return render_to_response('classifieds/checkout.html', {'ad': ad, 'form': form}, context_instance=RequestContext(request))
def view_ask_money_ipn(request): # What you want the button to do. paypal_dict = { "business":settings.PAYPAL_RECEIVER_EMAIL, "amount":"0.01", "item_name":"Ttagit Pro Account", "invoice":"unique-invoice-id", "notify_url":"http://dev.ttagit.com/paypal-ipn", "return_url":"http://dev.ttagit.com/paypal/pdt/", "cancel_return":"", } form = PayPalPaymentsForm(initial=paypal_dict) context = {"form":form.sandbox()} return render_to_response("payment.html", context)
def process_payment(request): order_id = request.session.get('order_id') if order_id == 'forexsilver': vari_x = 'Forex' account_type = get_object_or_404(Account_price, account_type=vari_x) paypal_dict = { 'business': settings.PAYPAL_RECEIVER_EMAIL, 'amount': '%.2f' % account_type.price, 'item_name': '{}'.format(account_type.account_type), 'invoice': str(random.randint(00000, 99999)), 'currency_code': 'USD', 'notify_url': 'https://forex254.herokuapp.com/q-forex-binary-f-k-defw-dshsgdtdhvdsss-scczzc-url/', 'return_url': 'https://forex254.herokuapp.com/payment-done/', 'cancel_return': 'https://forex254.herokuapp.com/payment-cancelled/', } form = PayPalPaymentsForm(initial=paypal_dict) return render(request, 'paypal/process_payment.html', { 'account_type': account_type, 'form': form }) else: vari_y = 'Binary' account_type = get_object_or_404(Account_price, account_type=vari_y) paypal_dict = { 'business': settings.PAYPAL_RECEIVER_EMAIL, 'amount': '%.2f' % account_type.price, 'item_name': '{}'.format(account_type.account_type), 'invoice': str(random.randint(00000, 99999)), 'currency_code': 'USD', 'notify_url': 'https://forex254.herokuapp.com/q-forex-binary-f-k-defw-dshsgdtdhvdsss-scczzc-url/', 'return_url': 'https://forex254.herokuapp.com/payment-done/', 'cancel_return': 'https://forex254.herokuapp.com/payment-cancelled/', } form = PayPalPaymentsForm(initial=paypal_dict) return render(request, 'paypal/process_payment.html', { 'account_type': account_type, 'form': form })
def subscribe(request, id): item = get_object_or_404(Item, id=id) today = timezone.now() item_name = item.name price = item.price billing_cycle = 1 billing_cycle_unit = "Y" # What you want the button to do. paypal_dict = { "cmd": "_xclick-subscriptions", "business": settings.PAYPAL_RECEIVER_EMAIL, "a3": price, "p3": billing_cycle, # duration of each unit (depends on unit) "t3": billing_cycle_unit, # duration unit ("M for Month") "src": "1", # make payments recur "sra": "1", # reattempt payment on payment error "no_note": "1", # remove extra notes (optional) 'item_name': item_name, 'custom': item.id, # custom data, pass something meaningful here 'currency_code': 'USD', "notify_url": request.build_absolute_uri(reverse('paypal-ipn')), "return": request.build_absolute_uri(reverse('payment-successful')), "cancel_return": request.build_absolute_uri(reverse('payment-canceled')), } # Create the instance. form = PayPalPaymentsForm(initial=paypal_dict, button_type="subscribe") return render(request, 'store/cart.html', { 'item': item, 'today': today, 'form': form })
def process_payment(request, id): transaction = get_object_or_404(Transaction, id=id) transaction.stage = 'make-payment' transaction.save() paypal_dict = { 'business': settings.PAYPAL_RECEIVER_EMAIL, 'amount': transaction.amount(), 'item_name': transaction.user, 'invoice': str(transaction.project.id), 'currency_code': 'USD', 'notify_url': request.build_absolute_uri(reverse('paypal-ipn')), 'return_url': request.build_absolute_uri( reverse('payments:done', args=[transaction.id])), 'cancel_return': request.build_absolute_uri( reverse('payments:canceled', args=[transaction.id])), } form = PayPalPaymentsForm(initial=paypal_dict) return render(request, 'payments/process.html', { 'form': form, 'transaction': transaction })
def payment_process(request): # 从session中获取订单号 order_id = request.session.get('order_id') # 通过订单号获取订单详情 order = get_object_or_404(Order, id=order_id) # 当前访问的域名 host = request.get_host() paypal_dict = { # PayPal商业账户 'business': settings.PAYPAL_RECEIVER_EMAIL, # 折扣后的总价,精度设置为0.01级别 'amount': '%.2f' % order.get_total_cost().quantize(Decimal('.01')), # PayPal账单中的商品名 'item_name': '订单号{}'.format(order.id), # PayPal账单名 'invoice': str(order.id), # 货币代码,和在PayPal账户中设置的货币一致 'currency_code': 'USD', # Paypal会发送IPN到支付通知URL,使用django-paypal提供的paypal-ipn的URL 'notify_url': 'http://{}{}'.format(host, reverse('paypal-ipn')), # 支付成功后返回页面 'return_url': 'http://{}{}'.format(host, reverse('payment:done')), # 取消支付后返回页面 'cancel_return': 'http://{}{}'.format(host, reverse('payment:canceled')), } # PayPalpaymentsForm 将会被渲染成用户只能看到Buy now按钮的带有隐藏字段的标准表单,用户点击该按钮时,表单将会通过POST方法提交到PayPal form = PayPalPaymentsForm(initial=paypal_dict) return render(request, 'payment/process.html', { 'order': order, 'form': form })
def buy_property_view(request, slug): context = {} user = request.user property_listings = get_object_or_404(PropertyListing, slug=slug) paypal_dict = { "business": "*****@*****.**", "amount": property_listings.price, "item_name": property_listings.title, "invoice": property_listings.title, "notify_url": request.build_absolute_uri(reverse('paypal-ipn')), "return": request.build_absolute_uri( reverse('payments:done', kwargs={'slug': property_listings.slug})), "cancel_return": request.build_absolute_uri(reverse('payments:canceled')), } form = PayPalPaymentsForm(initial=paypal_dict) context = {"form": form} return render(request, "payments.html", context)
def checkoutPage(request, ): checkoutForm = CheckoutForm() orders = [] total = 0 for order in json.loads(request.COOKIES.get('orders')): order['product'] = get_object_or_404(Product, pk=order['id']) order['price'] = int(order['product'].product_price)*int(order['count']) total = total + order['price'] orders.append(order) if request.method == "POST": paypal_dict = { "business": "*****@*****.**", "amount": "10000000.00", "item_name": "name of the item", "invoice": "unique-invoice-id", "notify_url": request.build_absolute_uri(reverse('paypal-ipn')), } # Create the instance. form = PayPalPaymentsForm(initial=paypal_dict) context = {"form": form} return render(request, "polls/payment.html", context) else: return render(request, "polls/checkout.html", {'form': checkoutForm, 'total': total, 'catalogs': Catalog.objects.all(), 'orders': orders })
def get_form(self, request): ''' Configures a paypal form and returns. Allows this code to be reused in other views. ''' order = self.shop.get_order(request) url_scheme = 'https' if request.is_secure() else 'http' # get_current_site requires Django 1.3 - backward compatibility? url_domain = get_current_site(request).domain paypal_dict = { "business": settings.PAYPAL_RECEIVER_EMAIL, "currency_code": settings.PAYPAL_CURRENCY_CODE, "amount": self.shop.get_order_total(order), "item_name": self.shop.get_order_short_name(order), "invoice": self.shop.get_order_unique_id(order), "notify_url": '%s://%s%s' % (url_scheme, url_domain, reverse('paypal-ipn')), # defined by django-paypal "return_url": '%s://%s%s' % (url_scheme, url_domain, reverse('paypal_success')), # That's this classe's view "cancel_return": '%s://%s%s' % (url_scheme, url_domain, self.shop.get_cancel_url()), # A generic one } if hasattr(settings, 'PAYPAL_LC'): paypal_dict['lc'] = settings.PAYPAL_LC # Create the instance. form = PayPalPaymentsForm(initial=paypal_dict) return form
def get(self, request): order_id = request.session.get('order_id') order = get_object_or_404(Order, id=order_id) order.payment = 'paypal' order.save() host = request.get_host() paypal_dict = { 'business': settings.PAYPAL_RECEIVER_EMAIL, 'amount': '%.2f' % order.total.quantize(Decimal('.01')), 'item_name': 'Order {}'.format(order.order_unid), 'invoice': str(order.id), #id will be used later in signal 'currency_code': 'EUR', #USD', 'notify_url': 'http://{}{}'.format(host, reverse('paypal-ipn')), 'return_url': 'http://{}{}'.format(host, reverse('payments:done')), 'cancel_return': 'http://{}{}'.format(host, reverse('payments:canceled')) } form = PayPalPaymentsForm(initial=paypal_dict) return render(request, 'payments/process.html', { 'order': order, 'form': form })
def thank_you(request, order_uuid): order = Order.objects.get(uuid=order_uuid) if order.is_paid: return render(request, 'mail_payment_confirm_template.html', {'order': order}) else: if order.payment_method == 'p': paypal_dict = { "business": "{}".format(settings.PAYPAL_ID), "amount": "{}".format(order.total_price), "item_name": order.orderdetail_set.first().__str__() + '...', "invoice": "{}".format(order.uuid), "notify_url": settings.PAYPAL_URL + reverse('paypal-ipn'), "return_url": settings.PAYPAL_URL + '/shop/thankyou/' + str(order.uuid), "cancel_return": settings.PAYPAL_URL + reverse('shop:shop_main'), "custom": "{}".format(order.user) } paypal_form = PayPalPaymentsForm(initial=paypal_dict).render() data = { 'order': order, 'paypal_form': paypal_form, } return render(request, 'payment/thankyou.html', data) elif order.payment_method == 'b': data = {'order': order} return render(request, 'payment/thankyou_krw.html', data)
def process_payment(request): order = Order.objects.get(user=request.user, ordered=False) host = request.get_host() order.ref_code = create_ref_code() amount = int(order.get_total()) # cents str(host) print('%s' % host) paypal_dict = { 'business': settings.PAYPAL_RECEIVER_EMAIL, 'amount': '%2f' % amount, 'item_name': order.ref_code, 'invoice': str(order.ref_code), 'currency_code': 'USD', 'notify_url': 'http://{}{}'.format(host, reverse('paypal-ipn')), 'return_url': 'http://{}{}'.format(host, reverse('core:payment-done')), 'cancel_return': 'http://{}{}'.format(host, reverse('core:payment-cancelled')), } form = PayPalPaymentsForm(initial=paypal_dict) return render(request, 'process-payment.html', { 'order': order, 'form': form })
def process_payment(request, id): order = get_object_or_404(Pay, id=id) if order.paid == True: request.invoice = order.id return render(request, 'payment_done.html') else: host = request.get_host() order.currency_type = order.get_currency_display() paypal_dict = { 'business': settings.PAYPAL_RECEIVER_EMAIL, 'amount': str(order.amount), 'item_name': order.description, 'invoice': str(id), 'currency_code': order.currency_type, 'notify_url': 'http://{}{}'.format(host, reverse('paypal-ipn')), 'return_url': 'http://{}{}'.format(host, reverse('payment_done')), 'cancel_return': 'http://{}{}'.format(host, reverse('payment_cancelled')), } form = PayPalPaymentsForm(initial=paypal_dict) return render(request, 'process_payment.html', { 'order': order, 'form': form })
def payment_process(request, pk): """ View for the generation of the "Buy Now" paypal button. Also provides all of the data required by paypal. """ e = get_object_or_404(Event, pk=pk) price = e.price category = 'extern' ionis = request.GET.get('ionis', '') if ionis != '': ionis = '?ionis=true' category = 'ionis' price = e.price_ionis user = request.user.first_name + " " + request.user.last_name user_id = str(request.user.id) eventname = e.title eventpk = e.pk paypal_dict = { "business": "*****@*****.**", "amount": str(price), "item_name": user + " : " + eventname, "invoice": user_id + "/" + str(eventpk) + "/" + category, "notify_url": request.build_absolute_uri(reverse('paypal-ipn')), "return": request.build_absolute_uri(reverse('paymentDone')), "cancel_return": request.build_absolute_uri(reverse('paymentCanceled')), "currency_code": "EUR", } form = PayPalPaymentsForm(initial=paypal_dict) return render(request, "payment/process.html", {'form': form})
def PaymentProcess(request): if request.method == 'POST': name = request.POST.get('NameClient') phone = request.POST.get('Phone') category = request.POST.get('Dropdown') msg = request.POST.get('Your-message') gg = Consultation(name=name, phone=phone, category=category, text=msg) gg.save() args = {} args['id'] = gg.id amount = Form_section.objects.get(s_name=category).price host = request.get_host() paypal_dict = { 'business': settings.PAYPAL_RECEIVER_EMAIL, 'amount': amount, 'item_name': 'Consultations', "invoice": str(args['id']), 'currency_code': 'USD', 'notify_url': 'http://{}{}'.format(host, reverse('paypal-ipn')), 'return_url': 'http://{}{}'.format(host, reverse('done')), 'cancel_return': 'http://{}{}'.format(host, reverse('canceled')) } form = PayPalPaymentsForm(initial=paypal_dict) context = {} context['mp_9'] = Bottom_footer.objects.get(id=1) context["form"] = form return render(request, 'payment/process.html', context)
def payment_process(request): order_id = request.session.get('order_id') order = get_object_or_404(Order, id=order_id) host = request.get_host() paypal_dict = { "business": "*****@*****.**", "amount": '%.2f' % order.get_total_cost().quantize(Decimal('0.01')), "item_name": 'Order {}'.format(order.id), "invoice": str(order.id), "currency_code": 'USD', # "notify_url": request.build_absolute_uri(reverse('paypal-ipn')), # "return": request.build_absolute_uri(reverse('your-return-view')), # "cancel_return": request.build_absolute_uri(reverse('your-cancel-view')), "notify_url": 'http://{}{}'.format(host, reverse('paypal-ipn')), "return": 'http://{}{}'.format(host, reverse('payment:done')), "cancel_return": 'http://{}{}'.format(host, reverse('payment:canceled')), # "custom": "premium_plan", # Custom command to correlate to some function later (optional) } # Create the instance. form = PayPalPaymentsForm(initial=paypal_dict) context = {"order": order, "form": form} return render(request, "payment/process.html", context)
def payment_process(request): """ 处理支付网关 :param request: 求情 :return: 一个render函数 """ order_id = request.session['order_id'] order = get_object_or_404(Order, id=order_id) host = request.get_host() paypal_dict = { # 使用的账户 'business': settings.PAYPAL_RECEIVER_EMAIL, # 支付的总价 'amount': '%.2f' % Decimal(order.get_total_cost()).quantize(Decimal('.01')), # 物品名称 'item_name': 'Order {}'.format(order.id), # 将订单id变成字符串 'invoice': str(order.id), # 设置交易货币,USD即为美金 'currency_code': 'USD', # Paypal的一个借口 'notify_url': 'http://{}{}'.format(host, reverse('paypal-ipn')), # 从定向支付成功后的跳转链接 'return_url': 'http://{}{}'.format(host, reverse('payment:done')), # 从定向取消支付或者支付失败的跳转链接 'cancel_return': 'http://{}{}'.format(host, reverse('payment:canceled')), } form = PayPalPaymentsForm(initial=paypal_dict) return render(request, 'payment/process.html', { 'order': order, 'form': form })
def get(self, request, *args, **kwargs): studentObj = getStudent(request) host = request.get_host() totalCost, allCourses = getCartCourses(request) kwargs["tcost"] = totalCost kwargs["cartCourses"] = allCourses paypal_dict = { 'business': settings.PAYPAL_RECEIVER_EMAIL, 'amount': totalCost, 'item_name': "Courses Enrolled", 'invoice': "Invoice for " + str(request.user.name), 'currency_code': 'USD', 'notify_url': '{}://{}{}'.format(request.scheme, host, reverse('paypal-ipn')), 'return_url': '{}://{}{}'.format(request.scheme, host, reverse('payments:done')), 'cancel_return': '{}://{}{}'.format(request.scheme, host, reverse('payments:canceled')), } form = PayPalPaymentsForm(initial=paypal_dict) kwargs["form"] = form return super().get(request, *args, **kwargs)
def payment_process(request): # This is responsible for Paypal payment integration host = request.get_host() cart_obj, new_obj = Cart.objects.new_or_get(request) products = cart_obj.products.all() itemNames = '' for product in products: itemNames += product.title + ', ' paypal_dict = { 'business': settings.PAYPAL_RECEIVER_EMAIL, 'amount': cart_obj.total, 'item_name': itemNames, 'invoice': 'unique-invoice-id', 'notify_url': 'http://{}{}'.format(host, reverse('paypal-ipn')), 'return_url': 'http://{}{}'.format(host, reverse('payment:done')), 'cancel_return': 'http://{}{}'.format(host, reverse('payment:canceled')), } form = PayPalPaymentsForm(initial=paypal_dict) context = {'form': form} if (cart_obj.products.count() > 0): return render(request, 'payment/process.html', context) else: return render(request, 'carts/home.html')
def show_book(request, book_id): result_book = Book.objects.filter(id=book_id) if not result_book: return HttpResponseRedirect("/") result_book = result_book[0] paypal_dict = { "business": "*****@*****.**", "amount": result_book.price, "item_name": result_book.title, "invoice": "unique-invoice-id", "notify_url": "http://localhost:8000/paypal/" + reverse('paypal-ipn'), "return_url": "http://localhost:8000/book/" + str(result_book.id), "cancel_return": "http://localhost:8000/book/" + str(result_book.id), "custom": "Upgrade all users!", # Custom command to correlate to some function later (optional) } payment_form = PayPalPaymentsForm(initial=paypal_dict) context = { "title": result_book.title, "result_book": result_book, "user": request.user, "seller": User.objects.filter(id=result_book.seller_id)[0], "payment_form": payment_form } return render(request, 'vetusbooks/show_book.html', context)
def payment_process(request): """ https://django-paypal.readthedocs.io/en/stable/standard/ipn.html :param request: :return: """ order_id = request.session.get('order_id') order = get_object_or_404(Order, id=order_id) # host = request.get_host() # What you want the button to do. paypal_dict = { 'business': settings.PAYPAL_RECEIVER_EMAIL, 'amount': '%.2f' % order.get_total_cost().quantize(Decimal('.01')), 'item_name': 'Заказ {}'.format(order.id), 'invoice': str(order.id), 'currency_code': 'USD', # 'notify_url': 'http://{}{}'.format(host, reverse('paypal-ipn')), # 'return_url': 'http://{}{}'.format(host, reverse('payment:done')), # 'cancel_url': 'http://{}{}'.format(host, reverse('payment:canceled')), "notify_url": request.build_absolute_uri(reverse('paypal-ipn')), "return": request.build_absolute_uri(reverse('payment:done')), "cancel_return": request.build_absolute_uri(reverse('payment:canceled')), } # Create the instance. form = PayPalPaymentsForm(initial=paypal_dict) context = { 'order': order, 'form': form, } return render(request, 'payment/process.html', context)
def payment_process(request): order_id = request.session.get('order_id') orders = get_object_or_404(order, id=order_id) host = request.get_host() paypal_dict = { 'business': settings.PAYPAL_RECEIVER_EMAIL, 'amount': '%.2f' % orders.get_total_cost(), 'item_name': 'Order {}'.format(order.id), 'invoice': str(orders.id), 'currency_code': 'USD', 'notify_url': 'http://{}{}'.format(host, reverse('paypal-ipn')), 'return_url': 'http://{}{}'.format(host, reverse('payment:done')), 'cancel_return': 'http://{}{}'.format(host, reverse('payment:canceled')), } form = PayPalPaymentsForm(initial=paypal_dict) context = { 'order': orders, 'form': form, } send_mail( 'Successful order', 'The payment was successfully done', '*****@*****.**', ['*****@*****.**'], fail_silently=False, ) return render(request, 'payment/process.html', context)
def process_payment(request): """Method to allow user to pay """ order_id = request.session.get('order_id') registration = get_object_or_404(Registration, order_id=order_id) host = request.get_host() paypal_dict = { 'business': settings.PAYPAL_RECEIVER_EMAIL, 'amount': registration.amount, 'item_name': 'Inscription {}'.format(registration.event.title), 'invoice': order_id, 'currency_code': 'EUR', 'notify_url': 'http://{}{}'.format(host, reverse('paypal-ipn')), 'return_url': 'http://{}{}'.format(host, reverse('payment:payment_done')), 'cancel_return': 'http://{}{}'.format(host, reverse('payment:payment_cancelled')), } form = PayPalPaymentsForm(initial=paypal_dict) return render(request, 'payment/process_payment.html', { 'registration': registration, 'form': form })
def process_payment(request): items = cart.objects.filter(user__id=request.user.id, status=False) products = "" amt = 0 inv = "INV1001-" cart_ids ="" p_ids ="" for j in items: products += str(j.products.product_name)+ "\n" p_ids += str(j.products.id) +"," amt += float(j.products.final_price) inv += str(j.id) cart_ids += str(j.id)+"," paypal_dict = { 'business': settings.PAYPAL_RECEIVER_EMAIL, 'amount': str(amt), 'item_name': products, 'invoice':inv, 'notify_url': 'http://{}{}'.format("127.0.0.1:8000", reverse('paypal-ipn')), 'return_url': 'http://{}{}'.format("127.0.0.1:8000", reverse('payment_done')), 'cancel_return': 'http://{}{}'.format("127.0.0.1:8000", reverse('payment_cancelled')), } usr = User.objects.get(username=request.user.username) ord = Order(cust_id=usr,cart_ids=cart_ids,product_ids=p_ids) ord.save() ord.invoice_id = str(ord.id)+inv ord.save() request.session["order_id"] = ord.id form = PayPalPaymentsForm(initial=paypal_dict) return render(request, 'process_payment.html', { 'form': form})
def process_payment(request): order_id = request.session.get('order_id') print(order_id) order = get_object_or_404(Order, id=order_id) item_price = get_object_or_404(OrderItem, order=order) price = item_price.price host = request.get_host() paypal_dict = { 'business': settings.PAYPAL_RECEIVER_EMAIL, 'amount': '%.2f' % price, 'item_name': 'Order {}'.format(order.id), 'invoice': str(order.id), 'currency_code': 'USD', 'notify_url': 'http://{}{}'.format(host, reverse('paypal-ipn')), 'return_url': 'http://{}{}'.format(host, redirect('/orders/payment_done/')), 'cancel_return': 'http://{}{}'.format(host, redirect('/orders/payment_cancelled/')) } form = PayPalPaymentsForm(initial=paypal_dict) return render(request, 'orders/make_payment.html', { 'order': order, 'form': form })
def admin_payment_process(request, id): try: field_reservation = FieldReseravtion.objects.get(id=id) league = field_reservation.league field = field_reservation.match.location except Exception as e: return render(request, 'expections/show.html', {'error': e}) # What you want the button to do. paypal_dict = { "business": settings.PAYPAL_RECEIVER_EMAIL, "amount": field.price, "item_name": "Field Reservation fees", "invoice": league.id, "notify_url": request.build_absolute_uri(reverse('paypal-ipn')), "return": request.build_absolute_uri( reverse('payment:admin_done', kwargs={'id': field_reservation.id})), "cancel_return": request.build_absolute_uri(reverse('payment:cancel')), "custom": "premium_plan", # Custom command to correlate to some function later (optional) } # Create the instance. form = PayPalPaymentsForm(initial=paypal_dict) context = {"form": form} return render(request, "payment/process.html", context)
def process_payment(request): domain = request.session.get('domain') app = request.session.get('app') app = app + ".apk" print(domain, app) email = str(request.user) data = domain + " " + app + " " + email releaseapk1 = releaseapk.objects.all() last = releaseapk1[len(releaseapk1) - 1] if releaseapk1 else None try: invoice = "INV-000000000" + str(last.invoice + 1) except: invoice = "INV-000000001" host = request.get_host() paypal_dict = { 'business': settings.PAYPAL_RECEIVER_EMAIL, 'amount': '19.00', 'item_name': 'Web App', 'invoice': invoice, 'currency_code': 'USD', 'custom': data, 'notify_url': 'http://{}{}'.format(host, reverse('paypal-ipn')), 'return_url': 'http://{}{}'.format(host, reverse('payment_done')), 'cancel_return': 'http://{}{}'.format(host, reverse('payment_cancelled')), } form = PayPalPaymentsForm(initial=paypal_dict) return render(request, 'payment/process.html', {'form': form})
def home_view(request): form = CreateCompanyForm() if request.method == 'POST': host = request.get_host() form = CreateCompanyForm(request.POST) if form.is_valid(): name = form.cleaned_data['name'].lower() admin_name = form.cleaned_data['admin_name'] admin_pass = form.cleaned_data['admin_pass'] paypal_dict = { 'business': settings.PAYPAL_RECEIVER_EMAIL, 'amount': '15', 'item_name': 'jiller', 'invoice': name, 'notify_url': 'http://{}{}'.format(host, reverse('paypal-ipn')), 'return_url': 'http://{}{}'.format(host, reverse('payment:done')), 'cancel_return': 'http://{}{}'.format(host, reverse('payment:canceled')), 'custom': "{" + "\"name\": \"" + name + "\"," + "\"admin_name\": \"" + admin_name + "\"," + "\"admin_pass\": \"" + admin_pass + "\"}" } request.session['company'] = name form = PayPalPaymentsForm(initial=paypal_dict) return render(request, 'payment/process.html', {'form': form}) return render(request, 'home.html', { 'form': form, })
def donate(request, experience_id): experience = get_object_or_404(Experience, pk=experience_id) paypal_form = None if experience.accepts_paypal: url = settings.PAYPAL_RETURN_URL paypal_dict = { 'business': experience.author.paypal_email_address, 'amount': 25.00, 'item_name': 'Experience: {0}'.format(experience), 'cmd': '_donations', 'bn': 'Acressity_Donate_WPS_US', 'alt': 'Donate', 'notify_url': url + reverse('paypal-ipn'), 'return_url': url + reverse('paypal_return', args=(experience_id, )), 'cancel_return': url + reverse('paypal_cancel', args=(experience_id, )), # Returned by PayPal so it can be used in event handler 'item_number': experience_id, } paypal_form = PayPalPaymentsForm(initial=paypal_dict, button_type='donate') return render(request, 'support/donate.html', { 'experience': experience, 'paypal_form': paypal_form })
def view_that_asks_for_money(request): # What you want the button to do. paypal_dict = { "business": settings.PAYPAL_RECEIVER_EMAIL, "amount": "1.00", "item_name": "name of the item", "invoice": "unique-invoice-id", "notify_url": "%s%s" % (settings.SITE_NAME, reverse('paypal-ipn')), "return_url": "http://0.0.0.0:8008/hello/", "cancel_return": "http://0.0.0.0:8008/hello/", } # Create the instance. form = PayPalPaymentsForm(initial=paypal_dict) context = {"form": form.sandbox(), "productID": request.POST["productID"]} return render_with_user(request, "paypal/payment.html", context)
def paypal_standard(request): ipn_url = 'http://%s%s' % (Site.objects.get_current().domain, reverse("paypal-ipn")) pdt_url = 'http://%s%s' % (Site.objects.get_current().domain, reverse("paypal-pdt")) return_url = pdt_url if config.PDT else ipn_url data = { "amount": "1.00", "item_name": "Samsung Galaxy S3", "invoice": "INVOICE001", "notify_url": ipn_url, "return_url": return_url, } form = PayPalPaymentsForm(initial=data) data['form'] = form.sandbox() if config.DEBUG else form.render() return render_to_response("payment/paypal/standard.html", data, context_instance=RequestContext(request))
def get_context_data(self, **kwargs): context = super(MerchDetailView, self).get_context_data(**kwargs) merch = context['merch'] paypal = { 'amount': merch.price, 'item_name': merch.title, 'item_number': merch.slug, 'currency_code': 'GBP', # PayPal wants a unique invoice ID 'invoice': str(uuid.uuid4()), 'return_url': '/merch/thanks', 'cancel_return': merch.get_absolute_url(), } form = PayPalPaymentsForm(initial=paypal) context['form'] = form.sandbox() if settings.DEBUG else form.render() return context
def paypal(request, publisher_id, product_id): # What you want the button to do. productchoice = Product.objects.get(id=product_id) publisher = Publisher.objects.get(id=publisher_id) paypal_dict = { "business": settings.PAYPAL_RECEIVER_EMAIL, "amount": "%.2f" % productchoice.product_cost, "item_name": "%s" % productchoice.product_type, "invoice": "unique-invoice-id", "notify_url": "%s%s" % (settings.SITE_NAME, reverse('paypal-ipn')), "return_url": "http://www.example.com/your-return-location/", "cancel_return": "http://www.example.com/your-cancel-location/", } # Create the instance. form = PayPalPaymentsForm(initial=paypal_dict) context = {"form": form.sandbox(), "productchoice": productchoice} return render_to_response("signup/paypal.html", context)
def carga(request, pago_id): pago=get_object_or_404(Pagos, pk=pago_id) usuario_pago=Usuarios_Pagos.objects.get(usuario=request.user, pago=pago) paypal_dict = { # "business": settings.PAYPAL_RECEIVER_EMAIL, "business": pago.correo, "amount": pago.get_precio, "item_name": pago.concepto, "invoice": "pagos_family" + str(pago.id)+"_"+str(request.user.id), "notify_url": "%s%s" % (SITE_NAME, reverse('paypal-ipn')), "return_url": "http://joinity.com/", "cancel_return": "http://joinity.com/", "custom": usuario_pago.id, "currency_code": "EUR", # currency } form = PayPalPaymentsForm(initial=paypal_dict) context={"pago":pago, "form":form.render(), "usuario":request.user} pagina_pago=render_to_string("joinitys/pagos/ajax_ver_pago.html", context) return simplejson.dumps({"pago":pagina_pago})
def create_paypal_form(order, return_page="unpaid_invoice"): pp_settings = PayPalSettings.objects.all() if pp_settings.count(): pp_settings = pp_settings[0] else: return None domain = Site.objects.get_current().domain paypal_dict = { "business": pp_settings.business, "amount": order.grand_total, "item_name": " ".join(["Fifth Season order #", str(order.id)]), "invoice": order.id, "notify_url": "http://%s%s" % (domain, reverse("paypal-ipn")), "return_url": "http://%s%s" % (domain, reverse(return_page, kwargs={"order_id": order.id})), "cancel_return": "http://%s%s" % (domain, reverse(return_page, kwargs={"order_id": order.id})), } form = PayPalPaymentsForm(initial=paypal_dict) form.use_sandbox = pp_settings.use_sandbox return form
def try_paypal(request): paypal_dict = { "business": settings.PAYPAL_RECEIVER_EMAIL, "amount": "1.00", # amount to charge for item "invoice": datetime.now(), # unique tracking variable paypal "item_name": "Cipő", "notify_url": "%s%s" % (settings.SITE_NAME, "atyalapatyala"), "cancel_return": "%s/try_paypal_cancel" % settings.SITE_NAME, # Express checkout cancel url "return_url": "%s/try_paypal_success" % settings.SITE_NAME} # Express checkout return url # kw = {"item": item, # what you're selling # "payment_template": "try_paypal.html", # template name for payment # "confirm_template": "try_paypal_confirmation.html", # template name for confirmation # "success_url": "/try_paypal_success/"} # redirect location after success #ppp = PayPalPro(**kw) #return ppp(request) form = PayPalPaymentsForm(initial=paypal_dict) context = {"form": form.sandbox()} return render(request, "try_paypal.html", context)
def view_ask_money_pdt(request): # What you want the button to do. access_token = '' if request.COOKIES.has_key('access_token'): access_token = str(request.COOKIES['access_token']) else: #print 'redirect user to the sign in page' #redirect user to the sign_in page _redirect = True paypal_dict = { "business":settings.PAYPAL_RECEIVER_EMAIL, "item_number": access_token, "item_name":"Ttagit Credits", "notify_url": paths.HTTPS+request.get_host() + "/3f2cf0fe3d994fb8dfe6d8f9g2h5", "return_url": paths.HTTPS+request.get_host() + "/paypal/pdt/", "cancel_return": paths.HTTPS+request.get_host()+ "/cancel", } form = PayPalPaymentsForm(initial=paypal_dict) context = {"form":form.sandbox()} return render_to_response("payment.html", context)
def image_show(request, image): try: colorscheme = ColorScheme.objects.get(use_for_galleries=True) except ColorScheme.DoesNotExist: colorscheme = None try: bgimage = BackgroundImage.objects.get(use_for_galleries=True) except BackgroundImage.DoesNotExist: bgimage = None image = get_object_or_404(models.Image, title_slug=image) gallery = image.gallery # Paypal form info mysite = Site.objects.get_current() domain = mysite.domain paypal_dict = { "business": settings.PAYPAL_RECEIVER_EMAIL, "amount": image.price, "item_name": image.title, "item_number": image.id, "no_shipping": PayPalPaymentsForm.SHIPPING_CHOICES[1][0], "invoice": random_string(), "notify_url": "http://%s%s"%(domain, reverse('paypal-ipn')), "return_url": "http://%s%s"%(domain, reverse("purchase_return",args=(image.title_slug,))), "cancel_return": "http://%s%s"%(domain, reverse("purchase_cancel",args=(image.title_slug,))) } the_form = PayPalPaymentsForm(initial=paypal_dict) # Change this in production! form = the_form.sandbox() # Use gallery colorscheme try: colorscheme = ColorScheme.objects.get(use_for_galleries=True) except ColorScheme.DoesNotExist: pass return render_to_response("image_show.html", locals(), context_instance=RequestContext(request))
def get(self, request, subscription_id): preferences = global_preferences_registry.manager() subscription = get_object_or_404(Subscription, id=int(subscription_id)) volunteer = subscription.volunteer form = PayPalPaymentsForm(initial={ 'business': preferences['payment__receiver_email'], 'amount': preferences['subscription__ticket_value'], 'custom': preferences['payment__campaign'], 'item_name': preferences['payment__item_name'].format(volunteer.name), 'item_number': subscription_id, 'notify_url': urljoin(preferences['general__site_url'], reverse('paypal-ipn')), 'invoice': 'Subscription(id=%s)' % subscription_id, 'currency_code': 'BRL', 'lc': 'BR', 'no_shipping': '1', 'address_override': '1', 'country': 'BR', 'first_name': volunteer.first_name(), 'last_name': volunteer.last_name(), 'address1': volunteer.address, 'address2': volunteer.complement, 'city': volunteer.city, 'state': volunteer.state, 'zip': volunteer.cep, 'night_phone_a': '', 'night_phone_b': '', 'night_phone_c': '', 'email': volunteer.email, }) data = dict([(f.name, f.value()) for f in form if f.value() is not None]) data['endpoint'] = form.get_endpoint() data['image_button'] = form.get_image() response = Response(data) return response
def do_subscribe(request): log.info("mypal module -> view.py -> do_subscribe()") paypal_dict={ "cmd":"_xclick-subscriptions", "business":settings.PAYPAL_RECEIVER_EMAIL, "a3":"0.01", "p1":1, "p2":1, "p3":1, "t3":"D", "src":"1", "sra":"1", "no_note":"1", "item_name":"ttagit_pro_market", #use item_number for user id "item_number":"4ffb5e1a0cf2c9e46dda6810", "notify_url":"https://dev.ttagit.com/3f2cf0fe3d994fb8dfe6d8f9g2h5", "return_url":"https://dev.ttagit.com/paypal/pdt/", "cancel_return":"https://dev.ttagit.com/cancel", } form = PayPalPaymentsForm(initial=paypal_dict, button_type="subscribe") context = {"form":form.sandbox()} return render_to_response("payment.html", context)
def paypal(request, treatment_id): # What you want the button to do. try: treatment = Treatment.objects.get(id=treatment_id) except: raise Http404 treatment_price = system.GET_TREATMENT_PRICE() treatment_time = system.GET_TREATMENT_TIME_LIMIT() paypal_dict = { "business": settings.PAYPAL_RECEIVER_EMAIL, "charset": "utf-8", "amount": "%s" % treatment_price, "item_name": u"Avaliação e Orientação Dermatológica", "custom": treatment_id, "invoice": treatment_id, "notify_url": "%s%s" % (settings.SITE_NAME, reverse('paypal-ipn')), "return_url": "%s%s" % (settings.SITE_NAME, reverse('paypalreturn')), "cancel_return": "%s%s" % (settings.SITE_NAME, reverse('paypal-cancel-return')), } # Create the instance. paypal_form = PayPalPaymentsForm(initial=paypal_dict) free_treatments = system.GET_FREE_TREATMENTS() if settings.PAYPAL_TEST: paypal_form = paypal_form.sandbox() else: paypal_form = paypal_form.render() context = {"paypal_form": paypal_form, "treatment": treatment, "treatment_time": treatment_time, "free_treatments": free_treatments} return render_to_response("treatments/checkout.html", context, context_instance=RequestContext(request)) from paypal.pro.views import PayPalPro
def pdt(request,item_check_callable=None): """ PayPal IPN endpoint (notify_url). Used by both PayPal Payments Pro and Payments Standard to confirm transactions. http://tinyurl.com/d9vu9d PayPal IPN Simulator: https://developer.paypal.com/cgi-bin/devscr?cmd=_ipn-link-session """ flag = None ipn_obj = None form = PayPalPaymentsForm(request.POST) if form.is_valid(): try: pdt_obj = form.save(commit=False) except Exception as e: flag = "Exception while processing. (%s)" % e else: flag = "Invalid form. (%s)" % form.errors if ipn_obj is None: ipn_obj = PayPalPDT() ipn_obj.initialize(request) if flag is not None: ipn_obj.set_flag(flag) else: # Secrets should only be used over SSL. if request.is_secure() and 'secret' in request.GET: ipn_obj.verify_secret(form, request.GET['secret']) else: try: ipn_obj.verify(item_check_callable) except Exception as e: flag = "Exception while processing. (%s)" % e ipn_obj.save() return HttpResponse("OKAY")
def test_form_endpont(self): with self.settings(PAYPAL_TEST=False): f = PayPalPaymentsForm(initial={}) self.assertNotIn('sandbox', f.render())
def donate(request, p, engine): if not can_accept_donations(p): return redirect("project-main", project_id=p.id) is_test_donation = getattr(settings, "DONATION_TEST", False) if request.method == "POST": donate_form = InvoiceForm(data=request.POST, project=p, engine=engine) if donate_form.is_valid(): description = u"Akvo-%d-%s" % (p.id, p.title) cd = donate_form.cleaned_data invoice = donate_form.save(commit=False) invoice.project = p invoice.engine = engine invoice.name = cd["name"] invoice.email = cd["email"] invoice.campaign_code = cd["campaign_code"] invoice.is_anonymous = not cd["is_public"] original_http_referer = request.session.get("original_http_referer", None) if original_http_referer: invoice.http_referer = original_http_referer del request.session["original_http_referer"] else: invoice.http_referer = request.META.get("HTTP_REFERER", None) if is_test_donation: invoice.test = True if request.session.get("donation_return_url", False): return_url = urljoin(request.session["donation_return_url"], reverse("donate_thanks")) else: return_url = urljoin(request.META['HTTP_ORIGIN'], reverse("donate_thanks")) if engine == "ideal": invoice.bank = cd["bank"] mollie_dict = dict( amount=invoice.amount * 100, bank_id=invoice.bank, partnerid=invoice.gateway, description=description, reporturl=urljoin(request.META['HTTP_ORIGIN'], reverse("mollie_report")), returnurl=return_url) try: mollie_response = query_mollie(mollie_dict, "fetch") invoice.transaction_id = mollie_response["transaction_id"] order_url = mollie_response["order_url"] invoice.save() except: return redirect("donate_500") return render_to_response("donate/donate_step3.html", dict(invoice=invoice, project=p, payment_engine=engine, mollie_order_url=order_url), context_instance=RequestContext(request)) elif engine == "paypal": invoice.save() pp_dict = dict( cmd="_donations", currency_code=invoice.currency, business=invoice.gateway, amount=invoice.amount, item_name=description, invoice=int(invoice.id), lc=invoice.locale, notify_url=urljoin(request.META['HTTP_ORIGIN'], reverse("paypal_ipn")), return_url=return_url, cancel_url=request.META['HTTP_ORIGIN']) pp_form = PayPalPaymentsForm(initial=pp_dict) if is_test_donation: pp_button = pp_form.sandbox() else: pp_button = pp_form.render() return render_to_response("donate/donate_step3.html", dict(invoice=invoice, payment_engine=engine, pp_form=pp_form, pp_button=pp_button, project=p), context_instance=RequestContext(request)) else: invoice_id = request.GET.get("invoice_id", None) if not invoice_id: donate_form = InvoiceForm(project=p, engine=engine, initial=dict(is_public=True)) else: invoice = get_object_or_404(Invoice, pk=invoice_id) donate_form = InvoiceForm(project=p, engine=engine, initial=dict(amount=invoice.amount, name=invoice.name, email=invoice.email, email2=invoice.email, campaign_code=invoice.campaign_code, is_public=not invoice.is_anonymous)) if request.session.get("donation_return_url", False): request.session["cancel_url"] = urljoin(request.session["donation_return_url"], reverse("project-main", kwargs={'project_id': p.id})) else: request.session["cancel_url"] = reverse("project-main", kwargs={'project_id': p.id}) return render_to_response("donate/donate_step2.html", dict(donate_form=donate_form, payment_engine=engine, project=p), context_instance=RequestContext(request))