Pausing a Kill Bill subscription - payment

We've been using Kill Bill to manage a delivery subscription service. You can sign up to a subscription to receive the items you choose, and be billed monthly.
We want to implement a pause feature so that customers could delay their subscriptions if they went on holiday, for example.
The problem is that we can't figure out how to do that with the API. There's a method to cancel the entitlement (another word for subscription, I think) and one to update it, but nothing obviously related to pausing.
Maybe there's a parameter we need to pass in the update method that we haven't found yet?
You can find the API here, and the majority of the mentions of pausing we could locate in the documentation are on this page.
Any help would be greatly appreciated!

There is indeed a pause/resume capability in Kill Bill. This is specified at the bundle level (meaning if you have a bundle with multiple subscriptions they would all be paused/resumed). There is also another mechanism with a lower granularity, but let's start with the basics:
Assuming the following:
a tenant 'bob'/'lazar'
a bundle with subscriptions whose bundle_id = '627a0b2a-82ef-4d7f-b1c7-a5a94be705bf'
Pause on 2016-05-14 (interpreted in account timezone):
curl -v \
-X PUT \
-u admin:password \
-H "X-Killbill-ApiKey: bob" \
-H "X-Killbill-ApiSecret: lazar" \
-H "Content-Type: application/json" \
-H "X-Killbill-CreatedBy: stephane" \
'http://127.0.0.1:8080/1.0/kb/bundles/627a0b2a-82ef-4d7f-b1c7-a5a94be705bf/pause?requestedDate=2016-05-14'
Resume on 2016-05-18 (interpreted in account timezone):
curl -v \
-X PUT \
-u admin:password \
-H "X-Killbill-ApiKey: bob" \
-H "X-Killbill-ApiSecret: lazar" \
-H "Content-Type: application/json" \
-H "X-Killbill-CreatedBy: stephane" \
'http://127.0.0.1:8080/1.0/kb/bundles/627a0b2a-82ef-4d7f-b1c7-a5a94be705bf/resume?requestedDate=2016-05-18'

Related

Stripe - get subscription for specific email

I have customer email. How to check does customer have valid subscription?
I'm using cUrl.
Thank you.
Stripe allows expand responses. Fortunately subscriptions property of customer object is expandable. Thus, you can reduce the number of API requests and lines of intermediate code.
curl https://api.stripe.com/v1/customers/search \
-u $API_KEY: \
--data-urlencode query="email:'test#example.com'" \
-d "expand[]"="data.subscriptions" \
-G
This would be a two-step process:
First, find the ID of the customer by using their email like this:
curl https://api.stripe.com/v1/customers \
-u sk_xxx: \
-d email=foo#bar.com \
-G
Second, use the customer ID to list all their subscriptions like this:
curl https://api.stripe.com/v1/subscriptions \
-u sk_xxx: \
-d customer=cu_xxx \
-G

How does urllib.request differ from curl or httpx in behaviour? Getting a 401 in a request to the Google Container Registry

I am currently working on some code to interact with images on the Google Container Registry. I have working code both using plain curl and also httpx. I am trying to build a package without 3rd party dependencies. My curiosity is around a particular endpoint from which I get a successful response in curl and httpx but a 401 Unauthorized using urllib.request.
The bash script that demonstrates what I'm trying to achieve is the following. It retrieves an access token from the registry API, then uses that token to verify that the API indeed runs version 2 and tries to access a particular Docker image configuration. I'm afraid that in order to test this, you will need access to a private GCR image and a digest for one of the tags.
#!/usr/bin/env bash
set -eu
token=$(gcloud auth print-access-token)
image=...
digest=sha256:...
get_token() {
curl -sSL \
-G \
--http1.1 \
-H "Authorization: Bearer ${token}" \
-H "Accept: application/vnd.docker.distribution.manifest.v2+json" \
--data-urlencode "scope=repository:$1:pull" \
--data-urlencode "service=gcr.io" \
"https://gcr.io/v2/token" | jq -r '.token'
}
echo "---"
echo "Retrieving access token."
access_token=$(get_token ${image})
echo
echo "---"
echo "Testing version 2 capability with access token."
curl -sSL \
--http1.1 \
-o /dev/null \
-w "%{http_code}" \
-H "Authorization: Bearer ${access_token}" \
-H "Accept: application/vnd.docker.distribution.manifest.v2+json" \
https://gcr.io/v2/
echo
echo "---"
echo "Retrieving image configuration with access token."
curl -vL \
--http1.1 \
-o /dev/null \
-w "%{http_code}" \
-H "Authorization: Bearer ${access_token}" \
-H "Accept: application/vnd.docker.distribution.manifest.v2+json" \
"https://gcr.io/v2/${image}/blobs/${digest}"
I additionally created two Jupyter notebooks demonstrating my solutions in httpx and bare urllib.request. The httpx one works perfectly while somehow urllib fails on the image configuration request. I'm running out of ideas trying to spot the difference. If you run the notebook yourself, you will see that the called URL contains a token as a query parameter (is this a security issue?). When I open that link I can actually successfully download the data myself. Maybe urllib still passes along the Authorization header with the Bearer token making that last call fail with 401 Unauthorized?
Any insights are greatly appreciated.
I did some investigation and I believe the difference is that the last call to "https://gcr.io/v2/${image}/blobs/${digest}" actually contains a redirect. Inspecting the curl and httpx calls showed me that both do not include the Authorization header in the second, redirected request, whereas in the way that I set up the urllib.request in the notebook, this header is always included. It's a bit odd that this leads to a 401 but now I know how to address it.
Edit: I can now confirm that by building a urllib.request.Request instance and unlike in the linked notebook, add the authorization header with the request's add_unredirected_header method, everything works as expected.

