SmartyStreets subscription balance - monitoring

In SmartyStreets, I can view my subscription balance while logged in on the portal. There's no way to check my subscription balance via the API. Our app requires address validation in order to sell. As part of operationalizing SmartyStreets, I want to monitor my subscription balance, so I can be alerted to renew before I run out of address validations.
Available monitoring tools are Nagios, Nimsoft and CA APM.
Has anyone built such a monitor?

SmartyStreets subscriptions renew on 2 occasions:
It expires (e.g. a month or year has passed)
Your lookups get depleted
The second trigger is there so that you don't have to worry about how used up your subscription is; if you run out, it just fills up with more without interrupting your service.
As for monitoring, it's kind of built-in. You should get emails when your subscription is running low, when it is about to renew, and when it actually does renew.

Screen-scraping using curl is one approach. Try:
Get a cookie jar from the auth app.
Grab your accounts from the subscription app.
Crunch the numbers.
This command will save your auth cookies in the SSCookies file:
$ curl -c SSCookies 'http://smartystreets.com/apps/accounting/auth' -d email=myEmail -d password=myPassword
Now use the cookie jar to auth with the subscription app. These commands will fetch your subscriptions:
$ subs=https://smartystreets.com/apps/accounting/subscription
$ curl -s -b #SSCookies $subs | python -mjson.tool
(The | python part makes the output pretty)
The resulting JSON will list your whole account history, including subscriptions that are no longer active and any that may be coming up for renewal. Look for the entry that has a status of "active":
[
{
"free": true,
"id": nnnnn,
"issued": 250.0,
"lapse_date": "2013-06-15T08:15:00Z",
"name": "LiveAddress API (Free)",
"sku": nnnnn,
"start_date": "2013-06-03T21:56:00Z",
"status": "expired",
"used": 250
},
{
"autorenew": true,
"id": nnnnn,
"issued": 1200000.0,
"lapse_date": "2015-06-20T20:11:00Z",
"name": "LiveAddress API (Yearly)",
"sku": nnnnn,
"start_date": "2014-06-20T20:11:00Z",
"status": "active",
"used": 934
},
{
"autorenew": true,
"cart_id": 0,
"issued": 1200000.0,
"lapse_date": "2016-07-20T20:11:00Z",
"name": "LiveAddress API (Yearly)",
"sku": nnnnn,
"start_date": "2015-07-20T20:11:00Z",
"status": "proposed"
}
]
My active subscription is #2 (index 1). Some Python to extract the vitals (I named this SSMonitor.py):
import json,sys;
obj=json.load(sys.stdin);
keys=obj[1].keys();
values=obj[1].values();
for i,key in enumerate(keys):
if (key=="used"): used=values[i];
if (key=="issued"): issued=values[i];
print "SmartyStreets subscription usage: {0}/{1}".format(used, issued);
$ curl -s -b #SSCookies $subs | python SSMonitor.py
SmartyStreets subscription usage: 934/1200000.0

Related

Graph explorer callrecords "could not find the requested call record"

I am trying to get call records from MS Teams and store it in another database and I'm calling callRecord to do that. I am running a python script on a console app and used these steps: (https://learn.microsoft.com/en-us/azure/active-directory/develop/console-app-quickstart?pivots=devlang-python).
I have created a subscription in the function app in the portal, and I'm able to grab the ID from there through an HTTP trigger. The app information is stored in a JSON file, as seen below and that's what I'm running through the script.
{
"authority": "https://login.microsoftonline.com/xxx",
"client_id": "xx",
"scope": [ "https://graph.microsoft.com/.default" ],
"secret": "xx",
"endpoint": "https://graph.microsoft.com/v1.0/communications/callRecords/ID(from subscription)
}
When I run the script, I get this:
Error
Any help would be appreciated!

ASPNET Waiting for a Webhook Response/Result on a WebPage

