Stripe Subscriptions module API explorer

/api/administrator/subscriptions/refund-requests (GET)

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

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

Returns array

[
  {
    "chargeid": "ch_3LEONpHHqepMFuCX1Vl737WP",
    "accountid": "acct_08f141ba98b7ac20",
    "subscriptionid": "sub_1LEONpHHqepMFuCXQFOg1Fp8",
    "customerid": "cus_LwGvDRGVWGZgmG",
    "paymentmethodid": null,
    "invoiceid": "in_1LEONpHHqepMFuCXyh4PimEB",
    "refundRequested": "2022-06-25T02:06:05.478Z",
    "refundReason": "unused subscription",
    "refundDenied": null,
    "refundDeniedReason": null,
    "object": "charge",
    "stripeObject": {
      "id": "ch_3LEONpHHqepMFuCX1Vl737WP",
      "object": "charge",
      "amount": 1000,
      "amount_captured": 1000,
      "amount_refunded": 0,
      "application": null,
      "application_fee": null,
      "application_fee_amount": null,
      "balance_transaction": "txn_3LEONpHHqepMFuCX1z0oVfvN",
      "billing_details": {
        "address": {
          "city": "New York",
          "country": "US",
          "line1": "285 Fulton St",
          "line2": "Apt 893",
          "postal_code": "10007",
          "state": "NY"
        },
        "email": null,
        "name": "Fernando Olson",
        "phone": null
      },
      "calculated_statement_descriptor": "PRODUCT194 DESCRIPTION",
      "captured": true,
      "created": 1656122762,
      "currency": "usd",
      "customer": "cus_LwGvDRGVWGZgmG",
      "description": "Subscription creation",
      "destination": null,
      "dispute": null,
      "disputed": false,
      "failure_balance_transaction": null,
      "failure_code": null,
      "failure_message": null,
      "fraud_details": {},
      "invoice": "in_1LEONpHHqepMFuCXyh4PimEB",
      "livemode": false,
      "metadata": {},
      "on_behalf_of": null,
      "order": null,
      "outcome": {
        "network_status": "approved_by_network",
        "reason": null,
        "risk_level": "normal",
        "risk_score": 23,
        "seller_message": "Payment complete.",
        "type": "authorized"
      },
      "paid": true,
      "payment_intent": "pi_3LEONpHHqepMFuCX1LcbNarK",
      "payment_method": "pm_1LEONmHHqepMFuCXAcmxmp6x",
      "payment_method_details": {
        "card": {
          "brand": "visa",
          "checks": {
            "address_line1_check": "pass",
            "address_postal_code_check": "pass",
            "cvc_check": "pass"
          },
          "country": "US",
          "exp_month": 1,
          "exp_year": 2023,
          "fingerprint": "IRcdqfBUCskmPkNV",
          "funding": "credit",
          "installments": null,
          "last4": "1111",
          "mandate": null,
          "network": "visa",
          "three_d_secure": null,
          "wallet": null
        },
        "type": "card"
      },
      "receipt_email": null,
      "receipt_number": null,
      "receipt_url": "https://pay.stripe.com/receipts/invoices/CAcaFwoVYWNjdF8xS2hpUDhISHFlcE1GdUNYKIzb2ZUGMgacBAH5DdY6LBbXcKN7mKX-i-zpl-7xpGR9hPYZT8fPCD_Z_yoI1VkN31nXRO4JSldZpzOu?s=ap",
      "refunded": false,
      "refunds": {
        "object": "list",
        "data": [],
        "has_more": false,
        "total_count": 0,
        "url": "/v1/charges/ch_3LEONpHHqepMFuCX1Vl737WP/refunds"
      },
      "review": null,
      "shipping": null,
      "source": null,
      "source_transfer": null,
      "statement_descriptor": "product194 description",
      "statement_descriptor_suffix": null,
      "status": "succeeded",
      "transfer_data": null,
      "transfer_group": null
    },
    "appid": "tests_1656122727",
    "createdAt": "2022-06-25T02:06:04.664Z",
    "updatedAt": "2022-06-25T02:06:05.478Z"
  },
  {
    "chargeid": "ch_3LEONiHHqepMFuCX1O3349zf",
    "accountid": "acct_005852e7691d02f4",
    "subscriptionid": "sub_1LEONiHHqepMFuCXjuZJYQB7",
    "customerid": "cus_LwGveNc7HVNxnN",
    "paymentmethodid": null,
    "invoiceid": "in_1LEONiHHqepMFuCXoj6DxBqh",
    "refundRequested": "2022-06-25T02:05:57.780Z",
    "refundReason": "unused subscription",
    "refundDenied": null,
    "refundDeniedReason": null,
    "object": "charge",
    "stripeObject": {
      "id": "ch_3LEONiHHqepMFuCX1O3349zf",
      "object": "charge",
      "amount": 1000,
      "amount_captured": 1000,
      "amount_refunded": 0,
      "application": null,
      "application_fee": null,
      "application_fee_amount": null,
      "balance_transaction": "txn_3LEONiHHqepMFuCX18RT0pmj",
      "billing_details": {
        "address": {
          "city": "New York",
          "country": "US",
          "line1": "285 Fulton St",
          "line2": "Apt 893",
          "postal_code": "10007",
          "state": "NY"
        },
        "email": null,
        "name": "Theodore VonRueden",
        "phone": null
      },
      "calculated_statement_descriptor": "PRODUCT194 DESCRIPTION",
      "captured": true,
      "created": 1656122755,
      "currency": "usd",
      "customer": "cus_LwGveNc7HVNxnN",
      "description": "Subscription creation",
      "destination": null,
      "dispute": null,
      "disputed": false,
      "failure_balance_transaction": null,
      "failure_code": null,
      "failure_message": null,
      "fraud_details": {},
      "invoice": "in_1LEONiHHqepMFuCXoj6DxBqh",
      "livemode": false,
      "metadata": {},
      "on_behalf_of": null,
      "order": null,
      "outcome": {
        "network_status": "approved_by_network",
        "reason": null,
        "risk_level": "normal",
        "risk_score": 0,
        "seller_message": "Payment complete.",
        "type": "authorized"
      },
      "paid": true,
      "payment_intent": "pi_3LEONiHHqepMFuCX1CCHznkK",
      "payment_method": "pm_1LEONbHHqepMFuCXcxoqMnsT",
      "payment_method_details": {
        "card": {
          "brand": "visa",
          "checks": {
            "address_line1_check": "pass",
            "address_postal_code_check": "pass",
            "cvc_check": "pass"
          },
          "country": "US",
          "exp_month": 1,
          "exp_year": 2023,
          "fingerprint": "IRcdqfBUCskmPkNV",
          "funding": "credit",
          "installments": null,
          "last4": "1111",
          "mandate": null,
          "network": "visa",
          "three_d_secure": null,
          "wallet": null
        },
        "type": "card"
      },
      "receipt_email": null,
      "receipt_number": null,
      "receipt_url": "https://pay.stripe.com/receipts/invoices/CAcaFwoVYWNjdF8xS2hpUDhISHFlcE1GdUNYKITb2ZUGMgaRZRhvLMM6LBaEISKka3sIg7tI9q-kMGwjoQoF2b21-VZG5Zph8qDNifakzeFOx90M0c-d?s=ap",
      "refunded": false,
      "refunds": {
        "object": "list",
        "data": [],
        "has_more": false,
        "total_count": 0,
        "url": "/v1/charges/ch_3LEONiHHqepMFuCX1O3349zf/refunds"
      },
      "review": null,
      "shipping": null,
      "source": null,
      "source_transfer": null,
      "statement_descriptor": "product194 description",
      "statement_descriptor_suffix": null,
      "status": "succeeded",
      "transfer_data": null,
      "transfer_group": null
    },
    "appid": "tests_1656122727",
    "createdAt": "2022-06-25T02:05:57.242Z",
    "updatedAt": "2022-06-25T02:05:57.780Z"
  },
  {
    "chargeid": "ch_3LEONXHHqepMFuCX1qvC2aVD",
    "accountid": "acct_1e5f2a9be912492a",
    "subscriptionid": "sub_1LEONWHHqepMFuCXkJ7ChQ7b",
    "customerid": "cus_LwGvBklBImTyLg",
    "paymentmethodid": null,
    "invoiceid": "in_1LEONXHHqepMFuCXTC1m85xk",
    "refundRequested": "2022-06-25T02:05:47.031Z",
    "refundReason": "unused subscription",
    "refundDenied": null,
    "refundDeniedReason": null,
    "object": "charge",
    "stripeObject": {
      "id": "ch_3LEONXHHqepMFuCX1qvC2aVD",
      "object": "charge",
      "amount": 1000,
      "amount_captured": 1000,
      "amount_refunded": 0,
      "application": null,
      "application_fee": null,
      "application_fee_amount": null,
      "balance_transaction": "txn_3LEONXHHqepMFuCX1x3sf2fV",
      "billing_details": {
        "address": {
          "city": "New York",
          "country": "US",
          "line1": "285 Fulton St",
          "line2": "Apt 893",
          "postal_code": "10007",
          "state": "NY"
        },
        "email": null,
        "name": "Oliver Schulist",
        "phone": null
      },
      "calculated_statement_descriptor": "PRODUCT194 DESCRIPTION",
      "captured": true,
      "created": 1656122744,
      "currency": "usd",
      "customer": "cus_LwGvBklBImTyLg",
      "description": "Subscription creation",
      "destination": null,
      "dispute": null,
      "disputed": false,
      "failure_balance_transaction": null,
      "failure_code": null,
      "failure_message": null,
      "fraud_details": {},
      "invoice": "in_1LEONXHHqepMFuCXTC1m85xk",
      "livemode": false,
      "metadata": {},
      "on_behalf_of": null,
      "order": null,
      "outcome": {
        "network_status": "approved_by_network",
        "reason": null,
        "risk_level": "normal",
        "risk_score": 19,
        "seller_message": "Payment complete.",
        "type": "authorized"
      },
      "paid": true,
      "payment_intent": "pi_3LEONXHHqepMFuCX1onOqqr4",
      "payment_method": "pm_1LEONRHHqepMFuCXvm6YK6oC",
      "payment_method_details": {
        "card": {
          "brand": "visa",
          "checks": {
            "address_line1_check": "pass",
            "address_postal_code_check": "pass",
            "cvc_check": "pass"
          },
          "country": "US",
          "exp_month": 1,
          "exp_year": 2023,
          "fingerprint": "IRcdqfBUCskmPkNV",
          "funding": "credit",
          "installments": null,
          "last4": "1111",
          "mandate": null,
          "network": "visa",
          "three_d_secure": null,
          "wallet": null
        },
        "type": "card"
      },
      "receipt_email": null,
      "receipt_number": null,
      "receipt_url": "https://pay.stripe.com/receipts/invoices/CAcaFwoVYWNjdF8xS2hpUDhISHFlcE1GdUNYKPna2ZUGMgah8TCvAM06LBY-ASs6SsbqmB34LwtrYTTtfW6-3KcRomSY2pwSNOGbmaXReMEAdnC7hrXH?s=ap",
      "refunded": false,
      "refunds": {
        "object": "list",
        "data": [],
        "has_more": false,
        "total_count": 0,
        "url": "/v1/charges/ch_3LEONXHHqepMFuCX1qvC2aVD/refunds"
      },
      "review": null,
      "shipping": null,
      "source": null,
      "source_transfer": null,
      "statement_descriptor": "product194 description",
      "statement_descriptor_suffix": null,
      "status": "succeeded",
      "transfer_data": null,
      "transfer_group": null
    },
    "appid": "tests_1656122727",
    "createdAt": "2022-06-25T02:05:46.319Z",
    "updatedAt": "2022-06-25T02:05:47.031Z"
  }
]

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')
const sequelize = require('sequelize')

