├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.md │ ├── config.yml │ ├── feature-request---new-table.md │ └── feature_request.md ├── PULL_REQUEST_TEMPLATE.md ├── dependabot.yml └── workflows │ ├── golangci-lint.yml │ ├── registry-publish.yml │ ├── stale.yml │ ├── steampipe-anywhere.yml │ └── sync-labels.yml ├── .gitignore ├── .goreleaser.yml ├── CHANGELOG.md ├── LICENSE ├── Makefile ├── README.md ├── config └── stripe.spc ├── docs ├── LICENSE ├── index.md └── tables │ ├── stripe_account.md │ ├── stripe_charge.md │ ├── stripe_coupon.md │ ├── stripe_customer.md │ ├── stripe_invoice.md │ ├── stripe_plan.md │ ├── stripe_product.md │ ├── stripe_subscription.md │ └── stripe_subscription_item.md ├── go.mod ├── go.sum ├── main.go └── stripe ├── common_columns.go ├── connection_config.go ├── error.go ├── plugin.go ├── table_stripe_account.go ├── table_stripe_charge.go ├── table_stripe_coupon.go ├── table_stripe_customer.go ├── table_stripe_invoice.go ├── table_stripe_plan.go ├── table_stripe_product.go ├── table_stripe_subscription.go ├── table_stripe_subscription_item.go └── utils.go /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: bug 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **Steampipe version (`steampipe -v`)** 14 | Example: v0.3.0 15 | 16 | **Plugin version (`steampipe plugin list`)** 17 | Example: v0.5.0 18 | 19 | **To reproduce** 20 | Steps to reproduce the behavior (please include relevant code and/or commands). 21 | 22 | **Expected behavior** 23 | A clear and concise description of what you expected to happen. 24 | 25 | **Additional context** 26 | Add any other context about the problem here. 27 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | blank_issues_enabled: false 2 | contact_links: 3 | - name: Questions 4 | url: https://turbot.com/community/join 5 | about: GitHub issues in this repository are only intended for bug reports and feature requests. Other issues will be closed. Please ask and answer questions through the Steampipe Slack community. 6 | - name: Steampipe CLI Bug Reports and Feature Requests 7 | url: https://github.com/turbot/steampipe/issues/new/choose 8 | about: Steampipe CLI has its own codebase. Bug reports and feature requests for those pieces of functionality should be directed to that repository. -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature-request---new-table.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request - New table 3 | about: Suggest a new table for this project 4 | title: Add table stripe_ 5 | labels: enhancement, new table 6 | assignees: "" 7 | --- 8 | 9 | **References** 10 | Add any related links that will help us understand the resource, including vendor documentation, related GitHub issues, and Go SDK documentation. 11 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: enhancement 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | # Example query results 2 |
3 | Results 4 | 5 | ``` 6 | Add example SQL query results here (please include the input queries as well) 7 | ``` 8 |
9 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # To get started with Dependabot version updates, you'll need to specify which 2 | # package ecosystems to update and where the package manifests are located. 3 | # Please see the documentation for all configuration options: 4 | # https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates 5 | 6 | version: 2 7 | updates: 8 | - package-ecosystem: "gomod" # See documentation for possible values 9 | directory: "/" # Location of package manifests 10 | schedule: 11 | interval: "weekly" 12 | pull-request-branch-name: 13 | separator: "-" 14 | assignees: 15 | - "misraved" 16 | - "madhushreeray30" 17 | labels: 18 | - "dependencies" 19 | -------------------------------------------------------------------------------- /.github/workflows/golangci-lint.yml: -------------------------------------------------------------------------------- 1 | name: golangci-lint 2 | on: 3 | push: 4 | tags: 5 | - v* 6 | branches: 7 | - main 8 | pull_request: 9 | 10 | jobs: 11 | golangci_lint_workflow: 12 | uses: turbot/steampipe-workflows/.github/workflows/golangci-lint.yml@main 13 | -------------------------------------------------------------------------------- /.github/workflows/registry-publish.yml: -------------------------------------------------------------------------------- 1 | name: Build and Deploy OCI Image 2 | 3 | on: 4 | push: 5 | tags: 6 | - 'v*' 7 | 8 | jobs: 9 | registry_publish_workflow_ghcr: 10 | uses: turbot/steampipe-workflows/.github/workflows/registry-publish-ghcr.yml@main 11 | secrets: inherit 12 | with: 13 | releaseTimeout: 60m 14 | -------------------------------------------------------------------------------- /.github/workflows/stale.yml: -------------------------------------------------------------------------------- 1 | name: Stale Issues and PRs 2 | on: 3 | schedule: 4 | - cron: "30 23 * * *" 5 | workflow_dispatch: 6 | inputs: 7 | dryRun: 8 | description: Set to true for a dry run 9 | required: false 10 | default: "false" 11 | type: string 12 | 13 | jobs: 14 | stale_workflow: 15 | uses: turbot/steampipe-workflows/.github/workflows/stale.yml@main 16 | with: 17 | dryRun: ${{ github.event.inputs.dryRun }} 18 | -------------------------------------------------------------------------------- /.github/workflows/steampipe-anywhere.yml: -------------------------------------------------------------------------------- 1 | name: Release Steampipe Anywhere Components 2 | 3 | on: 4 | push: 5 | tags: 6 | - 'v*' 7 | 8 | 9 | jobs: 10 | anywhere_publish_workflow: 11 | uses: turbot/steampipe-workflows/.github/workflows/steampipe-anywhere.yml@main 12 | secrets: inherit 13 | -------------------------------------------------------------------------------- /.github/workflows/sync-labels.yml: -------------------------------------------------------------------------------- 1 | name: Sync Labels 2 | on: 3 | schedule: 4 | - cron: "30 22 * * 1" 5 | workflow_dispatch: 6 | 7 | jobs: 8 | sync_labels_workflow: 9 | uses: turbot/steampipe-workflows/.github/workflows/sync-labels.yml@main 10 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Editor cache and lock files 2 | *.swp 3 | *.swo 4 | 5 | # Binaries for programs and plugins 6 | *.exe 7 | *.exe~ 8 | *.dll 9 | *.so 10 | *.dylib 11 | 12 | # Test binary, built with `go test -c` 13 | *.test 14 | 15 | # Output of the go coverage tool, specifically when used with LiteIDE 16 | *.out 17 | 18 | # Dependency directories (remove the comment below to include it) 19 | # vendor/ 20 | -------------------------------------------------------------------------------- /.goreleaser.yml: -------------------------------------------------------------------------------- 1 | # This is an example goreleaser.yaml file with some sane defaults. 2 | # Make sure to check the documentation at http://goreleaser.com 3 | before: 4 | hooks: 5 | - go mod tidy 6 | builds: 7 | - env: 8 | - CGO_ENABLED=0 9 | - GO111MODULE=on 10 | - GOPRIVATE=github.com/turbot 11 | goos: 12 | - linux 13 | - darwin 14 | 15 | goarch: 16 | - amd64 17 | - arm64 18 | 19 | id: "steampipe" 20 | binary: "{{ .ProjectName }}.plugin" 21 | flags: 22 | - -tags=netgo 23 | 24 | archives: 25 | - format: gz 26 | name_template: "{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}" 27 | files: 28 | - none* 29 | checksum: 30 | name_template: "{{ .ProjectName }}_{{ .Version }}_SHA256SUMS" 31 | algorithm: sha256 32 | changelog: 33 | sort: asc 34 | filters: 35 | exclude: 36 | - "^docs:" 37 | - "^test:" 38 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## v1.1.0 [2025-04-17] 2 | 3 | _What's new?_ 4 | 5 | - New tables added 6 | - [stripe_charge](https://hub.steampipe.io/plugins/turbot/stripe/tables/stripe_charge) 7 | - [stripe_subscription_item](https://hub.steampipe.io/plugins/turbot/stripe/tables/stripe_subscription_item) 8 | 9 | _Dependencies_ 10 | 11 | - Recompiled plugin with Go version `1.23.1`. ([#47](https://github.com/turbot/steampipe-plugin-stripe/pull/47)) 12 | - Recompiled plugin with [steampipe-plugin-sdk v5.11.5](https://github.com/turbot/steampipe-plugin-sdk/blob/v5.11.5/CHANGELOG.md#v5115-2025-03-31) that addresses critical and high vulnerabilities in dependent packages. ([#47](https://github.com/turbot/steampipe-plugin-stripe/pull/47)) 13 | 14 | ## v1.0.0 [2024-10-22] 15 | 16 | There are no significant changes in this plugin version; it has been released to align with [Steampipe's v1.0.0](https://steampipe.io/changelog/steampipe-cli-v1-0-0) release. This plugin adheres to [semantic versioning](https://semver.org/#semantic-versioning-specification-semver), ensuring backward compatibility within each major version. 17 | 18 | _Dependencies_ 19 | 20 | - Recompiled plugin with Go version `1.22`. ([#44](https://github.com/turbot/steampipe-plugin-stripe/pull/44)) 21 | - Recompiled plugin with [steampipe-plugin-sdk v5.10.4](https://github.com/turbot/steampipe-plugin-sdk/blob/develop/CHANGELOG.md#v5104-2024-08-29) that fixes logging in the plugin export tool. ([#44](https://github.com/turbot/steampipe-plugin-stripe/pull/44)) 22 | 23 | ## v0.6.0 [2023-12-12] 24 | 25 | _What's new?_ 26 | 27 | - The plugin can now be downloaded and used with the [Steampipe CLI](https://steampipe.io/docs), as a [Postgres FDW](https://steampipe.io/docs/steampipe_postgres/overview), as a [SQLite extension](https://steampipe.io/docs//steampipe_sqlite/overview) and as a standalone [exporter](https://steampipe.io/docs/steampipe_export/overview). ([#36](https://github.com/turbot/steampipe-plugin-stripe/pull/36)) 28 | - The table docs have been updated to provide corresponding example queries for Postgres FDW and SQLite extension. ([#36](https://github.com/turbot/steampipe-plugin-stripe/pull/36)) 29 | - Docs license updated to match Steampipe [CC BY-NC-ND license](https://github.com/turbot/steampipe-plugin-stripe/blob/main/docs/LICENSE). ([#36](https://github.com/turbot/steampipe-plugin-stripe/pull/36)) 30 | 31 | _Dependencies_ 32 | 33 | - Recompiled plugin with [steampipe-plugin-sdk v5.8.0](https://github.com/turbot/steampipe-plugin-sdk/blob/main/CHANGELOG.md#v580-2023-12-11) that includes plugin server encapsulation for in-process and GRPC usage, adding Steampipe Plugin SDK version to `_ctx` column, and fixing connection and potential divide-by-zero bugs. ([#35](https://github.com/turbot/steampipe-plugin-stripe/pull/35)) 34 | 35 | ## v0.5.1 [2023-10-05] 36 | 37 | _Dependencies_ 38 | 39 | - Recompiled plugin with [steampipe-plugin-sdk v5.6.2](https://github.com/turbot/steampipe-plugin-sdk/blob/main/CHANGELOG.md#v562-2023-10-03) which prevents nil pointer reference errors for implicit hydrate configs. ([#27](https://github.com/turbot/steampipe-plugin-stripe/pull/27)) 40 | 41 | ## v0.5.0 [2023-10-02] 42 | 43 | _Dependencies_ 44 | 45 | - Upgraded to [steampipe-plugin-sdk v5.6.1](https://github.com/turbot/steampipe-plugin-sdk/blob/main/CHANGELOG.md#v561-2023-09-29) with support for rate limiters. ([#25](https://github.com/turbot/steampipe-plugin-stripe/pull/25)) 46 | - Recompiled plugin with Go version `1.21`. ([#25](https://github.com/turbot/steampipe-plugin-stripe/pull/25)) 47 | 48 | ## v0.4.0 [2023-04-06] 49 | 50 | _Dependencies_ 51 | 52 | - Recompiled plugin with [steampipe-plugin-sdk v5.3.0](https://github.com/turbot/steampipe-plugin-sdk/blob/main/CHANGELOG.md#v530-2023-03-16) which includes fixes for query cache pending item mechanism and aggregator connections not working for dynamic tables. ([#21](https://github.com/turbot/steampipe-plugin-stripe/pull/21)) 53 | 54 | ## v0.3.1 [2022-10-03] 55 | 56 | _Bug fixes_ 57 | 58 | - Fixed `account_balance` -> `balance` column names in `stripe_customer` table document examples. ([#19](https://github.com/turbot/steampipe-plugin-stripe/pull/19)) (Thanks to [@fabpot](https://github.com/fabpot) for the fixes!) 59 | 60 | ## v0.3.0 [2022-09-28] 61 | 62 | _Dependencies_ 63 | 64 | - Recompiled plugin with [steampipe-plugin-sdk v4.1.7](https://github.com/turbot/steampipe-plugin-sdk/blob/main/CHANGELOG.md#v417-2022-09-08) which includes several caching and memory management improvements. ([#17](https://github.com/turbot/steampipe-plugin-stripe/pull/17)) 65 | - Recompiled plugin with Go version `1.19`. ([#16](https://github.com/turbot/steampipe-plugin-stripe/pull/16)) 66 | 67 | ## v0.2.1 [2022-05-23] 68 | 69 | _Bug fixes_ 70 | 71 | - Fixed the Slack community links in README and docs/index.md files. ([#12](https://github.com/turbot/steampipe-plugin-stripe/pull/12)) 72 | 73 | ## v0.2.0 [2022-04-28] 74 | 75 | _Enhancements_ 76 | 77 | - Added support for native Linux ARM and Mac M1 builds. ([#10](https://github.com/turbot/steampipe-plugin-stripe/pull/10)) 78 | - Recompiled plugin with [steampipe-plugin-sdk v3.1.0](https://github.com/turbot/steampipe-plugin-sdk/blob/main/CHANGELOG.md#v310--2022-03-30) and Go version `1.18`. ([#9](https://github.com/turbot/steampipe-plugin-stripe/pull/9)) 79 | 80 | ## v0.1.0 [2021-11-23] 81 | 82 | _Enhancements_ 83 | 84 | - Recompiled plugin with [steampipe-plugin-sdk v1.8.2](https://github.com/turbot/steampipe-plugin-sdk/blob/main/CHANGELOG.md#v182--2021-11-22) and Go version 1.17 ([#5](https://github.com/turbot/steampipe-plugin-stripe/pull/5)) 85 | 86 | ## v0.0.2 [2021-09-22] 87 | 88 | _Enhancements_ 89 | 90 | - Recompiled plugin with [steampipe-plugin-sdk v1.6.1](https://github.com/turbot/steampipe-plugin-sdk/blob/main/CHANGELOG.md#v161--2021-09-21) ([#2](https://github.com/turbot/steampipe-plugin-stripe/pull/2)) 91 | 92 | ## v0.0.1 [2021-07-12] 93 | 94 | _What's new?_ 95 | 96 | - New tables added 97 | - [stripe_account](https://hub.steampipe.io/plugins/turbot/stripe/tables/stripe_account) 98 | - [stripe_coupon](https://hub.steampipe.io/plugins/turbot/stripe/tables/stripe_coupon) 99 | - [stripe_customer](https://hub.steampipe.io/plugins/turbot/stripe/tables/stripe_customer) 100 | - [stripe_invoice](https://hub.steampipe.io/plugins/turbot/stripe/tables/stripe_invoice) 101 | - [stripe_plan](https://hub.steampipe.io/plugins/turbot/stripe/tables/stripe_plan) 102 | - [stripe_product](https://hub.steampipe.io/plugins/turbot/stripe/tables/stripe_product) 103 | - [stripe_subscription](https://hub.steampipe.io/plugins/turbot/stripe/tables/stripe_subscription) 104 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | STEAMPIPE_INSTALL_DIR ?= ~/.steampipe 2 | BUILD_TAGS = netgo 3 | install: 4 | go build -o $(STEAMPIPE_INSTALL_DIR)/plugins/hub.steampipe.io/plugins/turbot/stripe@latest/steampipe-plugin-stripe.plugin -tags "${BUILD_TAGS}" *.go 5 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![image](https://hub.steampipe.io/images/plugins/turbot/stripe-social-graphic.png) 2 | 3 | # Stripe Plugin for Steampipe 4 | 5 | Use SQL to query customers, products, invoices, subscriptions and more from Stripe. 6 | 7 | - **[Get started →](https://hub.steampipe.io/plugins/turbot/stripe)** 8 | - Documentation: [Table definitions & examples](https://hub.steampipe.io/plugins/turbot/stripe/tables) 9 | - Community: [Join #steampipe on Slack →](https://turbot.com/community/join) 10 | - Get involved: [Issues](https://github.com/turbot/steampipe-plugin-stripe/issues) 11 | 12 | ## Quick start 13 | 14 | Install the plugin with [Steampipe](https://steampipe.io): 15 | 16 | ```shell 17 | steampipe plugin install stripe 18 | ``` 19 | 20 | Run a query: 21 | 22 | ```sql 23 | select id, name, description from stripe_product; 24 | ``` 25 | 26 | ## Engines 27 | 28 | This plugin is available for the following engines: 29 | 30 | | Engine | Description 31 | |---------------|------------------------------------------ 32 | | [Steampipe](https://steampipe.io/docs) | The Steampipe CLI exposes APIs and services as a high-performance relational database, giving you the ability to write SQL-based queries to explore dynamic data. Mods extend Steampipe's capabilities with dashboards, reports, and controls built with simple HCL. The Steampipe CLI is a turnkey solution that includes its own Postgres database, plugin management, and mod support. 33 | | [Postgres FDW](https://steampipe.io/docs/steampipe_postgres/overview) | Steampipe Postgres FDWs are native Postgres Foreign Data Wrappers that translate APIs to foreign tables. Unlike Steampipe CLI, which ships with its own Postgres server instance, the Steampipe Postgres FDWs can be installed in any supported Postgres database version. 34 | | [SQLite Extension](https://steampipe.io/docs//steampipe_sqlite/overview) | Steampipe SQLite Extensions provide SQLite virtual tables that translate your queries into API calls, transparently fetching information from your API or service as you request it. 35 | | [Export](https://steampipe.io/docs/steampipe_export/overview) | Steampipe Plugin Exporters provide a flexible mechanism for exporting information from cloud services and APIs. Each exporter is a stand-alone binary that allows you to extract data using Steampipe plugins without a database. 36 | | [Turbot Pipes](https://turbot.com/pipes/docs) | Turbot Pipes is the only intelligence, automation & security platform built specifically for DevOps. Pipes provide hosted Steampipe database instances, shared dashboards, snapshots, and more. 37 | 38 | ## Developing 39 | 40 | Prerequisites: 41 | 42 | - [Steampipe](https://steampipe.io/downloads) 43 | - [Golang](https://golang.org/doc/install) 44 | 45 | Clone: 46 | 47 | ```sh 48 | git clone https://github.com/turbot/steampipe-plugin-stripe.git 49 | cd steampipe-plugin-stripe 50 | ``` 51 | 52 | Build, which automatically installs the new version to your `~/.steampipe/plugins` directory: 53 | 54 | ``` 55 | make 56 | ``` 57 | 58 | Configure the plugin: 59 | 60 | ``` 61 | cp config/* ~/.steampipe/config 62 | vi ~/.steampipe/config/stripe.spc 63 | ``` 64 | 65 | Try it! 66 | 67 | ``` 68 | steampipe query 69 | > .inspect stripe 70 | ``` 71 | 72 | Further reading: 73 | 74 | - [Writing plugins](https://steampipe.io/docs/develop/writing-plugins) 75 | - [Writing your first table](https://steampipe.io/docs/develop/writing-your-first-table) 76 | 77 | ## Open Source & Contributing 78 | 79 | This repository is published under the [Apache 2.0](https://www.apache.org/licenses/LICENSE-2.0) (source code) and [CC BY-NC-ND](https://creativecommons.org/licenses/by-nc-nd/2.0/) (docs) licenses. Please see our [code of conduct](https://github.com/turbot/.github/blob/main/CODE_OF_CONDUCT.md). We look forward to collaborating with you! 80 | 81 | [Steampipe](https://steampipe.io) is a product produced from this open source software, exclusively by [Turbot HQ, Inc](https://turbot.com). It is distributed under our commercial terms. Others are allowed to make their own distribution of the software, but cannot use any of the Turbot trademarks, cloud services, etc. You can learn more in our [Open Source FAQ](https://turbot.com/open-source). 82 | 83 | ## Get Involved 84 | 85 | **[Join #steampipe on Slack →](https://turbot.com/community/join)** 86 | 87 | Want to help but don't know where to start? Pick up one of the `help wanted` issues: 88 | 89 | - [Steampipe](https://github.com/turbot/steampipe/labels/help%20wanted) 90 | - [Stripe Plugin](https://github.com/turbot/steampipe-plugin-stripe/labels/help%20wanted) 91 | -------------------------------------------------------------------------------- /config/stripe.spc: -------------------------------------------------------------------------------- 1 | connection "stripe" { 2 | plugin = "stripe" 3 | 4 | # Docs to your Stripe secret API key are at https://stripe.com/docs/keys 5 | # api_key = "sk_test_giG4MlyrcybGi1YFDEXAMPLE" 6 | } 7 | -------------------------------------------------------------------------------- /docs/LICENSE: -------------------------------------------------------------------------------- 1 | Attribution-NonCommercial-NoDerivatives 4.0 International 2 | 3 | ======================================================================= 4 | 5 | Creative Commons Corporation ("Creative Commons") is not a law firm and 6 | does not provide legal services or legal advice. Distribution of 7 | Creative Commons public licenses does not create a lawyer-client or 8 | other relationship. Creative Commons makes its licenses and related 9 | information available on an "as-is" basis. Creative Commons gives no 10 | warranties regarding its licenses, any material licensed under their 11 | terms and conditions, or any related information. Creative Commons 12 | disclaims all liability for damages resulting from their use to the 13 | fullest extent possible. 14 | 15 | Using Creative Commons Public Licenses 16 | 17 | Creative Commons public licenses provide a standard set of terms and 18 | conditions that creators and other rights holders may use to share 19 | original works of authorship and other material subject to copyright 20 | and certain other rights specified in the public license below. The 21 | following considerations are for informational purposes only, are not 22 | exhaustive, and do not form part of our licenses. 23 | 24 | Considerations for licensors: Our public licenses are 25 | intended for use by those authorized to give the public 26 | permission to use material in ways otherwise restricted by 27 | copyright and certain other rights. Our licenses are 28 | irrevocable. Licensors should read and understand the terms 29 | and conditions of the license they choose before applying it. 30 | Licensors should also secure all rights necessary before 31 | applying our licenses so that the public can reuse the 32 | material as expected. Licensors should clearly mark any 33 | material not subject to the license. This includes other CC- 34 | licensed material, or material used under an exception or 35 | limitation to copyright. More considerations for licensors: 36 | wiki.creativecommons.org/Considerations_for_licensors 37 | 38 | Considerations for the public: By using one of our public 39 | licenses, a licensor grants the public permission to use the 40 | licensed material under specified terms and conditions. If 41 | the licensor's permission is not necessary for any reason--for 42 | example, because of any applicable exception or limitation to 43 | copyright--then that use is not regulated by the license. Our 44 | licenses grant only permissions under copyright and certain 45 | other rights that a licensor has authority to grant. Use of 46 | the licensed material may still be restricted for other 47 | reasons, including because others have copyright or other 48 | rights in the material. A licensor may make special requests, 49 | such as asking that all changes be marked or described. 50 | Although not required by our licenses, you are encouraged to 51 | respect those requests where reasonable. More considerations 52 | for the public: 53 | wiki.creativecommons.org/Considerations_for_licensees 54 | 55 | ======================================================================= 56 | 57 | Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 58 | International Public License 59 | 60 | By exercising the Licensed Rights (defined below), You accept and agree 61 | to be bound by the terms and conditions of this Creative Commons 62 | Attribution-NonCommercial-NoDerivatives 4.0 International Public 63 | License ("Public License"). To the extent this Public License may be 64 | interpreted as a contract, You are granted the Licensed Rights in 65 | consideration of Your acceptance of these terms and conditions, and the 66 | Licensor grants You such rights in consideration of benefits the 67 | Licensor receives from making the Licensed Material available under 68 | these terms and conditions. 69 | 70 | 71 | Section 1 -- Definitions. 72 | 73 | a. Adapted Material means material subject to Copyright and Similar 74 | Rights that is derived from or based upon the Licensed Material 75 | and in which the Licensed Material is translated, altered, 76 | arranged, transformed, or otherwise modified in a manner requiring 77 | permission under the Copyright and Similar Rights held by the 78 | Licensor. For purposes of this Public License, where the Licensed 79 | Material is a musical work, performance, or sound recording, 80 | Adapted Material is always produced where the Licensed Material is 81 | synched in timed relation with a moving image. 82 | 83 | b. Copyright and Similar Rights means copyright and/or similar rights 84 | closely related to copyright including, without limitation, 85 | performance, broadcast, sound recording, and Sui Generis Database 86 | Rights, without regard to how the rights are labeled or 87 | categorized. For purposes of this Public License, the rights 88 | specified in Section 2(b)(1)-(2) are not Copyright and Similar 89 | Rights. 90 | 91 | c. Effective Technological Measures means those measures that, in the 92 | absence of proper authority, may not be circumvented under laws 93 | fulfilling obligations under Article 11 of the WIPO Copyright 94 | Treaty adopted on December 20, 1996, and/or similar international 95 | agreements. 96 | 97 | d. Exceptions and Limitations means fair use, fair dealing, and/or 98 | any other exception or limitation to Copyright and Similar Rights 99 | that applies to Your use of the Licensed Material. 100 | 101 | e. Licensed Material means the artistic or literary work, database, 102 | or other material to which the Licensor applied this Public 103 | License. 104 | 105 | f. Licensed Rights means the rights granted to You subject to the 106 | terms and conditions of this Public License, which are limited to 107 | all Copyright and Similar Rights that apply to Your use of the 108 | Licensed Material and that the Licensor has authority to license. 109 | 110 | g. Licensor means the individual(s) or entity(ies) granting rights 111 | under this Public License. 112 | 113 | h. NonCommercial means not primarily intended for or directed towards 114 | commercial advantage or monetary compensation. For purposes of 115 | this Public License, the exchange of the Licensed Material for 116 | other material subject to Copyright and Similar Rights by digital 117 | file-sharing or similar means is NonCommercial provided there is 118 | no payment of monetary compensation in connection with the 119 | exchange. 120 | 121 | i. Share means to provide material to the public by any means or 122 | process that requires permission under the Licensed Rights, such 123 | as reproduction, public display, public performance, distribution, 124 | dissemination, communication, or importation, and to make material 125 | available to the public including in ways that members of the 126 | public may access the material from a place and at a time 127 | individually chosen by them. 128 | 129 | j. Sui Generis Database Rights means rights other than copyright 130 | resulting from Directive 96/9/EC of the European Parliament and of 131 | the Council of 11 March 1996 on the legal protection of databases, 132 | as amended and/or succeeded, as well as other essentially 133 | equivalent rights anywhere in the world. 134 | 135 | k. You means the individual or entity exercising the Licensed Rights 136 | under this Public License. Your has a corresponding meaning. 137 | 138 | 139 | Section 2 -- Scope. 140 | 141 | a. License grant. 142 | 143 | 1. Subject to the terms and conditions of this Public License, 144 | the Licensor hereby grants You a worldwide, royalty-free, 145 | non-sublicensable, non-exclusive, irrevocable license to 146 | exercise the Licensed Rights in the Licensed Material to: 147 | 148 | a. reproduce and Share the Licensed Material, in whole or 149 | in part, for NonCommercial purposes only; and 150 | 151 | b. produce and reproduce, but not Share, Adapted Material 152 | for NonCommercial purposes only. 153 | 154 | 2. Exceptions and Limitations. For the avoidance of doubt, where 155 | Exceptions and Limitations apply to Your use, this Public 156 | License does not apply, and You do not need to comply with 157 | its terms and conditions. 158 | 159 | 3. Term. The term of this Public License is specified in Section 160 | 6(a). 161 | 162 | 4. Media and formats; technical modifications allowed. The 163 | Licensor authorizes You to exercise the Licensed Rights in 164 | all media and formats whether now known or hereafter created, 165 | and to make technical modifications necessary to do so. The 166 | Licensor waives and/or agrees not to assert any right or 167 | authority to forbid You from making technical modifications 168 | necessary to exercise the Licensed Rights, including 169 | technical modifications necessary to circumvent Effective 170 | Technological Measures. For purposes of this Public License, 171 | simply making modifications authorized by this Section 2(a) 172 | (4) never produces Adapted Material. 173 | 174 | 5. Downstream recipients. 175 | 176 | a. Offer from the Licensor -- Licensed Material. Every 177 | recipient of the Licensed Material automatically 178 | receives an offer from the Licensor to exercise the 179 | Licensed Rights under the terms and conditions of this 180 | Public License. 181 | 182 | b. No downstream restrictions. You may not offer or impose 183 | any additional or different terms or conditions on, or 184 | apply any Effective Technological Measures to, the 185 | Licensed Material if doing so restricts exercise of the 186 | Licensed Rights by any recipient of the Licensed 187 | Material. 188 | 189 | 6. No endorsement. Nothing in this Public License constitutes or 190 | may be construed as permission to assert or imply that You 191 | are, or that Your use of the Licensed Material is, connected 192 | with, or sponsored, endorsed, or granted official status by, 193 | the Licensor or others designated to receive attribution as 194 | provided in Section 3(a)(1)(A)(i). 195 | 196 | b. Other rights. 197 | 198 | 1. Moral rights, such as the right of integrity, are not 199 | licensed under this Public License, nor are publicity, 200 | privacy, and/or other similar personality rights; however, to 201 | the extent possible, the Licensor waives and/or agrees not to 202 | assert any such rights held by the Licensor to the limited 203 | extent necessary to allow You to exercise the Licensed 204 | Rights, but not otherwise. 205 | 206 | 2. Patent and trademark rights are not licensed under this 207 | Public License. 208 | 209 | 3. To the extent possible, the Licensor waives any right to 210 | collect royalties from You for the exercise of the Licensed 211 | Rights, whether directly or through a collecting society 212 | under any voluntary or waivable statutory or compulsory 213 | licensing scheme. In all other cases the Licensor expressly 214 | reserves any right to collect such royalties, including when 215 | the Licensed Material is used other than for NonCommercial 216 | purposes. 217 | 218 | 219 | Section 3 -- License Conditions. 220 | 221 | Your exercise of the Licensed Rights is expressly made subject to the 222 | following conditions. 223 | 224 | a. Attribution. 225 | 226 | 1. If You Share the Licensed Material, You must: 227 | 228 | a. retain the following if it is supplied by the Licensor 229 | with the Licensed Material: 230 | 231 | i. identification of the creator(s) of the Licensed 232 | Material and any others designated to receive 233 | attribution, in any reasonable manner requested by 234 | the Licensor (including by pseudonym if 235 | designated); 236 | 237 | ii. a copyright notice; 238 | 239 | iii. a notice that refers to this Public License; 240 | 241 | iv. a notice that refers to the disclaimer of 242 | warranties; 243 | 244 | v. a URI or hyperlink to the Licensed Material to the 245 | extent reasonably practicable; 246 | 247 | b. indicate if You modified the Licensed Material and 248 | retain an indication of any previous modifications; and 249 | 250 | c. indicate the Licensed Material is licensed under this 251 | Public License, and include the text of, or the URI or 252 | hyperlink to, this Public License. 253 | 254 | For the avoidance of doubt, You do not have permission under 255 | this Public License to Share Adapted Material. 256 | 257 | 2. You may satisfy the conditions in Section 3(a)(1) in any 258 | reasonable manner based on the medium, means, and context in 259 | which You Share the Licensed Material. For example, it may be 260 | reasonable to satisfy the conditions by providing a URI or 261 | hyperlink to a resource that includes the required 262 | information. 263 | 264 | 3. If requested by the Licensor, You must remove any of the 265 | information required by Section 3(a)(1)(A) to the extent 266 | reasonably practicable. 267 | 268 | 269 | Section 4 -- Sui Generis Database Rights. 270 | 271 | Where the Licensed Rights include Sui Generis Database Rights that 272 | apply to Your use of the Licensed Material: 273 | 274 | a. for the avoidance of doubt, Section 2(a)(1) grants You the right 275 | to extract, reuse, reproduce, and Share all or a substantial 276 | portion of the contents of the database for NonCommercial purposes 277 | only and provided You do not Share Adapted Material; 278 | 279 | b. if You include all or a substantial portion of the database 280 | contents in a database in which You have Sui Generis Database 281 | Rights, then the database in which You have Sui Generis Database 282 | Rights (but not its individual contents) is Adapted Material; and 283 | 284 | c. You must comply with the conditions in Section 3(a) if You Share 285 | all or a substantial portion of the contents of the database. 286 | 287 | For the avoidance of doubt, this Section 4 supplements and does not 288 | replace Your obligations under this Public License where the Licensed 289 | Rights include other Copyright and Similar Rights. 290 | 291 | 292 | Section 5 -- Disclaimer of Warranties and Limitation of Liability. 293 | 294 | a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE 295 | EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS 296 | AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF 297 | ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS, 298 | IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION, 299 | WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR 300 | PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS, 301 | ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT 302 | KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT 303 | ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU. 304 | 305 | b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE 306 | TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION, 307 | NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT, 308 | INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES, 309 | COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR 310 | USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN 311 | ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR 312 | DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR 313 | IN PART, THIS LIMITATION MAY NOT APPLY TO YOU. 314 | 315 | c. The disclaimer of warranties and limitation of liability provided 316 | above shall be interpreted in a manner that, to the extent 317 | possible, most closely approximates an absolute disclaimer and 318 | waiver of all liability. 319 | 320 | 321 | Section 6 -- Term and Termination. 322 | 323 | a. This Public License applies for the term of the Copyright and 324 | Similar Rights licensed here. However, if You fail to comply with 325 | this Public License, then Your rights under this Public License 326 | terminate automatically. 327 | 328 | b. Where Your right to use the Licensed Material has terminated under 329 | Section 6(a), it reinstates: 330 | 331 | 1. automatically as of the date the violation is cured, provided 332 | it is cured within 30 days of Your discovery of the 333 | violation; or 334 | 335 | 2. upon express reinstatement by the Licensor. 336 | 337 | For the avoidance of doubt, this Section 6(b) does not affect any 338 | right the Licensor may have to seek remedies for Your violations 339 | of this Public License. 340 | 341 | c. For the avoidance of doubt, the Licensor may also offer the 342 | Licensed Material under separate terms or conditions or stop 343 | distributing the Licensed Material at any time; however, doing so 344 | will not terminate this Public License. 345 | 346 | d. Sections 1, 5, 6, 7, and 8 survive termination of this Public 347 | License. 348 | 349 | 350 | Section 7 -- Other Terms and Conditions. 351 | 352 | a. The Licensor shall not be bound by any additional or different 353 | terms or conditions communicated by You unless expressly agreed. 354 | 355 | b. Any arrangements, understandings, or agreements regarding the 356 | Licensed Material not stated herein are separate from and 357 | independent of the terms and conditions of this Public License. 358 | 359 | 360 | Section 8 -- Interpretation. 361 | 362 | a. For the avoidance of doubt, this Public License does not, and 363 | shall not be interpreted to, reduce, limit, restrict, or impose 364 | conditions on any use of the Licensed Material that could lawfully 365 | be made without permission under this Public License. 366 | 367 | b. To the extent possible, if any provision of this Public License is 368 | deemed unenforceable, it shall be automatically reformed to the 369 | minimum extent necessary to make it enforceable. If the provision 370 | cannot be reformed, it shall be severed from this Public License 371 | without affecting the enforceability of the remaining terms and 372 | conditions. 373 | 374 | c. No term or condition of this Public License will be waived and no 375 | failure to comply consented to unless expressly agreed to by the 376 | Licensor. 377 | 378 | d. Nothing in this Public License constitutes or may be interpreted 379 | as a limitation upon, or waiver of, any privileges and immunities 380 | that apply to the Licensor or You, including from the legal 381 | processes of any jurisdiction or authority. 382 | 383 | ======================================================================= 384 | 385 | Creative Commons is not a party to its public 386 | licenses. Notwithstanding, Creative Commons may elect to apply one of 387 | its public licenses to material it publishes and in those instances 388 | will be considered the “Licensor.” The text of the Creative Commons 389 | public licenses is dedicated to the public domain under the CC0 Public 390 | Domain Dedication. Except for the limited purpose of indicating that 391 | material is shared under a Creative Commons public license or as 392 | otherwise permitted by the Creative Commons policies published at 393 | creativecommons.org/policies, Creative Commons does not authorize the 394 | use of the trademark "Creative Commons" or any other trademark or logo 395 | of Creative Commons without its prior written consent including, 396 | without limitation, in connection with any unauthorized modifications 397 | to any of its public licenses or any other arrangements, 398 | understandings, or agreements concerning use of licensed material. For 399 | the avoidance of doubt, this paragraph does not form part of the 400 | public licenses. 401 | 402 | Creative Commons may be contacted at creativecommons.org. -------------------------------------------------------------------------------- /docs/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | organization: Turbot 3 | category: ["saas"] 4 | icon_url: "/images/plugins/turbot/stripe.svg" 5 | brand_color: "#635BFF" 6 | display_name: "Stripe" 7 | short_name: "stripe" 8 | description: "Steampipe plugin for querying customers, products, invoices and more from Stripe." 9 | og_description: "Query Stripe with SQL! Open source CLI. No DB required." 10 | og_image: "/images/plugins/turbot/stripe-social-graphic.png" 11 | engines: ["steampipe", "sqlite", "postgres", "export"] 12 | --- 13 | 14 | # Stripe + Steampipe 15 | 16 | [Stripe](https://stripe.com) provides payment processing software and application programming interfaces (APIs) for e-commerce websites and mobile applications. 17 | 18 | [Steampipe](https://steampipe.io) is an open-source zero-ETL engine to instantly query cloud APIs using SQL. 19 | 20 | For example: 21 | 22 | ```sql 23 | select 24 | id, 25 | name, 26 | description 27 | from 28 | stripe_product 29 | ``` 30 | 31 | ``` 32 | +---------------------+-----------------------+------------------------+ 33 | | id | name | description | 34 | +---------------------+-----------------------+------------------------+ 35 | | prod_Gm5Ugng0ZhPIxt | Airstream Deluxe A4 | The Cadillac of Paper. | 36 | | prod_Hx0RdoxVyNJ3aC | 40 pound Letter Stock | | 37 | | prod_GnCKT8Km8WsOwK | Premium Copy Paper | | 38 | +---------------------+-----------------------+------------------------+ 39 | ``` 40 | 41 | ## Documentation 42 | 43 | - **[Table definitions & examples →](/plugins/turbot/stripe/tables)** 44 | 45 | ## Get started 46 | 47 | ### Install 48 | 49 | Download and install the latest Stripe plugin: 50 | 51 | ```bash 52 | steampipe plugin install stripe 53 | ``` 54 | 55 | ### Credentials 56 | 57 | | Item | Description | 58 | | :---------- | :--------------------------------------------------------------------------- | 59 | | Credentials | Stripe requires an [API key](https://stripe.com/docs/keys) for all requests. | 60 | | Radius | Each connection represents a single Stripe account. | 61 | 62 | ### Configuration 63 | 64 | Installing the latest stripe plugin will create a config file (`~/.steampipe/config/stripe.spc`) with a single connection named `stripe`: 65 | 66 | ```hcl 67 | connection "stripe" { 68 | plugin = "stripe" 69 | api_key = "sk_test_giG4MlyrcybGi1YFDEXAMPLE" 70 | } 71 | ``` 72 | 73 | - `api_key` - Your Stripe API key for test or live data. 74 | 75 | 76 | -------------------------------------------------------------------------------- /docs/tables/stripe_account.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Steampipe Table: stripe_account - Query Stripe Accounts using SQL" 3 | description: "Allows users to query Stripe Accounts, providing detailed information about the accounts associated with your Stripe platform." 4 | --- 5 | 6 | # Table: stripe_account - Query Stripe Accounts using SQL 7 | 8 | Stripe Account is a resource within the Stripe payment processing platform that represents an account on Stripe. These accounts can be associated with individual users or businesses and contain information about the account's details, balances, capabilities, and settings. They are integral to managing and understanding the financial transactions occurring on your Stripe platform. 9 | 10 | ## Table Usage Guide 11 | 12 | The `stripe_account` table provides insights into the accounts within your Stripe platform. As a financial analyst or platform administrator, explore account-specific details through this table, including balances, capabilities, and settings. Utilize it to uncover information about each account, such as the account type, its capabilities, and the currencies it can handle. 13 | 14 | ## Examples 15 | 16 | ### List all accounts 17 | Explore all your Stripe accounts to gain a comprehensive overview and better manage your online transactions. This could be particularly useful for businesses with multiple accounts, helping to streamline their financial operations. 18 | 19 | ```sql+postgres 20 | select 21 | * 22 | from 23 | stripe_account; 24 | ``` 25 | 26 | ```sql+sqlite 27 | select 28 | * 29 | from 30 | stripe_account; 31 | ``` 32 | 33 | ### Are card payments active for this account? 34 | Explore whether card payments are enabled for a given account. This can be useful for businesses to ensure they can process card payments and maintain smooth operations. 35 | 36 | ```sql+postgres 37 | select 38 | id, 39 | (capabilities -> 'card_payments')::bool as card_payments 40 | from 41 | stripe_account; 42 | ``` 43 | 44 | ```sql+sqlite 45 | select 46 | id, 47 | json_extract(capabilities, '$.card_payments') as card_payments 48 | from 49 | stripe_account; 50 | ``` -------------------------------------------------------------------------------- /docs/tables/stripe_charge.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Steampipe Table: stripe_charge - Query Stripe Charges using SQL" 3 | description: "Allows users to query Stripe charges, providing detailed information on charge amounts, payment methods, customers, and more." 4 | --- 5 | 6 | # Table: stripe_charge - Query Stripe Charges using SQL 7 | 8 | Stripe charges represent payments made by customers to businesses through the Stripe platform. Each charge contains detailed information about the transaction, including amounts, currency, customer details, payment methods, and dispute status. The `stripe_charge` table in Steampipe enables you to query and analyze charges, helping you manage transactions, refunds, and customer details. 9 | 10 | ## Table Usage Guide 11 | 12 | The `stripe_charge` table is useful for finance teams, data analysts, and developers who need insights into Stripe charge data. You can query various attributes such as charge amounts, payment methods, refunds, and customer details. This table is especially helpful for monitoring transactions, analyzing payment trends, managing disputes, and ensuring payment processes are functioning as expected. 13 | 14 | ## Examples 15 | 16 | ### Basic charge information 17 | Retrieve basic information about Stripe charges, including the amount, currency, and status. 18 | 19 | ```sql+postgres 20 | select 21 | id, 22 | amount, 23 | currency, 24 | created, 25 | status 26 | from 27 | stripe_charge; 28 | ``` 29 | 30 | ```sql+sqlite 31 | select 32 | id, 33 | amount, 34 | currency, 35 | created, 36 | status 37 | from 38 | stripe_charge; 39 | ``` 40 | 41 | ### List charges by customer 42 | Retrieve charges made by a specific customer, identified by the `customer` field. 43 | 44 | ```sql+postgres 45 | select 46 | id, 47 | customer, 48 | amount, 49 | currency, 50 | status 51 | from 52 | stripe_charge 53 | where 54 | customer = 'cus_12345ABC'; 55 | ``` 56 | 57 | ```sql+sqlite 58 | select 59 | id, 60 | customer, 61 | amount, 62 | currency, 63 | status 64 | from 65 | stripe_charge 66 | where 67 | customer = 'cus_12345ABC'; 68 | ``` 69 | 70 | ### List refunded charges 71 | Identify charges that have been refunded and retrieve the refund amount. 72 | 73 | ```sql+postgres 74 | select 75 | id, 76 | amount, 77 | amount_refunded, 78 | refunded, 79 | created 80 | from 81 | stripe_charge 82 | where 83 | refunded = true; 84 | ``` 85 | 86 | ```sql+sqlite 87 | select 88 | id, 89 | amount, 90 | amount_refunded, 91 | refunded, 92 | created 93 | from 94 | stripe_charge 95 | where 96 | refunded = 1; 97 | ``` 98 | 99 | ### List charges by payment method 100 | Fetch charges based on the payment method used, such as credit card or bank transfer. 101 | 102 | ```sql+postgres 103 | select 104 | id, 105 | payment_method, 106 | amount, 107 | currency, 108 | status 109 | from 110 | stripe_charge 111 | where 112 | payment_method = 'pm_123456789'; 113 | ``` 114 | 115 | ```sql+sqlite 116 | select 117 | id, 118 | payment_method, 119 | amount, 120 | currency, 121 | status 122 | from 123 | stripe_charge 124 | where 125 | payment_method = 'pm_123456789'; 126 | ``` 127 | 128 | ### List disputed charges 129 | Identify charges that are disputed and view the dispute details. 130 | 131 | ```sql+postgres 132 | select 133 | id, 134 | amount, 135 | currency, 136 | disputed, 137 | dispute 138 | from 139 | stripe_charge 140 | where 141 | disputed = true; 142 | ``` 143 | 144 | ```sql+sqlite 145 | select 146 | id, 147 | amount, 148 | currency, 149 | disputed, 150 | dispute 151 | from 152 | stripe_charge 153 | where 154 | disputed = 1; 155 | ``` -------------------------------------------------------------------------------- /docs/tables/stripe_coupon.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Steampipe Table: stripe_coupon - Query Stripe Coupons using SQL" 3 | description: "Allows users to query Stripe Coupons, specifically the properties and details of each coupon, providing insights into discounts and promotions." 4 | --- 5 | 6 | # Table: stripe_coupon - Query Stripe Coupons using SQL 7 | 8 | Stripe Coupon is a feature within Stripe that allows you to create, manage, and distribute discount codes for your customers. It provides a flexible way to set up and manage coupons for various Stripe services, including subscriptions, invoices, and more. Stripe Coupon helps you attract new customers, reward loyal ones, or reactivate past customers with discounts and promotions. 9 | 10 | ## Table Usage Guide 11 | 12 | The `stripe_coupon` table provides insights into coupons within Stripe. As a business owner or marketing manager, explore coupon-specific details through this table, including discount values, duration, and associated metadata. Utilize it to uncover information about coupons, such as those with high discount values, the duration of the coupons, and the verification of redemption limits. 13 | 14 | ## Examples 15 | 16 | ### List all coupons 17 | Explore all the promotional coupons available in your system to understand the various discount schemes you offer. This can help in assessing the effectiveness of your marketing strategies and plan future campaigns. 18 | 19 | ```sql+postgres 20 | select 21 | * 22 | from 23 | stripe_coupon; 24 | ``` 25 | 26 | ```sql+sqlite 27 | select 28 | * 29 | from 30 | stripe_coupon; 31 | ``` 32 | 33 | ### Coupons that are currently valid 34 | Explore which coupons are currently active. This can be useful for understanding which promotional offers are available for customers at a given time. 35 | 36 | ```sql+postgres 37 | select 38 | id, 39 | name 40 | from 41 | stripe_coupon 42 | where 43 | valid; 44 | ``` 45 | 46 | ```sql+sqlite 47 | select 48 | id, 49 | name 50 | from 51 | stripe_coupon 52 | where 53 | valid = 1; 54 | ``` 55 | 56 | ### Coupons by popularity 57 | Discover the segments that are most popular based on the number of times they've been redeemed. This can help prioritize marketing efforts and understand customer behavior. 58 | 59 | ```sql+postgres 60 | select 61 | id, 62 | name, 63 | times_redeemed 64 | from 65 | stripe_coupon 66 | order by 67 | times_redeemed desc; 68 | ``` 69 | 70 | ```sql+sqlite 71 | select 72 | id, 73 | name, 74 | times_redeemed 75 | from 76 | stripe_coupon 77 | order by 78 | times_redeemed desc; 79 | ``` -------------------------------------------------------------------------------- /docs/tables/stripe_customer.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Steampipe Table: stripe_customer - Query Stripe Customers using SQL" 3 | description: "Allows users to query Stripe Customers, providing insights into customer data including payment methods, transactions, and associated metadata." 4 | --- 5 | 6 | # Table: stripe_customer - Query Stripe Customers using SQL 7 | 8 | Stripe is a technology company that builds economic infrastructure for the internet. Businesses of every size from new startups to public companies use the software to accept payments and manage their businesses online. Stripe combines a payments platform with applications that put revenue data at the heart of business operations. 9 | 10 | ## Table Usage Guide 11 | 12 | The `stripe_customer` table provides insights into customer data within Stripe. As a financial analyst, you can explore customer-specific details through this table, including payment methods, transactions, and associated metadata. Utilize it to uncover information about customers, such as their payment history, preferred payment methods, and transaction patterns. 13 | 14 | ## Examples 15 | 16 | ### List all customers 17 | Explore all customer data to gain insights into your customer base and understand their activity and behavior better. This can assist in creating targeted marketing strategies and improving customer service. 18 | 19 | ```sql+postgres 20 | select 21 | * 22 | from 23 | stripe_customer; 24 | ``` 25 | 26 | ```sql+sqlite 27 | select 28 | * 29 | from 30 | stripe_customer; 31 | ``` 32 | 33 | ### Customers added in the last week 34 | Discover the segments that represent new customers by identifying those who have been added in the past week. This can help businesses understand recent growth patterns and tailor their marketing efforts accordingly. 35 | 36 | ```sql+postgres 37 | select 38 | id, 39 | name, 40 | created 41 | from 42 | stripe_customer 43 | where 44 | created > (current_timestamp - interval '7 days') 45 | order by 46 | created desc; 47 | ``` 48 | 49 | ```sql+sqlite 50 | select 51 | id, 52 | name, 53 | created 54 | from 55 | stripe_customer 56 | where 57 | created > (strftime('%s','now') - 7*24*60*60) 58 | order by 59 | created desc; 60 | ``` 61 | 62 | ### All customers with a credit on their account 63 | Discover the segments that consist of customers who have a credit balance on their account. This is useful to identify potential areas for revenue recovery or customer engagement. 64 | 65 | ```sql+postgres 66 | select 67 | id, 68 | name, 69 | balance, 70 | currency 71 | from 72 | stripe_customer 73 | where 74 | balance < 0; 75 | ``` 76 | 77 | ```sql+sqlite 78 | select 79 | id, 80 | name, 81 | balance, 82 | currency 83 | from 84 | stripe_customer 85 | where 86 | balance < 0; 87 | ``` 88 | 89 | ### All customers with an outstanding balance to add to their next invoice 90 | Gain insights into customers who have a pending balance, which will be added to their next invoice. This helps in understanding the financial standing of the customers and planning future billing accordingly. 91 | 92 | ```sql+postgres 93 | select 94 | id, 95 | name, 96 | balance, 97 | currency 98 | from 99 | stripe_customer 100 | where 101 | balance > 0; 102 | ``` 103 | 104 | ```sql+sqlite 105 | select 106 | id, 107 | name, 108 | balance, 109 | currency 110 | from 111 | stripe_customer 112 | where 113 | balance > 0; 114 | ``` -------------------------------------------------------------------------------- /docs/tables/stripe_invoice.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Steampipe Table: stripe_invoice - Query Stripe Invoices using SQL" 3 | description: "Allows users to query Stripe Invoices, specifically the details of all invoices created, paid, or attempted for a customer." 4 | --- 5 | 6 | # Table: stripe_invoice - Query Stripe Invoices using SQL 7 | 8 | Stripe is a payment processing platform that allows businesses to accept payments online and in mobile apps. It provides the technical, fraud prevention, and banking infrastructure required to operate online payment systems. Invoices in Stripe represent a bill for goods or services, and they are often tied to a subscription, but can also be used for one-off billing. 9 | 10 | ## Table Usage Guide 11 | 12 | The `stripe_invoice` table provides insights into Stripe invoices within the Stripe Payment processing platform. As a financial analyst or business owner, explore invoice-specific details through this table, including amounts, currency, customer details, and payment status. Utilize it to uncover information about invoices, such as those unpaid, partially paid, or fully paid, and the details of the associated customer. 13 | 14 | ## Examples 15 | 16 | ### List invoices 17 | Explore the most recent financial transactions by listing the latest five invoices. This is useful for getting a quick overview of recent billing activity. 18 | 19 | ```sql+postgres 20 | select 21 | * 22 | from 23 | stripe_invoice 24 | limit 25 | 5; 26 | ``` 27 | 28 | ```sql+sqlite 29 | select 30 | * 31 | from 32 | stripe_invoice 33 | limit 34 | 5; 35 | ``` 36 | 37 | ### Invoices created in the last 24 hours 38 | Discover the segments that have generated invoices in the last day. This can be used to gain insights into recent billing activity and customer engagement. 39 | 40 | ```sql+postgres 41 | select 42 | id, 43 | customer_name, 44 | amount_due 45 | from 46 | stripe_invoice 47 | where 48 | created > current_timestamp - interval '1 day' 49 | order by 50 | created; 51 | ``` 52 | 53 | ```sql+sqlite 54 | select 55 | id, 56 | customer_name, 57 | amount_due 58 | from 59 | stripe_invoice 60 | where 61 | created > datetime('now', '-1 day') 62 | order by 63 | created; 64 | ``` 65 | 66 | ### Invoices due in a given month 67 | Analyze the settings to understand which invoices are due within a specific month. This can help businesses to manage their cash flow by anticipating incoming payments. 68 | 69 | ```sql+postgres 70 | select 71 | id, 72 | customer_name, 73 | amount_due 74 | from 75 | stripe_invoice 76 | where 77 | due_date >= '2021-07-01' 78 | and due_date < '2021-08-01'; 79 | ``` 80 | 81 | ```sql+sqlite 82 | Error: The corresponding SQLite query is unavailable. 83 | ``` 84 | 85 | ### All open invoices 86 | Explore which invoices are still open by identifying the outstanding amounts due and unpaid. This can help in tracking payments and managing financial records effectively. 87 | 88 | ```sql+postgres 89 | select 90 | id, 91 | customer_name, 92 | amount_due, 93 | amount_paid, 94 | amount_remaining 95 | from 96 | stripe_invoice 97 | where 98 | status = 'outstanding' 99 | order by 100 | created; 101 | ``` 102 | 103 | ```sql+sqlite 104 | select 105 | id, 106 | customer_name, 107 | amount_due, 108 | amount_paid, 109 | amount_remaining 110 | from 111 | stripe_invoice 112 | where 113 | status = 'outstanding' 114 | order by 115 | created; 116 | ``` -------------------------------------------------------------------------------- /docs/tables/stripe_plan.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Steampipe Table: stripe_plan - Query Stripe Plans using SQL" 3 | description: "Allows users to query Stripe Plans, specifically the details of each pricing plan for products, providing insights into billing and subscription patterns." 4 | --- 5 | 6 | # Table: stripe_plan - Query Stripe Plans using SQL 7 | 8 | Stripe Plans is a service within Stripe that allows businesses to set up recurring payments for their products or services. It provides a way to create and manage different pricing tiers for subscriptions, including details about the billing cycle, pricing, and currency. Stripe Plans helps businesses to automate their billing process and manage subscriptions efficiently. 9 | 10 | ## Table Usage Guide 11 | 12 | The `stripe_plan` table provides insights into the pricing plans within Stripe. As a billing manager, explore plan-specific details through this table, including pricing, intervals, and associated products. Utilize it to uncover information about plans, such as their cost, billing frequency, and the product they are associated with. 13 | 14 | ## Examples 15 | 16 | ### List all plans 17 | Explore the different plans available in your Stripe account. This can be useful for understanding your billing structure and identifying any plans that may need to be updated or changed. 18 | 19 | ```sql+postgres 20 | select 21 | * 22 | from 23 | stripe_plan; 24 | ``` 25 | 26 | ```sql+sqlite 27 | select 28 | * 29 | from 30 | stripe_plan; 31 | ``` 32 | 33 | ### List all plans with a trial period 34 | Discover the segments that offer trial periods in your subscription plans. This can help you assess the elements within your business model that may be contributing to customer acquisition and retention. 35 | 36 | ```sql+postgres 37 | select 38 | id, 39 | nickname, 40 | trial_period_days 41 | from 42 | stripe_plan 43 | where 44 | trial_period_days > 0; 45 | ``` 46 | 47 | ```sql+sqlite 48 | select 49 | id, 50 | nickname, 51 | trial_period_days 52 | from 53 | stripe_plan 54 | where 55 | trial_period_days > 0; 56 | ``` 57 | 58 | ### List all products with their associated plans 59 | Explore which products are linked to specific plans, allowing you to analyze the relationship between your offerings and their associated plans for better product management and strategic planning. 60 | 61 | ```sql+postgres 62 | select 63 | p.id, 64 | p.name, 65 | pl.id, 66 | pl.nickname 67 | from 68 | stripe_product as p, 69 | stripe_plan as pl 70 | where 71 | p.id = pl.product_id 72 | order by 73 | p.name, 74 | pl.nickname; 75 | ``` 76 | 77 | ```sql+sqlite 78 | select 79 | p.id, 80 | p.name, 81 | pl.id, 82 | pl.nickname 83 | from 84 | stripe_product as p, 85 | stripe_plan as pl 86 | where 87 | p.id = pl.product_id 88 | order by 89 | p.name, 90 | pl.nickname; 91 | ``` -------------------------------------------------------------------------------- /docs/tables/stripe_product.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Steampipe Table: stripe_product - Query Stripe Products using SQL" 3 | description: "Allows users to query Stripe Products, specifically product details like ID, name, description, active status, and more." 4 | --- 5 | 6 | # Table: stripe_product - Query Stripe Products using SQL 7 | 8 | Stripe Products is a resource within the Stripe payment processing service that represents the different products or services that a business offers. It provides a way to define and manage the catalog of items for which a business accepts payments. Stripe Products facilitates the organization of these items, including their pricing, description, and other related information. 9 | 10 | ## Table Usage Guide 11 | 12 | The `stripe_product` table provides insights into the various products or services within Stripe's payment processing service. As a financial analyst or business owner, explore product-specific details through this table, including product ID, name, description, and active status. Utilize it to manage and organize your product catalog, monitor active products, and gain a comprehensive overview of your business offerings. 13 | 14 | ## Examples 15 | 16 | ### List all products 17 | Explore all available products in your inventory to manage and oversee your product catalog more efficiently. This can help you keep track of your offerings and make strategic decisions based on the comprehensive overview. 18 | 19 | ```sql+postgres 20 | select 21 | * 22 | from 23 | stripe_product; 24 | ``` 25 | 26 | ```sql+sqlite 27 | select 28 | * 29 | from 30 | stripe_product; 31 | ``` 32 | 33 | ### All products that are not active 34 | Explore which of your Stripe products are currently inactive. This can be useful for identifying items that may need updating or reactivation, helping to ensure your product offerings remain current and relevant. 35 | 36 | ```sql+postgres 37 | select 38 | * 39 | from 40 | stripe_product 41 | where 42 | not active; 43 | ``` 44 | 45 | ```sql+sqlite 46 | select 47 | * 48 | from 49 | stripe_product 50 | where 51 | active = 0; 52 | ``` -------------------------------------------------------------------------------- /docs/tables/stripe_subscription.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Steampipe Table: stripe_subscription - Query Stripe Subscriptions using SQL" 3 | description: "Allows users to query Stripe Subscriptions, specifically the details of active, past, and upcoming subscriptions." 4 | --- 5 | 6 | # Table: stripe_subscription - Query Stripe Subscriptions using SQL 7 | 8 | Stripe Subscriptions is a service within Stripe that allows businesses to manage recurring billing for their customers. It provides a simplified way to set up and manage subscriptions, including various billing models, prorations, and tax rates. Stripe Subscriptions helps businesses automate their recurring billing, stay informed about subscription changes, and take appropriate actions when predefined conditions are met. 9 | 10 | ## Table Usage Guide 11 | 12 | The `stripe_subscription` table provides insights into subscriptions within Stripe. As a financial analyst or a business owner, explore subscription-specific details through this table, including the status, items, and associated customer information. Utilize it to uncover information about subscriptions, such as those with upcoming invoices, the relationships between customers and their subscriptions, and the verification of billing details. 13 | 14 | ## Examples 15 | 16 | ### List all subscriptions 17 | Explore all active subscriptions to understand the scope and scale of your service usage. This can aid in assessing revenue streams and identifying potential areas for growth or improvement. 18 | 19 | ```sql+postgres 20 | select 21 | * 22 | from 23 | stripe_subscription; 24 | ``` 25 | 26 | ```sql+sqlite 27 | select 28 | * 29 | from 30 | stripe_subscription; 31 | ``` 32 | 33 | ### Subscriptions currently in the trial period 34 | Explore which subscriptions are presently in their trial period to manage customer engagement and retention strategies effectively. This allows for a timely review of customer behavior and interactions during the trial phase. 35 | 36 | ```sql+postgres 37 | select 38 | * 39 | from 40 | stripe_subscription 41 | where 42 | status = 'trialing' 43 | order by 44 | created desc; 45 | ``` 46 | 47 | ```sql+sqlite 48 | select 49 | * 50 | from 51 | stripe_subscription 52 | where 53 | status = 'trialing' 54 | order by 55 | created desc; 56 | ``` 57 | 58 | ### Subscriptions set to cancel at the end of this period 59 | Identify the Stripe subscriptions that are scheduled to cancel at the end of the current billing period. This is useful for understanding your upcoming subscription churn and potentially reaching out to these customers to prevent cancellation. 60 | 61 | ```sql+postgres 62 | select 63 | * 64 | from 65 | stripe_subscription 66 | where 67 | cancel_at_period_end; 68 | ``` 69 | 70 | ```sql+sqlite 71 | select 72 | * 73 | from 74 | stripe_subscription 75 | where 76 | cancel_at_period_end = 1; 77 | ``` 78 | 79 | ### Subscriptions created in the last 7 days 80 | Discover the segments that have newly subscribed to your service within the past week. This can be useful in understanding recent customer behavior and trends. 81 | 82 | ```sql+postgres 83 | select 84 | * 85 | from 86 | stripe_subscription 87 | where 88 | created > current_timestamp - interval '7 days' 89 | order by 90 | created; 91 | ``` 92 | 93 | ```sql+sqlite 94 | select 95 | * 96 | from 97 | stripe_subscription 98 | where 99 | created > datetime('now', '-7 days') 100 | order by 101 | created; 102 | ``` -------------------------------------------------------------------------------- /docs/tables/stripe_subscription_item.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Steampipe Table: stripe_subscription_item - Query Stripe Subscriptions using SQL" 3 | description: "Query the items associaated with a Stripe Subscription." 4 | --- 5 | 6 | # Table: stripe_subscription_item - Query Stripe Subscription Items using SQL 7 | 8 | Stripe Subscriptions is a service within Stripe that allows businesses to manage recurring billing for their customers. Subscription Items provide details including price, quantity, and billing thresholds. 9 | 10 | ## Table Usage Guide 11 | 12 | The `stripe_subscription_item` table in Steampipe provides detailed information about subscription records in your Stripe account. This table allows you, as a financial analyst or developer, to query subscription-specific details, including the status, customer, start and end dates, billing cycle, pricing plans, discounts, and metadata. You can leverage this table to analyze active or canceled subscriptions, monitor revenue streams, identify subscriptions with specific plans or discounts, and more. The schema outlines the attributes of a Stripe subscription, such as the subscription ID, customer information, pricing details, discount information, and metadata, enabling a comprehensive view of your subscription data. 13 | 14 | **Important Notes** 15 | - You must specify a `subscription_id` in a where or join clause in order to use this table. 16 | 17 | ## Examples 18 | 19 | ### List details for a subscription 20 | Explore all the stripe subscriptions. 21 | 22 | ```sql+postgres 23 | select 24 | * 25 | from 26 | stripe_subscription_item 27 | where 28 | subscription_id = 'sub_1Oo64zCWwOK68BLnfPDrQWIX' 29 | ``` 30 | 31 | ```sql+sqlite 32 | select 33 | * 34 | from 35 | stripe_subscription_item 36 | where 37 | subscription_id = 'sub_1Oo64zCWwOK68BLnfPDrQWIX' 38 | ``` 39 | 40 | ### Retrieve subscription items with applied discounts 41 | Identify subscription items from a specific subscription that have discounts applied. 42 | 43 | ```sql+postgres 44 | select 45 | subscription_id, 46 | plan, 47 | price -> 'discounts' as discounts 48 | from 49 | stripe_subscription_item 50 | where 51 | subscription_id = 'sub_1Oo64zCWwOK68BLnfPDrQWIX' 52 | and (price -> 'discounts') is not null; 53 | ``` 54 | 55 | ```sql+sqlite 56 | select 57 | subscription_id, 58 | plan, 59 | json_extract(price, '$.discounts') as discounts 60 | from 61 | stripe_subscription_item 62 | where 63 | subscription_id = 'sub_1Oo64zCWwOK68BLnfPDrQWIX' 64 | and json_extract(price, '$.discounts') is not null; 65 | ``` 66 | 67 | ### Retrieve plan details for a subscription item 68 | Fetch detailed information about plans associated with a specific subscription, including their activity status, billing scheme, ID, usage type, and tiers. 69 | 70 | ```sql+postgres 71 | select 72 | subscription_id, 73 | plan ->> 'active' as is_active, 74 | plan -> 'billingScheme' as billing_scheme, 75 | plan ->> 'id' as plan_id, 76 | plan ->> 'usageType' as usage_type, 77 | plan ->> 'tiers' as plan_tiers 78 | from 79 | from 80 | stripe_subscription_item 81 | where 82 | subscription_id = 'sub_1Oo64zCWwOK68BLnfPDrQWIX'; 83 | ``` 84 | 85 | ```sql+sqlite 86 | select 87 | subscription_id, 88 | json_extract(plan, '$.active') as is_active, 89 | json_extract(plan, '$.billingScheme') as billing_scheme, 90 | json_extract(plan, '$.id') as plan_id, 91 | json_extract(plan, '$.usageType') as usage_type, 92 | json_extract(plan, '$.tiers') as plan_tiers 93 | from 94 | stripe_subscription_item 95 | where 96 | subscription_id = 'sub_1Oo64zCWwOK68BLnfPDrQWIX'; 97 | ``` -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/turbot/steampipe-plugin-stripe 2 | 3 | go 1.23.1 4 | 5 | toolchain go1.23.2 6 | 7 | require ( 8 | github.com/stripe/stripe-go/v76 v76.0.0 9 | github.com/turbot/steampipe-plugin-sdk/v5 v5.11.5 10 | ) 11 | 12 | require ( 13 | cloud.google.com/go v0.112.1 // indirect 14 | cloud.google.com/go/compute/metadata v0.3.0 // indirect 15 | cloud.google.com/go/iam v1.1.6 // indirect 16 | cloud.google.com/go/storage v1.38.0 // indirect 17 | github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d // indirect 18 | github.com/agext/levenshtein v1.2.3 // indirect 19 | github.com/allegro/bigcache/v3 v3.1.0 // indirect 20 | github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect 21 | github.com/aws/aws-sdk-go v1.44.183 // indirect 22 | github.com/beorn7/perks v1.0.1 // indirect 23 | github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect 24 | github.com/btubbs/datetime v0.1.1 // indirect 25 | github.com/cenkalti/backoff/v4 v4.3.0 // indirect 26 | github.com/cespare/xxhash/v2 v2.3.0 // indirect 27 | github.com/danwakefield/fnmatch v0.0.0-20160403171240-cbb64ac3d964 // indirect 28 | github.com/dgraph-io/ristretto v0.2.0 // indirect 29 | github.com/dustin/go-humanize v1.0.1 // indirect 30 | github.com/eko/gocache/lib/v4 v4.1.6 // indirect 31 | github.com/eko/gocache/store/bigcache/v4 v4.2.1 // indirect 32 | github.com/eko/gocache/store/ristretto/v4 v4.2.1 // indirect 33 | github.com/fatih/color v1.17.0 // indirect 34 | github.com/felixge/httpsnoop v1.0.4 // indirect 35 | github.com/fsnotify/fsnotify v1.7.0 // indirect 36 | github.com/gertd/go-pluralize v0.2.1 // indirect 37 | github.com/ghodss/yaml v1.0.0 // indirect 38 | github.com/go-logr/logr v1.4.1 // indirect 39 | github.com/go-logr/stdr v1.2.2 // indirect 40 | github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect 41 | github.com/golang/mock v1.6.0 // indirect 42 | github.com/golang/protobuf v1.5.4 // indirect 43 | github.com/google/go-cmp v0.6.0 // indirect 44 | github.com/google/s2a-go v0.1.7 // indirect 45 | github.com/google/uuid v1.6.0 // indirect 46 | github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect 47 | github.com/googleapis/gax-go/v2 v2.12.3 // indirect 48 | github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.1 // indirect 49 | github.com/hashicorp/go-cleanhttp v0.5.2 // indirect 50 | github.com/hashicorp/go-getter v1.7.5 // indirect 51 | github.com/hashicorp/go-hclog v1.6.3 // indirect 52 | github.com/hashicorp/go-plugin v1.6.1 // indirect 53 | github.com/hashicorp/go-safetemp v1.0.0 // indirect 54 | github.com/hashicorp/go-version v1.7.0 // indirect 55 | github.com/hashicorp/hcl/v2 v2.20.1 // indirect 56 | github.com/hashicorp/yamux v0.1.1 // indirect 57 | github.com/iancoleman/strcase v0.3.0 // indirect 58 | github.com/jmespath/go-jmespath v0.4.0 // indirect 59 | github.com/klauspost/compress v1.17.2 // indirect 60 | github.com/mattn/go-colorable v0.1.13 // indirect 61 | github.com/mattn/go-isatty v0.0.20 // indirect 62 | github.com/mattn/go-runewidth v0.0.15 // indirect 63 | github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect 64 | github.com/mitchellh/go-homedir v1.1.0 // indirect 65 | github.com/mitchellh/go-testing-interface v1.14.1 // indirect 66 | github.com/mitchellh/go-wordwrap v1.0.0 // indirect 67 | github.com/mitchellh/mapstructure v1.5.0 // indirect 68 | github.com/oklog/run v1.0.0 // indirect 69 | github.com/olekukonko/tablewriter v0.0.5 // indirect 70 | github.com/pkg/errors v0.9.1 // indirect 71 | github.com/prometheus/client_golang v1.14.0 // indirect 72 | github.com/prometheus/client_model v0.3.0 // indirect 73 | github.com/prometheus/common v0.37.0 // indirect 74 | github.com/prometheus/procfs v0.8.0 // indirect 75 | github.com/rivo/uniseg v0.2.0 // indirect 76 | github.com/sethvargo/go-retry v0.2.4 // indirect 77 | github.com/stevenle/topsort v0.2.0 // indirect 78 | github.com/tkrajina/go-reflector v0.5.6 // indirect 79 | github.com/turbot/go-kit v1.1.0 // indirect 80 | github.com/ulikunitz/xz v0.5.10 // indirect 81 | github.com/zclconf/go-cty v1.14.4 // indirect 82 | go.opencensus.io v0.24.0 // indirect 83 | go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.49.0 // indirect 84 | go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect 85 | go.opentelemetry.io/otel v1.26.0 // indirect 86 | go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.26.0 // indirect 87 | go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.24.0 // indirect 88 | go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.24.0 // indirect 89 | go.opentelemetry.io/otel/metric v1.26.0 // indirect 90 | go.opentelemetry.io/otel/sdk v1.26.0 // indirect 91 | go.opentelemetry.io/otel/sdk/metric v1.26.0 // indirect 92 | go.opentelemetry.io/otel/trace v1.26.0 // indirect 93 | go.opentelemetry.io/proto/otlp v1.2.0 // indirect 94 | golang.org/x/crypto v0.35.0 // indirect 95 | golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 // indirect 96 | golang.org/x/mod v0.19.0 // indirect 97 | golang.org/x/net v0.36.0 // indirect 98 | golang.org/x/oauth2 v0.21.0 // indirect 99 | golang.org/x/sync v0.11.0 // indirect 100 | golang.org/x/sys v0.30.0 // indirect 101 | golang.org/x/text v0.22.0 // indirect 102 | golang.org/x/time v0.5.0 // indirect 103 | golang.org/x/tools v0.23.0 // indirect 104 | google.golang.org/api v0.171.0 // indirect 105 | google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de // indirect 106 | google.golang.org/genproto/googleapis/api v0.0.0-20240604185151-ef581f913117 // indirect 107 | google.golang.org/genproto/googleapis/rpc v0.0.0-20240604185151-ef581f913117 // indirect 108 | google.golang.org/grpc v1.66.0 // indirect 109 | google.golang.org/protobuf v1.34.2 // indirect 110 | gopkg.in/yaml.v2 v2.4.0 // indirect 111 | ) 112 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/turbot/steampipe-plugin-sdk/v5/plugin" 5 | "github.com/turbot/steampipe-plugin-stripe/stripe" 6 | ) 7 | 8 | func main() { 9 | plugin.Serve(&plugin.ServeOpts{PluginFunc: stripe.Plugin}) 10 | } 11 | -------------------------------------------------------------------------------- /stripe/common_columns.go: -------------------------------------------------------------------------------- 1 | package stripe 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/stripe/stripe-go/v76" 7 | "github.com/turbot/steampipe-plugin-sdk/v5/grpc/proto" 8 | "github.com/turbot/steampipe-plugin-sdk/v5/memoize" 9 | "github.com/turbot/steampipe-plugin-sdk/v5/plugin" 10 | "github.com/turbot/steampipe-plugin-sdk/v5/plugin/transform" 11 | ) 12 | 13 | func commonColumns(c []*plugin.Column) []*plugin.Column { 14 | return append([]*plugin.Column{ 15 | { 16 | Name: "account_id", 17 | Description: "The Stripe account ID.", 18 | Type: proto.ColumnType_STRING, 19 | Hydrate: getAccountId, 20 | Transform: transform.FromValue(), 21 | }, 22 | }, c...) 23 | } 24 | 25 | // if the caching is required other than per connection, build a cache key for the call and use it in Memoize. 26 | var getAccountMemoized = plugin.HydrateFunc(getAccountUncached).Memoize(memoize.WithCacheKeyFunction(getAccountCacheKey)) 27 | 28 | func getAccountId(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { 29 | acc, err := getAccountMemoized(ctx, d, h) 30 | if err != nil { 31 | return nil, err 32 | } 33 | return acc.(*stripe.Account).ID, nil 34 | } 35 | 36 | // Build a cache key for the call to getAccountIdCacheKey. 37 | func getAccountCacheKey(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { 38 | key := "getAccountId" 39 | return key, nil 40 | } 41 | 42 | func getAccountUncached(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { 43 | 44 | conn, err := connect(ctx, d) 45 | if err != nil { 46 | plugin.Logger(ctx).Error("stripe_account.listAccount", "connection_error", err) 47 | return nil, err 48 | } 49 | 50 | item, err := conn.Accounts.Get() 51 | if err != nil { 52 | plugin.Logger(ctx).Error("stripe_account.listAccount", "query_error", err) 53 | return nil, err 54 | } 55 | 56 | return item, nil 57 | } 58 | -------------------------------------------------------------------------------- /stripe/connection_config.go: -------------------------------------------------------------------------------- 1 | package stripe 2 | 3 | import ( 4 | "github.com/turbot/steampipe-plugin-sdk/v5/plugin" 5 | ) 6 | 7 | type stripeConfig struct { 8 | APIKey *string `hcl:"api_key"` 9 | } 10 | 11 | func ConfigInstance() interface{} { 12 | return &stripeConfig{} 13 | } 14 | 15 | // GetConfig :: retrieve and cast connection config from query data 16 | func GetConfig(connection *plugin.Connection) stripeConfig { 17 | if connection == nil || connection.Config == nil { 18 | return stripeConfig{} 19 | } 20 | config, _ := connection.Config.(stripeConfig) 21 | return config 22 | } 23 | -------------------------------------------------------------------------------- /stripe/error.go: -------------------------------------------------------------------------------- 1 | package stripe 2 | 3 | import ( 4 | "github.com/stripe/stripe-go/v76" 5 | ) 6 | 7 | func isNotFoundError(err error) bool { 8 | if stripeErr, ok := err.(*stripe.Error); ok { 9 | switch stripeErr.Code { 10 | case stripe.ErrorCodeMissing, stripe.ErrorCodeResourceMissing: 11 | return true 12 | } 13 | } 14 | return false 15 | } 16 | -------------------------------------------------------------------------------- /stripe/plugin.go: -------------------------------------------------------------------------------- 1 | package stripe 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/turbot/steampipe-plugin-sdk/v5/plugin" 7 | "github.com/turbot/steampipe-plugin-sdk/v5/plugin/transform" 8 | ) 9 | 10 | func Plugin(ctx context.Context) *plugin.Plugin { 11 | p := &plugin.Plugin{ 12 | Name: "steampipe-plugin-stripe", 13 | ConnectionConfigSchema: &plugin.ConnectionConfigSchema{ 14 | NewInstance: ConfigInstance, 15 | }, 16 | ConnectionKeyColumns: []plugin.ConnectionKeyColumn{ 17 | { 18 | Name: "account_id", 19 | Hydrate: getAccountId, 20 | }, 21 | }, 22 | DefaultTransform: transform.FromGo().NullIfZero(), 23 | DefaultGetConfig: &plugin.GetConfig{ 24 | ShouldIgnoreError: isNotFoundError, 25 | }, 26 | TableMap: map[string]*plugin.Table{ 27 | "stripe_account": tableStripeAccount(ctx), 28 | "stripe_charge": tableStripeCharge(ctx), 29 | "stripe_coupon": tableStripeCoupon(ctx), 30 | "stripe_customer": tableStripeCustomer(ctx), 31 | "stripe_invoice": tableStripeInvoice(ctx), 32 | "stripe_plan": tableStripePlan(ctx), 33 | "stripe_product": tableStripeProduct(ctx), 34 | "stripe_subscription": tableStripeSubscription(ctx), 35 | "stripe_subscription_item": tableStripeSubscriptionItem(ctx), 36 | }, 37 | } 38 | return p 39 | } 40 | -------------------------------------------------------------------------------- /stripe/table_stripe_account.go: -------------------------------------------------------------------------------- 1 | package stripe 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/turbot/steampipe-plugin-sdk/v5/grpc/proto" 7 | "github.com/turbot/steampipe-plugin-sdk/v5/plugin" 8 | "github.com/turbot/steampipe-plugin-sdk/v5/plugin/transform" 9 | ) 10 | 11 | func tableStripeAccount(ctx context.Context) *plugin.Table { 12 | return &plugin.Table{ 13 | Name: "stripe_account", 14 | Description: "This is an object representing a Stripe account.", 15 | List: &plugin.ListConfig{ 16 | Hydrate: listAccount, 17 | }, 18 | Columns: commonColumns([]*plugin.Column{ 19 | // Top columns 20 | {Name: "id", Type: proto.ColumnType_STRING, Description: "Unique identifier for the account."}, 21 | {Name: "email", Type: proto.ColumnType_STRING, Description: "An email address associated with the account. You can treat this as metadata: it is not used for authentication or messaging account holders."}, 22 | // Other columns 23 | {Name: "business_profile", Type: proto.ColumnType_JSON, Description: "Business information about the account."}, 24 | {Name: "business_type", Type: proto.ColumnType_STRING, Description: "The business type."}, 25 | {Name: "capabilities", Type: proto.ColumnType_JSON, Description: "A hash containing the set of capabilities that was requested for this account and their associated states. Keys are names of capabilities. You can see the full list here. Values may be active, inactive, or pending."}, 26 | {Name: "charges_enabled", Type: proto.ColumnType_BOOL, Description: "Whether the account can create live charges."}, 27 | {Name: "company", Type: proto.ColumnType_JSON, Description: "Information about the company or business. This field is available for any business_type."}, 28 | {Name: "country", Type: proto.ColumnType_STRING, Description: "The account’s country."}, 29 | {Name: "created", Type: proto.ColumnType_TIMESTAMP, Transform: transform.FromField("Created").Transform(transform.UnixToTimestamp), Description: "Time at which the account was created."}, 30 | {Name: "default_currency", Type: proto.ColumnType_STRING, Description: "Three-letter ISO currency code representing the default currency for the account."}, 31 | {Name: "deleted", Type: proto.ColumnType_BOOL, Description: "True if the customer is marked as deleted."}, 32 | {Name: "details_submitted", Type: proto.ColumnType_BOOL, Description: "Whether account details have been submitted. Standard accounts cannot receive payouts before this is true."}, 33 | {Name: "external_accounts", Type: proto.ColumnType_JSON, Description: "External accounts (bank accounts and debit cards) currently attached to this account."}, 34 | {Name: "individual", Type: proto.ColumnType_JSON, Description: "Information about the person represented by the account. This field is null unless business_type is set to individual."}, 35 | {Name: "metadata", Type: proto.ColumnType_JSON, Description: "Set of key-value pairs that you can attach to an account. This can be useful for storing additional information about the account in a structured format."}, 36 | {Name: "payouts_enabled", Type: proto.ColumnType_BOOL, Description: "Whether Stripe can send payouts to this account."}, 37 | {Name: "requirements", Type: proto.ColumnType_JSON, Description: "Information about the requirements for the account, including what information needs to be collected, and by when."}, 38 | {Name: "settings", Type: proto.ColumnType_JSON, Description: "Options for customizing how the account functions within Stripe."}, 39 | {Name: "tos_acceptance", Type: proto.ColumnType_JSON, Transform: transform.FromField("TOSAcceptance"), Description: "Details on the acceptance of the Stripe Services Agreement."}, 40 | {Name: "type", Type: proto.ColumnType_STRING, Description: "The Stripe account type. Can be standard, express, or custom."}, 41 | }), 42 | } 43 | } 44 | 45 | func listAccount(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData) (interface{}, error) { 46 | conn, err := connect(ctx, d) 47 | if err != nil { 48 | plugin.Logger(ctx).Error("stripe_account.listAccount", "connection_error", err) 49 | return nil, err 50 | } 51 | 52 | item, err := conn.Accounts.Get() 53 | if err != nil { 54 | plugin.Logger(ctx).Error("stripe_account.listAccount", "query_error", err) 55 | return nil, err 56 | } 57 | 58 | d.StreamListItem(ctx, item) 59 | return nil, nil 60 | } 61 | -------------------------------------------------------------------------------- /stripe/table_stripe_charge.go: -------------------------------------------------------------------------------- 1 | package stripe 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/stripe/stripe-go/v76" 7 | "github.com/turbot/steampipe-plugin-sdk/v5/grpc/proto" 8 | "github.com/turbot/steampipe-plugin-sdk/v5/plugin" 9 | "github.com/turbot/steampipe-plugin-sdk/v5/plugin/transform" 10 | ) 11 | 12 | func tableStripeCharge(ctx context.Context) *plugin.Table { 13 | return &plugin.Table{ 14 | Name: "stripe_charge", 15 | Description: "Retrieves comprehensive details of historical Stripe charges or a specific charge by ID.", 16 | List: &plugin.ListConfig{ 17 | Hydrate: listCharges, 18 | KeyColumns: []*plugin.KeyColumn{ 19 | {Name: "created", Operators: []string{">", ">=", "=", "<", "<="}, Require: plugin.Optional}, 20 | {Name: "payment_intent", Require: plugin.Optional, Operators: []string{"="}}, 21 | {Name: "transfer_group", Require: plugin.Optional, Operators: []string{"="}}, 22 | {Name: "customer", Require: plugin.Optional, Operators: []string{"="}}, 23 | }, 24 | }, 25 | Get: &plugin.GetConfig{ 26 | Hydrate: getCharge, 27 | KeyColumns: plugin.SingleColumn("id"), 28 | }, 29 | Columns: commonColumns([]*plugin.Column{ 30 | // Basic fields 31 | { 32 | Name: "id", 33 | Description: "Unique identifier for the charge.", 34 | Type: proto.ColumnType_STRING, 35 | }, 36 | { 37 | Name: "amount", 38 | Description: "Amount charged in cents.", 39 | Type: proto.ColumnType_INT, 40 | }, 41 | { 42 | Name: "amount_refunded", 43 | Description: "Amount refunded in cents.", 44 | Type: proto.ColumnType_INT, 45 | }, 46 | { 47 | Name: "authorization_code", 48 | Description: "Authorization code for the charge.", 49 | Type: proto.ColumnType_STRING, 50 | }, 51 | { 52 | Name: "balance_transaction", 53 | Description: "Balance transaction related to the charge.", 54 | Type: proto.ColumnType_STRING, 55 | }, 56 | { 57 | Name: "captured", 58 | Description: "Indicates whether the charge was captured.", 59 | Type: proto.ColumnType_BOOL, 60 | }, 61 | { 62 | Name: "created", 63 | Description: "Timestamp when the charge was created.", 64 | Type: proto.ColumnType_TIMESTAMP, 65 | Transform: transform.FromField("Created").Transform(transform.UnixToTimestamp), 66 | }, 67 | { 68 | Name: "currency", 69 | Description: "Currency of the charge.", 70 | Type: proto.ColumnType_STRING, 71 | }, 72 | { 73 | Name: "customer", 74 | Description: "Customer related to the charge.", 75 | Type: proto.ColumnType_STRING, 76 | }, 77 | { 78 | Name: "description", 79 | Description: "Description of the charge.", 80 | Type: proto.ColumnType_STRING, 81 | }, 82 | { 83 | Name: "disputed", 84 | Description: "Indicates whether the charge is disputed.", 85 | Type: proto.ColumnType_BOOL, 86 | }, 87 | { 88 | Name: "failure_code", 89 | Description: "Failure code if the charge failed.", 90 | Type: proto.ColumnType_STRING, 91 | }, 92 | { 93 | Name: "failure_message", 94 | Description: "Failure message if the charge failed.", 95 | Type: proto.ColumnType_STRING, 96 | }, 97 | { 98 | Name: "livemode", 99 | Description: "Indicates whether the charge was created in live mode.", 100 | Type: proto.ColumnType_BOOL, 101 | }, 102 | { 103 | Name: "paid", 104 | Description: "Indicates whether the charge was paid.", 105 | Type: proto.ColumnType_BOOL, 106 | }, 107 | { 108 | Name: "payment_intent", 109 | Description: "Payment intent related to the charge.", 110 | Type: proto.ColumnType_STRING, 111 | }, 112 | { 113 | Name: "payment_method", 114 | Description: "Payment method used for the charge.", 115 | Type: proto.ColumnType_STRING, 116 | }, 117 | { 118 | Name: "receipt_email", 119 | Description: "Receipt email for the charge.", 120 | Type: proto.ColumnType_STRING, 121 | }, 122 | { 123 | Name: "receipt_number", 124 | Description: "Receipt number for the charge.", 125 | Type: proto.ColumnType_STRING, 126 | }, 127 | { 128 | Name: "receipt_url", 129 | Description: "URL to the receipt of the charge.", 130 | Type: proto.ColumnType_STRING, 131 | }, 132 | { 133 | Name: "refunded", 134 | Description: "Indicates whether the charge was refunded.", 135 | Type: proto.ColumnType_BOOL, 136 | }, 137 | { 138 | Name: "status", 139 | Description: "Status of the charge (e.g., succeeded, pending, failed).", 140 | Type: proto.ColumnType_STRING, 141 | }, 142 | { 143 | Name: "transfer_group", 144 | Description: "Transfer group related to the charge.", 145 | Type: proto.ColumnType_STRING, 146 | }, 147 | 148 | // JSON columns for complex data 149 | { 150 | Name: "application", 151 | Description: "Application that initiated the charge.", 152 | Type: proto.ColumnType_JSON, 153 | }, 154 | { 155 | Name: "application_fee", 156 | Description: "Application fee related to the charge.", 157 | Type: proto.ColumnType_JSON, 158 | }, 159 | { 160 | Name: "billing_details", 161 | Description: "Billing details associated with the charge.", 162 | Type: proto.ColumnType_JSON, 163 | }, 164 | { 165 | Name: "destination", 166 | Description: "Destination account receiving the funds.", 167 | Type: proto.ColumnType_JSON, 168 | }, 169 | { 170 | Name: "dispute", 171 | Description: "Details about the dispute if the charge is disputed.", 172 | Type: proto.ColumnType_JSON, 173 | }, 174 | { 175 | Name: "fraud_details", 176 | Description: "Fraud details for the charge.", 177 | Type: proto.ColumnType_JSON, 178 | }, 179 | { 180 | Name: "invoice", 181 | Description: "Invoice associated with the charge.", 182 | Type: proto.ColumnType_JSON, 183 | }, 184 | { 185 | Name: "level3", 186 | Description: "Level 3 data for the charge.", 187 | Type: proto.ColumnType_JSON, 188 | }, 189 | { 190 | Name: "metadata", 191 | Description: "Metadata associated with the charge.", 192 | Type: proto.ColumnType_JSON, 193 | }, 194 | { 195 | Name: "outcome", 196 | Description: "Details about the outcome of the charge.", 197 | Type: proto.ColumnType_JSON, 198 | }, 199 | { 200 | Name: "payment_method_details", 201 | Description: "Details about the payment method used for the charge.", 202 | Type: proto.ColumnType_JSON, 203 | }, 204 | { 205 | Name: "refunds", 206 | Description: "List of refunds applied to the charge.", 207 | Type: proto.ColumnType_JSON, 208 | }, 209 | { 210 | Name: "review", 211 | Description: "Review associated with the charge.", 212 | Type: proto.ColumnType_JSON, 213 | }, 214 | { 215 | Name: "shipping", 216 | Description: "Shipping details for the charge.", 217 | Type: proto.ColumnType_JSON, 218 | }, 219 | { 220 | Name: "source", 221 | Description: "Payment source for the charge.", 222 | Type: proto.ColumnType_JSON, 223 | }, 224 | { 225 | Name: "source_transfer", 226 | Description: "Transfer related to the charge source.", 227 | Type: proto.ColumnType_JSON, 228 | }, 229 | { 230 | Name: "transfer", 231 | Description: "Transfer related to the charge.", 232 | Type: proto.ColumnType_JSON, 233 | }, 234 | { 235 | Name: "transfer_data", 236 | Description: "Transfer data for the charge.", 237 | Type: proto.ColumnType_JSON, 238 | }, 239 | }), 240 | } 241 | } 242 | 243 | func listCharges(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData) (interface{}, error) { 244 | conn, err := connect(ctx, d) 245 | if err != nil { 246 | plugin.Logger(ctx).Error("stripe_charge.listCharges", "connection_error", err) 247 | return nil, err 248 | } 249 | params := &stripe.ChargeListParams{ 250 | ListParams: stripe.ListParams{ 251 | Context: ctx, 252 | Limit: stripe.Int64(100), 253 | }, 254 | } 255 | 256 | q := d.EqualsQuals 257 | if q["customer"] != nil { 258 | params.Customer = stripe.String(q["customer"].GetStringValue()) 259 | } 260 | if q["payment_intent"] != nil { 261 | params.PaymentIntent = stripe.String(q["payment_intent"].GetStringValue()) 262 | } 263 | if q["transfer_group"] != nil { 264 | params.TransferGroup = stripe.String(q["transfer_group"].GetStringValue()) 265 | } 266 | 267 | // Comparison values 268 | quals := d.Quals 269 | 270 | if quals["created"] != nil { 271 | for _, q := range quals["created"].Quals { 272 | tsSecs := q.Value.GetTimestampValue().GetSeconds() 273 | switch q.Operator { 274 | case ">": 275 | if params.CreatedRange == nil { 276 | params.CreatedRange = &stripe.RangeQueryParams{} 277 | } 278 | params.CreatedRange.GreaterThan = tsSecs 279 | case ">=": 280 | if params.CreatedRange == nil { 281 | params.CreatedRange = &stripe.RangeQueryParams{} 282 | } 283 | params.CreatedRange.GreaterThanOrEqual = tsSecs 284 | case "=": 285 | params.Created = stripe.Int64(tsSecs) 286 | case "<=": 287 | if params.CreatedRange == nil { 288 | params.CreatedRange = &stripe.RangeQueryParams{} 289 | } 290 | params.CreatedRange.LesserThanOrEqual = tsSecs 291 | case "<": 292 | if params.CreatedRange == nil { 293 | params.CreatedRange = &stripe.RangeQueryParams{} 294 | } 295 | params.CreatedRange.LesserThan = tsSecs 296 | } 297 | } 298 | } 299 | 300 | limit := d.QueryContext.Limit 301 | if d.QueryContext.Limit != nil { 302 | if *limit < *params.ListParams.Limit { 303 | params.ListParams.Limit = limit 304 | } 305 | } 306 | 307 | var count int64 308 | i := conn.Charges.List(params) 309 | for i.Next() { 310 | d.StreamListItem(ctx, i.Charge()) 311 | count++ 312 | if limit != nil { 313 | if count >= *limit { 314 | break 315 | } 316 | } 317 | } 318 | if err := i.Err(); err != nil { 319 | plugin.Logger(ctx).Error("stripe_charge.listCharges", "query_error", err, "params", params, "i", i) 320 | return nil, err 321 | } 322 | 323 | return nil, nil 324 | } 325 | 326 | func getCharge(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData) (interface{}, error) { 327 | conn, err := connect(ctx, d) 328 | if err != nil { 329 | plugin.Logger(ctx).Error("stripe_charge.getCharge", "connection_error", err) 330 | return nil, err 331 | } 332 | quals := d.EqualsQuals 333 | id := quals["id"].GetStringValue() 334 | item, err := conn.Charges.Get(id, &stripe.ChargeParams{}) 335 | if err != nil { 336 | plugin.Logger(ctx).Error("stripe_charge.getCharge", "query_error", err, "id", id) 337 | return nil, err 338 | } 339 | return item, nil 340 | } 341 | -------------------------------------------------------------------------------- /stripe/table_stripe_coupon.go: -------------------------------------------------------------------------------- 1 | package stripe 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/stripe/stripe-go/v76" 7 | "github.com/turbot/steampipe-plugin-sdk/v5/grpc/proto" 8 | "github.com/turbot/steampipe-plugin-sdk/v5/plugin" 9 | "github.com/turbot/steampipe-plugin-sdk/v5/plugin/transform" 10 | ) 11 | 12 | func tableStripeCoupon(ctx context.Context) *plugin.Table { 13 | return &plugin.Table{ 14 | Name: "stripe_coupon", 15 | Description: "Coupons available for purchase or subscription.", 16 | List: &plugin.ListConfig{ 17 | Hydrate: listCoupon, 18 | KeyColumns: []*plugin.KeyColumn{ 19 | {Name: "created", Operators: []string{">", ">=", "=", "<", "<="}, Require: plugin.Optional}, 20 | }, 21 | }, 22 | Get: &plugin.GetConfig{ 23 | Hydrate: getCoupon, 24 | KeyColumns: plugin.SingleColumn("id"), 25 | }, 26 | Columns: commonColumns([]*plugin.Column{ 27 | // Top columns 28 | {Name: "id", Type: proto.ColumnType_STRING, Description: "Unique identifier for the coupon."}, 29 | {Name: "name", Type: proto.ColumnType_STRING, Description: "The coupon’s full name or business name."}, 30 | // Other columns 31 | {Name: "amount_off", Type: proto.ColumnType_INT, Transform: transform.FromField("AmountOff"), Description: "Amount (in the currency specified) that will be taken off the subtotal of any invoices for this customer."}, 32 | {Name: "created", Type: proto.ColumnType_TIMESTAMP, Transform: transform.FromField("Created").Transform(transform.UnixToTimestamp), Description: "Time at which the coupon was created."}, 33 | {Name: "currency", Type: proto.ColumnType_STRING, Description: "If amount_off has been set, the three-letter ISO code for the currency of the amount to take off."}, 34 | {Name: "deleted", Type: proto.ColumnType_BOOL, Description: "True if the customer is marked as deleted."}, 35 | {Name: "duration", Type: proto.ColumnType_STRING, Description: "One of forever, once, and repeating. Describes how long a customer who applies this coupon will get the discount."}, 36 | {Name: "duration_in_months", Type: proto.ColumnType_INT, Transform: transform.FromField("DurationInMonths"), Description: "If duration is repeating, the number of months the coupon applies. Null if coupon duration is forever or once."}, 37 | {Name: "livemode", Type: proto.ColumnType_BOOL, Description: "Has the value true if the coupon exists in live mode or the value false if the coupon exists in test mode."}, 38 | {Name: "max_redemptions", Type: proto.ColumnType_INT, Transform: transform.FromField("MaxRedemptions"), Description: "Maximum number of times this coupon can be redeemed, in total, across all customers, before it is no longer valid."}, 39 | {Name: "metadata", Type: proto.ColumnType_JSON, Description: "Set of key-value pairs that you can attach to an coupon. This can be useful for storing additional information about the coupon in a structured format."}, 40 | {Name: "percent_off", Type: proto.ColumnType_DOUBLE, Transform: transform.FromField("PercentOff"), Description: "Percent that will be taken off the subtotal of any invoices for this customer for the duration of the coupon. For example, a coupon with percent_off of 50 will make a $100 invoice $50 instead."}, 41 | {Name: "redeem_by", Type: proto.ColumnType_TIMESTAMP, Description: "Date after which the coupon can no longer be redeemed."}, 42 | {Name: "times_redeemed", Type: proto.ColumnType_INT, Transform: transform.FromField("TimesRedeemed"), Description: "Number of times this coupon has been applied to a customer."}, 43 | {Name: "valid", Type: proto.ColumnType_BOOL, Description: "Taking account of the above properties, whether this coupon can still be applied to a customer."}, 44 | }), 45 | } 46 | } 47 | 48 | func listCoupon(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData) (interface{}, error) { 49 | conn, err := connect(ctx, d) 50 | if err != nil { 51 | plugin.Logger(ctx).Error("stripe_coupon.listCoupon", "connection_error", err) 52 | return nil, err 53 | } 54 | 55 | params := &stripe.CouponListParams{ 56 | ListParams: stripe.ListParams{ 57 | Context: ctx, 58 | Limit: stripe.Int64(100), 59 | }, 60 | } 61 | 62 | quals := d.Quals 63 | 64 | if quals["created"] != nil { 65 | for _, q := range quals["created"].Quals { 66 | tsSecs := q.Value.GetTimestampValue().GetSeconds() 67 | switch q.Operator { 68 | case ">": 69 | if params.CreatedRange == nil { 70 | params.CreatedRange = &stripe.RangeQueryParams{} 71 | } 72 | params.CreatedRange.GreaterThan = tsSecs 73 | case ">=": 74 | if params.CreatedRange == nil { 75 | params.CreatedRange = &stripe.RangeQueryParams{} 76 | } 77 | params.CreatedRange.GreaterThanOrEqual = tsSecs 78 | case "=": 79 | params.Created = stripe.Int64(tsSecs) 80 | case "<=": 81 | if params.CreatedRange == nil { 82 | params.CreatedRange = &stripe.RangeQueryParams{} 83 | } 84 | params.CreatedRange.LesserThanOrEqual = tsSecs 85 | case "<": 86 | if params.CreatedRange == nil { 87 | params.CreatedRange = &stripe.RangeQueryParams{} 88 | } 89 | params.CreatedRange.LesserThan = tsSecs 90 | } 91 | } 92 | } 93 | 94 | limit := d.QueryContext.Limit 95 | if d.QueryContext.Limit != nil { 96 | if *limit < *params.ListParams.Limit { 97 | params.ListParams.Limit = limit 98 | } 99 | } 100 | 101 | var count int64 102 | i := conn.Coupons.List(params) 103 | for i.Next() { 104 | d.StreamListItem(ctx, i.Coupon()) 105 | count++ 106 | if limit != nil { 107 | if count >= *limit { 108 | break 109 | } 110 | } 111 | } 112 | if err := i.Err(); err != nil { 113 | plugin.Logger(ctx).Error("stripe_coupon.listCoupon", "query_error", err, "params", params, "i", i) 114 | return nil, err 115 | } 116 | 117 | return nil, nil 118 | } 119 | 120 | func getCoupon(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData) (interface{}, error) { 121 | conn, err := connect(ctx, d) 122 | if err != nil { 123 | plugin.Logger(ctx).Error("stripe_coupon.getCoupon", "connection_error", err) 124 | return nil, err 125 | } 126 | quals := d.EqualsQuals 127 | id := quals["id"].GetStringValue() 128 | item, err := conn.Coupons.Get(id, &stripe.CouponParams{}) 129 | if err != nil { 130 | plugin.Logger(ctx).Error("stripe_coupon.getCoupon", "query_error", err, "id", id) 131 | return nil, err 132 | } 133 | return item, nil 134 | } 135 | -------------------------------------------------------------------------------- /stripe/table_stripe_customer.go: -------------------------------------------------------------------------------- 1 | package stripe 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/stripe/stripe-go/v76" 7 | "github.com/turbot/steampipe-plugin-sdk/v5/grpc/proto" 8 | "github.com/turbot/steampipe-plugin-sdk/v5/plugin" 9 | "github.com/turbot/steampipe-plugin-sdk/v5/plugin/transform" 10 | ) 11 | 12 | func tableStripeCustomer(ctx context.Context) *plugin.Table { 13 | return &plugin.Table{ 14 | Name: "stripe_customer", 15 | Description: "Customer details.", 16 | List: &plugin.ListConfig{ 17 | Hydrate: listCustomer, 18 | KeyColumns: []*plugin.KeyColumn{ 19 | {Name: "created", Operators: []string{">", ">=", "=", "<", "<="}, Require: plugin.Optional}, 20 | {Name: "email", Require: plugin.Optional}, 21 | }, 22 | }, 23 | Get: &plugin.GetConfig{ 24 | Hydrate: getCustomer, 25 | KeyColumns: plugin.SingleColumn("id"), 26 | }, 27 | Columns: commonColumns([]*plugin.Column{ 28 | // Top columns 29 | {Name: "id", Type: proto.ColumnType_STRING, Description: "Unique identifier for the customer."}, 30 | {Name: "email", Type: proto.ColumnType_STRING, Description: "The customer’s email address."}, 31 | // Other columns 32 | {Name: "address", Type: proto.ColumnType_JSON, Description: "The customer’s address."}, 33 | {Name: "balance", Type: proto.ColumnType_INT, Transform: transform.FromField("Balance"), Description: "Current balance, if any, being stored on the customer. If negative, the customer has credit to apply to their next invoice. If positive, the customer has an amount owed that will be added to their next invoice. The balance does not refer to any unpaid invoices; it solely takes into account amounts that have yet to be successfully applied to any invoice. This balance is only taken into account as invoices are finalized."}, 34 | {Name: "created", Type: proto.ColumnType_TIMESTAMP, Transform: transform.FromField("Created").Transform(transform.UnixToTimestamp), Description: "Time at which the object was created."}, 35 | {Name: "currency", Type: proto.ColumnType_STRING, Description: "Three-letter ISO code for the currency the customer can be charged in for recurring billing purposes."}, 36 | {Name: "default_source", Type: proto.ColumnType_JSON, Description: "ID of the default payment source for the customer."}, 37 | {Name: "deleted", Type: proto.ColumnType_BOOL, Description: "True if the customer is marked as deleted."}, 38 | {Name: "delinquent", Type: proto.ColumnType_BOOL, Description: "When the customer’s latest invoice is billed by charging automatically, delinquent is true if the invoice’s latest charge failed. When the customer’s latest invoice is billed by sending an invoice, delinquent is true if the invoice isn’t paid by its due date. If an invoice is marked uncollectible by dunning, delinquent doesn’t get reset to false."}, 39 | {Name: "description", Type: proto.ColumnType_STRING, Description: "An arbitrary string attached to the object. Often useful for displaying to users."}, 40 | {Name: "discount", Type: proto.ColumnType_JSON, Description: "Describes the current discount active on the customer, if there is one."}, 41 | {Name: "invoice_prefix", Type: proto.ColumnType_STRING, Description: "The prefix for the customer used to generate unique invoice numbers."}, 42 | {Name: "invoice_settings", Type: proto.ColumnType_JSON, Description: "The customer’s default invoice settings."}, 43 | {Name: "livemode", Type: proto.ColumnType_BOOL, Description: "Has the value true if the object exists in live mode or the value false if the object exists in test mode."}, 44 | {Name: "metadata", Type: proto.ColumnType_JSON, Description: "Set of key-value pairs that you can attach to an object. This can be useful for storing additional information about the object in a structured format."}, 45 | {Name: "name", Type: proto.ColumnType_STRING, Description: "The customer’s full name or business name."}, 46 | {Name: "next_invoice_sequence", Type: proto.ColumnType_INT, Description: "The suffix of the customer’s next invoice number, e.g., 0001."}, 47 | {Name: "phone", Type: proto.ColumnType_STRING, Description: "The customer’s phone number."}, 48 | {Name: "preferred_locales", Type: proto.ColumnType_JSON, Description: "The customer’s preferred locales (languages), ordered by preference."}, 49 | {Name: "shipping", Type: proto.ColumnType_JSON, Description: "Mailing and shipping address for the customer. Appears on invoices emailed to this customer."}, 50 | //{Name: "sources", Type: proto.ColumnType_JSON, Transform: transform.FromField("Sources.Data"), Description: "The customer’s payment sources, if any."}, 51 | //{Name: "subscriptions", Type: proto.ColumnType_JSON, Transform: transform.FromField("Subscriptions.Data"), Description: "The customer’s current subscriptions, if any."}, 52 | {Name: "tax_exempt", Type: proto.ColumnType_STRING, Description: "Describes the customer’s tax exemption status. One of none, exempt, or reverse."}, 53 | {Name: "tax_ids", Type: proto.ColumnType_JSON, Description: "The customer’s tax IDs."}, 54 | }), 55 | } 56 | } 57 | 58 | func listCustomer(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData) (interface{}, error) { 59 | conn, err := connect(ctx, d) 60 | if err != nil { 61 | plugin.Logger(ctx).Error("stripe_customer.listCustomer", "connection_error", err) 62 | return nil, err 63 | } 64 | params := &stripe.CustomerListParams{ 65 | ListParams: stripe.ListParams{ 66 | Context: ctx, 67 | Limit: stripe.Int64(100), 68 | }, 69 | } 70 | 71 | q := d.EqualsQuals 72 | if q["email"] != nil { 73 | params.Email = stripe.String(q["email"].GetStringValue()) 74 | } 75 | 76 | // Comparison values 77 | quals := d.Quals 78 | 79 | if quals["created"] != nil { 80 | for _, q := range quals["created"].Quals { 81 | tsSecs := q.Value.GetTimestampValue().GetSeconds() 82 | switch q.Operator { 83 | case ">": 84 | if params.CreatedRange == nil { 85 | params.CreatedRange = &stripe.RangeQueryParams{} 86 | } 87 | params.CreatedRange.GreaterThan = tsSecs 88 | case ">=": 89 | if params.CreatedRange == nil { 90 | params.CreatedRange = &stripe.RangeQueryParams{} 91 | } 92 | params.CreatedRange.GreaterThanOrEqual = tsSecs 93 | case "=": 94 | params.Created = stripe.Int64(tsSecs) 95 | case "<=": 96 | if params.CreatedRange == nil { 97 | params.CreatedRange = &stripe.RangeQueryParams{} 98 | } 99 | params.CreatedRange.LesserThanOrEqual = tsSecs 100 | case "<": 101 | if params.CreatedRange == nil { 102 | params.CreatedRange = &stripe.RangeQueryParams{} 103 | } 104 | params.CreatedRange.LesserThan = tsSecs 105 | } 106 | } 107 | } 108 | 109 | limit := d.QueryContext.Limit 110 | if d.QueryContext.Limit != nil { 111 | if *limit < *params.ListParams.Limit { 112 | params.ListParams.Limit = limit 113 | } 114 | } 115 | 116 | var count int64 117 | i := conn.Customers.List(params) 118 | for i.Next() { 119 | d.StreamListItem(ctx, i.Customer()) 120 | count++ 121 | if limit != nil { 122 | if count >= *limit { 123 | break 124 | } 125 | } 126 | } 127 | if err := i.Err(); err != nil { 128 | plugin.Logger(ctx).Error("stripe_customer.listCustomer", "query_error", err, "params", params, "i", i) 129 | return nil, err 130 | } 131 | 132 | return nil, nil 133 | } 134 | 135 | func getCustomer(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData) (interface{}, error) { 136 | conn, err := connect(ctx, d) 137 | if err != nil { 138 | plugin.Logger(ctx).Error("stripe_customer.getCustomer", "connection_error", err) 139 | return nil, err 140 | } 141 | quals := d.EqualsQuals 142 | id := quals["id"].GetStringValue() 143 | item, err := conn.Customers.Get(id, &stripe.CustomerParams{}) 144 | if err != nil { 145 | plugin.Logger(ctx).Error("stripe_customer.getCustomer", "query_error", err, "id", id) 146 | return nil, err 147 | } 148 | return item, nil 149 | } 150 | -------------------------------------------------------------------------------- /stripe/table_stripe_invoice.go: -------------------------------------------------------------------------------- 1 | package stripe 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/stripe/stripe-go/v76" 7 | 8 | "github.com/turbot/steampipe-plugin-sdk/v5/grpc/proto" 9 | "github.com/turbot/steampipe-plugin-sdk/v5/plugin" 10 | "github.com/turbot/steampipe-plugin-sdk/v5/plugin/transform" 11 | ) 12 | 13 | func tableStripeInvoice(ctx context.Context) *plugin.Table { 14 | return &plugin.Table{ 15 | Name: "stripe_invoice", 16 | Description: "Invoices available for purchase or subscription.", 17 | List: &plugin.ListConfig{ 18 | Hydrate: listInvoice, 19 | KeyColumns: []*plugin.KeyColumn{ 20 | {Name: "collection_method", Require: plugin.Optional}, 21 | {Name: "created", Operators: []string{">", ">=", "=", "<", "<="}, Require: plugin.Optional}, 22 | {Name: "due_date", Operators: []string{">", ">=", "=", "<", "<="}, Require: plugin.Optional}, 23 | {Name: "subscription_id", Require: plugin.Optional}, 24 | {Name: "status", Require: plugin.Optional}, 25 | }, 26 | }, 27 | Get: &plugin.GetConfig{ 28 | Hydrate: getInvoice, 29 | KeyColumns: plugin.SingleColumn("id"), 30 | }, 31 | Columns: commonColumns([]*plugin.Column{ 32 | // Top columns 33 | {Name: "id", Type: proto.ColumnType_STRING, Description: "Unique identifier for the invoice."}, 34 | {Name: "number", Type: proto.ColumnType_STRING, Description: "A unique, identifying string that appears on emails sent to the customer for this invoice. This starts with the customer’s unique invoice_prefix if it is specified."}, 35 | {Name: "amount_due", Type: proto.ColumnType_INT, Transform: transform.FromField("AmountDue"), Description: "Final amount due at this time for this invoice. If the invoice’s total is smaller than the minimum charge amount, for example, or if there is account credit that can be applied to the invoice, the amount_due may be 0. If there is a positive starting_balance for the invoice (the customer owes money), the amount_due will also take that into account. The charge that gets generated for the invoice will be for the amount specified in amount_due."}, 36 | {Name: "amount_paid", Type: proto.ColumnType_INT, Transform: transform.FromField("AmountPaid"), Description: "The amount, in cents, that was paid."}, 37 | {Name: "amount_remaining", Type: proto.ColumnType_INT, Transform: transform.FromField("AmountRemaining"), Description: "The amount remaining, in cents, that is due."}, 38 | {Name: "created", Type: proto.ColumnType_TIMESTAMP, Transform: transform.FromField("Created").Transform(transform.UnixToTimestamp), Description: "Time at which the invoice was created."}, 39 | {Name: "status", Type: proto.ColumnType_STRING, Description: "The status of the invoice, one of draft, open, paid, uncollectible, or void."}, 40 | // Other columns 41 | {Name: "account_country", Type: proto.ColumnType_STRING, Description: "The country of the business associated with this invoice, most often the business creating the invoice."}, 42 | {Name: "account_name", Type: proto.ColumnType_STRING, Description: "The public name of the business associated with this invoice, most often the business creating the invoice."}, 43 | {Name: "application_fee_amount", Type: proto.ColumnType_INT, Transform: transform.FromField("ApplicationFeeAmount"), Description: "The fee in cents that will be applied to the invoice and transferred to the application owner’s Stripe account when the invoice is paid."}, 44 | {Name: "attempt_count", Type: proto.ColumnType_INT, Transform: transform.FromField("AttemptCount"), Description: "Number of payment attempts made for this invoice, from the perspective of the payment retry schedule. Any payment attempt counts as the first attempt, and subsequently only automatic retries increment the attempt count. In other words, manual payment attempts after the first attempt do not affect the retry schedule."}, 45 | {Name: "attempted", Type: proto.ColumnType_BOOL, Description: "Whether an attempt has been made to pay the invoice. An invoice is not attempted until 1 hour after the invoice.created webhook, for example, so you might not want to display that invoice as unpaid to your users."}, 46 | {Name: "auto_advance", Type: proto.ColumnType_BOOL, Description: "Controls whether Stripe will perform automatic collection of the invoice. When false, the invoice’s state will not automatically advance without an explicit action."}, 47 | {Name: "billing_reason", Type: proto.ColumnType_STRING, Description: "Indicates the reason why the invoice was created. subscription_cycle indicates an invoice created by a subscription advancing into a new period. subscription_create indicates an invoice created due to creating a subscription. subscription_update indicates an invoice created due to updating a subscription. subscription is set for all old invoices to indicate either a change to a subscription or a period advancement. manual is set for all invoices unrelated to a subscription (for example: created via the invoice editor). The upcoming value is reserved for simulated invoices per the upcoming invoice endpoint. subscription_threshold indicates an invoice created due to a billing threshold being reached."}, 48 | {Name: "charge", Type: proto.ColumnType_JSON, Description: "ID of the latest charge generated for this invoice, if any."}, 49 | {Name: "collection_method", Type: proto.ColumnType_STRING, Description: "Either charge_automatically, or send_invoice. When charging automatically, Stripe will attempt to pay this invoice using the default source attached to the customer. When sending an invoice, Stripe will email this invoice to the customer with payment instructions."}, 50 | {Name: "currency", Type: proto.ColumnType_STRING, Description: "Three-letter ISO currency code, in lowercase. Must be a supported currency."}, 51 | {Name: "custom_fields", Type: proto.ColumnType_JSON, Description: "Custom fields displayed on the invoice."}, 52 | {Name: "customer", Type: proto.ColumnType_JSON, Description: "The ID of the customer who will be billed."}, 53 | {Name: "customer_address", Type: proto.ColumnType_JSON, Description: "The customer’s address. Until the invoice is finalized, this field will equal customer.address. Once the invoice is finalized, this field will no longer be updated."}, 54 | {Name: "customer_email", Type: proto.ColumnType_STRING, Description: "The customer’s email. Until the invoice is finalized, this field will equal customer.email. Once the invoice is finalized, this field will no longer be updated."}, 55 | {Name: "customer_name", Type: proto.ColumnType_STRING, Description: "The customer’s name. Until the invoice is finalized, this field will equal customer.name. Once the invoice is finalized, this field will no longer be updated."}, 56 | {Name: "customer_phone", Type: proto.ColumnType_STRING, Description: "The customer’s phone number. Until the invoice is finalized, this field will equal customer.phone. Once the invoice is finalized, this field will no longer be updated."}, 57 | {Name: "customer_shipping", Type: proto.ColumnType_JSON, Description: "The customer’s shipping information. Until the invoice is finalized, this field will equal customer.shipping. Once the invoice is finalized, this field will no longer be updated."}, 58 | {Name: "customer_tax_exempt", Type: proto.ColumnType_STRING, Description: "The customer’s tax exempt status. Until the invoice is finalized, this field will equal customer.tax_exempt. Once the invoice is finalized, this field will no longer be updated."}, 59 | {Name: "customer_tax_ids", Type: proto.ColumnType_JSON, Description: "The customer’s tax IDs. Until the invoice is finalized, this field will contain the same tax IDs as customer.tax_ids. Once the invoice is finalized, this field will no longer be updated."}, 60 | {Name: "default_payment_method", Type: proto.ColumnType_STRING, Description: "ID of the default payment method for the invoice. It must belong to the customer associated with the invoice. If not set, defaults to the subscription’s default payment method, if any, or to the default payment method in the customer’s invoice settings."}, 61 | {Name: "default_source", Type: proto.ColumnType_STRING, Description: "ID of the default payment source for the invoice. It must belong to the customer associated with the invoice and be in a chargeable state. If not set, defaults to the subscription’s default source, if any, or to the customer’s default source."}, 62 | {Name: "default_tax_rates", Type: proto.ColumnType_JSON, Description: "The tax rates applied to this invoice, if any."}, 63 | {Name: "description", Type: proto.ColumnType_STRING, Description: "An arbitrary string attached to the object. Often useful for displaying to users. Referenced as ‘memo’ in the Dashboard."}, 64 | {Name: "discount", Type: proto.ColumnType_JSON, Description: "Describes the current discount applied to this invoice, if there is one. Not populated if there are multiple discounts."}, 65 | {Name: "due_date", Type: proto.ColumnType_TIMESTAMP, Transform: transform.FromField("DueDate").Transform(transform.UnixToTimestamp), Description: "The date on which payment for this invoice is due. This value will be null for invoices where collection_method=charge_automatically."}, 66 | {Name: "ending_balance", Type: proto.ColumnType_INT, Transform: transform.FromField("EndingBalance"), Description: "Ending customer balance after the invoice is finalized. Invoices are finalized approximately an hour after successful webhook delivery or when payment collection is attempted for the invoice. If the invoice has not been finalized yet, this will be null."}, 67 | {Name: "footer", Type: proto.ColumnType_STRING, Description: "Footer displayed on the invoice."}, 68 | {Name: "hosted_invoice_url", Type: proto.ColumnType_STRING, Description: "The URL for the hosted invoice page, which allows customers to view and pay an invoice. If the invoice has not been finalized yet, this will be null."}, 69 | {Name: "invoice_pdf", Type: proto.ColumnType_STRING, Description: "The link to download the PDF for the invoice. If the invoice has not been finalized yet, this will be null."}, 70 | {Name: "lines", Type: proto.ColumnType_JSON, Description: "The individual line items that make up the invoice. lines is sorted as follows: invoice items in reverse chronological order, followed by the subscription, if any."}, 71 | {Name: "livemode", Type: proto.ColumnType_BOOL, Description: "Has the value true if the invoice exists in live mode or the value false if the invoice exists in test mode."}, 72 | {Name: "metadata", Type: proto.ColumnType_JSON, Description: "Set of key-value pairs that you can attach to an invoice. This can be useful for storing additional information about the invoice in a structured format."}, 73 | {Name: "next_payment_attempt", Type: proto.ColumnType_TIMESTAMP, Transform: transform.FromField("NextPaymentAttempt").Transform(transform.UnixToTimestamp), Description: "The time at which payment will next be attempted. This value will be null for invoices where collection_method=send_invoice."}, 74 | {Name: "paid", Type: proto.ColumnType_BOOL, Description: "Whether payment was successfully collected for this invoice. An invoice can be paid (most commonly) with a charge or with credit from the customer’s account balance."}, 75 | {Name: "payment_intent", Type: proto.ColumnType_JSON, Description: "The PaymentIntent associated with this invoice. The PaymentIntent is generated when the invoice is finalized, and can then be used to pay the invoice. Note that voiding an invoice will cancel the PaymentIntent."}, 76 | {Name: "period_end", Type: proto.ColumnType_TIMESTAMP, Transform: transform.FromField("PeriodEnd").Transform(transform.UnixToTimestamp), Description: "End of the usage period during which invoice items were added to this invoice."}, 77 | {Name: "period_start", Type: proto.ColumnType_TIMESTAMP, Transform: transform.FromField("PeriodStart").Transform(transform.UnixToTimestamp), Description: "Start of the usage period during which invoice items were added to this invoice."}, 78 | {Name: "post_payment_credit_notes_amount", Type: proto.ColumnType_INT, Transform: transform.FromField("PostPaymentCreditNotesAmount"), Description: "Total amount of all post-payment credit notes issued for this invoice."}, 79 | {Name: "pre_payment_credit_notes_amount", Type: proto.ColumnType_INT, Transform: transform.FromField("PrePaymentCreditNotesAmount"), Description: "Total amount of all pre-payment credit notes issued for this invoice."}, 80 | {Name: "receipt_number", Type: proto.ColumnType_STRING, Description: "This is the transaction number that appears on email receipts sent for this invoice."}, 81 | {Name: "starting_balance", Type: proto.ColumnType_INT, Transform: transform.FromField("StartingBalance"), Description: "Starting customer balance before the invoice is finalized. If the invoice has not been finalized yet, this will be the current customer balance."}, 82 | {Name: "statement_descriptor", Type: proto.ColumnType_STRING, Description: "Extra information about an invoice for the customer’s credit card statement."}, 83 | {Name: "status_transitions", Type: proto.ColumnType_JSON, Description: "The timestamps at which the invoice status was updated."}, 84 | //{Name: "subscription", Type: proto.ColumnType_JSON, Description: "The subscription that this invoice was prepared for, if any."}, 85 | {Name: "subscription_id", Type: proto.ColumnType_STRING, Transform: transform.FromField("Subscription.ID"), Description: "ID of the subscription that this invoice was prepared for, if any."}, 86 | {Name: "subscription_proration_date", Type: proto.ColumnType_TIMESTAMP, Transform: transform.FromField("SubscriptionProrationDate").Transform(transform.UnixToTimestamp), Description: "Only set for upcoming invoices that preview prorations. The time used to calculate prorations."}, 87 | {Name: "subtotal", Type: proto.ColumnType_INT, Transform: transform.FromField("Subtotal"), Description: "Total of all subscriptions, invoice items, and prorations on the invoice before any invoice level discount or tax is applied. Item discounts are already incorporated"}, 88 | {Name: "tax", Type: proto.ColumnType_INT, Transform: transform.FromField("Tax"), Description: "The amount of tax on this invoice. This is the sum of all the tax amounts on this invoice."}, 89 | {Name: "threshold_reason", Type: proto.ColumnType_JSON, Description: "If billing_reason is set to subscription_threshold this returns more information on which threshold rules triggered the invoice."}, 90 | {Name: "total", Type: proto.ColumnType_INT, Transform: transform.FromField("Total"), Description: "Total after discounts and taxes."}, 91 | {Name: "total_tax_amounts", Type: proto.ColumnType_JSON, Description: "The aggregate amounts calculated per tax rate for all line items."}, 92 | {Name: "transfer_data", Type: proto.ColumnType_JSON, Description: "The account (if any) the payment will be attributed to for tax reporting, and where funds from the payment will be transferred to for the invoice."}, 93 | {Name: "webhooks_delivered_at", Type: proto.ColumnType_TIMESTAMP, Transform: transform.FromField("WebhooksDeliveredAt").Transform(transform.UnixToTimestamp), Description: "Invoices are automatically paid or sent 1 hour after webhooks are delivered, or until all webhook delivery attempts have been exhausted. This field tracks the time when webhooks for this invoice were successfully delivered. If the invoice had no webhooks to deliver, this will be set while the invoice is being created."}, 94 | }), 95 | } 96 | } 97 | 98 | func listInvoice(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData) (interface{}, error) { 99 | conn, err := connect(ctx, d) 100 | if err != nil { 101 | plugin.Logger(ctx).Error("stripe_invoice.listInvoice", "connection_error", err) 102 | return nil, err 103 | } 104 | 105 | params := &stripe.InvoiceListParams{ 106 | ListParams: stripe.ListParams{ 107 | Context: ctx, 108 | Limit: stripe.Int64(100), 109 | Expand: stripe.StringSlice([]string{"data.default_payment_method", "data.default_source", "data.subscription"}), 110 | }, 111 | } 112 | 113 | equalQuals := d.EqualsQuals 114 | if equalQuals["status"] != nil { 115 | params.Status = stripe.String(equalQuals["status"].GetStringValue()) 116 | } 117 | if equalQuals["collection_method"] != nil { 118 | params.CollectionMethod = stripe.String(equalQuals["collection_method"].GetStringValue()) 119 | } 120 | if equalQuals["subscription_id"] != nil { 121 | params.Subscription = stripe.String(equalQuals["subscription_id"].GetStringValue()) 122 | } 123 | 124 | // Comparison values 125 | quals := d.Quals 126 | 127 | if quals["created"] != nil { 128 | for _, q := range quals["created"].Quals { 129 | tsSecs := q.Value.GetTimestampValue().GetSeconds() 130 | switch q.Operator { 131 | case ">": 132 | if params.CreatedRange == nil { 133 | params.CreatedRange = &stripe.RangeQueryParams{} 134 | } 135 | params.CreatedRange.GreaterThan = tsSecs 136 | case ">=": 137 | if params.CreatedRange == nil { 138 | params.CreatedRange = &stripe.RangeQueryParams{} 139 | } 140 | params.CreatedRange.GreaterThanOrEqual = tsSecs 141 | case "=": 142 | params.Created = stripe.Int64(tsSecs) 143 | case "<=": 144 | if params.CreatedRange == nil { 145 | params.CreatedRange = &stripe.RangeQueryParams{} 146 | } 147 | params.CreatedRange.LesserThanOrEqual = tsSecs 148 | case "<": 149 | if params.CreatedRange == nil { 150 | params.CreatedRange = &stripe.RangeQueryParams{} 151 | } 152 | params.CreatedRange.LesserThan = tsSecs 153 | } 154 | } 155 | } 156 | 157 | if quals["due_date"] != nil { 158 | for _, q := range quals["due_date"].Quals { 159 | tsSecs := q.Value.GetTimestampValue().GetSeconds() 160 | switch q.Operator { 161 | case ">": 162 | if params.DueDateRange == nil { 163 | params.DueDateRange = &stripe.RangeQueryParams{} 164 | } 165 | params.DueDateRange.GreaterThan = tsSecs 166 | case ">=": 167 | if params.DueDateRange == nil { 168 | params.DueDateRange = &stripe.RangeQueryParams{} 169 | } 170 | params.DueDateRange.GreaterThanOrEqual = tsSecs 171 | case "=": 172 | params.DueDate = stripe.Int64(tsSecs) 173 | case "<=": 174 | if params.DueDateRange == nil { 175 | params.DueDateRange = &stripe.RangeQueryParams{} 176 | } 177 | params.DueDateRange.LesserThanOrEqual = tsSecs 178 | case "<": 179 | if params.DueDateRange == nil { 180 | params.DueDateRange = &stripe.RangeQueryParams{} 181 | } 182 | params.DueDateRange.LesserThan = tsSecs 183 | } 184 | } 185 | } 186 | 187 | limit := d.QueryContext.Limit 188 | if d.QueryContext.Limit != nil { 189 | if *limit < *params.ListParams.Limit { 190 | params.ListParams.Limit = limit 191 | } 192 | } 193 | 194 | var count int64 195 | i := conn.Invoices.List(params) 196 | for i.Next() { 197 | d.StreamListItem(ctx, i.Invoice()) 198 | count++ 199 | if limit != nil { 200 | if count >= *limit { 201 | break 202 | } 203 | } 204 | } 205 | if err := i.Err(); err != nil { 206 | plugin.Logger(ctx).Error("stripe_invoice.listInvoice", "query_error", err, "params", params, "i", i) 207 | return nil, err 208 | } 209 | 210 | return nil, nil 211 | } 212 | 213 | func getInvoice(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData) (interface{}, error) { 214 | conn, err := connect(ctx, d) 215 | if err != nil { 216 | plugin.Logger(ctx).Error("stripe_invoice.getInvoice", "connection_error", err) 217 | return nil, err 218 | } 219 | quals := d.EqualsQuals 220 | id := quals["id"].GetStringValue() 221 | item, err := conn.Invoices.Get(id, &stripe.InvoiceParams{}) 222 | if err != nil { 223 | plugin.Logger(ctx).Error("stripe_invoice.getInvoice", "query_error", err, "id", id) 224 | return nil, err 225 | } 226 | return item, nil 227 | } 228 | -------------------------------------------------------------------------------- /stripe/table_stripe_plan.go: -------------------------------------------------------------------------------- 1 | package stripe 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/stripe/stripe-go/v76" 7 | "github.com/turbot/steampipe-plugin-sdk/v5/grpc/proto" 8 | "github.com/turbot/steampipe-plugin-sdk/v5/plugin" 9 | "github.com/turbot/steampipe-plugin-sdk/v5/plugin/transform" 10 | ) 11 | 12 | func tableStripePlan(ctx context.Context) *plugin.Table { 13 | return &plugin.Table{ 14 | Name: "stripe_plan", 15 | Description: "Plans define the base price, currency, and billing cycle for recurring purchases of products.", 16 | List: &plugin.ListConfig{ 17 | Hydrate: listPlan, 18 | KeyColumns: []*plugin.KeyColumn{ 19 | {Name: "active", Operators: []string{"=", "<>"}, Require: plugin.Optional}, 20 | {Name: "created", Operators: []string{">", ">=", "=", "<", "<="}, Require: plugin.Optional}, 21 | {Name: "product_id", Require: plugin.Optional}, 22 | }, 23 | }, 24 | Get: &plugin.GetConfig{ 25 | Hydrate: getPlan, 26 | KeyColumns: plugin.SingleColumn("id"), 27 | }, 28 | Columns: commonColumns([]*plugin.Column{ 29 | // Top columns 30 | {Name: "id", Type: proto.ColumnType_STRING, Description: "Unique identifier for the plan."}, 31 | {Name: "nickname", Type: proto.ColumnType_STRING, Description: "A brief description of the plan, hidden from customers."}, 32 | // Other columns 33 | {Name: "active", Type: proto.ColumnType_BOOL, Description: "Whether the plan is currently available for purchase."}, 34 | {Name: "aggregate_usage", Type: proto.ColumnType_STRING, Description: "Specifies a usage aggregation strategy for plans of usage_type=metered. Allowed values are sum for summing up all usage during a period, last_during_period for using the last usage record reported within a period, last_ever for using the last usage record ever (across period bounds) or max which uses the usage record with the maximum reported usage during a period. Defaults to sum."}, 35 | {Name: "amount", Type: proto.ColumnType_INT, Transform: transform.FromField("Amount"), Description: "The unit amount in cents to be charged, represented as a whole integer if possible. Only set if billing_scheme=per_unit."}, 36 | {Name: "amount_decimal", Type: proto.ColumnType_DOUBLE, Transform: transform.FromField("AmountDecimal"), Description: "The unit amount in cents to be charged, represented as a decimal string with at most 12 decimal places. Only set if billing_scheme=per_unit."}, 37 | {Name: "billing_scheme", Type: proto.ColumnType_STRING, Description: "Describes how to compute the price per period. Either per_unit or tiered."}, 38 | {Name: "created", Type: proto.ColumnType_TIMESTAMP, Transform: transform.FromField("Created").Transform(transform.UnixToTimestamp), Description: "Time at which the plan was created."}, 39 | {Name: "currency", Type: proto.ColumnType_STRING, Description: "Three-letter ISO currency code, in lowercase. Must be a supported currency."}, 40 | {Name: "deleted", Type: proto.ColumnType_BOOL, Description: "True if the plan is marked as deleted."}, 41 | {Name: "interval", Type: proto.ColumnType_STRING, Description: "The frequency at which a subscription is billed. One of day, week, month or year."}, 42 | {Name: "interval_count", Type: proto.ColumnType_INT, Transform: transform.FromField("IntervalCount"), Description: "The number of intervals (specified in the interval attribute) between subscription billings. For example, interval=month and interval_count=3 bills every 3 months."}, 43 | {Name: "livemode", Type: proto.ColumnType_BOOL, Description: "Has the value true if the plan exists in live mode or the value false if the plan exists in test mode."}, 44 | {Name: "metadata", Type: proto.ColumnType_JSON, Description: "Set of key-value pairs that you can attach to an plan. This can be useful for storing additional information about the plan in a structured format."}, 45 | {Name: "product_id", Type: proto.ColumnType_STRING, Transform: transform.FromField("Product.ID"), Description: "ID of the product whose pricing this plan determines."}, 46 | {Name: "tiers", Type: proto.ColumnType_JSON, Description: "Each element represents a pricing tier. This parameter requires billing_scheme to be set to tiered."}, 47 | {Name: "tiers_mode", Type: proto.ColumnType_STRING, Description: "Defines if the tiering price should be graduated or volume based. In volume-based tiering, the maximum quantity within a period determines the per unit price. In graduated tiering, pricing can change as the quantity grows."}, 48 | {Name: "transform_usage", Type: proto.ColumnType_JSON, Description: "Apply a transformation to the reported usage or set quantity before computing the amount billed."}, 49 | {Name: "trial_period_days", Type: proto.ColumnType_INT, Transform: transform.FromField("TrialPeriodDays"), Description: "Default number of trial days when subscribing a customer to this plan using trial_from_plan=true."}, 50 | {Name: "usage_type", Type: proto.ColumnType_STRING, Description: "Configures how the quantity per period should be determined. Can be either metered or licensed. licensed automatically bills the quantity set when adding it to a subscription. metered aggregates the total usage based on usage records. Defaults to licensed."}, 51 | }), 52 | } 53 | } 54 | 55 | func listPlan(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData) (interface{}, error) { 56 | conn, err := connect(ctx, d) 57 | if err != nil { 58 | plugin.Logger(ctx).Error("stripe_plan.listPlan", "connection_error", err) 59 | return nil, err 60 | } 61 | params := &stripe.PlanListParams{ 62 | ListParams: stripe.ListParams{ 63 | Context: ctx, 64 | Limit: stripe.Int64(100), 65 | }, 66 | } 67 | 68 | equalQuals := d.EqualsQuals 69 | if equalQuals["product_id"] != nil { 70 | params.Product = stripe.String(equalQuals["product_id"].GetStringValue()) 71 | } 72 | 73 | // Comparison values 74 | quals := d.Quals 75 | 76 | if quals["active"] != nil { 77 | for _, q := range quals["active"].Quals { 78 | switch q.Operator { 79 | case "=": 80 | params.Active = stripe.Bool(q.Value.GetBoolValue()) 81 | case "<>": 82 | params.Active = stripe.Bool(!q.Value.GetBoolValue()) 83 | } 84 | } 85 | } 86 | 87 | if quals["created"] != nil { 88 | for _, q := range quals["created"].Quals { 89 | tsSecs := q.Value.GetTimestampValue().GetSeconds() 90 | switch q.Operator { 91 | case ">": 92 | if params.CreatedRange == nil { 93 | params.CreatedRange = &stripe.RangeQueryParams{} 94 | } 95 | params.CreatedRange.GreaterThan = tsSecs 96 | case ">=": 97 | if params.CreatedRange == nil { 98 | params.CreatedRange = &stripe.RangeQueryParams{} 99 | } 100 | params.CreatedRange.GreaterThanOrEqual = tsSecs 101 | case "=": 102 | params.Created = stripe.Int64(tsSecs) 103 | case "<=": 104 | if params.CreatedRange == nil { 105 | params.CreatedRange = &stripe.RangeQueryParams{} 106 | } 107 | params.CreatedRange.LesserThanOrEqual = tsSecs 108 | case "<": 109 | if params.CreatedRange == nil { 110 | params.CreatedRange = &stripe.RangeQueryParams{} 111 | } 112 | params.CreatedRange.LesserThan = tsSecs 113 | } 114 | } 115 | } 116 | 117 | limit := d.QueryContext.Limit 118 | if d.QueryContext.Limit != nil { 119 | if *limit < *params.ListParams.Limit { 120 | params.ListParams.Limit = limit 121 | } 122 | } 123 | 124 | var count int64 125 | i := conn.Plans.List(params) 126 | for i.Next() { 127 | d.StreamListItem(ctx, i.Plan()) 128 | count++ 129 | if limit != nil { 130 | if count >= *limit { 131 | break 132 | } 133 | } 134 | } 135 | if err := i.Err(); err != nil { 136 | plugin.Logger(ctx).Error("stripe_plan.listPlan", "query_error", err, "params", params, "i", i) 137 | return nil, err 138 | } 139 | 140 | return nil, nil 141 | } 142 | 143 | func getPlan(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData) (interface{}, error) { 144 | conn, err := connect(ctx, d) 145 | if err != nil { 146 | plugin.Logger(ctx).Error("stripe_plan.getPlan", "connection_error", err) 147 | return nil, err 148 | } 149 | quals := d.EqualsQuals 150 | id := quals["id"].GetStringValue() 151 | item, err := conn.Plans.Get(id, &stripe.PlanParams{}) 152 | if err != nil { 153 | plugin.Logger(ctx).Error("stripe_plan.getPlan", "query_error", err, "id", id) 154 | return nil, err 155 | } 156 | return item, nil 157 | } 158 | -------------------------------------------------------------------------------- /stripe/table_stripe_product.go: -------------------------------------------------------------------------------- 1 | package stripe 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/stripe/stripe-go/v76" 7 | "github.com/turbot/steampipe-plugin-sdk/v5/grpc/proto" 8 | "github.com/turbot/steampipe-plugin-sdk/v5/plugin" 9 | "github.com/turbot/steampipe-plugin-sdk/v5/plugin/transform" 10 | ) 11 | 12 | func tableStripeProduct(ctx context.Context) *plugin.Table { 13 | return &plugin.Table{ 14 | Name: "stripe_product", 15 | Description: "Products available for purchase or subscription.", 16 | List: &plugin.ListConfig{ 17 | Hydrate: listProduct, 18 | KeyColumns: []*plugin.KeyColumn{ 19 | {Name: "active", Operators: []string{"=", "<>"}, Require: plugin.Optional}, 20 | {Name: "created", Operators: []string{">", ">=", "=", "<", "<="}, Require: plugin.Optional}, 21 | {Name: "shippable", Operators: []string{"=", "<>"}, Require: plugin.Optional}, 22 | {Name: "url", Require: plugin.Optional}, 23 | }, 24 | }, 25 | Get: &plugin.GetConfig{ 26 | Hydrate: getProduct, 27 | KeyColumns: plugin.SingleColumn("id"), 28 | }, 29 | Columns: commonColumns([]*plugin.Column{ 30 | // Top columns 31 | {Name: "id", Type: proto.ColumnType_STRING, Description: "Unique identifier for the product."}, 32 | {Name: "name", Type: proto.ColumnType_STRING, Description: "The product’s full name or business name."}, 33 | {Name: "type", Type: proto.ColumnType_STRING, Description: "The product type."}, 34 | {Name: "unit_label", Type: proto.ColumnType_STRING, Description: "A label that represents units of this product in Stripe and on customers’ receipts and invoices. When set, this will be included in associated invoice line item descriptions."}, 35 | // Other columns 36 | {Name: "active", Type: proto.ColumnType_BOOL, Description: "Whether the product is currently available for purchase."}, 37 | {Name: "created", Type: proto.ColumnType_TIMESTAMP, Transform: transform.FromField("Created").Transform(transform.UnixToTimestamp), Description: "Time at which the product was created."}, 38 | {Name: "description", Type: proto.ColumnType_STRING, Description: "An arbitrary string attached to the product. Often useful for displaying to users."}, 39 | {Name: "images", Type: proto.ColumnType_JSON, Description: "A list of up to 8 URLs of images for this product, meant to be displayable to the customer."}, 40 | {Name: "livemode", Type: proto.ColumnType_BOOL, Description: "Has the value true if the product exists in live mode or the value false if the product exists in test mode."}, 41 | {Name: "metadata", Type: proto.ColumnType_JSON, Description: "Set of key-value pairs that you can attach to an product. This can be useful for storing additional information about the product in a structured format."}, 42 | {Name: "package_dimensions", Type: proto.ColumnType_JSON, Description: "The dimensions of this product for shipping purposes."}, 43 | {Name: "shippable", Type: proto.ColumnType_BOOL, Description: "Whether this product is shipped (i.e., physical goods)."}, 44 | {Name: "statement_descriptor", Type: proto.ColumnType_STRING, Description: "Extra information about a product which will appear on your customer’s credit card statement. In the case that multiple products are billed at once, the first statement descriptor will be used."}, 45 | {Name: "updated", Type: proto.ColumnType_TIMESTAMP, Transform: transform.FromField("Updated").Transform(transform.UnixToTimestamp), Description: "Time at which the product was updated."}, 46 | {Name: "url", Type: proto.ColumnType_STRING, Description: "A URL of a publicly-accessible webpage for this product."}, 47 | }), 48 | } 49 | } 50 | 51 | func listProduct(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData) (interface{}, error) { 52 | conn, err := connect(ctx, d) 53 | if err != nil { 54 | plugin.Logger(ctx).Error("stripe_product.listProduct", "connection_error", err) 55 | return nil, err 56 | } 57 | 58 | params := &stripe.ProductListParams{ 59 | ListParams: stripe.ListParams{ 60 | Context: ctx, 61 | Limit: stripe.Int64(100), 62 | }, 63 | } 64 | 65 | equalQuals := d.EqualsQuals 66 | if equalQuals["url"] != nil { 67 | // Note: I can't work out how to set and test a URL for a product? 68 | params.URL = stripe.String(equalQuals["url"].GetStringValue()) 69 | } 70 | 71 | quals := d.Quals 72 | 73 | if quals["active"] != nil { 74 | for _, q := range quals["active"].Quals { 75 | switch q.Operator { 76 | case "=": 77 | params.Active = stripe.Bool(q.Value.GetBoolValue()) 78 | case "<>": 79 | params.Active = stripe.Bool(!q.Value.GetBoolValue()) 80 | } 81 | } 82 | } 83 | 84 | if quals["shippable"] != nil { 85 | for _, q := range quals["shippable"].Quals { 86 | switch q.Operator { 87 | case "=": 88 | params.Shippable = stripe.Bool(q.Value.GetBoolValue()) 89 | case "<>": 90 | params.Shippable = stripe.Bool(!q.Value.GetBoolValue()) 91 | } 92 | } 93 | } 94 | 95 | if quals["created"] != nil { 96 | for _, q := range quals["created"].Quals { 97 | tsSecs := q.Value.GetTimestampValue().GetSeconds() 98 | switch q.Operator { 99 | case ">": 100 | if params.CreatedRange == nil { 101 | params.CreatedRange = &stripe.RangeQueryParams{} 102 | } 103 | params.CreatedRange.GreaterThan = tsSecs 104 | case ">=": 105 | if params.CreatedRange == nil { 106 | params.CreatedRange = &stripe.RangeQueryParams{} 107 | } 108 | params.CreatedRange.GreaterThanOrEqual = tsSecs 109 | case "=": 110 | params.Created = stripe.Int64(tsSecs) 111 | case "<=": 112 | if params.CreatedRange == nil { 113 | params.CreatedRange = &stripe.RangeQueryParams{} 114 | } 115 | params.CreatedRange.LesserThanOrEqual = tsSecs 116 | case "<": 117 | if params.CreatedRange == nil { 118 | params.CreatedRange = &stripe.RangeQueryParams{} 119 | } 120 | params.CreatedRange.LesserThan = tsSecs 121 | } 122 | } 123 | } 124 | 125 | limit := d.QueryContext.Limit 126 | if d.QueryContext.Limit != nil { 127 | if *limit < *params.ListParams.Limit { 128 | params.ListParams.Limit = limit 129 | } 130 | } 131 | 132 | var count int64 133 | i := conn.Products.List(params) 134 | for i.Next() { 135 | d.StreamListItem(ctx, i.Product()) 136 | count++ 137 | if limit != nil { 138 | if count >= *limit { 139 | break 140 | } 141 | } 142 | } 143 | if err := i.Err(); err != nil { 144 | plugin.Logger(ctx).Error("stripe_product.listProduct", "query_error", err, "params", params, "i", i) 145 | return nil, err 146 | } 147 | 148 | return nil, nil 149 | } 150 | 151 | func getProduct(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData) (interface{}, error) { 152 | conn, err := connect(ctx, d) 153 | if err != nil { 154 | plugin.Logger(ctx).Error("stripe_product.getProduct", "connection_error", err) 155 | return nil, err 156 | } 157 | quals := d.EqualsQuals 158 | id := quals["id"].GetStringValue() 159 | item, err := conn.Products.Get(id, &stripe.ProductParams{}) 160 | if err != nil { 161 | plugin.Logger(ctx).Error("stripe_product.getProduct", "query_error", err, "id", id) 162 | return nil, err 163 | } 164 | return item, nil 165 | } 166 | -------------------------------------------------------------------------------- /stripe/table_stripe_subscription.go: -------------------------------------------------------------------------------- 1 | package stripe 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/stripe/stripe-go/v76" 7 | "github.com/turbot/steampipe-plugin-sdk/v5/grpc/proto" 8 | "github.com/turbot/steampipe-plugin-sdk/v5/plugin" 9 | "github.com/turbot/steampipe-plugin-sdk/v5/plugin/transform" 10 | ) 11 | 12 | func tableStripeSubscription(ctx context.Context) *plugin.Table { 13 | return &plugin.Table{ 14 | Name: "stripe_subscription", 15 | Description: "Subscriptions available for purchase or subscription.", 16 | List: &plugin.ListConfig{ 17 | Hydrate: listSubscription, 18 | KeyColumns: []*plugin.KeyColumn{ 19 | {Name: "collection_method", Require: plugin.Optional}, 20 | {Name: "customer_id", Require: plugin.Optional}, 21 | {Name: "created", Operators: []string{">", ">=", "=", "<", "<="}, Require: plugin.Optional}, 22 | {Name: "current_period_end", Operators: []string{">", ">=", "=", "<", "<="}, Require: plugin.Optional}, 23 | {Name: "current_period_start", Operators: []string{">", ">=", "=", "<", "<="}, Require: plugin.Optional}, 24 | {Name: "status", Require: plugin.Optional}, 25 | }, 26 | }, 27 | Get: &plugin.GetConfig{ 28 | Hydrate: getSubscription, 29 | KeyColumns: plugin.SingleColumn("id"), 30 | }, 31 | Columns: commonColumns([]*plugin.Column{ 32 | // Top columns 33 | {Name: "id", Type: proto.ColumnType_STRING, Description: "Unique identifier for the subscription."}, 34 | {Name: "customer_id", Type: proto.ColumnType_STRING, Transform: transform.FromField("Customer.ID"), Description: "ID of the customer who owns the subscription."}, 35 | {Name: "status", Type: proto.ColumnType_STRING, Description: "Possible values are incomplete, incomplete_expired, trialing, active, past_due, canceled, or unpaid."}, 36 | // Other columns 37 | {Name: "application_fee_percent", Type: proto.ColumnType_DOUBLE, Transform: transform.FromField("ApplicationFeePercent"), Description: "A non-negative decimal between 0 and 100, with at most two decimal places. This represents the percentage of the subscription invoice subtotal that will be transferred to the application owner’s Stripe account."}, 38 | {Name: "billing_cycle_anchor", Type: proto.ColumnType_TIMESTAMP, Transform: transform.FromField("BillingCycleAnchor").Transform(transform.UnixToTimestamp), Description: "Determines the date of the first full invoice, and, for plans with month or year intervals, the day of the month for subsequent invoices."}, 39 | {Name: "billing_thresholds", Type: proto.ColumnType_JSON, Description: "Define thresholds at which an invoice will be sent, and the subscription advanced to a new billing period."}, 40 | {Name: "cancel_at", Type: proto.ColumnType_TIMESTAMP, Transform: transform.FromField("CancelAt").Transform(transform.UnixToTimestamp), Description: "A date in the future at which the subscription will automatically get canceled."}, 41 | {Name: "cancel_at_period_end", Type: proto.ColumnType_BOOL, Description: "If the subscription has been canceled with the at_period_end flag set to true, cancel_at_period_end on the subscription will be true. You can use this attribute to determine whether a subscription that has a status of active is scheduled to be canceled at the end of the current period."}, 42 | {Name: "canceled_at", Type: proto.ColumnType_TIMESTAMP, Transform: transform.FromField("CanceledAt").Transform(transform.UnixToTimestamp), Description: "If the subscription has been canceled, the date of that cancellation. If the subscription was canceled with cancel_at_period_end, canceled_at will reflect the time of the most recent update request, not the end of the subscription period when the subscription is automatically moved to a canceled state."}, 43 | {Name: "collection_method", Type: proto.ColumnType_STRING, Description: "Either charge_automatically, or send_invoice. When charging automatically, Stripe will attempt to pay this subscription at the end of the cycle using the default source attached to the customer. When sending an invoice, Stripe will email your customer an invoice with payment instructions."}, 44 | {Name: "created", Type: proto.ColumnType_TIMESTAMP, Transform: transform.FromField("Created").Transform(transform.UnixToTimestamp), Description: "Time at which the subscription was created."}, 45 | {Name: "current_period_end", Type: proto.ColumnType_TIMESTAMP, Transform: transform.FromField("CurrentPeriodEnd").Transform(transform.UnixToTimestamp), Description: "End of the current period that the subscription has been invoiced for. At the end of this period, a new invoice will be created."}, 46 | {Name: "current_period_start", Type: proto.ColumnType_TIMESTAMP, Transform: transform.FromField("CurrentPeriodStart").Transform(transform.UnixToTimestamp), Description: "Start of the current period that the subscription has been invoiced for."}, 47 | //{Name: "customer", Type: proto.ColumnType_JSON, Description: "Customer who owns the subscription."}, 48 | {Name: "days_until_due", Type: proto.ColumnType_INT, Transform: transform.FromField("DaysUntilDue"), Description: "Number of days a customer has to pay invoices generated by this subscription. This value will be null for subscriptions where collection_method=charge_automatically."}, 49 | {Name: "default_payment_method", Type: proto.ColumnType_JSON, Description: "ID of the default payment method for the subscription. It must belong to the customer associated with the subscription. This takes precedence over default_source. If neither are set, invoices will use the customer’s invoice_settings.default_payment_method or default_source."}, 50 | {Name: "default_source", Type: proto.ColumnType_JSON, Description: "ID of the default payment source for the subscription. It must belong to the customer associated with the subscription and be in a chargeable state. If default_payment_method is also set, default_payment_method will take precedence. If neither are set, invoices will use the customer’s invoice_settings.default_payment_method or default_source."}, 51 | {Name: "default_tax_rates", Type: proto.ColumnType_JSON, Description: "The tax rates that will apply to any subscription item that does not have tax_rates set. Invoices created will have their default_tax_rates populated from the subscription."}, 52 | {Name: "discount", Type: proto.ColumnType_JSON, Description: "Describes the current discount applied to this subscription, if there is one. When billing, a discount applied to a subscription overrides a discount applied on a customer-wide basis."}, 53 | {Name: "ended_at", Type: proto.ColumnType_TIMESTAMP, Transform: transform.FromField("EndedAt").Transform(transform.UnixToTimestamp), Description: "If the subscription has ended, the date the subscription ended."}, 54 | {Name: "items", Type: proto.ColumnType_JSON, Transform: transform.FromField("Items.Data"), Description: "List of subscription items, each with an attached price."}, 55 | //{Name: "latest_invoice", Type: proto.ColumnType_JSON, Description: "The most recent invoice this subscription has generated."}, 56 | {Name: "latest_invoice_id", Type: proto.ColumnType_STRING, Transform: transform.FromField("LatestInvoice.ID"), Description: "ID of the most recent invoice this subscription has generated."}, 57 | {Name: "livemode", Type: proto.ColumnType_BOOL, Description: "Has the value true if the subscription exists in live mode or the value false if the subscription exists in test mode."}, 58 | {Name: "metadata", Type: proto.ColumnType_JSON, Description: "Set of key-value pairs that you can attach to an subscription. This can be useful for storing additional information about the subscription in a structured format."}, 59 | {Name: "next_pending_invoice_item_invoice", Type: proto.ColumnType_TIMESTAMP, Transform: transform.FromField("EndedAt").Transform(transform.UnixToTimestamp), Description: "Specifies the approximate timestamp on which any pending invoice items will be billed according to the schedule provided at pending_invoice_item_interval."}, 60 | {Name: "pause_collection", Type: proto.ColumnType_JSON, Description: "If specified, payment collection for this subscription will be paused."}, 61 | {Name: "pending_invoice_item_interval", Type: proto.ColumnType_JSON, Description: "Specifies an interval for how often to bill for any pending invoice items. It is analogous to calling Create an invoice for the given subscription at the specified interval."}, 62 | {Name: "pending_setup_intent", Type: proto.ColumnType_STRING, Description: "You can use this SetupIntent to collect user authentication when creating a subscription without immediate payment or updating a subscription’s payment method, allowing you to optimize for off-session payments. Learn more in the SCA Migration Guide."}, 63 | {Name: "pending_update", Type: proto.ColumnType_JSON, Description: "If specified, pending updates that will be applied to the subscription once the latest_invoice has been paid."}, 64 | //{Name: "plan", Type: proto.ColumnType_JSON, Description: ""}, 65 | //{Name: "quantity", Type: proto.ColumnType_INT, Transform: transform.FromField("Quantity"), Description: ""}, 66 | {Name: "schedule", Type: proto.ColumnType_JSON, Description: "The schedule attached to the subscription."}, 67 | {Name: "start_date", Type: proto.ColumnType_TIMESTAMP, Transform: transform.FromField("StartDate").Transform(transform.UnixToTimestamp), Description: "Date when the subscription was first created. The date might differ from the created date due to backdating."}, 68 | {Name: "transfer_data", Type: proto.ColumnType_JSON, Description: "The account (if any) the subscription’s payments will be attributed to for tax reporting, and where funds from each payment will be transferred to for each of the subscription’s invoices."}, 69 | {Name: "trial_end", Type: proto.ColumnType_TIMESTAMP, Transform: transform.FromField("TrialEnd").Transform(transform.UnixToTimestamp), Description: "If the subscription has a trial, the end of that trial."}, 70 | {Name: "trial_start", Type: proto.ColumnType_TIMESTAMP, Transform: transform.FromField("TrialStart").Transform(transform.UnixToTimestamp), Description: "If the subscription has a trial, the start of that trial."}, 71 | }), 72 | } 73 | } 74 | 75 | func listSubscription(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData) (interface{}, error) { 76 | conn, err := connect(ctx, d) 77 | if err != nil { 78 | plugin.Logger(ctx).Error("stripe_subscription.listSubscription", "connection_error", err) 79 | return nil, err 80 | } 81 | 82 | params := &stripe.SubscriptionListParams{ 83 | ListParams: stripe.ListParams{ 84 | Context: ctx, 85 | Limit: stripe.Int64(100), 86 | }, 87 | } 88 | 89 | // Exact values can leverage optional key quals for optimal caching 90 | q := d.EqualsQuals 91 | 92 | customerId := q["customer_id"].GetStringValue() 93 | if customerId != "" { 94 | params.Customer = &customerId 95 | } 96 | 97 | if q["collection_method"] != nil { 98 | params.CollectionMethod = stripe.String(q["collection_method"].GetStringValue()) 99 | } 100 | 101 | status := q["status"].GetStringValue() 102 | if status != "" { 103 | params.Status = &status 104 | } 105 | 106 | // Comparison values 107 | quals := d.Quals 108 | 109 | if quals["created"] != nil { 110 | for _, q := range quals["created"].Quals { 111 | tsSecs := q.Value.GetTimestampValue().GetSeconds() 112 | switch q.Operator { 113 | case ">": 114 | if params.CreatedRange == nil { 115 | params.CreatedRange = &stripe.RangeQueryParams{} 116 | } 117 | params.CreatedRange.GreaterThan = tsSecs 118 | case ">=": 119 | if params.CreatedRange == nil { 120 | params.CreatedRange = &stripe.RangeQueryParams{} 121 | } 122 | params.CreatedRange.GreaterThanOrEqual = tsSecs 123 | case "=": 124 | params.Created = &tsSecs 125 | case "<=": 126 | if params.CreatedRange == nil { 127 | params.CreatedRange = &stripe.RangeQueryParams{} 128 | } 129 | params.CreatedRange.LesserThanOrEqual = tsSecs 130 | case "<": 131 | if params.CreatedRange == nil { 132 | params.CreatedRange = &stripe.RangeQueryParams{} 133 | } 134 | params.CreatedRange.LesserThan = tsSecs 135 | } 136 | } 137 | } 138 | 139 | if quals["current_period_start"] != nil { 140 | for _, q := range quals["current_period_start"].Quals { 141 | tsSecs := q.Value.GetTimestampValue().GetSeconds() 142 | switch q.Operator { 143 | case ">": 144 | if params.CurrentPeriodStartRange == nil { 145 | params.CurrentPeriodStartRange = &stripe.RangeQueryParams{} 146 | } 147 | params.CurrentPeriodStartRange.GreaterThan = tsSecs 148 | case ">=": 149 | if params.CurrentPeriodStartRange == nil { 150 | params.CurrentPeriodStartRange = &stripe.RangeQueryParams{} 151 | } 152 | params.CurrentPeriodStartRange.GreaterThanOrEqual = tsSecs 153 | case "=": 154 | params.CurrentPeriodStart = stripe.Int64(tsSecs) 155 | case "<=": 156 | if params.CurrentPeriodStartRange == nil { 157 | params.CurrentPeriodStartRange = &stripe.RangeQueryParams{} 158 | } 159 | params.CurrentPeriodStartRange.LesserThanOrEqual = tsSecs 160 | case "<": 161 | if params.CurrentPeriodStartRange == nil { 162 | params.CurrentPeriodStartRange = &stripe.RangeQueryParams{} 163 | } 164 | params.CurrentPeriodStartRange.LesserThan = tsSecs 165 | } 166 | } 167 | } 168 | 169 | if quals["current_period_end"] != nil { 170 | for _, q := range quals["current_period_end"].Quals { 171 | tsSecs := q.Value.GetTimestampValue().GetSeconds() 172 | switch q.Operator { 173 | case ">": 174 | if params.CurrentPeriodEndRange == nil { 175 | params.CurrentPeriodEndRange = &stripe.RangeQueryParams{} 176 | } 177 | params.CurrentPeriodEndRange.GreaterThan = tsSecs 178 | case ">=": 179 | if params.CurrentPeriodEndRange == nil { 180 | params.CurrentPeriodEndRange = &stripe.RangeQueryParams{} 181 | } 182 | params.CurrentPeriodEndRange.GreaterThanOrEqual = tsSecs 183 | case "=": 184 | params.CurrentPeriodEnd = stripe.Int64(tsSecs) 185 | case "<=": 186 | if params.CurrentPeriodEndRange == nil { 187 | params.CurrentPeriodEndRange = &stripe.RangeQueryParams{} 188 | } 189 | params.CurrentPeriodEndRange.LesserThanOrEqual = tsSecs 190 | case "<": 191 | if params.CurrentPeriodEndRange == nil { 192 | params.CurrentPeriodEndRange = &stripe.RangeQueryParams{} 193 | } 194 | params.CurrentPeriodEndRange.LesserThan = tsSecs 195 | } 196 | } 197 | } 198 | 199 | limit := d.QueryContext.Limit 200 | if d.QueryContext.Limit != nil { 201 | if *limit < *params.ListParams.Limit { 202 | params.ListParams.Limit = limit 203 | } 204 | } 205 | 206 | var count int64 207 | i := conn.Subscriptions.List(params) 208 | for i.Next() { 209 | d.StreamListItem(ctx, i.Subscription()) 210 | count++ 211 | if limit != nil { 212 | if count >= *limit { 213 | break 214 | } 215 | } 216 | } 217 | if err := i.Err(); err != nil { 218 | plugin.Logger(ctx).Error("stripe_subscription.listSubscription", "query_error", err, "params", params, "i", i) 219 | return nil, err 220 | } 221 | 222 | return nil, nil 223 | } 224 | 225 | func getSubscription(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData) (interface{}, error) { 226 | conn, err := connect(ctx, d) 227 | if err != nil { 228 | plugin.Logger(ctx).Error("stripe_subscription.getSubscription", "connection_error", err) 229 | return nil, err 230 | } 231 | quals := d.EqualsQuals 232 | id := quals["id"].GetStringValue() 233 | item, err := conn.Subscriptions.Get(id, &stripe.SubscriptionParams{}) 234 | if err != nil { 235 | plugin.Logger(ctx).Error("stripe_subscription.getSubscription", "query_error", err, "id", id) 236 | return nil, err 237 | } 238 | return item, nil 239 | } 240 | -------------------------------------------------------------------------------- /stripe/table_stripe_subscription_item.go: -------------------------------------------------------------------------------- 1 | package stripe 2 | 3 | import ( 4 | "context" 5 | //"time" 6 | 7 | "github.com/stripe/stripe-go/v76" 8 | "github.com/turbot/steampipe-plugin-sdk/v5/grpc/proto" 9 | "github.com/turbot/steampipe-plugin-sdk/v5/plugin" 10 | "github.com/turbot/steampipe-plugin-sdk/v5/plugin/transform" 11 | ) 12 | 13 | func tableStripeSubscriptionItem(ctx context.Context) *plugin.Table { 14 | return &plugin.Table{ 15 | Name: "stripe_subscription_item", 16 | Description: "Subscription Items in Stripe represent the individual products that a customer is subscribed to.", 17 | List: &plugin.ListConfig{ 18 | KeyColumns: plugin.SingleColumn("subscription_id"), 19 | Hydrate: listSubscriptionItem, 20 | }, 21 | Columns: commonColumns([]*plugin.Column{ 22 | // Add columns relevant to SubscriptionItems here 23 | {Name: "id", Type: proto.ColumnType_STRING, Description: "Unique identifier for the subscription."}, 24 | {Name: "plan", Type: proto.ColumnType_JSON, Transform: transform.FromField("Plan"), Description: "A plan represents a billing configuration. (Deprecated)"}, 25 | {Name: "price", Type: proto.ColumnType_JSON, Transform: transform.FromField("Price"), Description: "A price represents a unit cost for a product, specifying the amount, currency, and billing frequency."}, 26 | {Name: "subscription_id", Type: proto.ColumnType_STRING, Transform: transform.FromField("Subscription"), Description: "The ID of the subscription this item belongs to."}, 27 | {Name: "usage_record_summaries", Type: proto.ColumnType_JSON, Hydrate: listUsageRecordSummaries, Transform: transform.FromValue()}, 28 | }), 29 | } 30 | } 31 | 32 | // listSubscriptionItem lists all subscription items 33 | func listSubscriptionItem(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData) (interface{}, error) { 34 | conn, err := connect(ctx, d) 35 | if err != nil { 36 | plugin.Logger(ctx).Error("stripe_subscription.listSubscriptionItem", "connection_error", err) 37 | return nil, err 38 | } 39 | 40 | subscription_id := d.EqualsQuals["subscription_id"].GetStringValue() 41 | plugin.Logger(ctx).Debug("stripe_subscription.listSubscriptionItem", "subscription_id", subscription_id) 42 | 43 | params := &stripe.SubscriptionItemListParams{ 44 | Subscription: stripe.String(subscription_id), 45 | } 46 | 47 | i := conn.SubscriptionItems.List(params) 48 | 49 | for i.Next() { 50 | d.StreamListItem(ctx, i.SubscriptionItem()) 51 | } 52 | 53 | return nil, nil 54 | } 55 | 56 | func listUsageRecordSummaries(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { 57 | item := h.Item.(*stripe.SubscriptionItem) 58 | 59 | plugin.Logger(ctx).Debug("stripe_subscription.listUsageRecordSummaries", "item", item) 60 | 61 | conn, err := connect(ctx, d) 62 | if err != nil { 63 | plugin.Logger(ctx).Error("stripe_subscription.listSubscriptionItem", "connection_error", err) 64 | return nil, err 65 | } 66 | 67 | params := &stripe.SubscriptionItemUsageRecordSummariesParams{ 68 | SubscriptionItem: stripe.String(item.ID), 69 | } 70 | 71 | var summaries []*stripe.UsageRecordSummary 72 | u := conn.SubscriptionItems.UsageRecordSummaries(params) 73 | for u.Next() { 74 | summary := u.UsageRecordSummary() 75 | summaries = append(summaries, summary) 76 | } 77 | 78 | return summaries, nil 79 | } 80 | -------------------------------------------------------------------------------- /stripe/utils.go: -------------------------------------------------------------------------------- 1 | package stripe 2 | 3 | import ( 4 | "context" 5 | "errors" 6 | "os" 7 | 8 | "github.com/stripe/stripe-go/v76" 9 | "github.com/stripe/stripe-go/v76/client" 10 | 11 | "github.com/turbot/steampipe-plugin-sdk/v5/plugin" 12 | ) 13 | 14 | func connect(_ context.Context, d *plugin.QueryData) (*client.API, error) { 15 | 16 | // Load connection from cache, which preserves throttling protection etc 17 | cacheKey := "stripe" 18 | if cachedData, ok := d.ConnectionManager.Cache.Get(cacheKey); ok { 19 | return cachedData.(*client.API), nil 20 | } 21 | 22 | // Define our app information 23 | stripe.SetAppInfo(&stripe.AppInfo{ 24 | Name: "Steampipe", 25 | URL: "https://hub.steampipe.io/plugins/turbot/stripe", 26 | }) 27 | 28 | // Default to using env vars 29 | apiKey := os.Getenv("STRIPE_API_KEY") 30 | 31 | // But prefer the config 32 | stripeConfig := GetConfig(d.Connection) 33 | if stripeConfig.APIKey != nil { 34 | apiKey = *stripeConfig.APIKey 35 | } 36 | 37 | if apiKey == "" { 38 | // Credentials not set 39 | return nil, errors.New("api_key must be configured") 40 | } 41 | 42 | maxRetries := int64(10) 43 | config := &stripe.BackendConfig{ 44 | MaxNetworkRetries: &maxRetries, 45 | } 46 | 47 | conn := &client.API{} 48 | conn.Init(apiKey, &stripe.Backends{ 49 | API: stripe.GetBackendWithConfig(stripe.APIBackend, config), 50 | Uploads: stripe.GetBackendWithConfig(stripe.UploadsBackend, config), 51 | }) 52 | 53 | // Save to cache 54 | d.ConnectionManager.Cache.Set(cacheKey, conn) 55 | 56 | return conn, nil 57 | } 58 | --------------------------------------------------------------------------------