def post(self, request): name = request.POST.get('name') email = request.POST.get('email') amount = request.POST.get('amount') transaction = Transaction() transaction.amount = amount transaction.email = email transaction.name = name transaction.save() request_result = ws_proxy.request_payment(settings.MERCHANT_ID, settings.MERCHANT_PASSWORD, amount, '1Hes Donation', name, '09121231231', email, transaction.id, settings.SERVER_BASE_ADDRESS + '/payment/result/' + str(transaction.id)) if request_result.ResultStatus == 'Succeed': return HttpResponseRedirect(request_result.PaymentPath)
def post(self, request): name = request.POST.get('name') email = request.POST.get('email') amount = request.POST.get('amount') transaction = Transaction() transaction.amount = amount transaction.email = email transaction.name = name transaction.save() request_result = ws_proxy.request_payment( settings.MERCHANT_ID, settings.MERCHANT_PASSWORD, amount, '1Hes Donation', name, '09121231231', email, transaction.id, settings.SERVER_BASE_ADDRESS + '/payment/result/' + str(transaction.id)) if request_result.ResultStatus == 'Succeed': return HttpResponseRedirect(request_result.PaymentPath)
def buy_now(request): transaction = Transaction(user=request.user, ip=request.META.get('HTTP_X_REAL_IP') or request.META.get('REMOTE_ADDR')) form = BuyNowForm(request.POST, instance=transaction) if form.is_valid(): transaction = form.save(commit=False) transaction.type = 'buy_item' transaction.amount = transaction.item.price if transaction.shipping_method == 'standard': transaction.amount += transaction.item.standard_shipping_price else: transaction.amount += transaction.item.priority_shipping_price transaction.save() if transaction.payment_method == 'paypal': paypalrestsdk.configure({ 'mode': PAYPAL_MODE, 'client_id': PAYPAL_CLIENT_ID, 'client_secret': PAYPAL_SECRET }) payment = paypalrestsdk.Payment({ "intent": "sale", "redirect_urls": { "return_url": PAYPAL_BUY_NOW_RETURN_URL, "cancel_url": PAYPAL_BUY_NOW_CANCEL_URL }, "payer": { "payment_method": "paypal", }, "transactions": [{ "item_list": { "items": [ { "name": transaction.item.name, "sku": transaction.item.code, "price": str(transaction.item.price), "currency": "USD", "quantity": 1 }, { "name": "Shipping", "sku": transaction.shipping_method, "price": str(transaction.amount - transaction.item.price), "currency": "USD", "quantity": 1 }, ] }, "amount": { "total": str(transaction.amount), "currency": "USD" }, "description": "This is the payment transaction description." }] }) if payment.create(): print("Payment %s created successfully" % payment.id) for link in payment.links: if link.method == "REDIRECT": redirect_url = link.href print("Redirect for approval: %s" % redirect_url) request.user.last_payment_id = payment.id request.user.last_transaction_id = transaction.id request.user.save() # can't make here direct redirect or redirect via js 'next' due to facebook callback_js = "$('#buy-now-form').attr('action', '%s'); " \ "$('#buy-now').removeClass('ajax-submit');" \ "$('#buy-now').text('redirecting...');" \ "$('#buy-now').attr('type', 'submit');" \ "$('#buy-now').click();" % redirect_url return HttpResponse( json.dumps({ 'result': 'success', 'callback_js': callback_js })) else: print(payment.error) # return HttpResponse(json.dumps({'result': 'success', 'next': '/checkout/review/{}/'.format(order.id)})) else: pass else: print form._errors response = {} for k in form.errors: response[k] = form.errors[k][0] print response return HttpResponse( json.dumps({ 'response': response, 'result': 'error' }))