Problems with Stripe level2 & level3 data while saving network costs

Problems with Stripe level2 & level3 data while saving network costs

Intro

Recently I came across Stripe's one of the long running beta feature that can save money on each transaction your customers make in your app. They provide multiple ways to save costs, however passing level2 and level3 data is very much helpful to reduce costs while making online in-app transactions using Stripe.

Here is the stripe doc for more info : https://stripe.com/in/guides/guide-to-managing-network-costs

How does it work then ??

So basically, you create the payment intent with extra data (related to payment) that goes inside the level3 object.

import stripe
stripe.api_key = "sk_test_blahBlahSecret"

stripe.PaymentIntent.create(
    amount = 100,
    currency = "usd",
    payment_method_types = ["card"],
    level3 = {
        "merchant_reference": "<number>",
        "customer_reference": "<number>",
        "shipping_address_zip": "<zip/postal_code>",
        "shipping_from_zip": "<zip/postal_code>",
        "shipping_amount": 0,
        "line_items": [
            {
                "product_code": "<product_code/number>",
                "product_description": "item Description",
                "unit_cost": 80,
                "quantity": 1,
                "tax_amount": 10,
                "discount_amount": 0,
            },
            {
                "product_code": "<product_code/number>",
                "product_description": "Second item Description",
                "unit_cost": 10,
                "quantity": 1,
                "tax_amount": 0,
                "discount_amount": 0,
            },
        ]
    }
)

Stripe will use those extra data mentioned inside level3 object and save network costs resulting a lower per-charge cost.

Note : Make sure the total amount of the payment intent should always be equal to the sum of all items inside the level3 object.
Intent's total amount = sum(unit_cost * quantity) + sum(tax_amount) - sum(discount_amount) + shipping_amount

Example : 100 = (80 + 10) + (10) - (0) + (0)

When you try doing like this and create your payment intents then you will see the less charges after sometimes and you would be saving like $0.80 on a $100 corporate card transaction. So where is the problem then?

Restrictions and problems

Problem 1 : The level2 and level3 data are restricted to payment intents only.

So if you try to do it for Invoice payments then it won't work because Stripe doesn't support the level3 param while creating invoices just like payment intents and if you try to fetch the payment intent from within that invoice and try to update the payment intent with the level3 data then stripe will throw error saying "You cannot update the intent generated from invoice".

Problem 2 : You cannot handle the authorized amount with un-captured status of payment intents.

So if you have an app logic where you create a payment intent with X amount authorize the amount from the customer (the amount is on hold in stripe) and then you perform your operations in your app and after completion of those operations you finalize(or you can say capture) the amount. This finalized amount can be less than or equal to the authorized amount X.
In this flow, you cannot utilize the level3 object param because at the finalized step you can charge the amount less than the authorized and this creates an issue where you created the payment intent with 100$ but you are finalizing it with, let's say, 90$. This causes Stripe to throw an error "Pricing must be consistent in level3 and intent amount". Here the level3 pricing was 100$ but the payment intent was 90$, hence the error.

To fix this issue, you must be thinking that updating the payment intent with latest amount i.e 90$ will fix the issue but it won't because Stripe will not allows to update any payment intent amount if it's in un-captured status. You can't even update the level3 data to match as 90$, Stripe will throw the same error of inconsistent pricing.

Where this is helpful ?

Stripe's level2 and level3 data is useful where you are selling a product rather than a service which includes computation around "how much we should charge out of X dollars".

Example : If you have a Learning management system app and you are selling courses to the user where the cost of the courses are fixed not changing then level2 and level3 is quite useful here. This is just one example, there could be many examples where cost of the product or service is fixed.

Extra Points

  1. Stripe level3 is not a open feature, you need to ask your stripe support team to enable it in your account.

  2. At this moment, Stripe level2/3 works on only in USA payments with Visa and Mastercard cards.

  3. You will not see huge amount of money being saved after implementing this. You will save the amount gradually when you make very large number of payments.