gpt4 book ai didi

python - Django 支付集成

转载 作者:太空宇宙 更新时间:2023-11-03 16:27:22 26 4
gpt4 key购买 nike

我有一个由 View 方法 A 渲染的购物车,我想通过 pesapal package 获取购物车中的详细信息以提交到 pesapal api。 。我使用与 sandbox app, PaymentView 相同的方法。购物车有一个结帐按钮,用于将数据提交到 api。 Sandbox 方法 simlpy 将数据作为字典 (order_info) 获取,并提供给 url (get_ payment_url),然后将其提供给 api,因此,当我打开模板时,api 的 iframe 指示我要提取字典中指定的金额。如何通过购物车提交数据?

## Sandbox method submitting data to the api
class PaymentView(TemplateView, PaymentRequestMixin):
template_name = 'payment/payment.html'
# how the sandbox app submits data to api:

def get_context_data(self, **kwargs):
ctx = super(PaymentView, self).get_context_data(**kwargs)

order_info = {
'amount': '1000',
'description': 'Payment for Stuff',
'reference': 2,
'email': 'you@email.com'
}

ctx['pesapal_url'] = self.get_payment_url(**order_info)
return ctx

## view method A:
def show_cart(request, template_name="payment/cart.html"):
if request.method == 'POST':
postdata = request.POST.copy()
if postdata['submit'] == 'Remove':
cart.remove_from_cart(request)
if postdata['submit'] == 'Update':
cart.update_cart(request)
if postdata['submit'] == 'Checkout':
# submission to api should occur here
cart_items = cart.get_cart_items(request)
cart_subtotal = cart.cart_subtotal(request)
return render_to_response(template_name, locals(), context_instance=RequestContext(request))

# my url
urlpatterns = patterns('cart.views',
(r'^$', 'show_cart', { 'template_name': 'payment/cart.html' }, 'show_cart'),
)

最佳答案

通过让 django 将数据解析到模板(在本例中为购物车),您可以快速摆脱困境。这可以通过让您的方法返回您想要的数据来完成。像这样的东西:

return render(request, 'yourpage.html', 
{'yourvariable':yourvariable}, context_instance=RequestContext(request))

然后只需在模板中获取您的值(在您的情况下为购物车),例如:

{{yourvariable}}

然后让 api 完成剩下的工作。

关于python - Django 支付集成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37886555/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com