Reputation: 641
I'm implementing a payment platform with Stripe. For a single payment I create a Charge. It works, no problem, but I also need to apply a tax fee to the product which is defined in the Order object. Does that mean I need to replace Charges with Orders somehow or is Order a parent object for the charge? If so how do I link those 2 together? Or there is a way to apply tax fees to charges I didn't see? Thanks
EDIT:
public async Task<StripeCharge> CreateStripeChargeAsync(StripeProduct product, StripeSku sku, StripeCustomer customer, string orderId)
{
var charge = await _chargeService.CreateAsync(new StripeChargeCreateOptions
{
Amount = sku.Price,
Currency = sku.Currency,
Description = product.Description,
CustomerId = customer.Id,
SourceTokenOrExistingSourceId = customer.DefaultSourceId,
ReceiptEmail = customer.Email,
Metadata = new Dictionary<string, string>
{
{ "OrderId", orderId }
}
});
return charge;
}
Upvotes: 0
Views: 1202
Reputation: 550
You can add a tax to your order by creating an order item with the type set to tax, for example
Stripe\OrderItem JSON: {
"object": "order_item",
"type": "tax",
"amount": 1234,
"currency": "usd",
"description": "Tax",
"parent": "null",
"quantity": null
}
Attach this to your orders item list. I can't really give a code example since you didn't mention a language but your order object would look like...
Stripe\Order JSON: {
"id": "or_1CZfbeCAQSQw5dVw1BSP63dZ",
"object": "order",
"amount": 1500,
"amount_returned": null,
"application": null,
"application_fee": null,
"charge": null,
"created": 1528206830,
"currency": "usd",
"customer": null,
"email": null,
"items": [
{
"object": "order_item",
"amount": 10000,
"currency": "usd",
"description": "My Product name",
"parent": "sk_1BQuNoCAQSQw5dVwjf30OpxH",
"quantity": null,
"type": "sku"
},
"object": "order_item",
"type": "tax",
"amount": 1234,
"currency": "usd",
"description": "Tax",
"parent": "null",
"quantity": null
], etc...
You can use the same idea for adding shipping costs or even applying discounts by using type="shipping" or "discount".
Notice the order object contains a charge field. Once the order is paid this is populated with the charge id. No need to replace charges with orders, Stripe will do this update for you linking the payment to the order.
See the API Docs for more information.
Upvotes: 1