We have a web page which takes a Stripe payment, once the payment is complete Stripe can call a webhook on our server.
At this point, we can mark an Order as complete and complete any other additional tasks.
How can we have the order webpage update/move the user onto to order complete?
Should we consistently hit the server in AJAX to check if it's now complete, or is there a better way of doing this.
Q: How can we have the order webpage update/move the user onto to order complete?
Most payment engines will redirect the payment session to a URL of your choosing with a result code or a different URL per result code. These can generally be configured at the moment the request is being made or for the entire site in a general configuration. These results should not be relied on for the actual payment as that is the job for the web hook. They can be trusted enough for your site to show a general success/fail error message and let the user continue doing whatever.
Stripe also allows for this, you can specify a success_url (or successUrl in the client integration).
See Create a Checkout Session on your server for how to pass this URL to the request. You can also include a cancel_url. See the last 2 parameters in the code sample below:
curl https://api.stripe.com/v1/checkout/sessions \
-u sk_test_4eC39HqLyjWDarjtT1zdp7dc: \
-d payment_method_types[]=card \
-d line_items[][name]=T-shirt \
-d line_items[][description]="Comfortable cotton t-shirt" \
-d line_items[][images][]="https://example.com/t-shirt.png" \
-d line_items[][amount]=500 \
-d line_items[][currency]=usd \
-d line_items[][quantity]=1 \
-d success_url="https://example.com/success" \
-d cancel_url="https://example.com/cancel"
See also Checkout Purchase Fulfillment.
When your customer successfully completes their payment or initiates a subscription using Checkout, Stripe redirects them to the URL that you specified in the success_url parameter (or successUrl in the client integration). Typically, this is a page on your website that informs your customer that their payment was successful.
And as I stated above do not rely on this as the actual indicator if the payment succeeded. You should use the web hooks for that.
Do not rely on the redirect to the success_url alone for fulfilling purchases as:
Malicious users could directly access the success_url without paying and gain access to your goods or services.
Customers may not always reach the success_url after a successful payment. It is possible they close their browser tab before the redirect occurs.
Good question,
You can handle the stripe payment result to take a new effect on your page
var cardholderName = document.getElementById('cardholder-name');
var cardButton = document.getElementById('card-button');
var clientSecret = cardButton.dataset.secret;
cardButton.addEventListener('click', function(ev) {
stripe.handleCardPayment(
clientSecret, cardElement, {
payment_method_data: {
billing_details: {name: cardholderName.value}
}
}
).then(function(result) {
if (result.error) {
// Display error.message in your UI.
} else {
// The payment has succeeded. update your front-end
}
});
});
Should we consistently hit the server in AJAX to check if it's now
complete, or is there a better way of doing this.
An Ajax example is here but beter way to doing that is the fetch api. You can find out all detail in here
Should we consistently hit the server in AJAX to check if it's now complete, or is there a better way of doing this.
No you shouldn't and yes there is a better way. Callback pages/webhooks would make sense if you didn't have an asp.net server handing the transaction, but they aren't necessary here.
How can we have the order webpage update/move the user onto to order
complete?
The stripe payment process only takes a couple seconds to respond with a status code. It's not the same as Paypal where the user is directed to a Paypal site and then back to your site.
The process is supposed to go:
The user enters their payment information into stripe generated
elements on your page.
Stripe gives your front end javascript a
token that represents the customer's payment data.
You post that information to your server using ajax or even a regular old fashioned form request.
The server side script handling the call uses the asp.net stripe library to send the payment and gets an answer back like the one below.
Save the transaction result to your database as needed.
a. If the stripe resonse includes "status":"succeeded" then you can serve the customer with a new page with the paid receipt.
b. If it failed for some reason you can reload the payment page and use the "failure_message" to tell the customer why their card is no good.
Let the user wait until stripe replies with a message regarding the success or failure of the payment and send him because it only takes a second.
/* SAMPLE RESPONSE FROM STRIPE
{
"id": "ch_1D658SDJ46dzUiasdfsdfaDq",
"object": "charge",
"amount": 2125,
"amount_refunded": 0,
"application": null,
"application_fee": null,
"balance_transaction": "txn_1D658SDJ46dzUilftNXRCz64",
"captured": true,
"created": 1565431460,
"currency": "usd",
"customer": null,
"description": "856 addresses",
"destination": null,
"dispute": null,
"failure_code": null,
"failure_message": null,
"fraud_details": {},
"invoice": null,
"livemode": false,
"metadata": {},
"on_behalf_of": null,
"order": null,
"outcome": {
"network_status": "approved_by_network",
"reason": null,
"risk_level": "normal",
"seller_message": "Payment complete.",
"type": "authorized"
},
"paid": true,
"receipt_email": null,
"receipt_number": null,
"refunded": false,
"refunds": {
"object": "list",
"data": [],
"has_more": false,
"total_count": 0,
"url": "/v1/charges/ch_1D658SDJ46dzUilfalFFraDq/refunds"
},
"review": null,
"shipping": null,
"source": {
"id": "card_1D658RDJ46dzUilfbkLSOIwp",
"object": "card",
"address_city": "test",
"address_country": "US",
"address_line1": "123 test",
"address_line1_check": "pass",
"address_line2": "",
"address_state": null,
"address_zip": "32121",
"address_zip_check": "pass",
"brand": "Visa",
"country": "US",
"customer": null,
"cvc_check": "pass",
"dynamic_last4": null,
"exp_month": 12,
"exp_year": 2033,
"fingerprint": "fNMgYIntTkOnLVzk",
"funding": "credit",
"last4": "4242",
"metadata": {},
"name": "Test",
"tokenization_method": null
},
"source_transfer": null,
"statement_descriptor": null,
"status": "succeeded",
"transfer_group": null
}

Rails: How to disable app after certain amount of usage

I have a Rails/Shopify app that processes orders from the User's Shopify store. I want to have tiered plans (e.g. Bronze < 20 orders, Silver < 100 orders, Gold 100+).
What's the best way to implement this?
1) How do I track which subscription plan they are on, when it changes etc?
2) How do I disable the app once a user hits their limit?
Any links to articles/tutorials/gems to help would be great.
I would do it the following way. Once you have the token you can access the application charges for the shop you're in. You could either use
GET /admin/recurring_application_charges/455696195.json
or like I use it
ShopifyAPI::RecurringApplicationCharges.current
which gets you the current plan the user is on. You can access the name of the plan etc. To track how many orders were processed I would write a controller and implement a simple counter. Each time a request is being sent the counter is incremented. Once the limit is reached you can redirect him to an error page or somewhere else.
To answer the second part of your question you could access the current charge as mentioned above and get all the information you need (e.g. "billing_on": "2015-03-27T00:00:00+00:00")
Here is a sample response with all the available fields:
HTTP/1.1 200 OK
{
"recurring_application_charge": {
"activated_on": null,
"api_client_id": 755357713,
"billing_on": "2015-03-27T00:00:00+00:00",
"cancelled_on": null,
"created_at": "2015-03-28T13:31:19-04:00",
"id": 455696195,
"name": "Super Mega Plan",
"price": "15.00",
"return_url": "http:\/\/yourapp.com",
"status": "pending",
"test": null,
"trial_days": 0,
"trial_ends_on": null,
"updated_at": "2015-03-28T13:31:19-04:00",
"decorated_return_url": "http:\/\/yourapp.com?charge_id=455696195",
"confirmation_url": "https:\/\/apple.myshopify.com\/admin\/charges\/455696195\/confirm_recurring_application_charge?signature=BAhpBENfKRs%3D--a911ece9470850c96f6c7735c684b8a3f6869594"
}
}
You can find more under https://docs.shopify.com/api/recurringapplicationcharge or https://docs.shopify.com/api/applicationcharge
Hope I could help

How to create a new sprint in JIRA programmatically?

I'm migrating a number of projects from one JIRA instance to another using JSON importer. Although the importer can assign issues to existing sprints, the sprints themselves must already exist -- a limitation of the current version of JIRA Importer.
We've been creating sprints by hand 'till now, but some of our projects have a large number of them, which make the manual process both tedious and error-prone.
It does not appear like JIRA REST API can create new sprints either -- although people talk about the greenhopper/1.0/sprint/create endpoint, it does not exist.
Is there, perhaps, some other way to create sprints programmatically? I have no problems with obtaining the full list of them from the source JIRA instance, it is creating them in the target instance, that does not seem possible...
Any hope? Can I INSERT new records into the AO_60DB71_SPRINT-table with a SQL-client? Thanks!
This can be done using the JIRA Agile API. See JIRA Agile REST API Reference
So, for example using curl:
## Request JIRA Sprint POST Create
curl -X "POST" "https://jira.foobar.com/rest/agile/1.0/sprint" \
-H 'Content-Type: application/json' \
-u 'myusername:mypassword' \
-d $'{
"startDate": "2018-04-23T00:00:00.000+01:00",
"name": "Cool Sprint",
"endDate": "2018-05-03T13:00:00.000+01:00",
"originBoardId": 1072
}'
The response of which would be:
{
"id": 1130,
"self": "https://jira.foobar.com/rest/agile/1.0/sprint/1130",
"state": "future",
"name": ""Cool Sprint",
"startDate": "2018-04-23T01:00:00.000+02:00",
"endDate": "2018-05-03T14:00:00.000+02:00",
"originBoardId": 1072
}

how to get an openstack token and validate it?

I followed this guide: http://keystone.openstack.org/api_curl_examples.html
and it seemed that I got a valid token by ran:
curl -d '{"auth":{"passwordCredentials":{"username": "can", "password": "mypassword"}}}' -H "Content-type: application/json" http://url:35357/v2.0/tokens
and it returned:
{
"access":
{
"token":
{
"expires": "2012-05-21T14:35:17Z",
"id": "468da447bd1c4821bbc5def0498fd441"
},
"serviceCatalog": {},
"user":
{
"username": "can",
"roles_links": [],
"id": "bb6d3a09ad0c4924bf20c1a32ccb5781",
"roles": [],
"name": "can"
}
}
}
but when I came to the next few sections to validate this token, I encountered this magic number: X-Auth-Token:999888777666. At first I thought it's the token I got but I was wrong.
I think I may have missed something, so I read related sections in openstack documents( http://keystone.openstack.org/configuration.html and http://docs.openstack.org/api/openstack-compute/programmer/content/ ), but still no idea how the number comes from.
could anyone explain to me
what's the meaning of that magic number
how to get the right value of it so I can get a working token to manage other parts of openstack
That magic number (string really) is the admin_token setting in your keystone.conf file. Under the [DEFAULT] section in keystone.conf set
admin_token = abcd1234
If you don't use it for admin actions, you'll see something like
ubuntu#i-000004bc:~/devstack$ curl http://localhost:35357/v2.0/tenants
{"error": {"message": "The request you have made requires authentication.", "code": 401, "title": "Not Authorized"}}
If you do use it, you'll see something like
ubuntu#i-000004bc:~/devstack$ curl -H "X-Auth-Token: abcd1234" http://localhost:35357/v2.0/tenants
{"tenants_links": [], "tenants": [{"enabled": true, "description": null, "name": "demo", "id": "aee8a46babcb4e4286021c8f6ef996cd"}, {"enabled": true, "description": null, "name": "invisible_to_admin", "id": "de17fea45de148ada0a58e998e6c3e73"}, {"enabled": true, "description": null, "name": "admin", "id": "f34b0c8ab30e450489b121fbe723fde5"}, {"enabled": true, "description": null, "name": "service", "id": "fbe3e2e530fd47298cb2cba1b4afa3da"}]}
To get the list of tenants, in our current implementation, we authenticate with admin credentials and use the token returned to get list of tenants.
The implementation works smooth with the authentication token. It may work with admin_token but I have not verified.
If you see the examples you are referring to, there are 2 types of endpoints used
Endpoint pointing to port 5000 - public port
Endpoint pointing to port 35357 - admin port
In examples which are hitting admin port you would need to specify the "X-Auth-Token" header as the admin_token (specified in the keystone.conf file)
The token itself is in dict["access"]["token"]["id"] which is that part that will go in the header of subsequent HTTP requests, i.e
X-Auth-Token: 468da447bd1c4821bbc5def0498fd441
The value 999888777666 is from the curl example tutorial and will definitely not work.
As for the value of the token itself, it's randomly generated by the OpenStack service and shouldn't contain any useful information from your point of view.
(BTW, you probably shouldn't go pasting the tokens into forums as they're valid for 24 hours and anyone with a copy of the token and access to your compute endpoint can use it to impersonate you).

Resources