This Data Connector allows you to import Stripe objects into Treasure Data.

Prerequisites

  • Basic knowledge of Treasure Data

  • Basic knowledge of Stripe

  • (Optional) Stripe Webhooks

Use TD Console

Create a New Connection

Go to Integrations Hub > Catalog and search and select Stripe.


We support the following Authentication Methods:

Method 1: OAuth —recommended

Select an existing OAuth connection for Stripe, or select the link under OAuth connection to create a new one.


Create a New OAuth Connection

Login to your Stripe account:


And grant access to Treasure Data app:


You will be redirected back to Integrations Hub. Repeat Create a new connection and choose your new OAuth connection.


Internal Testing Purposes: Secret Key —deprecated, replaced by OAuth

Enter Live Secret Key from Stripe > Your Account > Account Settings > API Keys.


Create a New Transfer

After creating the above connection, you will be automatically taken to My Connections tab. Look for the connection you created and select New Transfer. The incremental option is only supported for the event object.


Edit the details and select Next.


Preview your data. If you wish to change anything, select on Advanced Settings or else select on Next.


Select the database and table where you want to transfer the data, as per the following dialog:


Specify the schedule of the data transfer using the dialog below and select Start Transfer.


You see the new data transfer in progress listed under the My Input Transfers tab and a corresponding job are listed in the Jobs section.

Parallel Data Import

You can improve data import performance by using parallel import.

The plugin creates a time range that depends on Start datetime and End datetime and send parallel HTTP requests to Stripe API. If you don't edit the End datetime plugin tries to get the timestamp of the latest record stored in Stripe first and use it as End datetime.

In the following example, the plugin creates 4 time ranges and all time ranges are processed in parallel.

Start datetime: 2016-01-25T00:00:00
End datetime: 2017-05-25T00.00.00
Time splitting
  Period for each parallel input: 6
  unit: month

:::terminal
Time range 1
  gte: 2016-01-25T00:00:00
  lt: 2016-01-31T00:00:00 # start_datetime to first end of the month
Time range 2
  gte: 2016-01-31T00:00:00 # has 6 month period
  lt: 2016-07-31T00.00.00
Time range 3
  gte: 2016-07-31T00.00.00.000Z # has 6 month period
  lt: 2017-02-28T00.00.00
Time range 4
  gte: 2017-02-28T00.00.00
  lt: 2017-05-25T00.00.00 # to end_datetime


Use Command Line

Install ‘td’ command v0.11.9 or later

You can install the newest TD Toolbelt.

$ td --version
0.15.0

Create Configuration File

Prepare configuration file (for eg: load.yml) as follows, with your Stripe account access information.

in:
  type: stripe
  client_id: xxxxxxxxxxxxx
  client_secret: xxxxxxxxxxxxx
  refresh_token: xxxxxxxxxxxxx
  target: event
  incremental: true
  start_datetime: 2017-01-01T07:36:22.000Z
  formula: gt
out:
  mode: replace

The steps for specifying the import of Stripe Event objects is as follows:

  1. client_id and client_secret: your Stripe app credentials

  2. refresh_token: Stripe OAuth2 refresh_token, you need to grant access to your Stripe app, using an Stripe user account

  3. target: Stripe object you want to import. Supported values: account, application_fee, balance_history, charge, coupon, customer, dispute, file_upload, event, invoice_item, invoice, order, plan, product, refund, subscription, transfer

  4. start_datetime: import data from this date, format is: yyyy-MM-ddThh:mm:ss.000Z

  5. formula: Formula to evaluate start_datetime. Supported values: gt(greater than), gte(greater than or equal), lt(less than), lte(less than or equal).

  6. incremental: should data import be continuous or once, default as true. Incremental is only supported when target is event.

For more details on available out modes, see the Appendix.

Preview Data to Import (Optional)

You can preview data to be imported using the command td connector:preview.

$ td connector:preview load.yml
+--------------------------------+---------------+--------------------+----
| id:string                      | object:string | api_version:string | ...
+--------------------------------+---------------+--------------------+----
| "evt_19cs52EC2hHOQuTd4SejXK0W" | "event"       | "2016-07-06"       |
| "evt_19cs52EC2hHOQuTdG7Qm4fS3" | "event"       | "2016-07-06"       |
| "evt_19cs4REC2hHOQuTdhZZD58uw" | "event"       | "2016-07-06"       |
| "evt_19cs4QEC2hHOQuTdjADeyQcC" | "event"       | "2016-07-06"       |
| "evt_19cs3oEC2hHOQuTdjZm6u0pB" | "event"       | "2016-07-06"       |
+--------------------------------+---------------+--------------------+----

Execute Load Job

Submit the load job. It may take a couple of hours depending on the data size. Users need to specify the database and table where their data are stored.

It is recommended to specify the --time-column option, since Treasure Data’s storage is partitioned by time (see also data partitioning). If the option is not given, the Data Connector will choose the first long or timestamp column as the partitioning time. The type of the column specified for --time-column must be either of long or timestamp type.

