forked from denoland/std
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: cleanup Stripe logic (denoland#525)
This PR applies various fixes, cleanups and improvements to Stripe logic.
- Loading branch information
Showing
15 changed files
with
81 additions
and
90 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 |
---|---|---|
|
@@ -32,7 +32,7 @@ | |
"twind-preset-tailwind/": "https://esm.sh/@twind/[email protected]/", | ||
"twind-preset-ext": "https://esm.sh/@twind/[email protected]/", | ||
"std/": "https://raw.githubusercontent.com/lino-levan/deno_std/feat-ulid/", | ||
"stripe": "./stripe.ts", | ||
"stripe": "npm:/stripe@12.6.0", | ||
"feed": "https://esm.sh/[email protected]", | ||
"kv_oauth": "https://deno.land/x/[email protected]/mod.ts", | ||
"tabler_icons_tsx/": "https://deno.land/x/[email protected]/tsx/", | ||
|
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
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
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
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 was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright 2023 the Deno authors. All rights reserved. MIT license. | ||
import Stripe from "stripe"; | ||
import "std/dotenv/load.ts"; | ||
|
||
const STRIPE_SECRET_KEY = Deno.env.get("STRIPE_SECRET_KEY"); | ||
|
||
export function isStripeEnabled() { | ||
return Deno.env.has("STRIPE_SECRET_KEY"); | ||
} | ||
|
||
export const stripe = new Stripe(STRIPE_SECRET_KEY!, { | ||
apiVersion: "2022-11-15", | ||
// Use the Fetch API instead of Node's HTTP client. | ||
httpClient: Stripe.createFetchHttpClient(), | ||
}); | ||
|
||
/** | ||
* We assume that the product has a default price. | ||
* The official types allow for the default_price to be `undefined | null | string` | ||
*/ | ||
export type StripProductWithPrice = Stripe.Product & { | ||
default_price: Stripe.Price; | ||
}; | ||
|
||
export function isProductWithPrice( | ||
product: Stripe.Product, | ||
): product is StripProductWithPrice { | ||
return product.default_price !== undefined && | ||
product.default_price !== null && | ||
typeof product.default_price !== "string"; | ||
} |