Join us for an upcoming Shopify Partner webinar on February 27, 2024. Discover the latest Checkout Extensibility features, and deep dive on improvements to Shopify Functions and Web Pixels. Register now for either the 10am EST or 2pm EST sessions.

Partner API: Associate transaction with billing period (BrokeredSale)

erandagan
Shopify Partner
4 0 3

The partner API allows us to access transactions, such as AppSubscriptionSale. Each transaction is associated with a chargeId (the subscription itself) and an amount. However, there's no information on the service period the transaction is associated with - for instance, when a customer upgrades a subscription, there might be two transactions on his next billing interval - one prorated for the overlapping period with the old subscription, and one for the new subscription. Attached is an example response from the API on one of our customers (details redacted):

 

 

 

 

  "data": {
    "transactions": {
      "edges": [
        {
          "node": {
            "grossAmount": {
              "amount": "20.0"
            },
            "netAmount": {
              "amount": "19.42"
            },
            "chargeId": "gid://shopify/AppSubscription/CHARGE01",
            "id": "gid://partners/AppSubscriptionSale/ID02",
            "createdAt": "2023-07-27T09:38:45.000000Z"
          }
        },
        {
          "node": {
            "grossAmount": {
              "amount": "149.99"
            },
            "netAmount": {
              "amount": "145.64"
            },
            "chargeId": "gid://shopify/AppSubscription/CHARGE01",
            "id": "gid://partners/AppSubscriptionSale/ID01",
            "createdAt": "2023-07-27T09:38:45.000000Z"
          }
        }
      ]
    }
  }
}

 

 

 

 

In this case, the customer has switched plans, thus there were 2 transactions - one for $20 (for partial usage of the new subscription), and one for $150 (for the following month).

 

However, there's no way to associate each charge with the actual period it refers to - for example, how do we know which dates of service are under the $20 charge? We could guess by using the "full price" and prorating, then looking back at the entire subscription history to figure out the cycle, but this gets very complicated quickly, as transactions can happen on all sorts of occasions - before / after an upgrade / a downgrade, before / after a frozen subscription, with / without a discount, with or without a trial, during or long after a subscription, etc.

 

I noticed that in the Shopify Partner dashboard, the information does exist (https://partners.shopify.com/PARTNER_ID/apps/APP_ID/stores/STORE_ID/charges/subscription/SUB_ID) - it uses an unreleased API with an object called BrokeredSale that contains the exact service period.

 

Right now, there's no way to connect a transaction to a subscription period due to this issue, which makes financial analytics very hard to calculate. Would it be possible to add the service period from the BrokeredSale into the AppSubscriptionTransaction?

Replies 0 (0)