module.exports = {
  get: async (req) => {
    req.query = req.query || {}
    const minDate = new Date()
    minDate.setDate(minDate.getDate() + 1)
    const where = {
      refundRequested: {
        [sequelize.Op.lte]: minDate
      },
      appid: req.appid || global.appid
    }
    let chargeids
    if (req.query.all) {
      chargeids = await subscriptions.Storage.Charge.findAll({
        where,
        attributes: ['chargeid'],
        order: [
          ['refundRequested', '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
      chargeids = await subscriptions.Storage.Charge.findAll({
        where,
        attributes: ['chargeid'],
        offset,
        limit,
        order: [
          ['refundRequested', 'DESC']
        ]
      })
    }
    if (!chargeids || !chargeids.length) {
      return null
    }
    const items = []
    for (const chargeInfo of chargeids) {
      req.query.chargeid = chargeInfo.dataValues.chargeid
      const charge = await global.api.administrator.subscriptions.Charge.get(req)
      items.push(charge)
    }
    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/refund-requests', function () {
  before(TestHelper.disableMetrics)
  after(TestHelper.enableMetrics)
  let cachedResponses, cachedRefundRequests
  async function bundledData (retryNumber) {
    if (retryNumber > 0) {
      cachedResponses = {}
    }
    if (cachedResponses && cachedResponses.finished) {
      return
    }
    cachedResponses = {}
    cachedRefundRequests = []
    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.requestRefund(user, user.charge.chargeid)
      cachedRefundRequests.unshift(user.charge.chargeid)
    }
    const req1 = TestHelper.createRequest('/api/administrator/subscriptions/refund-requests?offset=1')
    req1.account = administrator.account
    req1.session = administrator.session
    cachedResponses.offset = await req1.get()
    const req2 = TestHelper.createRequest('/api/administrator/subscriptions/refund-requests?limit=1')
    req2.account = administrator.account
    req2.session = administrator.session
    cachedResponses.limit = await req2.get()
    const req3 = TestHelper.createRequest('/api/administrator/subscriptions/refund-requests?all=true')
    req3.account = administrator.account
    req3.session = administrator.session
    cachedResponses.all = await req3.get()
    const req4 = TestHelper.createRequest('/api/administrator/subscriptions/refund-requests')
    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 refundRequestsNow = cachedResponses.offset
      for (let i = 0, len = global.pageSize; i < len; i++) {
        assert.strictEqual(refundRequestsNow[i].chargeid, cachedRefundRequests[offset + i])
      }
    })

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

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

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

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