Skip to content

Commit

Permalink
feat: require payment plans to provision spaces
Browse files Browse the repository at this point in the history
Most of the heavy lifting here is done by upgrading the `@web3-storage/upload-api` dependency. There is a new "feature flag" in the context that changes whether payment plans are required for provisioning - I'm going to set it to `false` for now in production and we can flip it once we're ready to turn this on.

I spent a bit of time working toward extending our integration tests to exercise the Stripe webhook handler, but it turned into a big enough project that I decided to defer and recorded what I learned in an issue here:

#267
  • Loading branch information
travis committed Nov 7, 2023
1 parent ef8e87c commit 50dfa6c
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 68 deletions.
2 changes: 2 additions & 0 deletions .env.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,5 @@ SATNAV_BUCKET_NAME = ''
MAILSLURP_API_KEY = ''
MAILSLURP_TIMEOUT = '120000'

# Feature flags
REQUIRE_PAYMENT_PLAN = 'true'
2 changes: 1 addition & 1 deletion billing/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"@sentry/serverless": "^7.74.1",
"@ucanto/interface": "^9.0.0",
"@ucanto/server": "^9.0.1",
"@web3-storage/capabilities": "^10.0.0",
"@web3-storage/capabilities": "^11.2.0",
"big.js": "^6.2.1",
"multiformats": "^12.1.2",
"p-retry": "^6.1.0",
Expand Down
74 changes: 11 additions & 63 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions stacks/upload-api-stack.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export function UploadApiStack({ stack, app }) {
R2_DUDEWHERE_BUCKET_NAME: process.env.R2_DUDEWHERE_BUCKET_NAME ?? '',
R2_DELEGATION_BUCKET_NAME: process.env.R2_DELEGATION_BUCKET_NAME ?? '',
R2_ENDPOINT: process.env.R2_ENDPOINT ?? '',
REQUIRE_PAYMENT_PLAN: process.env.REQUIRE_PAYMENT_PLAN ?? '',
UPLOAD_API_DID: process.env.UPLOAD_API_DID ?? '',
},
bind: [
Expand Down
2 changes: 1 addition & 1 deletion ucan-invocation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"@aws-sdk/client-dynamodb": "^3.226.0",
"@aws-sdk/client-eventbridge": "^3.218.0",
"@sentry/serverless": "^7.22.0",
"@web3-storage/capabilities": "^10.2.0",
"@web3-storage/capabilities": "^11.2.0",
"uint8arrays": "^4.0.2"
},
"devDependencies": {
Expand Down
7 changes: 6 additions & 1 deletion upload-api/functions/ucan-invocation-router.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ export async function ucanInvocationRouter(request) {
aggregatorDid,
pieceOfferQueueUrl,
filecoinSubmitQueueUrl,
requirePaymentPlan,
// set for testing
dbEndpoint,
accessServiceURL,
Expand Down Expand Up @@ -187,7 +188,10 @@ export async function ucanInvocationRouter(request) {
// We may change this to validate user provided piece
skipFilecoinSubmitQueue: true
},
plansStorage
plansStorage,
requirePaymentPlan,
// @ts-expect-error - not yet implemented
usageStorage: {},
})

const processingCtx = {
Expand Down Expand Up @@ -293,6 +297,7 @@ function getLambdaEnv () {
providers: mustGetEnv('PROVIDERS'),
accessServiceURL: mustGetEnv('ACCESS_SERVICE_URL'),
aggregatorDid: mustGetEnv('AGGREGATOR_DID'),
requirePaymentPlan: (process.env.REQUIRE_PAYMENT_PLAN === 'true'),
// set for testing
dbEndpoint: process.env.DYNAMO_DB_ENDPOINT,
}
Expand Down
4 changes: 2 additions & 2 deletions upload-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
"@ucanto/validator": "^9.0.0",
"@web-std/fetch": "^4.1.0",
"@web3-storage/access": "^16.3.0",
"@web3-storage/capabilities": "^11.1.0",
"@web3-storage/upload-api": "^7.1.2",
"@web3-storage/capabilities": "^11.2.0",
"@web3-storage/upload-api": "^7.2.0",
"@web3-storage/w3infra-ucan-invocation": "*",
"multiformats": "^12.1.2",
"nanoid": "^5.0.2",
Expand Down

0 comments on commit 50dfa6c

Please sign in to comment.