Create, update and delete stripe webhooks with your app deployment
Project description
@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.
License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for cloudcomponents.cdk-stripe-webhook-2.0.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | ba2f7f8736df2c72802a24fad88347d7ee60d20a6e4caae683dec818270c1617 |
|
MD5 | b4b8f3bbf8428500a09c5ea21e255f78 |
|
BLAKE2b-256 | 978e1f25e0bad686505c8368cd05a6b76889ea28870723a0a06271804cc46305 |
Close
Hashes for cloudcomponents.cdk_stripe_webhook-2.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9a485029052693faf467725a95656e9f1cb9b3d6cd1d18630e4cdf39b0fb7299 |
|
MD5 | 50cc4a38fceccce850f037d7a29e4d3c |
|
BLAKE2b-256 | f4cae85627193d965501406c60a49e13a09a185219bb09b8151dc91e688db4a5 |