使用 django-paypal 实现 Paypal“_cart”

问题描述 投票:0回答:2

我正在使用 django-paypal ipn.standard 并尝试使其与 paypal 的“_cart”选项一起使用。但是,我无法让它发挥作用。

我使用这本字典来初始化表格:

cart {
  'amount_1': '0.99',
  'amount_2': '0.99',
  'business': '[email protected]',
  'cancel_return': 'http://www.foo.com/ccled/',
  'cmd': '_cart',
  'invoice': '1',
  'item_name_1': 'Item 1',
  'item_name_2': 'Item 2',
  'notify_url': 'http://www.foo.com/ntfy/',
  'return_url': 'http://www.doo.com/done/'
}

form = PayPalPaymentForm(initial=cart)

我也尝试将“CMD_CHOICES”:“_cart”添加到上面的字典中,但没有产生任何影响

但是,在使用 {{ form.render }} 时,我得到了带有以下 html 的“立即购买”按钮:

<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
  <input type="hidden" name="business" value="[email protected]" id="id_business" />
  <input type="hidden" name="notify_url" value="'http://www.foo.com/ntfy//" id="id_notify_url" />
  <input type="hidden" name="cancel_return" value="http://www.foo.com/ccled/" id="id_cancel_return" />
  <input type="hidden" name="return" value="http://www.foo.com/done/" id="id_return_url" />
  <input type="hidden" name="invoice" value="1" id="id_invoice" />
  <input type="hidden" name="cmd" value="_cart" id="id_cmd" />
  <input type="hidden" name="charset" value="utf-8" id="id_charset" />
  <input type="hidden" name="currency_code" value="USD" id="id_currency_code" />
  <input type="hidden" name="no_shipping" value="1" id="id_no_shipping" />
  <input type="image" src="https://www.sandbox.paypal.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="Buy it Now" />
</form>

未显示任何购物车商品。

我正在查看其他几个线程,例如django-paypal 中的多个项目。为了尝试一下,我从该示例中剪切粘贴了“item”字典,并将其传递到我的 PayPalPaymentForm。然而,同样,在表格中,我没有看到正在出售的物品。

请问我缺少什么?

paypal django-forms django-paypal
2个回答
1
投票

我发现我错过了什么。应使用“购物车”选项创建表单:

form = PayPalPaymentForm(initial=cart, button_type="cart")

0
投票

如果有人再次遇到这个问题,以下是我如何为我的项目解决这个问题。我在这方面花了太多时间,因为它没有很好的文档记录,而且我找不到有效的示例:

paypal_dict = {
    'upload': 1, 
    'business': '[email protected]', 
    'invoice': 'INVOICE1', 
    'currency_code': 'CAD', 
    'cmd': '_cart', 
    'charset': 'utf-8', 
    'notify_url': 'http://website.ca/paypal/', 
    'return_url': 'http://website.ca/payment-completed', 
    'cancel_return': 'http://website.ca/payment-failed', 
    'quantity_1': 1, 
    'item_name_1': 'item 1', 
    'item_number_1': 1, #This is just a product ID for your reference
    'shipping_1': 0, 
    'amount_1': 150, 
    'quantity_2': 1, 
    'item_name_2': 'item2', 
    'item_number_2': 2, 
    'shipping_2': 0, 
    'amount_2': 125,
}
paypal_payment_button = PayPalPaymentsForm(initial=paypal_dict, button_type="buy")

所以我所做的基本上只是在 PaymentsForm 中指定每个产品的所有要求,并且我还确保将 cmd 指定为 _cart。我还向上传到 PayPal 的购物车提供上传标志。

有了这个,我可以将所有带有产品 ID 和描述的商品直接显示在 PayPal 发票上。

© www.soinside.com 2019 - 2024. All rights reserved.