-
-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
202 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
create table if not exists | ||
"stripe"."tax_ids" ( | ||
"id" text primary key, | ||
"object" text, | ||
"country" text, | ||
"customer" text, | ||
"type" text, | ||
"value" text, | ||
"created" integer not null, | ||
"livemode" boolean, | ||
"owner" jsonb | ||
); | ||
|
||
create index stripe_tax_ids_customer_idx on "stripe"."tax_ids" using btree (customer); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import Stripe from 'stripe' | ||
import { getConfig } from '../utils/config' | ||
import { constructUpsertSql } from '../utils/helpers' | ||
import { backfillCustomers } from './customers' | ||
import { getUniqueIds, upsertMany } from './database_utils' | ||
import { taxIdSchema } from '../schemas/tax_id' | ||
import { pg as sql } from 'yesql' | ||
import { query } from '../utils/PostgresConnection' | ||
|
||
const config = getConfig() | ||
|
||
export const upsertTaxIds = async ( | ||
taxIds: Stripe.TaxId[], | ||
backfillRelatedEntities: boolean = true | ||
): Promise<Stripe.TaxId[]> => { | ||
if (backfillRelatedEntities) { | ||
await backfillCustomers(getUniqueIds(taxIds, 'customer')) | ||
} | ||
|
||
return upsertMany(taxIds, () => constructUpsertSql(config.SCHEMA, 'tax_ids', taxIdSchema)) | ||
} | ||
|
||
export const deleteTaxId = async (id: string): Promise<boolean> => { | ||
const prepared = sql(` | ||
delete from "${config.SCHEMA}"."tax_ids" | ||
where id = :id | ||
returning id; | ||
`)({ id }) | ||
const { rows } = await query(prepared.text, prepared.values) | ||
return rows.length > 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { JsonSchema } from '../types/types' | ||
|
||
export const taxIdSchema: JsonSchema = { | ||
$id: 'taxIdSchema', | ||
type: 'object', | ||
properties: { | ||
id: { type: 'string' }, | ||
country: { type: 'string' }, | ||
customer: { type: 'string' }, | ||
type: { type: 'string' }, | ||
value: { type: 'string' }, | ||
object: { type: 'string' }, | ||
created: { type: 'integer' }, | ||
livemode: { type: 'boolean' }, | ||
owner: { type: 'object' }, | ||
}, | ||
required: ['id'], | ||
} as const |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"id": "evt_3KtQThJDPojXS6LN0E06aNxq", | ||
"object": "event", | ||
"api_version": "2020-03-02", | ||
"created": 1619701111, | ||
"data": { | ||
"object": { | ||
"id": "txi_1NuMB12eZvKYlo2CMecoWkZd", | ||
"object": "tax_id", | ||
"country": "DE", | ||
"created": 123456789, | ||
"customer": null, | ||
"livemode": false, | ||
"type": "eu_vat", | ||
"value": "DE123456789", | ||
"verification": null, | ||
"owner": { | ||
"type": "self", | ||
"customer": null | ||
} | ||
} | ||
}, | ||
"livemode": false, | ||
"pending_webhooks": 4, | ||
"request": { | ||
"id": "req_QyDCzn33ls4m1t", | ||
"idempotency_key": null | ||
}, | ||
"type": "customer.tax_id.created" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"id": "evt_3KtQThJDPojXS6LN0E06aNxq", | ||
"object": "event", | ||
"api_version": "2020-03-02", | ||
"created": 1619701111, | ||
"data": { | ||
"object": { | ||
"id": "txi_1NuMB12eZvKYlo2CMecoWkZd", | ||
"object": "tax_id", | ||
"country": "DE", | ||
"created": 123456789, | ||
"customer": null, | ||
"livemode": false, | ||
"type": "eu_vat", | ||
"value": "DE123456789", | ||
"verification": null, | ||
"owner": { | ||
"type": "self", | ||
"customer": null | ||
} | ||
} | ||
}, | ||
"livemode": false, | ||
"pending_webhooks": 4, | ||
"request": { | ||
"id": "req_QyDCzn33ls4m1t", | ||
"idempotency_key": null | ||
}, | ||
"type": "customer.tax_id.deleted" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"id": "evt_3KtQThJDPojXS6LN0E06aNxq", | ||
"object": "event", | ||
"api_version": "2020-03-02", | ||
"created": 1619701111, | ||
"data": { | ||
"object": { | ||
"id": "txi_1NuMB12eZvKYlo2CMecoWkZd", | ||
"object": "tax_id", | ||
"country": "DE", | ||
"created": 123456789, | ||
"customer": null, | ||
"livemode": false, | ||
"type": "eu_vat", | ||
"value": "DE123456789", | ||
"verification": null, | ||
"owner": { | ||
"type": "self", | ||
"customer": null | ||
} | ||
} | ||
}, | ||
"livemode": false, | ||
"pending_webhooks": 4, | ||
"request": { | ||
"id": "req_QyDCzn33ls4m1t", | ||
"idempotency_key": null | ||
}, | ||
"type": "customer.tax_id.updated" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters