Automate Stripe Integration Tasks from PowerShell
The CData ADO.NET Provider for Stripe is a standard ADO.NET Provider that make it easy to accomplish data cleansing, normalization, backup, and other integration tasks by enabling real-time and bidirectional access to Stripe.
ADO.NET Provider
The ADO.NET Provider provides a SQL interface for Stripe; this tutorial shows how to use the Provider to create, retrieve, update, and delete Stripe data.
Once you have acquired the necessary connection properties, accessing Stripe data in PowerShell can be enabled in three steps.
Use the OAuth authentication standard to connect to Stripe. To authenticate using OAuth, register an app to obtain the OAuthClientId, OAuthClientSecret, and CallbackURL connection properties. See the "Getting Started" chapter of the help documentation for a guide to using OAuth.
-
Load the provider's assembly:
[Reflection.Assembly]::LoadFile("C:\Program Files\CData\CData ADO.NET Provider for Stripe\lib\System.Data.CData.Stripe.dll") -
Connect to Stripe:
$conn= New-Object System.Data.CData.Stripe.StripeConnection("OAuthClientId=MyOAuthClientId;OAuthClientSecret=MyOAuthClientSecret;CallbackURL=http://localhost:33333;InitiateOAuth=GETANDREFRESH;") $conn.Open() -
Instantiate the StripeDataAdapter, execute an SQL query, and output the results:
$sql="SELECT Email, Discount from Customers" $da= New-Object System.Data.CData.Stripe.StripeDataAdapter($sql, $conn) $dt= New-Object System.Data.DataTable $da.Fill($dt) $dt.Rows | foreach { Write-Host $_.email $_.discount }
Update Stripe Data
$cmd = New-Object System.Data.CData.Stripe.StripeCommand("UPDATE Customers SET Delinquent='False' WHERE Id = @myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.Stripe.StripeParameter("@myId","10456255-0015501366")))
$cmd.ExecuteNonQuery()
Insert Stripe Data
$cmd = New-Object System.Data.CData.Stripe.StripeCommand("INSERT INTO Customers (Delinquent) VALUES (@myDelinquent)", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.Stripe.StripeParameter("@myDelinquent","False")))
$cmd.ExecuteNonQuery()
Delete Stripe Data
$cmd = New-Object System.Data.CData.Stripe.StripeCommand("DELETE FROM Customers WHERE Id=@myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.Stripe.StripeParameter("@myId","001d000000YBRseAAH")))
$cmd.ExecuteNonQuery()
CodeProject