Marketplace
>
stripeWebhook
rainbow

stripeWebhook

v
1.0.0
Latest Version
Likes
0
4
Installations
0
2
Views
0
2

Overview

Handle Stripe webhook events by translating them to Google Pub/Sub events.

Usage

### How this function works This HTTPS function handles webhook events sent by Stripe. It will verify the request was signed by Stripe, and then the events will be translated into Pub/Sub events where the topicName is the ${event.type} e.g. `payment_intent.succeeded`. ### Why should I use this function In addition to the request verification, this function improves the subscription to Stripe events by allowing you to subscribe to new events without worrying about updating your endpoint. Instead, you just subscribe to the corresponding Pub/Sub event and continue developing. > Keep in mind that you still need to add the events you want to receive in the webhook configuration on the Stripe dashboard. ### Prerequisites - You should have previous knowledge of **Stripe** ### Function details This function will be called for the different events that you configure in Stripe to call it. Follow this step-by-step guide to install the stripeWebhook function. ##### Step 1: Create an account in Stripe If you already use the Stripe services, you should already be logged in and can skip this step. If you don't, you should create an account to sign in to Stripe: - Go to [https://stripe.com/](https://stripe.com/) and create an account. - Sign in and continue with the process. ##### Step 2: Setup webhook URL and secret Configure your webhook URL and secret on the [Stripe Dashboard](https://dashboard.stripe.com/webhooks). If you need help to complete this step check the [Stripe docs](https://stripe.com/docs/webhooks/signatures). > In the webhook URL you must provide the function unique URL, which will look like this: `https://us-central1-<project-id>.cloudfunctions.net/stripeWebhook`. See [Call an HTTP function](https://firebase.google.com/docs/functions/http-events#invoke_an_http_function) if you need more information. ##### Step 3: Install the function To install this function, you will need to provide the following variables; * **STRIPE_SECRET_API_KEY**: Your Stripe secret API key. See [https://stripe.com/docs/keys](https://stripe.com/docs/keys) * **STRIPE_WEBHOOK_SECRET**: The Stripe webhook secret configured in the previous step. After filling the required data, click the Install button and you are done. #### Spep 4: Now you can listen for Pub/Sub events that the function will be publishing ``` exports.foo = functions.pubsub.topic('payment_intent.succeeded').onPublish((message) => { const stripeEvent = message.json; // ... }); ``` **notes** - Versions previous to 1.0.0 only sent `event.data.object` as the message of the pubsub. Version `1.0.0` intruduce a breaking change where we are now sending the entire stripe webhook `event`. **stripe event example** ``` { "id": "evt_3KUZ31J2OCLbQfOE0KMhIg5Q", "object": "event", "api_version": "2020-08-27", "created": 1645200671, "data": { "object": { "id": "pi_3KUZ31J2OCLbQfOE0SwXfbQY", "object": "payment_intent", "amount": 3000, "amount_capturable": 0, "amount_received": 3000, "application": null, "application_fee_amount": null, "automatic_payment_methods": null, "canceled_at": null, "cancellation_reason": null, "capture_method": "automatic", "charges": { "object": "list", "data": [ { "id": "ch_3KUZ31J2OCLbQfOE0r1MhXGA", "object": "charge", "amount": 3000, "amount_captured": 3000, "amount_refunded": 0, "application": null, "application_fee": null, "application_fee_amount": null, "balance_transaction": "txn_3KUZ31J2OCLbQfOE0VvYEuG0", "billing_details": { "address": { "city": null, "country": null, "line1": null, "line2": null, "postal_code": null, "state": null }, "email": "stripe@example.com", "name": null, "phone": null }, "calculated_statement_descriptor": "Stripe", "captured": true, "created": 1645200670, "currency": "usd", "customer": "cus_LAuscYGy3lPrW9", "description": null, "destination": null, "dispute": null, "disputed": false, "failure_code": null, "failure_message": null, "fraud_details": { }, "invoice": null, "livemode": false, "metadata": { }, "on_behalf_of": null, "order": null, "outcome": { "network_status": "approved_by_network", "reason": null, "risk_level": "normal", "risk_score": 45, "seller_message": "Payment complete.", "type": "authorized" }, "paid": true, "payment_intent": "pi_3KUZ31J2OCLbQfOE0SwXfbQY", "payment_method": "pm_1KUZ33J2OCLbQfOEnCi1Gdk3", "payment_method_details": { "card": { "brand": "visa", "checks": { "address_line1_check": null, "address_postal_code_check": null, "cvc_check": null }, "country": "US", "exp_month": 2, "exp_year": 2023, "fingerprint": "Ot8LHNYXsMORdpxc", "funding": "credit", "installments": null, "last4": "4242", "network": "visa", "three_d_secure": null, "wallet": null }, "type": "card" }, "receipt_email": null, "receipt_number": null, "receipt_url": "https://pay.stripe.com/receipts/acct_1KQFVOJ2OCLbQfOE/ch_3KUZ31J2OCLbQfOE0r1MhXGA/rcpt_LAusLbJx450mBUzMzJDZA0SayE5VLdM", "refunded": false, "refunds": { "object": "list", "data": [ ], "has_more": false, "total_count": 0, "url": "/v1/charges/ch_3KUZ31J2OCLbQfOE0r1MhXGA/refunds" }, "review": null, "shipping": { "address": { "city": "San Francisco", "country": "US", "line1": "510 Townsend St", "line2": null, "postal_code": "94103", "state": "CA" }, "carrier": null, "name": "Jenny Rosen", "phone": null, "tracking_number": null }, "source": null, "source_transfer": null, "statement_descriptor": null, "statement_descriptor_suffix": null, "status": "succeeded", "transfer_data": null, "transfer_group": null } ], "has_more": false, "total_count": 1, "url": "/v1/charges?payment_intent=pi_3KUZ31J2OCLbQfOE0SwXfbQY" }, "client_secret": "pi_3KUZ31J2OCLbQfOE0SwXfbQY_secret_hP71Jh6xdWr4aeb14vpM1E4xH", "confirmation_method": "automatic", "created": 1645200667, "currency": "usd", "customer": "cus_LAuscYGy3lPrW9", "description": null, "invoice": null, "last_payment_error": null, "livemode": false, "metadata": { }, "next_action": null, "on_behalf_of": null, "payment_method": "pm_1KUZ33J2OCLbQfOEnCi1Gdk3", "payment_method_options": { "card": { "installments": null, "network": null, "request_three_d_secure": "automatic" } }, "payment_method_types": [ "card" ], "processing": null, "receipt_email": null, "review": null, "setup_future_usage": null, "shipping": { "address": { "city": "San Francisco", "country": "US", "line1": "510 Townsend St", "line2": null, "postal_code": "94103", "state": "CA" }, "carrier": null, "name": "Jenny Rosen", "phone": null, "tracking_number": null }, "source": null, "statement_descriptor": null, "statement_descriptor_suffix": null, "status": "succeeded", "transfer_data": null, "transfer_group": null } }, "livemode": false, "pending_webhooks": 1, "request": { "id": "req_r06AUZDLcLv5k8", "idempotency_key": "7c799c26-8b99-4601-abb9-e8db0aa9b3e6" }, "type": "payment_intent.succeeded" } ```
Cost
FREE
Cost
Version
1.0.0
Language
JAVASCRIPT
Created At
Updated At
Workspace
rainbow
Tags
stripe
webhook
© 2022 Function Store