Stripe Subscriptions module API explorer

/api/administrator/subscriptions/refunds (GET)

Account information like email addresses is generated with faker-js it is not real user information.

await global.api.administrator.subscriptions.Refunds.get(req)

Returns array

[
  {
    "refundid": "re_3LEOPOHHqepMFuCX1nxlm2Bk",
    "object": "refund",
    "stripeObject": {
      "id": "re_3LEOPOHHqepMFuCX1nxlm2Bk",
      "object": "refund",
      "amount": 1000,
      "balance_transaction": "txn_3LEOPOHHqepMFuCX1USngHzp",
      "charge": "ch_3LEOPOHHqepMFuCX17aukT3M",
      "created": 1656122862,
      "currency": "usd",
      "metadata": {},
      "payment_intent": "pi_3LEOPOHHqepMFuCX17Vptryv",
      "reason": "requested_by_customer",
      "receipt_number": null,
      "source_transfer_reversal": null,
      "status": "succeeded",
      "transfer_reversal": null
    },
    "accountid": "acct_c29fe7727ce6723f",
    "subscriptionid": null,
    "customerid": null,
    "invoiceid": "in_1LEOPNHHqepMFuCX96SWoyek",
    "productid": null,
    "paymentmethodid": null,
    "appid": "tests_1656122823",
    "createdAt": "2022-06-25T02:07:42.606Z",
    "updatedAt": "2022-06-25T02:07:42.606Z"
  },
  {
    "refundid": "re_3LEOPFHHqepMFuCX0oDY1E1M",
    "object": "refund",
    "stripeObject": {
      "id": "re_3LEOPFHHqepMFuCX0oDY1E1M",
      "object": "refund",
      "amount": 1000,
      "balance_transaction": "txn_3LEOPFHHqepMFuCX0xp9YbA9",
      "charge": "ch_3LEOPFHHqepMFuCX0sN4tUph",
      "created": 1656122852,
      "currency": "usd",
      "metadata": {},
      "payment_intent": "pi_3LEOPFHHqepMFuCX0MDEDwSW",
      "reason": "requested_by_customer",
      "receipt_number": null,
      "source_transfer_reversal": null,
      "status": "succeeded",
      "transfer_reversal": null
    },
    "accountid": "acct_da8d1c7579916277",
    "subscriptionid": null,
    "customerid": null,
    "invoiceid": "in_1LEOPFHHqepMFuCXnEiBhWTZ",
    "productid": null,
    "paymentmethodid": null,
    "appid": "tests_1656122823",
    "createdAt": "2022-06-25T02:07:33.416Z",
    "updatedAt": "2022-06-25T02:07:33.417Z"
  },
  {
    "refundid": "re_3LEOP6HHqepMFuCX1bYXW2de",
    "object": "refund",
    "stripeObject": {
      "id": "re_3LEOP6HHqepMFuCX1bYXW2de",
      "object": "refund",
      "amount": 1000,
      "balance_transaction": "txn_3LEOP6HHqepMFuCX1vKXOIRt",
      "charge": "ch_3LEOP6HHqepMFuCX1QjwCsCE",
      "created": 1656122844,
      "currency": "usd",
      "metadata": {},
      "payment_intent": "pi_3LEOP6HHqepMFuCX1IkR27CK",
      "reason": "requested_by_customer",
      "receipt_number": null,
      "source_transfer_reversal": null,
      "status": "succeeded",
      "transfer_reversal": null
    },
    "accountid": "acct_74ce85765fd30dbf",
    "subscriptionid": null,
    "customerid": null,
    "invoiceid": "in_1LEOP6HHqepMFuCXhyUg03zD",
    "productid": null,
    "paymentmethodid": null,
    "appid": "tests_1656122823",
    "createdAt": "2022-06-25T02:07:24.982Z",
    "updatedAt": "2022-06-25T02:07:24.982Z"
  }
]

Receives

API routes may receive parameters from the URL and POST supporting simple and multipart:

Field Value Required Type
all boolean optional URL
limit integer optional URL
offset integer optional URL

NodeJS source (view on github)

const subscriptions = require('../../../../../index.js')

