Skip to content

Instantly share code, notes, and snippets.

@blomdell
Created March 1, 2012 22:24
Show Gist options
  • Save blomdell/1953672 to your computer and use it in GitHub Desktop.
Save blomdell/1953672 to your computer and use it in GitHub Desktop.
Opentransact demo

OpenTransact

Get started with AT&T's opentransact API, a sample app can be found at:

http://pure-sunset-8157.herokuapp.com/

In order to get started:


  1. Register your application with AT&T's Developer Portal
  2. Obtain a client_id and client_secret from AT&T's Developer Portal
  3. Set up settlement options with AT&T in order to enable payments
  4. Register your URI where you would like to receive transaction validation

<!DOCTYPE html>
<html>
<head>
<title>Mega Music Store</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.min.css" />
<script src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
<script src="http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.min.js"></script>
</head>
<body>
<div data-role="page">
<div data-role="header" data-theme="b">
<h1>Mega Music Store</h1>
</div><!-- /header -->
<div data-role="content" data-theme="b">
<ul data-role="listview" data-inset="true" data-filter="true">
<li>
<form action="<%= @api_host%>/payments/usd?client_id=1&to=Mega Music Store&tariff=USD25&note=Robyn&redirect_uri=<%= @this_host %>/purchased/1&cancel_url=<%= @this_host %>" method="post">
<button type='submit' data-icon="arrow-r" data-iconpos="right">Robyn, $5.00 </button>
</form>
</li>
<li>
<form action="<%= @api_host%>/payments/usd?client_id=1&amount=USD3&note=Mando Diao&redirect_uri=<%= @this_host %>/purchased/3&to=Mega Music Store&cancel_url=<%= @this_host %>" method="post">
<button type='submit' data-icon="arrow-r" data-iconpos="right">Mando Diao, $3.00 </button>
</form>
</li>
<li>
<form action="<%= @api_host%>/payments/usd?client_id=1&to=Mega Music Store&tariff=USD2&note=The Hives&redirect_uri=<%= @this_host %>/purchased/2&cancel_url=<%= @this_host %>" method="post">
<button type='submit' data-icon="arrow-r" data-iconpos="right">The Hives, $2.00 </button>
</form>
</li>
</ul>
</div><!-- /content -->
</div><!-- /page -->
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>Mega Music Store</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.min.css" />
<script src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
<script src="http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.min.js"></script>
</head>
<body>
<div data-role="page">
<div data-role="header" data-theme="b">
<h1>Mega Music Store</h1>
</div><!-- /header -->
<div data-role="content" data-theme="b">
<h1>Your Purchase is complete!</h1>
</div><!-- /content -->
</div><!-- /page -->
</body>
</html>
!!!
%html{:lang => "en"}
%head
%meta{:charset => "utf-8"}/
%title Mega Music Store
%meta{:content => "Mega Music Store", :name => "description"}/
%meta{:content => "AT&T Foundry", :name => "author"}/
%script{:src => "js/bootstrap-modal.js"}
%script{:src => "js/bootstrap-popover.js"}
%script{:src => "js/bootstrap-twipsy.js"}
/ Le HTML5 shim, for IE6-8 support of HTML elements
/[if lt IE 9]
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
/ Le styles
%link{:href => "../css/bootstrap.css", :rel => "stylesheet"}/
:css
body {
padding-top: 60px;
}
%body
.topbar
.fill
.container
%a.brand{:href => "#"} Mega Music Store
%ul.nav
%li.active
%a{:href => "#"} Home
%li
%a{:href => "#about"} About
%li
%a{:href => "#contact"} Contact
.container
/ Main hero unit for a primary marketing message or call to action
.hero-unit
%h1 Mega music store
%p Come and enjoy the latest pop music from Sweden!
%p
%a.btn.primary.large.disabled Learn more &raquo;
/ Example row of columns
.row
.span-one-third
%form{:action => 'http://apifoundry-dev.pao1.tfoundry.com/alpha/opentransact/payments/usd?to=Mega Music Store&tariff=USD25&note=Robyn&redirect_uri=http://pure-sunset-8157.herokuapp.com/1/1&cancel_url=http://pure-sunset-8157.herokuapp.com/', :method => 'post'}
%h2 Robyn
%p Robin Miriam Carlsson (born 12 June 1979), better known by her stage name Robyn, is a Swedish recording artist and singer-songwriter. Robyn became known in the late nineties for her worldwide dance-pop hit "Do You Know (What It Takes)" from her debut album Robyn Is Here (1997). The popularity of her number-one hit "With Every Heartbeat" and subsequent album release Robyn (2005) brought her mainstream success worldwide. In January 2009 Robyn won a Swedish Grammis award for Best Live Act 2008.
%p
- if !@purchasedOne
%button.btn.primary{:type => 'submit'} Buy it now &raquo;
- if @purchasedOne
%a.btn.danger.disabled{:href => ''} Purchased &raquo;
.span-one-third
%form{:action => 'http://apifoundry-dev.pao1.tfoundry.com/alpha/opentransact/payments/usd?to=Mega Music Store&tariff=USD50&note=The Hives&redirect_uri=http://pure-sunset-8157.herokuapp.com/1/2&cancel_url=http://pure-sunset-8157.herokuapp.com/', :method => 'post'}
%h2 The Hives
%p The Hives are a Swedish garage rock band that first garnered attention in the early 2000s as a prominent group of the garage rock revival. Their mainstream success came with the release of the "greatest hits" album Your New Favourite Band, featuring their most well-known song "Hate to Say I Told You So". The Hives are known for performing in ever-changing black and white suits.
%p
- if !@purchasedTwo
%button.btn.primary{:type => 'submit'} Buy it now &raquo;
- if @purchasedTwo
%a.btn.danger.disabled{:href => ''} Purchased &raquo;
.span-one-third
%form{:action => 'http://apifoundry-dev.pao1.tfoundry.com/alpha/opentransact/payments/usd?to=Mega Music Store&tariff=USD75&note=Mando Diao&redirect_uri=http://pure-sunset-8157.herokuapp.com/1/3&cancel_url=http://pure-sunset-8157.herokuapp.com/', :method => 'post'}
%h2 Mando Diao
%p Mando Diao is an alternative rock band from Borlänge, Sweden. The band got their breakthrough with the release of the album Hurricane Bar. Their main fan base is in Sweden, Germany, and Japan although their influence has recently spread to Western Europe, most notably the UK.
%p
- if !@purchasedThree
%button.btn.primary{:type => 'submit'} Buy it now &raquo;
- if @purchasedThree
%a.btn.danger.disabled{:href => ''} Purchased &raquo;
%footer
%p &copy; Foundry 2012
/ /container
require 'rubygems'
require 'sinatra'
$LOAD_PATH.unshift(File.dirname(__FILE__))
require 'haml'
configure do
@purchasedOne = false
@purchasedTwo = false
@purchasedThree = false
end
get '/' do
haml :storefront
end
get "/mobile" do
@api_host=URI.encode("http://apifoundry-dev.pao1.tfoundry.com/alpha/opentransact/")
@this_host=URI.encode("http://pure-sunset-8157.herokuapp.com")
erb :mobile
end
get '/validateTransaction' do
require 'json'
p params.inspect
validation = Hash.new
validation['code'] = params['code']
validation['secret'] = 'xyz'
return validation.to_json
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment