├── .github ├── CONTRIBUTING.md ├── FUNDING.yml └── workflows │ └── ci.yml ├── .gitignore ├── .idea ├── .gitignore ├── .name ├── codeStyleSettings.xml ├── codeStyles │ ├── Project.xml │ └── codeStyleConfig.xml ├── copyright │ ├── apache.xml │ └── profiles_settings.xml ├── encodings.xml ├── inspectionProfiles │ ├── Project_Default.xml │ └── profiles_settings.xml ├── misc.xml ├── scopes │ └── scope_settings.xml └── vcs.xml ├── LICENSE ├── README.md ├── pom.xml └── src ├── main └── java │ └── org │ └── killbill │ └── billing │ └── plugin │ └── helloworld │ ├── HelloWorldActivator.java │ ├── HelloWorldConfigurationHandler.java │ ├── HelloWorldHealthcheck.java │ ├── HelloWorldHealthcheckServlet.java │ ├── HelloWorldInvoicePluginApi.java │ ├── HelloWorldListener.java │ ├── HelloWorldPaymentPluginApi.java │ ├── HelloWorldServlet.java │ └── MetricsGeneratorExample.java └── test └── resources └── log4jdbc.log4j2.properties /.github/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | ## How to contribute to Kill Bill 2 | 3 | **Do not open up a GitHub issue before reaching out to our [Mailing-List](https://groups.google.com/forum/#!forum/killbilling-users)**. GitHub issues are primarily intended for tracking bug reports and fixes by the core team. 4 | 5 | #### **Did you find a bug?** 6 | 7 | In your [Mailing-List](https://groups.google.com/forum/#!forum/killbilling-users) post, specify: 8 | 9 | * Step by step description on how to reproduce the issue 10 | * [Account data and system dump](http://docs.killbill.io/latest/debugging.html#_seeking_help) via KPM of an affected account 11 | 12 | #### **Do you intend to add a new feature or change an existing one?** 13 | 14 | Do not open an issue or pull request on GitHub until you have collected positive feedback about the change on the [Mailing-List](https://groups.google.com/forum/#!forum/killbilling-users). 15 | 16 | When submitting code, make sure to add [new tests](http://docs.killbill.io/latest/development.html#_navigating_the_kill_bill_codebase). 17 | 18 | #### **Do you want to contribute to the Kill Bill documentation?** 19 | 20 | Open a pull request on GitHub in the [killbill-docs](https://github.com/killbill/killbill-docs) repository. 21 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: [killbill] 4 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: ci 2 | 3 | on: 4 | push: 5 | pull_request: 6 | workflow_dispatch: 7 | 8 | jobs: 9 | ci: 10 | uses: killbill/gh-actions-shared/.github/workflows/ci.yml@main 11 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # 2 | # https://github.com/github/gitignore/blob/599646e9d0a26283d67715dead8f26e0eb2df753/Global/JetBrains.gitignore 3 | # 4 | 5 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider 6 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 7 | 8 | # User-specific stuff 9 | .idea/**/workspace.xml 10 | .idea/**/tasks.xml 11 | .idea/**/usage.statistics.xml 12 | .idea/**/dictionaries 13 | .idea/**/shelf 14 | 15 | # Generated files 16 | .idea/**/contentModel.xml 17 | 18 | # Sensitive or high-churn files 19 | .idea/**/dataSources/ 20 | .idea/**/dataSources.ids 21 | .idea/**/dataSources.local.xml 22 | .idea/**/sqlDataSources.xml 23 | .idea/**/dynamic.xml 24 | .idea/**/uiDesigner.xml 25 | .idea/**/dbnavigator.xml 26 | 27 | # Gradle 28 | .idea/**/gradle.xml 29 | .idea/**/libraries 30 | 31 | # Gradle and Maven with auto-import 32 | # When using Gradle or Maven with auto-import, you should exclude module files, 33 | # since they will be recreated, and may cause churn. Uncomment if using 34 | # auto-import. 35 | .idea/artifacts 36 | .idea/compiler.xml 37 | .idea/jarRepositories.xml 38 | .idea/modules.xml 39 | .idea/*.iml 40 | .idea/modules 41 | *.iml 42 | *.ipr 43 | 44 | # CMake 45 | cmake-build-*/ 46 | 47 | # Mongo Explorer plugin 48 | .idea/**/mongoSettings.xml 49 | 50 | # File-based project format 51 | *.iws 52 | 53 | # IntelliJ 54 | out/ 55 | 56 | # mpeltonen/sbt-idea plugin 57 | .idea_modules/ 58 | 59 | # JIRA plugin 60 | atlassian-ide-plugin.xml 61 | 62 | # Cursive Clojure plugin 63 | .idea/replstate.xml 64 | 65 | # Crashlytics plugin (for Android Studio and IntelliJ) 66 | com_crashlytics_export_strings.xml 67 | crashlytics.properties 68 | crashlytics-build.properties 69 | fabric.properties 70 | 71 | # Editor-based Rest Client 72 | .idea/httpRequests 73 | 74 | # Android studio 3.1+ serialized cache file 75 | .idea/caches/build_file_checksums.ser 76 | 77 | # 78 | # https://github.com/github/gitignore/blob/36ce3a894d9ddff2916bc98d71380aa7167ff1d7/Global/Eclipse.gitignore 79 | # 80 | 81 | .metadata 82 | bin/ 83 | tmp/ 84 | *.tmp 85 | *.bak 86 | *.swp 87 | *~.nib 88 | local.properties 89 | .settings/ 90 | .loadpath 91 | .recommenders 92 | .classpath 93 | 94 | # External tool builders 95 | .externalToolBuilders/ 96 | 97 | # Locally stored "Eclipse launch configurations" 98 | *.launch 99 | 100 | # PyDev specific (Python IDE for Eclipse) 101 | *.pydevproject 102 | 103 | # CDT-specific (C/C++ Development Tooling) 104 | .cproject 105 | 106 | # CDT- autotools 107 | .autotools 108 | 109 | # Java annotation processor (APT) 110 | .factorypath 111 | 112 | # PDT-specific (PHP Development Tools) 113 | .buildpath 114 | 115 | # sbteclipse plugin 116 | .target 117 | 118 | # Tern plugin 119 | .tern-project 120 | 121 | # TeXlipse plugin 122 | .texlipse 123 | 124 | # STS (Spring Tool Suite) 125 | .springBeans 126 | 127 | # Code Recommenders 128 | .recommenders/ 129 | 130 | # Annotation Processing 131 | .apt_generated/ 132 | .apt_generated_test/ 133 | 134 | # Scala IDE specific (Scala & Java development for Eclipse) 135 | .cache-main 136 | .scala_dependencies 137 | .worksheet 138 | 139 | # Uncomment this line if you wish to ignore the project description file. 140 | # Typically, this file would be tracked if it contains build/dependency configurations: 141 | .project 142 | 143 | # 144 | # https://github.com/github/gitignore/blob/6651bca9c83572f908474fc6206ed8a80df91290/Maven.gitignore 145 | # 146 | 147 | target/ 148 | pom.xml.tag 149 | pom.xml.releaseBackup 150 | pom.xml.versionsBackup 151 | pom.xml.next 152 | release.properties 153 | dependency-reduced-pom.xml 154 | buildNumber.properties 155 | .mvn/timing.properties 156 | # https://github.com/takari/maven-wrapper#usage-without-binary-jar 157 | .mvn/wrapper/maven-wrapper.jar 158 | 159 | # 160 | # https://github.com/github/gitignore/blob/36ce3a894d9ddff2916bc98d71380aa7167ff1d7/Java.gitignore 161 | # 162 | 163 | # Compiled class file 164 | *.class 165 | 166 | # Log file 167 | *.log 168 | 169 | # BlueJ files 170 | *.ctxt 171 | 172 | # Mobile Tools for Java (J2ME) 173 | .mtj.tmp/ 174 | 175 | # Package Files # 176 | *.jar 177 | *.war 178 | *.nar 179 | *.ear 180 | *.zip 181 | *.tar.gz 182 | *.rar 183 | 184 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 185 | hs_err_pid* 186 | 187 | # 188 | # https://github.com/github/gitignore/blob/320a610b9ffba3ff28166370b6dd9f73096e34b7/Global/macOS.gitignore 189 | # 190 | 191 | # General 192 | .DS_Store 193 | .AppleDouble 194 | .LSOverride 195 | 196 | # Icon must end with two \r 197 | Icon 198 | 199 | 200 | # Thumbnails 201 | ._* 202 | 203 | # Files that might appear in the root of a volume 204 | .DocumentRevisions-V100 205 | .fseventsd 206 | .Spotlight-V100 207 | .TemporaryItems 208 | .Trashes 209 | .VolumeIcon.icns 210 | .com.apple.timemachine.donotpresent 211 | 212 | # Directories potentially created on remote AFP share 213 | .AppleDB 214 | .AppleDesktop 215 | Network Trash Folder 216 | Temporary Items 217 | .apdisk 218 | 219 | # 220 | # https://github.com/github/gitignore/blob/320a610b9ffba3ff28166370b6dd9f73096e34b7/Global/TextMate.gitignore 221 | # 222 | 223 | *.tmproj 224 | *.tmproject 225 | tmtags 226 | -------------------------------------------------------------------------------- /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | # Datasource local storage ignored files 5 | /dataSources/ 6 | /dataSources.local.xml 7 | # Editor-based HTTP Client requests 8 | /httpRequests/ 9 | -------------------------------------------------------------------------------- /.idea/.name: -------------------------------------------------------------------------------- 1 | hello-world-plugin -------------------------------------------------------------------------------- /.idea/codeStyleSettings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 59 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /.idea/codeStyles/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 12 | 28 | 29 | 30 | 33 | 34 | 56 | 57 | -------------------------------------------------------------------------------- /.idea/codeStyles/codeStyleConfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | -------------------------------------------------------------------------------- /.idea/copyright/apache.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/Project_Default.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 53 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 9 | 10 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /.idea/scopes/scope_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # killbill-hello-world-java-plugin 2 | 3 | Hello World Kill Bill plugin in Java. It shows how to: 4 | 5 | * Build an OSGI plugin using Maven 6 | * Listen to Kill Bill events 7 | * Call Kill Bill APIs from the plugin 8 | * Register a custom HTTP servlet 9 | 10 | ## Getting Started 11 | 12 | To build, run `mvn clean install`. You can then install the plugin locally: 13 | 14 | ``` 15 | kpm install_java_plugin helloworld --from-source-file target/hello-world-plugin-*-SNAPSHOT.jar --destination /var/tmp/bundles 16 | ``` 17 | 18 | You can also use it as a template for your own plugins: 19 | 20 | ```bash 21 | curl https://codeload.github.com/killbill/killbill-hello-world-java-plugin/tar.gz/master | tar zxvf - --strip-components=1 22 | rm -rf .circleci LICENSE .idea/copyright 23 | 24 | PACKAGE=acme 25 | PREFIX=Acme 26 | 27 | mv src/main/java/org/killbill/billing/plugin/helloworld src/main/java/org/killbill/billing/plugin/$PACKAGE 28 | find . -name 'HelloWorld*.java' -exec bash -c 'mv $0 ${0/HelloWorld/'$PREFIX'}' {} \; 29 | 30 | find pom.xml src -type f -print0 | xargs -0 sed -i '' 's/org\.killbill\.billing\.plugin\.helloworld/org\.killbill\.billing\.plugin\.'$PACKAGE'/g' 31 | find pom.xml src -type f -print0 | xargs -0 sed -i '' 's/HelloWorld/'$PREFIX'/g' 32 | find pom.xml src -type f -print0 | xargs -0 sed -i '' 's/helloWorld/'$PACKAGE'/g' 33 | find .idea pom.xml src -type f -print0 | xargs -0 sed -i '' 's/hello-world-/'$PACKAGE'-/g' 34 | ``` 35 | 36 | Finally, modify the pom.xml with your own Git urls. 37 | 38 | ## About 39 | 40 | Kill Bill is the leading Open-Source Subscription Billing & Payments Platform. For more information about the project, go to https://killbill.io/. 41 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 4.0.0 22 | 23 | org.kill-bill.billing 24 | killbill-oss-parent 25 | 0.146.30 26 | 27 | org.kill-bill.billing.plugin.java 28 | hello-world-plugin 29 | 2.0.1-SNAPSHOT 30 | bundle 31 | Kill Bill OSGI Hello World bundle 32 | Kill Bill Hello World plugin 33 | http://github.com/killbill/killbill-hello-world-java-plugin 34 | 35 | scm:git:git://github.com/killbill/killbill-hello-world-java-plugin.git 36 | scm:git:git@github.com:killbill/killbill-hello-world-java-plugin.git 37 | http://github.com/killbill/killbill-hello-world-java-plugin/tree/master 38 | 39 | 40 | Github 41 | https://github.com/killbill/killbill-hello-world-java-plugin/issues 42 | 43 | 44 | true 45 | true 46 | true 47 | true 48 | true 49 | true 50 | true 51 | org.killbill.billing.plugin.helloworld.* 52 | 53 | 54 | 55 | com.fasterxml.jackson.core 56 | jackson-core 57 | 58 | 59 | com.google.code.findbugs 60 | jsr305 61 | 62 | 63 | com.google.inject 64 | guice 65 | 66 | 67 | jakarta.servlet 68 | jakarta.servlet-api 69 | provided 70 | 71 | 72 | javax.inject 73 | javax.inject 74 | 75 | 76 | joda-time 77 | joda-time 78 | provided 79 | 80 | 81 | org.apache.felix 82 | org.apache.felix.framework 83 | provided 84 | 85 | 86 | org.jooby 87 | jooby 88 | 89 | 90 | org.kill-bill.billing 91 | killbill-api 92 | provided 93 | 94 | 95 | org.kill-bill.billing 96 | killbill-platform-osgi-api 97 | provided 98 | 99 | 100 | org.kill-bill.billing 101 | killbill-platform-osgi-bundles-lib-killbill 102 | provided 103 | 104 | 105 | org.kill-bill.billing.plugin 106 | killbill-plugin-api-invoice 107 | 108 | 109 | org.kill-bill.billing.plugin 110 | killbill-plugin-api-notification 111 | provided 112 | 113 | 114 | org.kill-bill.billing.plugin 115 | killbill-plugin-api-payment 116 | provided 117 | 118 | 119 | org.kill-bill.billing.plugin.java 120 | killbill-base-plugin 121 | 122 | 123 | org.kill-bill.billing.plugin.java 124 | killbill-base-plugin 125 | test-jar 126 | test 127 | 128 | 129 | org.kill-bill.commons 130 | killbill-clock 131 | 132 | 133 | org.kill-bill.commons 134 | killbill-metrics-api 135 | provided 136 | 137 | 138 | org.slf4j 139 | slf4j-api 140 | provided 141 | 142 | 143 | 144 | org.testng 145 | testng 146 | test 147 | 148 | 149 | 150 | 151 | 152 | org.apache.felix 153 | maven-bundle-plugin 154 | 155 | 156 | 157 | 158 | -------------------------------------------------------------------------------- /src/main/java/org/killbill/billing/plugin/helloworld/HelloWorldActivator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2014 Ning, Inc. 3 | * Copyright 2014-2020 Groupon, Inc 4 | * Copyright 2020-2020 Equinix, Inc 5 | * Copyright 2014-2020 The Billing Project, LLC 6 | * 7 | * The Billing Project licenses this file to you under the Apache License, version 2.0 8 | * (the "License"); you may not use this file except in compliance with the 9 | * License. You may obtain a copy of the License at: 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 15 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 16 | * License for the specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package org.killbill.billing.plugin.helloworld; 21 | 22 | import java.util.Hashtable; 23 | import java.util.Properties; 24 | 25 | import javax.servlet.Servlet; 26 | import javax.servlet.http.HttpServlet; 27 | 28 | import org.killbill.billing.invoice.plugin.api.InvoicePluginApi; 29 | import org.killbill.billing.osgi.api.Healthcheck; 30 | import org.killbill.billing.osgi.api.OSGIPluginProperties; 31 | import org.killbill.billing.osgi.libs.killbill.KillbillActivatorBase; 32 | import org.killbill.billing.osgi.libs.killbill.OSGIKillbillEventDispatcher; 33 | import org.killbill.billing.osgi.libs.killbill.OSGIKillbillEventDispatcher.OSGIFrameworkEventHandler; 34 | import org.killbill.billing.payment.plugin.api.PaymentPluginApi; 35 | import org.killbill.billing.plugin.api.notification.PluginConfigurationEventHandler; 36 | import org.killbill.billing.plugin.core.config.PluginEnvironmentConfig; 37 | import org.killbill.billing.plugin.core.resources.jooby.PluginApp; 38 | import org.killbill.billing.plugin.core.resources.jooby.PluginAppBuilder; 39 | import org.osgi.framework.BundleContext; 40 | import org.osgi.util.tracker.ServiceTracker; 41 | import org.killbill.billing.invoice.plugin.api.InvoiceFormatterFactory; 42 | 43 | public class HelloWorldActivator extends KillbillActivatorBase { 44 | 45 | // 46 | // Ideally that string should match the pluginName on the filesystem, but there 47 | // is no enforcement 48 | // 49 | public static final String PLUGIN_NAME = "hello-world-plugin"; 50 | 51 | private HelloWorldConfigurationHandler helloWorldConfigurationHandler; 52 | private OSGIKillbillEventDispatcher.OSGIKillbillEventHandler killbillEventHandler; 53 | private MetricsGeneratorExample metricsGenerator; 54 | 55 | private ServiceTracker invoiceFormatterTracker; 56 | 57 | @Override 58 | public void start(final BundleContext context) throws Exception { 59 | super.start(context); 60 | 61 | final String region = PluginEnvironmentConfig.getRegion(configProperties.getProperties()); 62 | 63 | // Register an event listener for plugin configuration (optional) 64 | helloWorldConfigurationHandler = new HelloWorldConfigurationHandler(region, PLUGIN_NAME, killbillAPI); 65 | final Properties globalConfiguration = helloWorldConfigurationHandler 66 | .createConfigurable(configProperties.getProperties()); 67 | helloWorldConfigurationHandler.setDefaultConfigurable(globalConfiguration); 68 | 69 | // create a service tracker for a custom InvoiceFormatter service 70 | invoiceFormatterTracker = new ServiceTracker<>(context, InvoiceFormatterFactory.class, null); 71 | invoiceFormatterTracker.open(); 72 | 73 | 74 | // Register an event listener (optional) 75 | killbillEventHandler = new HelloWorldListener(killbillAPI, invoiceFormatterTracker, configProperties.getProperties()); 76 | 77 | // As an example, this plugin registers a PaymentPluginApi (this could be 78 | // changed to any other plugin api) 79 | final PaymentPluginApi paymentPluginApi = new HelloWorldPaymentPluginApi(); 80 | registerPaymentPluginApi(context, paymentPluginApi); 81 | 82 | // Expose metrics (optional) 83 | metricsGenerator = new MetricsGeneratorExample(metricRegistry); 84 | metricsGenerator.start(); 85 | 86 | // Expose a healthcheck (optional), so other plugins can check on the plugin status 87 | final Healthcheck healthcheck = new HelloWorldHealthcheck(); 88 | registerHealthcheck(context, healthcheck); 89 | 90 | // This Plugin registers a InvoicePluginApi 91 | final InvoicePluginApi invoicePluginApi = new HelloWorldInvoicePluginApi(killbillAPI, configProperties, null); 92 | registerInvoicePluginApi(context, invoicePluginApi); 93 | 94 | // Register a servlet (optional) 95 | final PluginApp pluginApp = new PluginAppBuilder(PLUGIN_NAME, killbillAPI, dataSource, super.clock, 96 | configProperties).withRouteClass(HelloWorldServlet.class) 97 | .withRouteClass(HelloWorldHealthcheckServlet.class).withService(healthcheck).build(); 98 | final HttpServlet httpServlet = PluginApp.createServlet(pluginApp); 99 | registerServlet(context, httpServlet); 100 | 101 | registerHandlers(); 102 | } 103 | 104 | @Override 105 | public void stop(final BundleContext context) throws Exception { 106 | // Do additional work on shutdown (optional) 107 | metricsGenerator.stop(); 108 | super.stop(context); 109 | } 110 | 111 | private void registerHandlers() { 112 | final PluginConfigurationEventHandler configHandler = new PluginConfigurationEventHandler( 113 | helloWorldConfigurationHandler); 114 | 115 | dispatcher.registerEventHandlers(configHandler, 116 | (OSGIFrameworkEventHandler) () -> dispatcher.registerEventHandlers(killbillEventHandler)); 117 | } 118 | 119 | private void registerServlet(final BundleContext context, final Servlet servlet) { 120 | final Hashtable props = new Hashtable(); 121 | props.put(OSGIPluginProperties.PLUGIN_NAME_PROP, PLUGIN_NAME); 122 | registrar.registerService(context, Servlet.class, servlet, props); 123 | } 124 | 125 | private void registerPaymentPluginApi(final BundleContext context, final PaymentPluginApi api) { 126 | final Hashtable props = new Hashtable(); 127 | props.put(OSGIPluginProperties.PLUGIN_NAME_PROP, PLUGIN_NAME); 128 | registrar.registerService(context, PaymentPluginApi.class, api, props); 129 | } 130 | 131 | private void registerInvoicePluginApi(final BundleContext context, final InvoicePluginApi api) { 132 | final Hashtable props = new Hashtable(); 133 | props.put(OSGIPluginProperties.PLUGIN_NAME_PROP, PLUGIN_NAME); 134 | registrar.registerService(context, InvoicePluginApi.class, api, props); 135 | } 136 | 137 | private void registerHealthcheck(final BundleContext context, final Healthcheck healthcheck) { 138 | final Hashtable props = new Hashtable(); 139 | props.put(OSGIPluginProperties.PLUGIN_NAME_PROP, PLUGIN_NAME); 140 | registrar.registerService(context, Healthcheck.class, healthcheck, props); 141 | } 142 | } 143 | -------------------------------------------------------------------------------- /src/main/java/org/killbill/billing/plugin/helloworld/HelloWorldConfigurationHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2014 Ning, Inc. 3 | * Copyright 2014-2020 Groupon, Inc 4 | * Copyright 2020-2020 Equinix, Inc 5 | * Copyright 2014-2020 The Billing Project, LLC 6 | * 7 | * The Billing Project licenses this file to you under the Apache License, version 2.0 8 | * (the "License"); you may not use this file except in compliance with the 9 | * License. You may obtain a copy of the License at: 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 15 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 16 | * License for the specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package org.killbill.billing.plugin.helloworld; 21 | 22 | import java.util.Properties; 23 | 24 | import org.killbill.billing.osgi.libs.killbill.OSGIKillbillAPI; 25 | import org.killbill.billing.plugin.api.notification.PluginTenantConfigurableConfigurationHandler; 26 | import org.slf4j.Logger; 27 | import org.slf4j.LoggerFactory; 28 | 29 | /** 30 | * When per-tenant config changes are made, the plugin automatically gets notified (and prints a log trace) 31 | *
32 |  * {@code
33 |  * curl -v \
34 |  *      -X POST \
35 |  *      -u admin:password \
36 |  *      -H "Content-Type: text/plain" \
37 |  *      -H "X-Killbill-ApiKey: bob" \
38 |  *      -H "X-Killbill-ApiSecret: lazar" \
39 |  *      -H "X-Killbill-CreatedBy: demo" \
40 |  *      -d 'key1=foo1
41 |  * key2=foo2' \
42 |  *      "http://127.0.0.1:8080/1.0/kb/tenants/uploadPluginConfig/hello-world-plugin"
43 |  * }
44 |  * 
45 | */ 46 | public class HelloWorldConfigurationHandler extends PluginTenantConfigurableConfigurationHandler { 47 | 48 | private static final Logger logger = LoggerFactory.getLogger(HelloWorldConfigurationHandler.class); 49 | 50 | private final String region; 51 | 52 | public HelloWorldConfigurationHandler(final String region, 53 | final String pluginName, 54 | final OSGIKillbillAPI osgiKillbillAPI) { 55 | super(pluginName, osgiKillbillAPI); 56 | this.region = region; 57 | } 58 | 59 | @Override 60 | protected Properties createConfigurable(final Properties properties) { 61 | logger.info("New properties for region {}: {}", region, properties); 62 | return properties; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/org/killbill/billing/plugin/helloworld/HelloWorldHealthcheck.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2014 Ning, Inc. 3 | * Copyright 2014-2020 Groupon, Inc 4 | * Copyright 2020-2020 Equinix, Inc 5 | * Copyright 2014-2020 The Billing Project, LLC 6 | * 7 | * The Billing Project licenses this file to you under the Apache License, version 2.0 8 | * (the "License"); you may not use this file except in compliance with the 9 | * License. You may obtain a copy of the License at: 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 15 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 16 | * License for the specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package org.killbill.billing.plugin.helloworld; 21 | 22 | import java.util.Map; 23 | 24 | import javax.annotation.Nullable; 25 | 26 | import org.killbill.billing.osgi.api.Healthcheck; 27 | import org.killbill.billing.tenant.api.Tenant; 28 | 29 | public class HelloWorldHealthcheck implements Healthcheck { 30 | 31 | @Override 32 | public HealthStatus getHealthStatus(@Nullable final Tenant tenant, @Nullable final Map properties) { 33 | return HealthStatus.healthy(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/org/killbill/billing/plugin/helloworld/HelloWorldHealthcheckServlet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2014 Ning, Inc. 3 | * Copyright 2014-2020 Groupon, Inc 4 | * Copyright 2020-2020 Equinix, Inc 5 | * Copyright 2014-2020 The Billing Project, LLC 6 | * 7 | * The Billing Project licenses this file to you under the Apache License, version 2.0 8 | * (the "License"); you may not use this file except in compliance with the 9 | * License. You may obtain a copy of the License at: 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 15 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 16 | * License for the specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package org.killbill.billing.plugin.helloworld; 21 | 22 | import java.util.Optional; 23 | 24 | import javax.inject.Named; 25 | import javax.inject.Singleton; 26 | 27 | import org.jooby.Result; 28 | import org.jooby.mvc.GET; 29 | import org.jooby.mvc.Local; 30 | import org.jooby.mvc.Path; 31 | import org.killbill.billing.plugin.core.resources.PluginHealthcheck; 32 | import org.killbill.billing.tenant.api.Tenant; 33 | 34 | import com.fasterxml.jackson.core.JsonProcessingException; 35 | import com.google.inject.Inject; 36 | 37 | @Singleton 38 | @Path("/healthcheck") 39 | public class HelloWorldHealthcheckServlet extends PluginHealthcheck { 40 | 41 | private final HelloWorldHealthcheck healthcheck; 42 | 43 | @Inject 44 | public HelloWorldHealthcheckServlet(final HelloWorldHealthcheck healthcheck) { 45 | this.healthcheck = healthcheck; 46 | } 47 | 48 | @GET 49 | public Result check(@Local @Named("killbill_tenant") final Optional tenant) throws JsonProcessingException { 50 | return check(healthcheck, tenant.orElse(null), null); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/org/killbill/billing/plugin/helloworld/HelloWorldInvoicePluginApi.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020-2022 Equinix, Inc 3 | * Copyright 2014-2022 The Billing Project, LLC 4 | * 5 | * The Billing Project licenses this file to you under the Apache License, version 2.0 6 | * (the "License"); you may not use this file except in compliance with the 7 | * License. You may obtain a copy of the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations 15 | * under the License. 16 | */ 17 | 18 | package org.killbill.billing.plugin.helloworld; 19 | 20 | import java.math.BigDecimal; 21 | import java.util.HashSet; 22 | import java.util.LinkedList; 23 | import java.util.List; 24 | import java.util.Set; 25 | import java.util.UUID; 26 | 27 | import org.killbill.billing.account.api.Account; 28 | import org.killbill.billing.invoice.api.Invoice; 29 | import org.killbill.billing.invoice.api.InvoiceItem; 30 | import org.killbill.billing.invoice.api.InvoiceItemType; 31 | import org.killbill.billing.invoice.plugin.api.AdditionalItemsResult; 32 | import org.killbill.billing.invoice.plugin.api.InvoiceContext; 33 | import org.killbill.billing.notification.plugin.api.ExtBusEvent; 34 | import org.killbill.billing.osgi.libs.killbill.OSGIConfigPropertiesService; 35 | import org.killbill.billing.osgi.libs.killbill.OSGIKillbillAPI; 36 | import org.killbill.billing.osgi.libs.killbill.OSGIKillbillEventDispatcher.OSGIKillbillEventHandler; 37 | import org.killbill.billing.payment.api.PluginProperty; 38 | import org.killbill.billing.plugin.api.invoice.PluginInvoiceItem; 39 | import org.killbill.billing.plugin.api.invoice.PluginInvoicePluginApi; 40 | import org.killbill.billing.util.callcontext.TenantContext; 41 | import org.killbill.clock.Clock; 42 | 43 | class HelloWorldInvoicePluginApi extends PluginInvoicePluginApi implements OSGIKillbillEventHandler { 44 | 45 | public HelloWorldInvoicePluginApi(final OSGIKillbillAPI killbillAPI, final OSGIConfigPropertiesService configProperties, 46 | final Clock clock) { 47 | super(killbillAPI, configProperties, clock); 48 | } 49 | 50 | /** 51 | * Returns additional invoice items to be added to invoice 52 | *

53 | * This method produces two types of invoice items a. Tax Item on Invoice Item 54 | * b. Adjustment Item on only the very first Historical Invoice Tax Item 55 | * automatically ( just for Demo purpose ) 56 | * 57 | * @param newInvoice The invoice that is being created. 58 | * @param dryRun Whether it is dryRun or not 59 | * @param properties Any user-specified plugin properties, coming straight out 60 | * of the API request that has triggered this code to run. 61 | * @param callCtx The context in which this code is running. 62 | * @return A new immutable list of new tax items, or adjustments on existing tax 63 | * items. 64 | */ 65 | @Override 66 | public AdditionalItemsResult getAdditionalInvoiceItems(final Invoice newInvoice, final boolean dryRun, 67 | final Iterable properties, final InvoiceContext invoiceContext) { 68 | 69 | final UUID accountId = newInvoice.getAccountId(); 70 | final Account account = getAccount(accountId, invoiceContext); 71 | final Set allInvoices = getAllInvoicesOfAccount(account, newInvoice, invoiceContext); 72 | final List additionalItems = new LinkedList(); 73 | 74 | // Creating tax item for first Item of new Invoice 75 | final List newInvoiceItems = newInvoice.getInvoiceItems(); 76 | final InvoiceItem newInvoiceItem = newInvoiceItems.get(0); 77 | BigDecimal charge = new BigDecimal("80"); 78 | final InvoiceItem taxItem = PluginInvoiceItem.createTaxItem(newInvoiceItem, newInvoiceItem.getInvoiceId(), 79 | newInvoice.getInvoiceDate(), null, charge, "Tax Item"); 80 | additionalItems.add(taxItem); 81 | 82 | // Creating External Charge for first Item of new Invoice 83 | final InvoiceItem externalItem = PluginInvoiceItem.create(newInvoiceItem, newInvoiceItem.getInvoiceId(), 84 | newInvoice.getInvoiceDate(), null, charge, "External Item", InvoiceItemType.EXTERNAL_CHARGE); 85 | additionalItems.add(externalItem); 86 | 87 | // Adding adjustment invoice item to the first historical invoice, if it does not have the adjustment item 88 | for (final Invoice invoice : allInvoices) { 89 | if (!invoice.getId().equals(newInvoice.getId())) { 90 | final List invoiceItems = invoice.getInvoiceItems(); 91 | // Check for if any adjustment item exists for Historical Invoice 92 | if (checkforAdjustmentItem(invoiceItems)) { 93 | break; 94 | } 95 | for (final InvoiceItem item : invoiceItems) { 96 | charge = new BigDecimal("-30"); 97 | final InvoiceItem adjItem = PluginInvoiceItem.createAdjustmentItem(item, item.getInvoiceId(), 98 | newInvoice.getInvoiceDate(), newInvoice.getInvoiceDate(), charge, "Adjustment Item"); 99 | additionalItems.add(adjItem); 100 | break; 101 | } 102 | break; 103 | } 104 | } 105 | 106 | return new AdditionalItemsResult() { 107 | @Override 108 | public List getAdditionalItems() { 109 | return additionalItems; 110 | } 111 | 112 | @Override 113 | public Iterable getAdjustedPluginProperties() { 114 | return null; 115 | } 116 | }; 117 | } 118 | 119 | /** 120 | * This method returns all invoices of account 121 | * 122 | * @param account The account to consider. 123 | * @param newInvoice New Invoice Item to be added to existing invoices of the 124 | * account 125 | * @param tenantCtx 126 | * @return All invoices of account 127 | */ 128 | private Set getAllInvoicesOfAccount(final Account account, final Invoice newInvoice, final TenantContext tenantCtx) { 129 | final Set invoices = new HashSet(); 130 | invoices.addAll(getInvoicesByAccountId(account.getId(), tenantCtx)); 131 | invoices.add(newInvoice); 132 | return invoices; 133 | } 134 | 135 | /** 136 | * Check whether adjustment item is already present in invoice Item of Invoice 137 | * 138 | * @param invoiceItems 139 | * @return 140 | */ 141 | private boolean checkforAdjustmentItem(final List invoiceItems) { 142 | boolean adjustmentItemPresent = false; 143 | for (final InvoiceItem invoiceItem : invoiceItems) { 144 | if (invoiceItem.getInvoiceItemType().equals(InvoiceItemType.ITEM_ADJ)) { 145 | adjustmentItemPresent = true; 146 | break; 147 | } 148 | } 149 | return adjustmentItemPresent; 150 | } 151 | 152 | protected boolean isTaxItem(final InvoiceItem invoiceItem) { 153 | return InvoiceItemType.TAX.equals(invoiceItem.getInvoiceItemType()); 154 | } 155 | 156 | @Override 157 | public void handleKillbillEvent(final ExtBusEvent killbillEvent) { 158 | } 159 | 160 | } 161 | -------------------------------------------------------------------------------- /src/main/java/org/killbill/billing/plugin/helloworld/HelloWorldListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2014 Ning, Inc. 3 | * Copyright 2014-2020 Groupon, Inc 4 | * Copyright 2020-2020 Equinix, Inc 5 | * Copyright 2014-2020 The Billing Project, LLC 6 | * 7 | * The Billing Project licenses this file to you under the Apache License, version 2.0 8 | * (the "License"); you may not use this file except in compliance with the 9 | * License. You may obtain a copy of the License at: 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 15 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 16 | * License for the specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package org.killbill.billing.plugin.helloworld; 21 | 22 | import java.util.List; 23 | import java.util.Locale; 24 | import java.util.Properties; 25 | 26 | import org.joda.time.LocalDate; 27 | import org.killbill.billing.account.api.Account; 28 | import org.killbill.billing.account.api.AccountApiException; 29 | import org.killbill.billing.invoice.api.Invoice; 30 | import org.killbill.billing.invoice.api.InvoiceItem; 31 | import org.killbill.billing.invoice.api.formatters.InvoiceFormatter; 32 | import org.killbill.billing.invoice.api.formatters.InvoiceItemFormatter; 33 | import org.killbill.billing.invoice.plugin.api.InvoiceFormatterFactory; 34 | import org.killbill.billing.notification.plugin.api.ExtBusEvent; 35 | import org.killbill.billing.osgi.libs.killbill.OSGIKillbillAPI; 36 | import org.killbill.billing.osgi.libs.killbill.OSGIKillbillEventDispatcher; 37 | import org.killbill.billing.plugin.api.PluginTenantContext; 38 | import org.killbill.billing.util.callcontext.TenantContext; 39 | import org.osgi.util.tracker.ServiceTracker; 40 | import org.slf4j.Logger; 41 | import org.slf4j.LoggerFactory; 42 | 43 | public class HelloWorldListener implements OSGIKillbillEventDispatcher.OSGIKillbillEventHandler { 44 | 45 | private static final Logger logger = LoggerFactory.getLogger(HelloWorldListener.class); 46 | 47 | private final OSGIKillbillAPI osgiKillbillAPI; 48 | 49 | private final ServiceTracker invoiceFormatterTracker; 50 | 51 | private final Properties configProperties; 52 | 53 | public HelloWorldListener(final OSGIKillbillAPI killbillAPI, final ServiceTracker invoiceFormatterTracker, Properties configProperties) { 54 | this.osgiKillbillAPI = killbillAPI; 55 | this.invoiceFormatterTracker = invoiceFormatterTracker; 56 | this.configProperties = configProperties; 57 | } 58 | 59 | private static final String defaultLocale = "en_US"; 60 | 61 | @Override 62 | public void handleKillbillEvent(final ExtBusEvent killbillEvent) { 63 | logger.info("Received event {} for object id {} of type {}", 64 | killbillEvent.getEventType(), 65 | killbillEvent.getObjectId(), 66 | killbillEvent.getObjectType()); 67 | 68 | final TenantContext context = new PluginTenantContext(killbillEvent.getAccountId(), killbillEvent.getTenantId()); 69 | switch (killbillEvent.getEventType()) { 70 | // 71 | // Handle ACCOUNT_CREATION and ACCOUNT_CHANGE only for demo purpose and just print the account 72 | // 73 | case ACCOUNT_CREATION: 74 | case ACCOUNT_CHANGE: 75 | try { 76 | final Account account = osgiKillbillAPI.getAccountUserApi().getAccountById(killbillEvent.getAccountId(), context); 77 | logger.info("Account information: " + account); 78 | } catch (final AccountApiException e) { 79 | logger.warn("Unable to find account", e); 80 | } 81 | break; 82 | case INVOICE_CREATION: 83 | 84 | final Account account; 85 | try { 86 | account = osgiKillbillAPI.getAccountUserApi().getAccountById(killbillEvent.getAccountId(), context); 87 | } catch (AccountApiException e) { 88 | throw new RuntimeException(e); 89 | } 90 | final List invoices = osgiKillbillAPI.getInvoiceUserApi().getInvoicesByAccount(killbillEvent.getAccountId(), false, false, true, context); 91 | logger.info("Invoices in hello-world-plugin {}: ",invoices.size()); 92 | 93 | final String invoiceFormatterPluginName = configProperties.getProperty("org.killbill.template.invoiceFormatterFactoryPluginName"); 94 | if(invoiceFormatterPluginName == null || invoiceFormatterPluginName.isEmpty()){ 95 | logger.info("Invoice formatter plugin not configured. set the org.killbill.template.invoiceFormatterFactoryPluginName property to configure it"); 96 | return; 97 | } 98 | 99 | final InvoiceFormatterFactory formatterFactory = (invoiceFormatterTracker != null ? invoiceFormatterTracker.getService() : null); 100 | Invoice invoice = invoices.get(0); //For demo purpose, we are only retrieving the formattedEndDate for the first invoice 101 | //TODO Using null for parameters like catalogBundlePath,bundle, defaultBundle, etc. Update this to use correct values if possible or verify that using null values has no adverse effect 102 | 103 | InvoiceFormatter invoiceFormatter = formatterFactory.createInvoiceFormatter(defaultLocale, null, invoice, Locale.forLanguageTag(account.getLocale()), osgiKillbillAPI.getCurrencyConversionApi(), null, null); 104 | 105 | List items = invoiceFormatter.getInvoiceItems(); 106 | logger.info("hello-world-plugin got items:{}",items.size()); 107 | for(InvoiceItem item:items) { 108 | final InvoiceItemFormatter invoiceItemFormatter = (InvoiceItemFormatter)item; 109 | final String formattedEndDate = invoiceItemFormatter.getFormattedEndDate(); 110 | logger.info("hello-world-plugin formattedEndDate:{}",formattedEndDate); 111 | } 112 | // Nothing 113 | default: 114 | break; 115 | 116 | } 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /src/main/java/org/killbill/billing/plugin/helloworld/HelloWorldPaymentPluginApi.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2014 Ning, Inc. 3 | * Copyright 2014-2020 Groupon, Inc 4 | * Copyright 2020-2020 Equinix, Inc 5 | * Copyright 2014-2020 The Billing Project, LLC 6 | * 7 | * The Billing Project licenses this file to you under the Apache License, version 2.0 8 | * (the "License"); you may not use this file except in compliance with the 9 | * License. You may obtain a copy of the License at: 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 15 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 16 | * License for the specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package org.killbill.billing.plugin.helloworld; 21 | 22 | import java.math.BigDecimal; 23 | import java.util.List; 24 | import java.util.UUID; 25 | 26 | import org.killbill.billing.catalog.api.Currency; 27 | import org.killbill.billing.payment.api.PaymentMethodPlugin; 28 | import org.killbill.billing.payment.api.PluginProperty; 29 | import org.killbill.billing.payment.plugin.api.GatewayNotification; 30 | import org.killbill.billing.payment.plugin.api.HostedPaymentPageFormDescriptor; 31 | import org.killbill.billing.payment.plugin.api.PaymentMethodInfoPlugin; 32 | import org.killbill.billing.payment.plugin.api.PaymentPluginApi; 33 | import org.killbill.billing.payment.plugin.api.PaymentPluginApiException; 34 | import org.killbill.billing.payment.plugin.api.PaymentTransactionInfoPlugin; 35 | import org.killbill.billing.util.callcontext.CallContext; 36 | import org.killbill.billing.util.callcontext.TenantContext; 37 | import org.killbill.billing.util.entity.Pagination; 38 | 39 | // 40 | // A 'real' payment plugin would of course implement this interface. 41 | // 42 | public class HelloWorldPaymentPluginApi implements PaymentPluginApi { 43 | 44 | @Override 45 | public PaymentTransactionInfoPlugin authorizePayment(final UUID kbAccountId, final UUID kbPaymentId, final UUID kbTransactionId, final UUID kbPaymentMethodId, final BigDecimal amount, final Currency currency, final Iterable properties, final CallContext context) throws PaymentPluginApiException { 46 | return null; 47 | } 48 | 49 | @Override 50 | public PaymentTransactionInfoPlugin capturePayment(final UUID kbAccountId, final UUID kbPaymentId, final UUID kbTransactionId, final UUID kbPaymentMethodId, final BigDecimal amount, final Currency currency, final Iterable properties, final CallContext context) throws PaymentPluginApiException { 51 | return null; 52 | } 53 | 54 | @Override 55 | public PaymentTransactionInfoPlugin purchasePayment(final UUID kbAccountId, final UUID kbPaymentId, final UUID kbTransactionId, final UUID kbPaymentMethodId, final BigDecimal amount, final Currency currency, final Iterable properties, final CallContext context) throws PaymentPluginApiException { 56 | return null; 57 | } 58 | 59 | @Override 60 | public PaymentTransactionInfoPlugin voidPayment(final UUID kbAccountId, final UUID kbPaymentId, final UUID kbTransactionId, final UUID kbPaymentMethodId, final Iterable properties, final CallContext context) throws PaymentPluginApiException { 61 | return null; 62 | } 63 | 64 | @Override 65 | public PaymentTransactionInfoPlugin creditPayment(final UUID kbAccountId, final UUID kbPaymentId, final UUID kbTransactionId, final UUID kbPaymentMethodId, final BigDecimal amount, final Currency currency, final Iterable properties, final CallContext context) throws PaymentPluginApiException { 66 | return null; 67 | } 68 | 69 | @Override 70 | public PaymentTransactionInfoPlugin refundPayment(final UUID kbAccountId, final UUID kbPaymentId, final UUID kbTransactionId, final UUID kbPaymentMethodId, final BigDecimal amount, final Currency currency, final Iterable properties, final CallContext context) throws PaymentPluginApiException { 71 | return null; 72 | } 73 | 74 | @Override 75 | public List getPaymentInfo(final UUID kbAccountId, final UUID kbPaymentId, final Iterable properties, final TenantContext context) throws PaymentPluginApiException { 76 | return null; 77 | } 78 | 79 | @Override 80 | public Pagination searchPayments(final String searchKey, final Long offset, final Long limit, final Iterable properties, final TenantContext context) throws PaymentPluginApiException { 81 | return null; 82 | } 83 | 84 | @Override 85 | public void addPaymentMethod(final UUID kbAccountId, final UUID kbPaymentMethodId, final PaymentMethodPlugin paymentMethodProps, final boolean setDefault, final Iterable properties, final CallContext context) throws PaymentPluginApiException { 86 | 87 | } 88 | 89 | @Override 90 | public void deletePaymentMethod(final UUID kbAccountId, final UUID kbPaymentMethodId, final Iterable properties, final CallContext context) throws PaymentPluginApiException { 91 | 92 | } 93 | 94 | @Override 95 | public PaymentMethodPlugin getPaymentMethodDetail(final UUID kbAccountId, final UUID kbPaymentMethodId, final Iterable properties, final TenantContext context) throws PaymentPluginApiException { 96 | return null; 97 | } 98 | 99 | @Override 100 | public void setDefaultPaymentMethod(final UUID kbAccountId, final UUID kbPaymentMethodId, final Iterable properties, final CallContext context) throws PaymentPluginApiException { 101 | 102 | } 103 | 104 | @Override 105 | public List getPaymentMethods(final UUID kbAccountId, final boolean refreshFromGateway, final Iterable properties, final CallContext context) throws PaymentPluginApiException { 106 | return null; 107 | } 108 | 109 | @Override 110 | public Pagination searchPaymentMethods(final String searchKey, final Long offset, final Long limit, final Iterable properties, final TenantContext context) throws PaymentPluginApiException { 111 | return null; 112 | } 113 | 114 | @Override 115 | public void resetPaymentMethods(final UUID kbAccountId, final List paymentMethods, final Iterable properties, final CallContext context) throws PaymentPluginApiException { 116 | 117 | } 118 | 119 | @Override 120 | public HostedPaymentPageFormDescriptor buildFormDescriptor(final UUID kbAccountId, final Iterable customFields, final Iterable properties, final CallContext context) throws PaymentPluginApiException { 121 | return null; 122 | } 123 | 124 | @Override 125 | public GatewayNotification processNotification(final String notification, final Iterable properties, final CallContext context) throws PaymentPluginApiException { 126 | return null; 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /src/main/java/org/killbill/billing/plugin/helloworld/HelloWorldServlet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2014 Ning, Inc. 3 | * Copyright 2014-2020 Groupon, Inc 4 | * Copyright 2020-2020 Equinix, Inc 5 | * Copyright 2014-2020 The Billing Project, LLC 6 | * 7 | * The Billing Project licenses this file to you under the Apache License, version 2.0 8 | * (the "License"); you may not use this file except in compliance with the 9 | * License. You may obtain a copy of the License at: 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 15 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 16 | * License for the specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package org.killbill.billing.plugin.helloworld; 21 | 22 | import java.util.Optional; 23 | import javax.inject.Named; 24 | import javax.inject.Singleton; 25 | 26 | import org.jooby.mvc.GET; 27 | import org.jooby.mvc.Local; 28 | import org.jooby.mvc.Path; 29 | import org.killbill.billing.tenant.api.Tenant; 30 | import org.slf4j.Logger; 31 | import org.slf4j.LoggerFactory; 32 | 33 | 34 | @Singleton 35 | @Path("/") 36 | public class HelloWorldServlet { 37 | 38 | private static final Logger logger = LoggerFactory.getLogger(HelloWorldServlet.class); 39 | 40 | public HelloWorldServlet() { 41 | } 42 | 43 | /** 44 | * Kill Bill automatically injects Tenant object in this method when this end point is accessed with the X-Killbill-ApiKey and X-Killbill-ApiSecret headers 45 | * @param tenant 46 | */ 47 | @GET 48 | public void hello(@Local @Named("killbill_tenant") final Optional tenant) { 49 | // Find me on http://127.0.0.1:8080/plugins/hello-world-plugin 50 | logger.info("Hello world"); 51 | if(tenant != null && tenant.isPresent() ) { 52 | logger.info("tenant is available"); 53 | Tenant t1 = tenant.get(); 54 | logger.info("tenant id:"+t1.getId()); 55 | } 56 | else { 57 | logger.info("tenant is not available"); 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/org/killbill/billing/plugin/helloworld/MetricsGeneratorExample.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020-2022 Equinix, Inc 3 | * Copyright 2014-2022 The Billing Project, LLC 4 | * 5 | * The Billing Project licenses this file to you under the Apache License, version 2.0 6 | * (the "License"); you may not use this file except in compliance with the 7 | * License. You may obtain a copy of the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations 15 | * under the License. 16 | */ 17 | 18 | package org.killbill.billing.plugin.helloworld; 19 | 20 | import org.killbill.billing.osgi.libs.killbill.OSGIMetricRegistry; 21 | import org.killbill.billing.osgi.libs.killbill.OSGIServiceNotAvailable; 22 | import org.slf4j.Logger; 23 | import org.slf4j.LoggerFactory; 24 | 25 | public class MetricsGeneratorExample { 26 | 27 | private static final Logger logger = LoggerFactory.getLogger(MetricsGeneratorExample.class); 28 | 29 | private final Thread thread; 30 | 31 | private volatile boolean stopMetrics; 32 | 33 | public MetricsGeneratorExample(final OSGIMetricRegistry metricRegistry) { 34 | this.thread = new Thread(new Runnable() { 35 | public void run() { 36 | while (!stopMetrics) { 37 | try { 38 | Thread.sleep(1000L); 39 | } catch (final InterruptedException ignored) { 40 | Thread.currentThread().interrupt(); 41 | logger.info("MetricsGenerator shutting down"); 42 | break; 43 | } 44 | 45 | try { 46 | metricRegistry.getMetricRegistry().counter("hello_counter").inc(1); 47 | } catch (final OSGIServiceNotAvailable ignored) { 48 | // No MetricRegistry available 49 | logger.warn("No MetricRegistry available"); 50 | } 51 | } 52 | } 53 | }); 54 | } 55 | 56 | public void start() { 57 | thread.start(); 58 | } 59 | 60 | public void stop() { 61 | stopMetrics = true; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/test/resources/log4jdbc.log4j2.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2020-2020 Equinix, Inc 3 | # Copyright 2020-2020 The Billing Project, LLC 4 | # 5 | # The Billing Project licenses this file to you under the Apache License, version 2.0 6 | # (the "License"); you may not use this file except in compliance with the 7 | # License. You may obtain a copy of the License at: 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | # License for the specific language governing permissions and limitations 15 | # under the License. 16 | # 17 | # Configure the SpyLogDelegator to use SLF4J. By default, the library expects Log4j2 (see SpyLogFactory#loadSpyLogDelegator), 18 | # which isn't in our classpath. Creating a new instance of DriverSpy would then fail in ServiceLoader.LazyIterator#nextService, 19 | # which would cause the loop in DriverManager#loadInitialDrivers to bail early (in which case some drivers might not be registered). 20 | log4jdbc.spylogdelegator.name=net.sf.log4jdbc.log.slf4j.Slf4jSpyLogDelegator --------------------------------------------------------------------------------