I believe we added an offsite gateway recently that takes line items, we could base it off of that. Paypal also has some apis with line items and discounts, might be worth using those as a reference.