Blog

Controlling Stripe With Python And Rules

Written by Adam Temple | Sep 14, 2015 7:00:00 AM

Notice: This article is maintained for historical purposes. The Bixly Automate/Nebri OS platform that Bixly built, and this article features, is no longer available. Checkout Serverless Providers as an alternative.

Are you interested in controlling Stripe based on rules? Maybe if a customer has been there for so long, they get a discount, or some billing change based on total purchases? Reacting to outside events with rules is a powerful way to achieve these features. You get a crap load of functionality with less code than usual.

Here’s the Github link to the Nebri Stripe App.

The docs describe how you also need our Python Client Lib which handles auth, including OAth, Token, and Basic HTTP auth. You can use Stripe’s webhooks to take each event and react to it with Nebri.

Here’s a sample request body:

{
  "created": 1326853478,
  "livemode": false,
  "id": "evt_00000000000000",
  "type": "charge.succeeded",
  "object": "event",
  "request": null,
  "pending_webhooks": 1,
  "api_version": "2015-09-08",
  "data": {
    "object": {
      "id": "ch_00000000000000",
      "object": "charge",
      "created": 1442251313,
      "livemode": false,
      "paid": true,
      "status": "succeeded",
      "amount": 100,
      "currency": "usd",
      "refunded": false,
      "source": {
        "id": "card_00000000000000",
        "object": "card",
        "last4": "4242",
        "brand": "Visa",
        "funding": "credit",
        "exp_month": 8,
        "exp_year": 2016,
        "country": "US",
        "name": null,
        "address_line1": null,
        "address_line2": null,
        "address_city": null,
        "address_state": null,
        "address_zip": null,
        "address_country": null,
        "cvc_check": null,
        "address_line1_check": null,
        "address_zip_check": null,
        "tokenization_method": null,
        "dynamic_last4": null,
        "metadata": {},
        "customer": null
      },
      "captured": true,
      "balance_transaction": "txn_00000000000000",
      "failure_message": null,
      "failure_code": null,
      "amount_refunded": 0,
      "customer": null,
      "invoice": null,
      "description": "My First Test Charge (created for API docs)",
      "dispute": null,
      "metadata": {},
      "statement_descriptor": null,
      "fraud_details": {},
      "receipt_email": null,
      "receipt_number": null,
      "shipping": null,
      "destination": null,
      "application_fee": null,
      "refunds": {
        "object": "list",
        "total_count": 0,
        "has_more": false,
        "url": "/v1/charges/ch_16l0eLHelsSEUOiEaPKtxBWj/refunds",
        "data": []
      }
    }
  }
}