Feel free to download and mess around with this app, it may or may not be updated regularly, when it is we will publicise on our twitter feed (@BlueVia)
There is little to do with python. The tutorial has been prepared with Python 2.6. Further on we need three additional python modules:
The easiest way to get these is easy_install from python setup tools:
easy_install httplib2
easy_install oauth2
easy_install simplejson
myMobileNumber = "44xxxxxxxxxx"
myShortcode = "445480605" # UK
myAdSpaceId = "xxxxx"
# App with all API's ticked
my3leggedConsumer = 'xxxxxxxxxxxxxxxx'
my3leggedSecret = 'xxxxxxxxxxxx'
# App with advertising only
my2leggedConsumer = 'xxxxxxxxxxxxxxxx'
my2leggedSecret = 'xxxxxxxxxxxx'
import bluevia
o3 = bluevia.BlueViaOauth(my3leggedConsumer, my3leggedSecret)
o3.fetch_request_token()
# returns the authorization URL. Paste into browser.
# When finished copy verifier, e.g 135791
o3.fetch_access_token("135791")
s = bluevia.BlueViaOutboundSms()
s.loadAccessToken("token.pkl")
r = s.sendSMS([myMobileNumber], "Hello BlueVia")
s.deliveryStatus(r[1])
Note: to use the real radio network call (this holds for all BlueVia calless below):
s = bluevia.BlueViaOutboundSms(sandbox="")
s.sendSMS([shortcode], "SANDBWTUT01 BlueVia")
si = bluevia.BlueViaInboundSMS()
si.loadAccessToken("token.pkl")
si.receiveSMS(shortcode)
m = bluevia.BlueViaOutboundMms()
m.loadAccessToken("token.pkl")
m.sendMMS(myMobileNumber, "Hello Multimedia BlueVia", \
["Message\n Number 1", "Yet another\n Message"], \
["samples/atextfile.txt", "samples/image.jpg"])
Receive MMS and retrieve the attachemnts (first send one or more MMS to the sandbox shortcode)
m.sendMMS(myShortcode, "SANDBWTUT01 BlueVia Multimedia", \
["Message\n Number 1", "Yet another\n Message"], \
["samples/atextfile.txt", "samples/image.jpg"])
mi = bluevia.BlueViaInboundMMS()
mi.loadAccessToken("token.pkl")
r = mi.receiveMMS(myShortcode)
mid = r[1]['receivedMessages']['messageIdentifier']
mi.retrieveAttachments(myShortCode, mid)
u = bluevia.BlueViaUserContext()
u.loadAccessToken("token.pkl")
u.getUserInfo()
l = bluevia.BlueViaLocation()
l.loadAccessToken("token.pkl")
l.locateTerminal()
a3 = bluevia.BlueViaAds(myAdSpaceId)
a3.loadAccessToken("token.pkl")
a3.getAd_3l()
import oauth2 as oauth
a2 = bluevia.BlueViaAds(myAdSpaceId)
a2.setConsumer(oauth.Token( my2leggedConsumer, my2leggedSecret))
a2.setDebug(debugFlag)
a2.getAd_2l("GB")
p = bluevia.BlueViaPayment(my3leggedConsumer, my3leggedSecret)
amount = 199 # no float, 199 means 1.99 EUR
currency = "EUR" # EUR, GBP, ...
# In sandbox any strings, commercially the service Id / Name given by the Mobile Payment Partner
serviceId = "123456"
serviceName = "My Digital Good"
p.fetch_request_token(amount, currency, serviceId, serviceName)
# When finished copy verifier, e.g 176539
p.fetch_access_token("176539")
p.savePaymentInfo("payment.pkl") # optional, token valid for 48 h
p.loadPaymentInfo("payment.pkl") # optional
result = p.issuePayment()
txid = result[1]["methodResponse"]["result"]["paymentResult"]["transactionId"]
p.checkPayment(txid)