|
| 1 | += Aviate Tax Tutorial |
| 2 | + |
| 3 | +include::{sourcedir}/aviate/includes/aviate-card.adoc[] |
| 4 | + |
| 5 | +== Introduction |
| 6 | + |
| 7 | +This document provides a tutorial on using the aviate tax feature. |
| 8 | + |
| 9 | +== Prerequisites |
| 10 | + |
| 11 | +You will need: |
| 12 | + |
| 13 | +* A running Kill Bill instance with the Aviate plugin installed. |
| 14 | +* A valid API access tokens for all Aviate APIs calls - referred to as `ID_TOKEN` |
| 15 | + |
| 16 | +== Setup: Configuring a Tenant |
| 17 | + |
| 18 | +=== Step 1: Create a tenant |
| 19 | + |
| 20 | +We start by creating a tenant `tax-scenario`. |
| 21 | + |
| 22 | +Use the standard https://killbill.github.io/slate/tenant.html#create-a-tenant[Create Tenant] Kill Bill API: |
| 23 | + |
| 24 | +[source,bash] |
| 25 | +----- |
| 26 | +curl -v -X POST -u admin:password \ |
| 27 | +-H "Content-Type: application/json" \ |
| 28 | +-H "Accept: application/json" \ |
| 29 | +-H "X-Killbill-CreatedBy: demo" \ |
| 30 | +-d '{ "apiKey": "tax-scenario", "apiSecret": "tax-scenario" }' \ |
| 31 | +"http://127.0.0.1:8080/1.0/kb/tenants" |
| 32 | +----- |
| 33 | + |
| 34 | +=== Step 2: Create a catalog |
| 35 | + |
| 36 | +Upload an XML catalog or create a plan/product via the Aviate Catalog APIs. |
| 37 | + |
| 38 | +To upload an XML catalog, you can use the standard https://apidocs.killbill.io/catalog#upload-a-catalog-as-xml[Upload Catalog API]: |
| 39 | + |
| 40 | +[source,bash] |
| 41 | +----- |
| 42 | +curl -v \ |
| 43 | + -X POST \ |
| 44 | + -u admin:password \ |
| 45 | + -H "X-Killbill-ApiKey: tax-scenario" \ |
| 46 | + -H "X-Killbill-ApiSecret: tax-scenario" \ |
| 47 | + -H "Content-Type: text/xml" \ |
| 48 | + -H "Accept: application/json" \ |
| 49 | + -H "X-Killbill-CreatedBy: demo" \ |
| 50 | + -H "X-Killbill-Reason: demo" \ |
| 51 | + -H "X-Killbill-Comment: demo" \ |
| 52 | + -d '<?xml version="1.0" encoding="UTF-8" standalone="yes"?><catalog> ...' \ |
| 53 | + "http://127.0.0.1:8080/1.0/kb/catalog/xml" |
| 54 | +----- |
| 55 | + |
| 56 | +Alternatively, you can create a plan/product via the Aviate Catalog https://apidocs.killbill.io/aviate-catalog#create-plan-product-pricelist[Create Plan, Product, Pricelist] API: |
| 57 | + |
| 58 | +[source, bash] |
| 59 | +---- |
| 60 | +curl -X POST \ |
| 61 | +-H'Content-Type: application/json' \ |
| 62 | +-H"Authorization: Bearer ${ID_TOKEN}" \ |
| 63 | +-H'X-killbill-apiKey: tax-scenario' \ |
| 64 | +-H'X-killbill-apisecret: tax-scenario' \ |
| 65 | +-d '{ |
| 66 | + "plans": [ |
| 67 | + { |
| 68 | + "name": "premium-annual", |
| 69 | + "prettyName": "Premium Annual", |
| 70 | + "recurringBillingMode": "IN_ADVANCE", |
| 71 | + "pricelistName": "DEFAULT", |
| 72 | + "productName": "Premium", |
| 73 | + "phases": [ |
| 74 | + { |
| 75 | + "prettyName": "Premium Annual Evergreen", |
| 76 | + "type": "EVERGREEN", |
| 77 | + "durationUnit": "UNLIMITED", |
| 78 | + "durationLength": -1, |
| 79 | + "fixedPrices": [ |
| 80 | + { |
| 81 | + "currency": "USD", |
| 82 | + "value": "0.50" |
| 83 | + } |
| 84 | + ], |
| 85 | + "recurringPrices": { |
| 86 | + "billingPeriod": "ANNUAL", |
| 87 | + "prices": [ |
| 88 | + { |
| 89 | + "currency": "USD", |
| 90 | + "value": "15" |
| 91 | + } |
| 92 | + ] |
| 93 | + } |
| 94 | + } |
| 95 | + ] |
| 96 | + } |
| 97 | + ], |
| 98 | + "products": [ |
| 99 | + { |
| 100 | + "name": "Premium", |
| 101 | + "category": "BASE" |
| 102 | + } |
| 103 | + ] |
| 104 | +}' \ |
| 105 | +http://127.0.0.1:8080/plugins/aviate-plugin/v1/catalog/inputData |
| 106 | +---- |
| 107 | + |
| 108 | + |
| 109 | +=== Step 3: Configure the tax related properties for the product |
| 110 | + |
| 111 | +The next step would be to configure the tax related information for the product created in Step 2. Assuming that you want the "Premium" product to be taxed at a rate of 19.6% for invoices created between 2025-01-01 to 2025-03-31 and at a rate of 20% for invoices created after 2025-03-31 when country is `US`, you can configure the plugin as follows: |
| 112 | + |
| 113 | +[source, bash] |
| 114 | +---- |
| 115 | +curl -v \ |
| 116 | + -X POST \ |
| 117 | + -u admin:password \ |
| 118 | + -H 'X-Killbill-ApiKey: tax-scenario' \ |
| 119 | + -H 'X-Killbill-ApiSecret: tax-scenario' \ |
| 120 | + -H 'X-Killbill-CreatedBy: admin' \ |
| 121 | + -H 'Content-Type: text/plain' \ |
| 122 | + -d '!!com.killbill.billing.plugin.aviate.AviateTenantConfig |
| 123 | + taxConfig: |
| 124 | + taxItemAmountPrecision: 2 |
| 125 | + taxationTimeZone: UTC |
| 126 | + taxCodes: |
| 127 | + TAX_US_std_2025_19_6: |
| 128 | + description: Sales Tax 19.6% |
| 129 | + rate: 0.196 |
| 130 | + startingOn: 2025-01-01 |
| 131 | + stoppingOn: 2025-03-31 |
| 132 | + country: US |
| 133 | + TAX_US_std_2025_20_0: |
| 134 | + description: Sales Tax 20% |
| 135 | + rate: 0.200 |
| 136 | + startingOn: 2025-04-01 |
| 137 | + stoppingOn: "" |
| 138 | + country: US |
| 139 | + products: |
| 140 | + Premium: TAX_US_std_2000_19_6, TAX_US_std_2014_20_0' \ |
| 141 | + http://127.0.0.1:8080/1.0/kb/tenants/uploadPluginConfig/aviate-plugin |
| 142 | +---- |
| 143 | + |
| 144 | +== Creating a Customer Account |
| 145 | + |
| 146 | +=== Step 1: Create a new account |
| 147 | + |
| 148 | +Use the standard Kill Bill https://killbill.github.io/slate/account.html#create-an-account[Create Account] API: |
| 149 | + |
| 150 | +[source,bash] |
| 151 | +----- |
| 152 | +curl -v -X POST -u admin:password \ |
| 153 | +-H "X-Killbill-ApiKey: tax-scenario" \ |
| 154 | +-H "X-killbill-apisecret: tax-scenario" \ |
| 155 | +-H "X-Killbill-CreatedBy: demo" \ |
| 156 | +-H "Content-Type: application/json" \ |
| 157 | +-d '{ "name": "John Doe", "email": "john.doe@somewhere.com", "currency": "USD" }' \ |
| 158 | +"http://127.0.0.1:8080/1.0/kb/accounts" |
| 159 | +----- |
| 160 | + |
| 161 | +=== Step 2: Create a billing account |
| 162 | + |
| 163 | +Use the Aviate Create Billing Account API to create a billing account corresponding to the account. Ensure that the appropriate country is specified as part of taxRegistration#address: |
| 164 | + |
| 165 | +[source, bash] |
| 166 | +---- |
| 167 | +curl -X POST \ |
| 168 | + -H'Content-Type: application/json' \ |
| 169 | + -H'X-killbill-apiKey: tax-scenario' \ |
| 170 | + -H'X-killbill-apisecret: tax-scenario' \ |
| 171 | + -d '{ "kbAccountId":"e5d3d5b5-4415-4166-b57f-33ca00a59e88", "taxRegistrations": [{ |
| 172 | + "name": "John Doe", |
| 173 | + "exempt": false, |
| 174 | + "trn": "TRN-987654", |
| 175 | + "address": { |
| 176 | + "addressLine1": "123 Main Street", |
| 177 | + "addressLine2": "Suite 4B", |
| 178 | + "city": "Springfield", |
| 179 | + "state": "Illinois", |
| 180 | + "country": "US", |
| 181 | + "postalCode": "62701" |
| 182 | + } |
| 183 | +}]}' \ |
| 184 | + http://127.0.0.1:8080/plugins/aviate-plugin/v1/ba |
| 185 | +---- |
| 186 | + |
| 187 | +=== Step 3: Create a subscription |
| 188 | + |
| 189 | +Create a subscription to the `premium-monthly` plan. Use the standard Kill Bill https://apidocs.killbill.io/subscription#create-a-subscription[Create Subscription] API: |
| 190 | + |
| 191 | +[source,bash] |
| 192 | +----- |
| 193 | +curl -v -X POST -u admin:password \ |
| 194 | +-H "X-Killbill-ApiKey: tax-scenario" \ |
| 195 | +-H "X-killbill-apisecret: tax-scenario" \ |
| 196 | +-H "X-Killbill-CreatedBy: demo" \ |
| 197 | +-H "Content-Type: application/json" \ |
| 198 | +-d '{ "accountId": "{accountId}", "planName": "premium-monthly" }' \ |
| 199 | +"http://127.0.0.1:8080/1.0/kb/subscriptions" |
| 200 | +----- |
| 201 | + |
| 202 | +=== Step 4: Retrieve Invoices |
| 203 | + |
| 204 | + |
| 205 | +Use the standard Kill Bill https://apidocs.killbill.io/account#retrieve-account-invoices[Retrieve Account Invoices] API: |
| 206 | + |
| 207 | +[source,bash] |
| 208 | +---- |
| 209 | +curl -v \ |
| 210 | + -u admin:password \ |
| 211 | + -H "X-Killbill-ApiKey: tax-scenario" \ |
| 212 | + -H "X-Killbill-ApiSecret: tax-scenario" \ |
| 213 | + -H "Accept: application/json" \ |
| 214 | + "http://127.0.0.1:8080/1.0/kb/accounts/{accountId}/invoices" |
| 215 | +---- |
| 216 | + |
| 217 | +Ensure that the invoice corresponding to the subscription includes a tax item. Assuming the base subscription price is `$100`, it should be taxed at *20%*. So the tax item should be for `$20`. |
| 218 | + |
0 commit comments