multi-product paypal invoice is very useful : say you want to refund 1 product in a multi-product order
info = {
"cmd": "_cart",
"upload": "1",
"business": settings.PAYPAL_RECEIVER_EMAIL,
"currency_code": default_currency,
"first_name": order.invoice_firstname,
"last_name": order.invoice_lastname,
"address_street": order.invoice_line1,
"address_city": order.invoice_city,
"address_state": order.invoice_state,
"address_zip": order.invoice_code,
"custom": order.uuid,
"invoice": "w-%i" % order.number,
"ipn_notification_url": "http://boutique.belleetrebelle.ca/paypal/ipn/",#change to fit all
"return": "http://boutique.belleetrebelle.ca/thank-you",#change to fit all
"address_country": order.invoice_country,
"shipping_1": order.shipping_price,
"shipping_method": "postes canada",#change to fit all
}
index_item=0
for order_item in order.items.all():
item = order.items.all().order_by('id')[index_item]
index_item+=1
info["item_name_%i" % index_item] = "%s" % item.product_name
info["amount_%i" % index_item] = "%.2f" % item.product_price_net
info["quantity_%i" % index_item] = "%i" % item.product_amount
info["tax_%i" % index_item] = "%.2f" % item.product_tax
variant_index=0
properties = item.product.get_variant_properties()
for d in properties:
info["on%i_%i" % (variant_index, index_item)] = "%s" % d['name']
info["os%i_%i" % (variant_index, index_item)] = "%s" % d['value']
variant_index+=1
parameters = "&".join(["%s=%s" % (k, v) for (k, v) in info.items()])
if getattr(settings, 'PAYPAL_DEBUG', settings.DEBUG):
url = SANDBOX_POSTBACK_ENDPOINT + "?" + parameters
else:
url = POSTBACK_ENDPOINT + "?" + parameters
return url
it works for me, would need some adjusting to fit all ; test it on your side, make it better and available for everyone to make lfs better