Updating all active twilio Flow to ended error - twilio

So I want to run this pythong script to end all active Flows currently executing
executions = client.studio \
.v1 \
.flows('FWXXXXXX') \
.executions \
.list(limit=20)
for record in executions:
if record.status == 'active':
execution = client.studio \
.flows('FWXXXXXX') \
.executions(record.sid) \
.update(status='ended')
print('ending', execution)
I get this error "'ExecutionContext' object has no attribute 'update'"
I want to end a Twilio flow, but the documentation on the twilio website does not work for me in this case.

Twilio developer evangelist here.
Since you have already collected the executions when you list them from the API, you should be able to use that object to update the status. Try this:
executions = client.studio \
.v1 \
.flows('FWXXXXXX') \
.executions \
.list(limit=20)
for record in executions:
if record.status == 'active':
record.update(status='ended')
print('ending', record)

Related

Eventarc triggers for crossproject

I have created a cloud run service. My event arc is not triggering the cross project to read the data. How to give the event filter for resource name in event arc with insert job/Job completed to trigger to BQ table.
gcloud eventarc triggers create ${SERVICE}-test1\
--location=${REGION} --service-account ${SVC_ACCOUNT} \
--destination-run-service ${SERVICE} \
--destination-run-region=${REGION} \
--event-filters type=google.cloud.audit.log.v1.written \
--event-filters methodName=google.cloud.bigquery.v2.JobService.InsertJob \
--event-filters serviceName=bigquery.googleapis.com \
--event-filters-path-pattern resourceName="/projects/destinationproject/locations/us-central1/jobs/*"
I have tried multiple options giving the resource name like:
"projects/projectname/datasets/outputdataset/tables/outputtable"

How to use a custom dataset for T5X?

I've created a custom seqio task and added it to the TaskRegistry following the instruction per the documentation. When I set the gin parameters, accounting for the new task I've created, I receive an error that says my task does not exist.
No Task or Mixture found with name [my task name]. Available:
Am I using the correct Mixture/Task module that needs to be imported? If not, what is the correct statement that would allow me to use my custom task?
--gin.MIXTURE_OR_TASK_MODULE=\"t5.data.tasks\"
Here is the full eval script I am using.
python3 t5x/eval.py \
--gin_file=t5x/examples/t5/t5_1_0/11B.gin \
--gin_file=t5x/configs/runs/eval.gin \
--gin.MIXTURE_OR_TASK_NAME=\"task_name\" \
--gin.MIXTURE_OR_TASK_MODULE=\"t5.data.tasks\" \
--gin.partitioning.PjitPartitioner.num_partitions=8 \
--gin.utils.DatasetConfig.split=\"test\" \
--gin.DROPOUT_RATE=0.0 \
--gin.CHECKPOINT_PATH=\"${CHECKPOINT_PATH}\" \
--gin.EVAL_OUTPUT_DIR=\"${EVAL_OUTPUT_DIR}\"

Payment intent doesn't create properly for 'Standard' connected account

