|
1 | 1 | # Webhooks |
| 2 | + |
| 3 | +Stripe sends a events for just about everything that happens in it's system as |
| 4 | +a JSON payload to a webhook. |
| 5 | + |
| 6 | +A webhook is an endpoint running your site that accepts `POST` requests. You |
| 7 | +provide the full url to this endpoint in the settings at Stripe so it knows |
| 8 | +where to send the payloads. |
| 9 | + |
| 10 | +## Setup |
| 11 | + |
| 12 | +Click onto your Stripe settings panel and then click on the Webhooks tab: |
| 13 | + |
| 14 | + |
| 15 | + |
| 16 | + |
| 17 | + |
| 18 | +From there click on add endpoint button and add the full url: |
| 19 | + |
| 20 | + |
| 21 | + |
| 22 | +`pinax-stripe` ships with a webhook view and all the code necessary to process |
| 23 | +and store events sent to your webhook. If you install the `pinax-stripe` urls |
| 24 | +like so: |
| 25 | + |
| 26 | +```python |
| 27 | +url(r"^payments/", include("pinax.stripe.urls")), |
| 28 | +``` |
| 29 | + |
| 30 | +Then the full url to your webhook that you'll need to enter into the Stripe UI |
| 31 | +pictured above is: |
| 32 | + |
| 33 | + https://yourdomain.com/payments/webhook/ |
| 34 | + |
| 35 | + |
| 36 | +## Security |
| 37 | + |
| 38 | +Since this is a wide open URL we don't want to record and react to any data |
| 39 | +sent our way. Therefore, we actually record the data that is sent, but then |
| 40 | +before processing it, we validate it against the Stripe API. If it validates |
| 41 | +as untampered data, then we continue the processing. |
| 42 | + |
| 43 | +If validation fails, then `Event.valid` will be set to `False` enabling at |
| 44 | +least some data to try and hunt down any malicious activity. |
| 45 | + |
| 46 | + |
| 47 | +## Signals |
| 48 | + |
| 49 | +`pinax-stripe` handles certain events in the webhook processing that are |
| 50 | +important for certain operations like syncing data or deleting cards. Every |
| 51 | +event, though, has a corresponding signal that is sent, so you can hook into |
| 52 | +these events in your project. See [the signals reference](signals.md) for |
| 53 | +details on how to wire those up. |
| 54 | + |
| 55 | +## Events |
| 56 | + |
| 57 | +* `account.updated` - Occurs whenever an account status or property has changed. |
| 58 | +* `account.application.deauthorized` - Occurs whenever a user deauthorizes an application. Sent to the related application only. |
| 59 | +* `account.external_account.created` - Occurs whenever an external account is created. |
| 60 | +* `account.external_account.deleted` - Occurs whenever an external account is deleted. |
| 61 | +* `account.external_account.updated` - Occurs whenever an external account is updated. |
| 62 | +* `application_fee.created` - Occurs whenever an application fee is created on a charge. |
| 63 | +* `application_fee.refunded` - Occurs whenever an application fee is refunded, whether from refunding a charge or from refunding the application fee directly, including partial refunds. |
| 64 | +* `application_fee.refund.updated` - Occurs whenever an application fee refund is updated. |
| 65 | +* `balance.available` - Occurs whenever your Stripe balance has been updated (e.g. when a charge collected is available to be paid out). By default, Stripe will automatically transfer any funds in your balance to your bank account on a daily basis. |
| 66 | +* `bitcoin.receiver.created` - Occurs whenever a receiver has been created. |
| 67 | +* `bitcoin.receiver.filled` - Occurs whenever a receiver is filled (that is, when it has received enough bitcoin to process a payment of the same amount). |
| 68 | +* `bitcoin.receiver.updated` - Occurs whenever a receiver is updated. |
| 69 | +* `bitcoin.receiver.transaction.created` - Occurs whenever bitcoin is pushed to a receiver. |
| 70 | +* `charge.captured` - Occurs whenever a previously uncaptured charge is captured. |
| 71 | +* `charge.failed` - Occurs whenever a failed charge attempt occurs. |
| 72 | +* `charge.refunded` - Occurs whenever a charge is refunded, including partial refunds. |
| 73 | +* `charge.succeeded` - Occurs whenever a new charge is created and is successful. |
| 74 | +* `charge.updated` - Occurs whenever a charge description or metadata is updated. |
| 75 | +* `charge.dispute.closed` - Occurs when the dispute is resolved and the dispute status changes to won or lost. |
| 76 | +* `charge.dispute.created` - Occurs whenever a customer disputes a charge with their bank (chargeback). |
| 77 | +* `charge.dispute.funds_reinstated` - Occurs when funds are reinstated to your account after a dispute is won. |
| 78 | +* `charge.dispute.funds_withdrawn` - Occurs when funds are removed from your account due to a dispute. |
| 79 | +* `charge.dispute.updated` - Occurs when the dispute is updated (usually with evidence). |
| 80 | +* `coupon.created` - Occurs whenever a coupon is created. |
| 81 | +* `coupon.deleted` - Occurs whenever a coupon is deleted. |
| 82 | +* `coupon.updated` - Occurs whenever a coupon is updated. |
| 83 | +* `customer.created` - Occurs whenever a new customer is created. |
| 84 | +* `customer.deleted` - Occurs whenever a customer is deleted. |
| 85 | +* `customer.updated` - Occurs whenever any property of a customer changes. |
| 86 | +* `customer.discount.created` - Occurs whenever a coupon is attached to a customer. |
| 87 | +* `customer.discount.deleted` - Occurs whenever a customer's discount is removed. |
| 88 | +* `customer.discount.updated` - Occurs whenever a customer is switched from one coupon to another. |
| 89 | +* `customer.source.created` - Occurs whenever a new source is created for the customer. |
| 90 | +* `customer.source.deleted` - Occurs whenever a source is removed from a customer. |
| 91 | +* `customer.source.updated` - Occurs whenever a source's details are changed. |
| 92 | +* `customer.subscription.created` - Occurs whenever a customer with no subscription is signed up for a plan. |
| 93 | +* `customer.subscription.deleted` - Occurs whenever a customer ends their subscription. |
| 94 | +* `customer.subscription.trial_will_end` - Occurs three days before the trial period of a subscription is scheduled to end. |
| 95 | +* `customer.subscription.updated` - Occurs whenever a subscription changes. Examples would include switching from one plan to another, or switching status from trial to active. |
| 96 | +* `invoice.created` - Occurs whenever a new invoice is created. If you are using webhooks, Stripe will wait one hour after they have all succeeded to attempt to pay the invoice; the only exception here is on the first invoice, which gets created and paid immediately when you subscribe a customer to a plan. If your webhooks do not all respond successfully, Stripe will continue retrying the webhooks every hour and will not attempt to pay the invoice. After 3 days, Stripe will attempt to pay the invoice regardless of whether or not your webhooks have succeeded. See how to respond to a webhook. |
| 97 | +* `invoice.payment_failed` - Occurs whenever an invoice attempts to be paid, and the payment fails. This can occur either due to a declined payment, or because the customer has no active card. A particular case of note is that if a customer with no active card reaches the end of its free trial, an invoice.payment_failed notification will occur. |
| 98 | +* `invoice.payment_succeeded` - Occurs whenever an invoice attempts to be paid, and the payment succeeds. |
| 99 | +* `invoice.updated` - Occurs whenever an invoice changes (for example, the amount could change). |
| 100 | +* `invoiceitem.created` - Occurs whenever an invoice item is created. |
| 101 | +* `invoiceitem.deleted` - Occurs whenever an invoice item is deleted. |
| 102 | +* `invoiceitem.updated` - Occurs whenever an invoice item is updated. |
| 103 | +* `order.created` - Occurs whenever an order is created. |
| 104 | +* `order.payment_failed` - Occurs whenever payment is attempted on an order, and the payment fails. |
| 105 | +* `order.payment_succeeded` - Occurs whenever payment is attempted on an order, and the payment succeeds. |
| 106 | +* `order.updated` - Occurs whenever an order is updated. |
| 107 | +* `plan.created` - Occurs whenever a plan is created. |
| 108 | +* `plan.deleted` - Occurs whenever a plan is deleted. |
| 109 | +* `plan.updated` - Occurs whenever a plan is updated. |
| 110 | +* `product.created` - Occurs whenever a product is created. |
| 111 | +* `product.updated` - Occurs whenever a product is updated. |
| 112 | +* `recipient.created` - Occurs whenever a recipient is created. |
| 113 | +* `recipient.deleted` - Occurs whenever a recipient is deleted. |
| 114 | +* `recipient.updated` - Occurs whenever a recipient is updated. |
| 115 | +* `sku.created` - Occurs whenever a SKU is created. |
| 116 | +* `sku.updated` - Occurs whenever a SKU is updated. |
| 117 | +* `transfer.created` - Occurs whenever a new transfer is created. |
| 118 | +* `transfer.failed` - Occurs whenever Stripe attempts to send a transfer and that transfer fails. |
| 119 | +* `transfer.paid` - Occurs whenever a sent transfer is expected to be available in the destination bank account. If the transfer failed, a transfer.failed webhook will additionally be sent at a later time. Note to Connect users: this event is only created for transfers from your connected Stripe accounts to their bank accounts, not for transfers to the connected accounts themselves. |
| 120 | +* `transfer.reversed` - Occurs whenever a transfer is reversed, including partial reversals. |
| 121 | +* `transfer.updated` - Occurs whenever the description or metadata of a transfer is updated. |
| 122 | +* `ping` - May be sent by Stripe at any time to see if a provided webhook URL is working. |
0 commit comments