If your data doesn’t have a time column you may add it using the add_time filter option. For more information, see add_time filter plugin.

$ td connector:issue load.yml --database td_sample_db --table td_sample_table --time-column updated_date

The preceding command assumes you have already created database(td_sample_db) and table(td_sample_table). If the database or the table do not exist in TD this command will not succeed, so create the database and table manually or use --auto-create-table option with the td connector:issue command to auto create the database and table:

$ td connector:issue load.yml --database td_sample_db --table td_sample_table --time-column updated_date --auto-create-table


You can assign the Time Format column to the "Partitioning Key" with the "--time-column" option.

Scheduled Execution

You can schedule a periodic Data Connector execution for a periodic Stripe import. We manage our scheduler to ensure high availability. By using this feature, you no longer need a cron daemon on your local data center.

Create the Schedule

A new schedule can be created using the td connector:create command. The name of the schedule, cron-style schedule, the database and table where their data will be stored, and the Data Connector configuration file are required.

$ td connector:create \
    daily_stripe_import \
    "10 0 * * *" \
    td_sample_db \
    td_sample_table \
    load.yml

The `cron` parameter also accepts these three options: `@hourly`, `@daily` and `@monthly`

By default, the schedule is setup in the UTC timezone. You can set the schedule in a timezone using -t or --timezone option. The `--timezone` option only supports extended timezone formats like 'Asia/Tokyo', 'America/Los_Angeles' etc. Timezone abbreviations like PST, CST are *not* supported and may lead to unexpected schedules.

List the Schedules

You can see the list of currently scheduled entries by td connector:list.

$ td connector:list
+-----------------------+--------------+----------+-------+--------------+-----------------+----------------------------+
| Name                  | Cron         | Timezone | Delay | Database     | Table           | Config                     |
+-----------------------+--------------+----------+-------+--------------+-----------------+----------------------------+
| daily_stripe_import   | 10 0 * * *   | UTC      | 0     | td_sample_db | td_sample_table | {"type"=>"stripe", ... }  |
+-----------------------+--------------+----------+-------+--------------+-----------------+----------------------------+

Show the Setting and History of Schedules

td connector:show shows the execution setting for a schedule entry.

% td connector:show daily_Stripe_import
Name     : daily_stripe_import
Cron     : 10 0 * * *
Timezone : UTC
Delay    : 0
Database : td_sample_db
Table    : td_sample_table

td connector:history shows the execution history of a schedule entry. To investigate the results of each individual execution, use td job <jobid>.

% td connector:history daily_stripe_import
+--------+---------+---------+--------------+-----------------+----------+---------------------------+----------+
| JobID  | Status  | Records | Database     | Table           | Priority | Started                   | Duration |
+--------+---------+---------+--------------+-----------------+----------+---------------------------+----------+
| 578066 | success | 10000   | td_sample_db | td_sample_table | 0        | 2015-04-18 00:10:05 +0000 | 160      |
| 577968 | success | 10000   | td_sample_db | td_sample_table | 0        | 2015-04-17 00:10:07 +0000 | 161      |
| 577914 | success | 10000   | td_sample_db | td_sample_table | 0        | 2015-04-16 00:10:03 +0000 | 152      |
| 577872 | success | 10000   | td_sample_db | td_sample_table | 0        | 2015-04-15 00:10:04 +0000 | 163      |
| 577810 | success | 10000   | td_sample_db | td_sample_table | 0        | 2015-04-14 00:10:04 +0000 | 164      |
| 577766 | success | 10000   | td_sample_db | td_sample_table | 0        | 2015-04-13 00:10:04 +0000 | 155      |
| 577710 | success | 10000   | td_sample_db | td_sample_table | 0        | 2015-04-12 00:10:05 +0000 | 156      |
| 577610 | success | 10000   | td_sample_db | td_sample_table | 0        | 2015-04-11 00:10:04 +0000 | 157      |
+--------+---------+---------+--------------+-----------------+----------+---------------------------+----------+
8 rows in set

Delete the Schedule

td connector:delete removes the schedule.

$ td connector:delete daily_stripe_import

Appendix

Modes for out plugin

You can specify file import mode in out section of load.yml.

Append (default)

This is the default mode and records are appended to the target table.

in:
  ...
out:
  mode: append

Replace (In td 0.11.10 and later)

This mode replaces data in the target table. Manual schema changes made to the target table will remain intact with this mode.

in:
  ...
out:
  mode: replace

Setup Stripe Webhooks

Webhooks can be used to capture events that happen in a Stripe account, instead of through direct API requests.

Login to Stripe account, select Webhooks —> Settings —> Add endpoint


In the URL text box, enter:
http://in.treasuredata.com/postback/v3/event/{td_database}/{td_table}?td_write_key={td_account_write_api_key}

Then select events that you want to ingest into the {td_database}.{td_table} specified in the preceding URL.



You can setup additional endpoints to ingest different types of events into different {td_database}.{td_table}.

  • No labels