I'm creating a payment intent as per the Stripe documentation:
payment_intent = Stripe::PaymentIntent.create({
payment_method_types: ['card'],
amount: '1000',
currency: 'aud',
application_fee_amount: '10',
}, stripe_account: 'pi_1IwLlIJuxAkCMV')
When stripe_account is an Express account, the payment intent gets created and appears in the dashboard as expected.
But when stripe_account is a Standard account, the payment intent appears to be created and is visible in the console, but the payment intent is not visible in the stripe dashboard, and nor can it be retrieved with Stripe::PaymentIntent.retrieve(id):
Stripe::PaymentIntent.retrieve(payment_intent.id)
Stripe::InvalidRequestError: No such payment_intent: 'pi_1IwLlIJuxAkCMV'
from stripe-5.26.0/lib/stripe/stripe_client.rb:592:in `handle_error_response'
Question
Why does creating a payment intent work for express connected accounts but not standard connected accounts?
In your initial snippet, you likely meant to include an account id like acct_123 in the optional stripeAccount header (ref). That optional parameter also should be within an {} object/hash, though that appears to not be used in the example you linked.
Authenticating as one of your connected accounts like this creates the payment intent as a direct charge on the connected account itself (as described eslewhere on the doc you linked).
After creating a direct charge like this, you need to include that same stripeAccount header to authenticate during the retrieval:
Stripe::PaymentIntent.retrieve(payment_intent.id, { stripeAccount: 'acc'})
Edit to add: Confirming this curl example works as expected:
curl --request POST \
--url https://api.stripe.com/v1/payment_intents \
-u sk_test_123: \
--header 'Stripe-Account: acct_123' \
--data amount=10000 \
--data currency=usd \
--data confirm=true \
--data payment_method=pm_card_visa \
--data application_fee_amount=500
Creates pi_456, then:
curl --request GET \
--url https://api.stripe.com/v1/payment_intents/pi_456 \
-u sk_test_123: \
--header 'Stripe-Account: acct_123' \

Parse curl information in Rails application

This is my first time using curl in my Rails 4 App. I am trying to use Plaid with Stripe. I am able to successful exchange the public token for the stripe bank account token.
Stripe with Plaid ACH
Here's my controller action.
def create
results = `curl https://tartan.plaid.com/exchange_token \
-d client_id="CLIENT_ID" \
-d secret="SECRET_KEY" \
-d public_token="#{params[:public_token]}" \
-d account_id="#{params[:meta][:account_id]}"`
end
In Terminal with JSON.parse(results)
{"account_id"=>"ACCOUNT_ID", "stripe_bank_account_token"=>"12345678abcd", "sandbox"=>true, "access_token"=>"test_citi"}
How does one get the stripe_bank_account_token into the controller?
UPDATE
I am using the Figaro Gem to hide the params/credentials..
results =
`curl https://tartan.plaid.com/exchange_token \
-d client_id="#{ ENV['PLAID_CLIENT_ID'] }" \
-d secret="#{ ENV['PLAID_SECRET_KEY'] }" \
-d public_token="#{params[:public_token]}" \
-d account_id="#{params[:meta][:account_id]}"`
# here's how I get the stripe_bank_account_token
break_down = JSON.parse(results)
x = break_down.select { |key, val| key == "stripe_bank_account_token" }
You shouldn't pipe to curl from Ruby code especially when it involves user input.
Rather you should use the built in Ruby HTTP Client, a gem like RestClient, or even better the Plaid Ruby Gem.
gem install plaid
then just
require 'Plaid'
Plaid.config do |p|
p.client_id = '<<< Plaid provided client ID >>>'
p.secret = '<<< Plaid provided secret key >>>'
p.env = :tartan # or :api for production
end
user = Plaid::User.exchange_token(params[:public_token], params[:meta][:account_id], product: :auth)
user.stripe_bank_account_token
Just create new method for plaid, smth like below.
Also, Good to use HTTP client or REST client
HTTP client
REST client
def create
res = plain_curl(params)
puts res.inspect #there you will see your respond json obj in rails console.
end
private
def plain_curl(params)
#it should return you json object, if not just add return before result.
results = `curl https://tartan.plaid.com/exchange_token \
-d client_id="CLIENT_ID" \
-d secret="SECRET_KEY" \
-d public_token="#{params[:public_token]}" \
-d account_id="#{params[:meta][:account_id]}"`
end

Cant access PFUsers from Parse

I am new to parse and ios development.
I want to use Parse for User management of an IOS app. With the help of documentation (https://parse.com/docs/ios/guide#users-signing-up) I was able to signup some sample users and I have the following in Parse app.
Then I want to retrieve all users (or query for specific) with following documentation help.
var query = PFUser.query()
query.whereKey("gender", equalTo:"female")
var girls = query.findObjects()
I was expected to receive an array of size 3 but surprisingly didn't receive any.
Later I figured out I can user API console feature of Parse and tried use it to receive PFUser objects. I received zero results.
Later I tried with sample table and I was successfully add, retrieve Objects to the table.
Not sure If I need to anything special for me to use PFUser.
I have tested using API Console and its working on my side. I have one entry in User table having gender = male.
I fired following curl query to retry all the users
curl -X GET \
-H "X-Parse-Application-Id: <#your-application-key>" \
-H "X-Parse-REST-API-Key: <#your-rest-api-key>" \
-G \
https://api.parse.com/1/users
Result from the above query is:
{"results":[{"gender":"male","createdAt":"2015-12-10T06:00:40.368Z","email":"sam07it22#gmail.com","objectId":"1KbxpYgeUb","updatedAt":"2015-12-10T06:01:32.885Z","username":"sam07it22#gmail.com"}]}
Now, I'm going to add Condition in above query to fetch records having gender = female. As per data expected result should have zero records
For gender = female
curl -X GET \
-H "X-Parse-Application-Id: <#your-application-key>" \
-H "X-Parse-REST-API-Key: <#your-rest-api-key>" \
-G \
--data-urlencode 'where={"gender":"female"}' \
https://api.parse.com/1/users
Output:
{"results":[]}
For gender = male
curl -X GET \
-H "X-Parse-Application-Id: <#your-application-key>" \
-H "X-Parse-REST-API-Key: <#your-rest-api-key>" \
-G \
--data-urlencode 'where={"gender":"male"}' \
https://api.parse.com/1/users
Output:
{"results":[{"gender":"male","createdAt":"2015-12-10T06:00:40.368Z","email":"sam07it22#gmail.com","objectId":"1KbxpYgeUb","updatedAt":"2015-12-10T06:01:32.885Z","username":"sam07it22#gmail.com"}]}
NOTE:
Don't forget to replace your API KEY and REST API KEY
ACL permissions has done the trick. ACL permissions has to be "public read" for them to be accessible. Here is more info about ACL in parse https://parse.com/docs/ios/guide#security-object-level-access-control

Resources