Stripe Subscriptions module API explorer

/api/administrator/subscriptions/refund (GET)

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

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

Returns object

{
  "refundid": "re_3LEOO5HHqepMFuCX1sLqggDZ",
  "object": "refund",
  "stripeObject": {
    "id": "re_3LEOO5HHqepMFuCX1sLqggDZ",
    "object": "refund",
    "amount": 3000,
    "balance_transaction": "txn_3LEOO5HHqepMFuCX1fKlBtrF",
    "charge": "ch_3LEOO5HHqepMFuCX1Pmnfrju",
    "created": 1656122782,
    "currency": "usd",
    "metadata": {},
    "payment_intent": "pi_3LEOO5HHqepMFuCX1pdRhxE4",
    "reason": "requested_by_customer",
    "receipt_number": null,
    "source_transfer_reversal": null,
    "status": "succeeded",
    "transfer_reversal": null
  },
  "accountid": "acct_a36ee1fa09affad6",
  "subscriptionid": null,
  "customerid": null,
  "invoiceid": "in_1LEOO5HHqepMFuCXqtrsDn7P",
  "productid": null,
  "paymentmethodid": null,
  "appid": "tests_1656122772",
  "createdAt": "2022-06-25T02:06:22.830Z",
  "updatedAt": "2022-06-25T02:06:22.830Z"
}

Exceptions

These exceptions are thrown (NodeJS) or returned as JSON (HTTP) if you provide incorrect data or do not meet the requirements:

Exception Circumstances
undefined invalid querystring refundid
missing querystring refundid

NodeJS source (view on github)

const dashboard = require('@layeredapps/dashboard')
const subscriptions = require('../../../../../index.js')

module.exports = {
  get: async (req) => {
    if (!req.query || !req.query.refundid) {
      throw new Error('invalid-refundid')
    }
    let refund = await dashboard.StorageCache.get(req.query.refundid)
    if (!refund) {
      const refundInfo = await subscriptions.Storage.Refund.findOne({
        where: {
          refundid: req.query.refundid,
          appid: req.appid || global.appid
        }
      })
      if (!refundInfo) {
        throw new Error('invalid-refundid')
      }
      refund = {}
      for (const field of refundInfo._options.attributes) {
        refund[field] = refundInfo.get(field)
      }
      await dashboard.StorageCache.set(req.query.refundid, refund)
    }
    return refund
  }
}

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')

describe('/api/administrator/subscriptions/refund', function () {
  before(TestHelper.disableMetrics)
  after(TestHelper.enableMetrics)
  describe('exceptions', () => {
    it('invalid querystring refundid', async () => {
      const administrator = await TestHelper.createOwner()
      const req = TestHelper.createRequest('/api/administrator/subscriptions/refund')
      req.account = administrator.account
      req.session = administrator.session
      let errorMessage
      try {
        await req.get()
      } catch (error) {
        errorMessage = error.message
      }
      assert.strictEqual(errorMessage, 'invalid-refundid')
    })

    it('missing querystring refundid', async () => {
      const administrator = await TestHelper.createOwner()
      const req = TestHelper.createRequest('/api/administrator/subscriptions/refund?refundid=invalid')
      req.account = administrator.account
      req.session = administrator.session
      let errorMessage
      try {
        await req.get()
      } catch (error) {
        errorMessage = error.message
      }
      assert.strictEqual(errorMessage, 'invalid-refundid')
    })
  })

  describe('returns', () => {
    it('object', async () => {
      const administrator = await TestStripeAccounts.createOwnerWithPrice({
        active: 'true',
        unit_amount: 3000,
        currency: 'usd',
        tax_behavior: 'inclusive',
        recurring_interval: 'month',
        recurring_interval_count: '1',
        recurring_usage_type: 'licensed'
      })
      const user = await TestStripeAccounts.createUserWithPaidSubscription(administrator.price)
      await TestHelper.createRefund(administrator, user.charge.chargeid)
      const req = TestHelper.createRequest(`/api/administrator/subscriptions/refund?refundid=${administrator.refund.refundid}`)
      req.account = administrator.account
      req.session = administrator.session
      req.filename = __filename
      req.saveResponse = true
      const refund = await req.get()
      assert.strictEqual(refund.refundid, administrator.refund.refundid)
    })
  })
})