@cloudcomponents/cdk-stripe-webhook
v2.4.0
Published
Create, update and delete stripe webhooks with your app deployment
Downloads
576
Maintainers
Readme
@cloudcomponents/cdk-stripe-webhook
Create, update and delete stripe webhooks with your app deployment
Install
TypeScript/JavaScript:
npm i @cloudcomponents/cdk-stripe-webhook
Python:
pip install cloudcomponents.cdk-stripe-webhook
How to use
EventBus Producer
import { SecretKey, SecretKeyStore } from '@cloudcomponents/cdk-secret-key';
import { StripeWebhook, StripeEventBusProducer } from '@cloudcomponents/cdk-stripe-webhook';
import { Stack, StackProps, aws_ssm } from 'aws-cdk-lib';
import { Construct } from 'constructs';
export class StripeWebhookEventBusStack extends Stack {
constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props);
if (typeof process.env.SECRET_KEY === 'undefined') {
throw new Error('environment variable SECRET_KEY undefined');
}
const secretKey = SecretKey.fromPlainText(process.env.SECRET_KEY);
const endpointSecretParameter = aws_ssm.StringParameter.fromSecureStringParameterAttributes(this, 'Param', {
parameterName: 'stripe',
version: 1,
});
const producer = new StripeEventBusProducer(this, 'Producer', {
secretKey,
endpointSecret: SecretKey.fromSSMParameter(endpointSecretParameter),
});
const events = ['charge.failed', 'charge.succeeded'];
const endpointSecretStore = SecretKeyStore.fromSSMParameter(endpointSecretParameter);
new StripeWebhook(this, 'StripeWebhook', {
secretKey,
url: producer.url,
events,
logLevel: 'debug',
endpointSecretStore,
});
}
}
Custom Handler
import { SecretKey } from '@cloudcomponents/cdk-secret-key';
import { StripeWebhook } from '@cloudcomponents/cdk-stripe-webhook';
import { Stack, StackProps, aws_apigateway } from 'aws-cdk-lib';
import { Construct } from 'constructs';
export class StripeWebhookStack extends Stack {
constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props);
const api = new aws_apigateway.RestApi(this, 'Endpoint');
api.root.addMethod('POST');
if (typeof process.env.SECRET_KEY === 'undefined') {
throw new Error('environment variable SECRET_KEY undefined');
}
const secretKey = SecretKey.fromPlainText(process.env.SECRET_KEY);
const events = ['charge.failed', 'charge.succeeded'];
new StripeWebhook(this, 'StripeWebhook', {
secretKey,
url: api.url,
events,
logLevel: 'debug',
});
}
}
API Reference
See API.md.
Example
See more complete examples.