Using CURL to upload to Dropbox and overwrite a file

I'm a small time admin and would say entry level to Linux. I am trying to use CURL to upload to Dropbox a small backup sqlitedb and have had success for the first upload, however, I am trying to accomplish uploading a file to Dropbox every 30 minutes and overwriting the current file in DROPBOX with the new file from my Linux server (as a jerry-rigged offsite backup of my Teamspeak database)
This is the code I have so far :
curl -X PUT https://content.dropboxapi.com/2/files/upload \
--header "Authorization: Bearer <dropbox code here>" \
--header "Dropbox-API-Arg: {\"path\": \"/home/ec2-user/ts3server.sqlitedb.bz2\"}" \
--header "Content-Type: application/octet-stream" \
--data-binary ts3server.sqlitedb.bz2
After running that code once, it doesn't OVERRIDE the current file in my Dropbox account with the updated file. Any help is appreciated
you need to use mode with parameter overwrite. The default is add.
Add - Do not overwrite an existing file if there is a conflict. The autorename strategy is to append a number to the file name. For
example, "document.txt" might become "document (2).txt".
overwrite - Always overwrite the existing file. The autorename strategy is the same as it is for add.
Reference: /upload
curl -X POST https://content.dropboxapi.com/2/files/upload \
--header "Authorization: Bearer " \
--header "Dropbox-API-Arg: {\"path\": \"/Homework/math/Matrices.txt\",\"mode\": \"overwrite\",\"autorename\": true,\"mute\": false}" \
--header "Content-Type: application/octet-stream" \
--data-binary #local_file.txt

Posting a Tweet with Unification Engine

When adding a connection using the Twitter connector offered by the Unification Engine, what are the parameters that need to be used and how are they to be passed in the URI?
To send tweet use
curl -XPOST https://apiv2.unificationengine.com/v2/message/send \
--data "{ \"message\": { \"receivers\": [{\"name\": \"name\", \"address\": \"TWITTER_HANDLE\" , \"Connector\": \"UNIQUE_CONNECTION_IDENTIFIER\"}],\"parts\": [{\"id\": \"1\",\"contentType\": \"text/plain\", \"data\":\"MESSAGE_CONTENT\" ,\"size\": MESSAGE_CONTENT_SIZE,\"type\": \"body\",\"sort\":0}]}}" \
-u USER_ACCESSKEY:USER_ACCESSSECRET -k
Where USER_ACCESSKEY:USER_ACCESSSECRET is got when you add the user using UE_APPKEY:UE_APPSECRET
curl -XPOST https://apiv2.unificationengine.com/v2/user/create -u UE_APPKEY:UE_APPSECRET \
--data '{}' -k
Response data:
{"status":200,"info":"200 OK","uri":"user://USER_ACCESSKEY:USER_ACCESSSECRET"}
Let me explain the commands used to add a twitter connection in #UnificationEngine
To add twitter connection in #UnificationEngine use
curl -XPOST https://apiv2.unificationengine.com/v2/connection/add \
-u USER_ACCESSKEY:USER_ACCESSSECRET \
--data '{"uri":"twitter://ACCESS_TOKEN:SECRET#twitter.com","name":"UNIQUE_CONNECTION_IDENTIFIER"}' \
-k
ACCESS_TOKEN:SECRET - is the one got by authentication the twitter connection in the user application.
UNIQUE_CONNECTION_IDENTIFIER - specified here will be further used to address this connection in UE.
f.e to send a tweet the user will have to use the variable specified under UNIQUE_CONNECTION_IDENTIFIER

Fiware: How to create lazy attributes through IDAS UltraLight

I'm using the IoT Agent Ultra-Light module to communicate with the Orion context broker. I can create services and devices and I have checked that the observations reach the context broker too.
curl -X POST XXX.XXX.XXX.XXX:8090/iot/services \
-i \
-H "Content-Type: application/json" \
-H "Fiware-Service: sanitysrv " \
-H "Fiware-ServicePath: / sanitysspath " \
-d '{"services": [{"apikey": "", "cbroker": "http://127.0.0.1:1026", "entity_type": "Dispositivo_tmp", "resource": "/iot/d"}]}'
curl -X POST XXX.XXX.XXX.XXX:8090/iot/devices \
-i \
-H "Content-Type: application/json" \
-H "Fiware-Service: sanitysrv" \
-H "Fiware-ServicePath: /sanitysspath" \
-d '{"devices":[{"device_id":"CE_BDM_3","protocol":"PDI-IoTA-UltraLight", "commands": [], "attributes": [{"type":"int","name":"temperature","object_id":"t"}]}]}'
My problem is that I don´t know how to register a device that contains lazy attributes, and I haven´t found any documentation with related examples. The examples from other IoT Agents that I have tried are not working here.
¿How can it be done?
Lazy attributes are not supported in the UL2.0/MQTT Agent so far but in IoT Agents developed with node.js.
We'll let you know as soon as this feature is available.
Cheers,

Resources