module.exports = {
  get: async (req) => {
    req.query = req.query || {}
    const where = {
      appid: req.appid || global.appid
    }
    let refundids
    if (req.query.all) {
      refundids = await subscriptions.Storage.Refund.findAll({
        where,
        attributes: ['refundid'],
        order: [
          ['createdAt', 'DESC']
        ]
      })
    } else {
      const offset = req.query.offset ? parseInt(req.query.offset, 10) : 0
      const limit = req.query.limit ? parseInt(req.query.limit, 10) : global.pageSize
      refundids = await subscriptions.Storage.Refund.findAll({
        where,
        attributes: ['refundid'],
        offset,
        limit,
        order: [
          ['createdAt', 'DESC']
        ]
      })
    }
    if (!refundids || !refundids.length) {
      return null
    }
    const items = []
    for (const refundInfo of refundids) {
      req.query.refundid = refundInfo.dataValues.refundid
      const refund = await global.api.administrator.subscriptions.Refund.get(req)
      items.push(refund)
    }
    return items
  }
}

Test source (view on github)

/* eslint-env mocha */
const assert = require('assert')
const TestHelper = require('../../../../../test-helper.js')
const TestStripeAccounts = require('../../../../../test-stripe-accounts.js')
const DashboardTestHelper = require('@layeredapps/dashboard/test-helper.js')

describe('/api/administrator/subscriptions/refunds', function () {
  before(TestHelper.disableMetrics)
  after(TestHelper.enableMetrics)
  let cachedResponses, cachedRefunds
  async function bundledData (retryNumber) {
    if (retryNumber > 0) {
      cachedResponses = {}
    }
    if (cachedResponses && cachedResponses.finished) {
      return
    }
    cachedResponses = {}
    cachedRefunds = []
    await TestHelper.setupBefore()
    await DashboardTestHelper.setupBeforeEach()
    await TestHelper.setupBeforeEach()
    const administrator = await TestStripeAccounts.createOwnerWithPrice()
    for (let i = 0, len = global.pageSize + 2; i < len; i++) {
      const user = await TestStripeAccounts.createUserWithPaidSubscription(administrator.price)
      await TestHelper.createRefund(administrator, user.charge.chargeid)
      cachedRefunds.unshift(administrator.refund.refundid)
    }
    const req1 = TestHelper.createRequest('/api/administrator/subscriptions/refunds?offset=1')
    req1.account = administrator.account
    req1.session = administrator.session
    cachedResponses.offset = await req1.get()
    const req2 = TestHelper.createRequest('/api/administrator/subscriptions/refunds?limit=1')
    req2.account = administrator.account
    req2.session = administrator.session
    cachedResponses.limit = await req2.get()
    const req3 = TestHelper.createRequest('/api/administrator/subscriptions/refunds?all=true')
    req3.account = administrator.account
    req3.session = administrator.session
    cachedResponses.all = await req3.get()
    const req4 = TestHelper.createRequest('/api/administrator/subscriptions/refunds')
    req4.account = administrator.account
    req4.session = administrator.session
    req4.filename = __filename
    req4.saveResponse = true
    cachedResponses.returns = await req4.get()
    global.pageSize = 3
    cachedResponses.pageSize = await req4.get()
    global.pageSize = 2
    cachedResponses.finished = true
  }
  describe('receives', () => {
    it('optional querystring offset (integer)', async function () {
      await bundledData(this.test.currentRetry())
      const offset = 1
      const refundsNow = cachedResponses.offset
      for (let i = 0, len = global.pageSize; i < len; i++) {
        assert.strictEqual(refundsNow[i].refundid, cachedRefunds[offset + i])
      }
    })

    it('optional querystring limit (integer)', async function () {
      await bundledData(this.test.currentRetry())
      const limit = 1
      const refundsNow = cachedResponses.limit
      assert.strictEqual(refundsNow.length, limit)
    })

    it('optional querystring all (boolean)', async () => {
      const refundsNow = cachedResponses.all
      assert.strictEqual(refundsNow.length, cachedRefunds.length)
    })
  })

  describe('returns', () => {
    it('array', async () => {
      const refundsNow = cachedResponses.returns
      assert.strictEqual(refundsNow.length, global.pageSize)
    })
  })

  describe('configuration', () => {
    it('environment PAGE_SIZE', async () => {
      const refundsNow = cachedResponses.pageSize
      assert.strictEqual(refundsNow.length, global.pageSize + 1)
    })
  })
})