Created
May 3, 2012 20:59
-
-
Save t2-support-gists/2589448 to your computer and use it in GitHub Desktop.
Payment PHP app1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AT&T API Samples - Payment app 1 | |
------------------------------ | |
This file describes how to set up, configure and run the Java Applications of the AT&T HTML5 Program sample applications. | |
It covers all steps required to register the application on DevConnect and, based on the generated API keys and secrets, | |
create and run one's own full-fledged sample applications. | |
1. Configuration | |
2. Installation | |
3. Parameters | |
4. Running the application | |
1. Configuration | |
Configuration consists of a few steps necessary to get an application registered on DevConnect with the proper services and | |
endpoints, depending on the type of client-side application (autonomous/non-autonomous). | |
To register an application, go to https://devconnect-api.att.com/ and login with your valid username and password. | |
Next, choose "My Apps" from the bar at the top of the page and click the "Setup a New Application" button. | |
Fill in the form, in particular all fields marked as "required". | |
Be careful while filling in the "OAuth Redirect URL" field. It should contain the URL that the oAuth provider will redirect | |
users to when he/she successfully authenticates and authorizes your application. For this application, it should point to | |
the oauth.jsp file inside this application folder. For example, if running on a local machine in a default Tomcat installation, | |
your OAuth Redirect URL might be http://localhost:8080/SampleApp/oauth.jsp | |
Also be careful when filling in the "Payment Listener URL" field when setting up your organization profile. This should point | |
to the paymentlistener.jsp file packaged with this application. This listener URL must be a public URL or IP address that the | |
gateway will be able to reach. For example, if running this application on a server with IP address 1.2.3.4 in a default Tomcat | |
instance, your listener URL might be https://1.2.3.4:8080/SampleApp/paymentlistener.jsp | |
NOTE: You MUST select Payment in the list of services under field 'Services' in order to use this sample application code. | |
Having your application registered, you will get back an important pair of data: an API key and Secret key. They are | |
necessary to get your applications working with the AT&T HTML5 APIs. See 'Adjusting parameters' below to learn how to use | |
these keys. | |
Initially your newly registered application is restricted to the "Sandbox" environment only. To move it to production, | |
you may promote it by clicking the "Promote to production" button. Notice that you will get a different API key and secret, | |
so these values in your application should be adjusted accordingly. | |
Depending on the kind of authentication used, an application may be based on either the Autonomous Client or the Web-Server | |
Client OAuth flow (see https://devconnect-api.att.com/docs/oauth20/autonomous-client-application-oauth-flow or | |
https://devconnect-api.att.com/docs/oauth20/web-server-client-application-oauth-flow respectively). | |
2. Installation | |
** Requirements | |
To run the examples you need a Java environment and at least Apache Tomcat 6, or another Java web server such as Jetty. | |
** Setting up multiple sample applications simultaneously | |
In case multiple applications need to be run at the same time, make sure to put each app in a separate folder and | |
adjust your OAuth Redirect URL accordingly. | |
3. Parameters | |
Each sample application contains a config.jsp file. It holds configurable parameters described in an easy to read format. | |
Please populate the following parameters in config.jsp as specified below: | |
1) clientIdAut : {set the value as per your registered appliaction 'API key' field value} | |
2) clientSecretAut : {set the value as per your registered appliaction 'Secret key' field value} | |
3) FQDN : https://api.att.com | |
Note: If your application is promoted from Sandbox environment to Production environment and you decide to use production | |
application settings, you must update parameters 1-2 as per production application details. | |
4. Running the application | |
To run the application, put the entire contents of the application folder into a separate folder named SampleApp inside the webapps | |
folder in your Apache Tomcat home directory. If you have specified a different home directory in Tomcat for your web applications, | |
put it there instead. | |
Depending on your security settings in Apache Tomcat, you might need to enable write access to the OauthStorage.jsp file. | |
Once you start tomcat, typically using the command "<your-tomcat-root-folder>/bin/startup.sh", your application becomes available | |
in a web browser, so you may visit: http://localhost:8080/SampleApp/singlepay.jsp to see it working. | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$oauth_file = "/tmp/paytoken.php"; | |
$api_key = ""; | |
$secret_key = ""; | |
$FQDN = "https://api.att.com"; | |
$singlepayRedirect = ""; | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> | |
<html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml" lang="en"><head> | |
<title>AT&T Sample Notary Application - Sign Payload Application</title> | |
<meta content="text/html; charset=ISO-8859-1" http-equiv="Content-Type"> | |
<link rel="stylesheet" type="text/css" href="style/common.css"/ > | |
</script> | |
<style type="text/css"> | |
pre { | |
white-space: pre; /* CSS 2.0 */ | |
white-space: pre-wrap; /* CSS 2.1 */ | |
white-space: pre-line; /* CSS 3.0 */ | |
white-space: -pre-wrap; /* Opera 4-6 */ | |
white-space: -o-pre-wrap; /* Opera 7 */ | |
white-space: -moz-pre-wrap; /* Mozilla */ | |
white-space: -hp-pre-wrap; /* HP Printers */ | |
word-wrap: break-word; /* IE 5+ */ | |
} | |
</style> | |
<?php header("Content-Type: text/html; charset=ISO-8859-1"); | |
session_start(); | |
include ("config.php"); | |
?> | |
<body> | |
<?php | |
$scope = "PAYMENT"; | |
$accessToken = ""; | |
$refreshToken = ""; | |
$expires_in = ""; | |
$signPayload = ""; | |
$payload =""; | |
$signPayload = $_REQUEST["signPayload"]; | |
$payload = $_REQUEST["payload"]; | |
if($payload==null || $payload ==''){ | |
$payload = $_SESSION["pay1_payload"]; | |
} | |
if($payload==null || $payload ==''){ | |
$payload = "{\"Amount\":0.99,\n \"Category\":2,\n \"Channel\":". | |
"\"MOBILE_WEB\",\n\"Description\":\"5 puzzles per month plan\",\n". | |
"\"MerchantTransactionId\":\"user573transaction1377\",\n \"MerchantProductId\":\"SudokuMthlyPlan5\",\n". | |
"\"MerchantApplicationId\":\"Sudoku\",\n". | |
"\"MerchantPaymentRedirectUrl\":". | |
"\"http://somewhere.com/OauthResponse.php\",\n". | |
"\"MerchantSubscriptionIdList\":". | |
"[\"p1\",". | |
"\"p2\",\"p3\",\"p4\",\"p5\"],\n". | |
"\"IsPurchaseOnNoActiveSubscription\":false,\n". | |
"\"SubscriptionRecurringNumber\": 5,\n \"SubscriptionRecurringPeriod\" : \"MONTHLY\",\n \"SubscriptionRecurringPeriodAmount\" : 1, }"; | |
} | |
$signedPayload = $_REQUEST["signedPayload"]; | |
if($signedPayload==null || $signedPayload == '') | |
$signedPayload = $_SESSION["pay1_signedPayload"]; | |
if($signedPayload==null || $signedPayload == '') | |
$signedPayload = "Sbe gur Abgnel ncc, fvzcyr gbby. Gurer fubhyq whfg or n Erdhrfg fvqr ba gur yrsg, pbagnvavat bar YNETR grkg obk jvgu ab qrsnhyg inyhr. Guvf vf jurer gur hfre pna chg va n obql bs grkg jvgu nyy gur cnenzrgref sbe n cnlzrag genafnpgvba, ohg gurl jvyy perngr guvf grkg gurzfryirf onfrq ba gur genafnpgvba qrgnvyf. Gura gurl pyvpx gur ohggba, juvpu qvfcynlf n grkg obk ba gur evtug jvgu gur Fvtarq Cnlybnq, naq gur Fvtangher, obgu bs juvpu gur hfre fubhyq or noyr gb pbcl rnfvyl naq cnfgr vagb gur cnlzrag nccyvpngvba yngre ba. Va erny yvsr, guvf jvyy or qbar nhgbzngvpnyyl ol pbqr, ohg guvf ncc whfg arrqf gb fubj gur onfvp vagrenpgvba jvgu guvf arj Abgnel NCV, juvpu yvgrenyyl whfg gnxrf gur grkg lbh fraq, naq ergheaf gur fvtarq cnlybnq (grkg) naq gur fvtangher. V ubcr gung znxrf frafr"; | |
$signature = $_POST["signature"]; | |
if($signature==null || $signature =='') | |
$signature = $_SESSION["pay1_signature"]; | |
if($signature==null || $signature == '') | |
$signature = "hfd7adsf76asffs987sdf98fs6a7a98ff6a"; | |
?> | |
<div id="container"> | |
<!-- open HEADER --><div id="header"> | |
<div> | |
<div id="hcRight"> | |
<?php echo date("D M j G:i:s T Y"); ?> | |
</div> | |
<div id="hcLeft">Server Time:</div> | |
</div> | |
<div> | |
<div id="hcRight"><script language="JavaScript" type="text/javascript"> | |
var myDate = new Date(); | |
document.write(myDate); | |
</script></div> | |
<div id="hcLeft">Client Time:</div> | |
</div> | |
<div> | |
<div id="hcRight"><script language="JavaScript" type="text/javascript"> | |
document.write("" + navigator.userAgent); | |
</script></div> | |
<div id="hcLeft">User Agent:</div> | |
</div> | |
<br clear="all" /> | |
</div><!-- close HEADER --> | |
<div id="wrapper"> | |
<div id="content"> | |
<h1>AT&T Sample Notary Application - Sign Payload Application</h1> | |
</div> | |
</div> | |
<?php | |
//If Sign Payload button was clicked, do this. | |
if($signPayload == "back"){ // go back to original page | |
header("location:singlepay.php"); | |
} | |
if($signPayload!=null) { | |
$_SESSION["pay1_payload"]=$payload; | |
$url = "$FQDN/Security/Notary/Rest/1/SignedPayload"; | |
$headers = array( | |
'Accept: application/json', | |
'client_id: '.$api_key, | |
'client_secret: '.$secret_key | |
); | |
$request = curl_init(); | |
curl_setopt($request, CURLOPT_URL, $url); | |
curl_setopt($request, CURLOPT_HTTPGET, 1); | |
curl_setopt($request, CURLOPT_HEADER, 0); | |
curl_setopt($request, CURLINFO_HEADER_OUT, 0); | |
curl_setopt($request, CURLOPT_HTTPHEADER, $headers); | |
curl_setopt($request, CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt($request, CURLOPT_SSL_VERIFYPEER, false); | |
curl_setopt($request, CURLOPT_POST, 1); | |
curl_setopt($request, CURLOPT_POSTFIELDS, $payload); | |
$response = curl_exec($request); | |
$responseCode=curl_getinfo($request,CURLINFO_HTTP_CODE); | |
if($responseCode==200) { | |
$jsonResponse = json_decode($response); | |
$signedPayload = $jsonResponse->{"SignedDocument"}; | |
$_SESSION["pay1_signedPayload"]=$signedPayload; | |
$signature = $jsonResponse->{"Signature"}; | |
$_SESSION["pay1_signature"] = $signature; | |
if($_REQUEST["return"]!=null){ | |
header("location:singlepay.php?signedPayload=".$signedPayload."&signature=".$signature); | |
} | |
} else { | |
echo curl_error($request).$response; | |
} | |
} | |
?> | |
<div id="wrapper"> | |
<div id="content"> | |
<h2><br /> | |
Feature 1: Sign Payload</h2> | |
<br/> | |
</div> | |
</div> | |
<form method="post" name="signPayload"> | |
<div id="navigation"> | |
<table border="0" width="950px"> | |
<tbody> | |
<tr> | |
<?php | |
$split = str_split($signedPayload,5); | |
$formattedSignedPayload =""; | |
foreach ( $split as $line ){ | |
$formattedSignedPayload .= $line." "; | |
} | |
$split = str_split($signature,5); | |
$formattedSignature =""; | |
foreach ( $split as $line ){ | |
$formattedSignature .= $line." "; | |
} | |
?> | |
<td valign="top" class="label">Request:</td> | |
<td class="cell" ><textarea rows="20" cols="60" name="payload" ><?php echo str_replace(",\n",",",$payload) ?></textarea> | |
</td> | |
<td width="50px"></td> | |
<td valign="top" class="label">Signed Payload:</td> | |
<td class="cell" width="400px" ><?php echo $formattedSignedPayload; ?></td> | |
</tr> | |
<tr> | |
<td></td> | |
<td></td> | |
<td width="50px"></td> | |
<td valign="top" class="label">Signature:</td> | |
<td class="cell"><?php echo $formattedSignature;?></td> | |
</tr> | |
<tr> | |
<td></td> | |
<td class="cell" align="right"><button type="submit" name="signPayload" value="back">Back</button></td> | |
</tr> | |
</tbody></table> | |
</div> | |
<br clear="all" /> | |
</form> | |
<div id="footer"> | |
<div style="float: right; width: 20%; font-size: 9px; text-align: right">Powered by AT&T Virtual Mobile</div> | |
<p>© 2011 AT&T Intellectual Property. All rights reserved. <a href="http://developer.att.com/" target="_blank">http://developer.att.com</a> | |
<br> | |
The Application hosted on this site are working examples intended to be used for reference in creating products to consume AT&T Services and not meant to be used as part of your product. The data in these pages is for test purposes only and intended only for use as a reference in how the services perform. | |
<br> | |
For download of tools and documentation, please go to <a href="https://devconnect-api.att.com/" target="_blank">https://devconnect-api.att.com</a> | |
<br> | |
For more information contact <a href="mailto:[email protected]">[email protected]</a> | |
</div> | |
</div> | |
</body></html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
header("Content-Type: text/html; charset=ISO-8859-1"); | |
include ("config.php"); | |
include ($oauth_file); | |
session_start(); | |
$db_filename = "transactionData.db"; | |
$scope = "PAYMENT"; | |
$newTransaction = $_REQUEST["newTransaction"]; | |
$getTransactionStatus = $_REQUEST["getTransactionStatus"]; | |
$refundTransaction = $_REQUEST["refundTransaction"]; | |
$refundReasonText = "User did not like product"; | |
$trxId = $_SESSION["pay1_trxId"]; | |
if($trxId==null || $trxId == "") | |
$trxId = ""; | |
$trxIdRefund = $_REQUEST["trxIdRefund"]; | |
if($trxIdRefund==null || $trxIdRefund == "") | |
$trxIdRefund = ""; | |
$merchantTrxId = $_REQUEST["merchantTrxId"]; | |
if($merchantTrxId==null || $merchantTrxId == "") | |
$merchantTrxId = $_SESSION["pay1_merchantTrxId"]; | |
$authCode = $_REQUEST["TransactionAuthCode"]; | |
if($authCode==null || $authCode == "") | |
$authCode = $_SESSION["pay1_authCode"]; | |
$consumerId = $_REQUEST["consumerId"]; | |
if($consumerId==null || $consumerId == "") | |
$consumerId = $_SESSION["pay1_consumerId"]; | |
if($consumerId==null || $consumerId == "") | |
$consumerId = ""; | |
$product = 0; | |
if($_REQUEST["product"]!=null) | |
$product = $_REQUEST["product"]; | |
$amount = ""; | |
$description = ""; | |
$merchantProductId = ""; | |
if($product==1) { | |
$amount = "0.99"; | |
$description = "Word Game 1"; | |
$merchantProductId = "WordGame1"; | |
} else if($product==2) { | |
$amount = "2.99"; | |
$description = "Number Game 1"; | |
$merchantProductId = "NumberGame1"; | |
} | |
function RefreshToken($FQDN,$api_key,$secret_key,$scope,$fullToken){ | |
$refreshToken=$fullToken["refreshToken"]; | |
$accessTok_Url = $FQDN."/oauth/token"; | |
//http header values | |
$accessTok_headers = array( | |
'Content-Type: application/x-www-form-urlencoded' | |
); | |
//Invoke the URL | |
$post_data="client_id=".$api_key."&client_secret=".$secret_key."&refresh_token=".$refreshToken."&grant_type=refresh_token"; | |
$accessTok = curl_init(); | |
curl_setopt($accessTok, CURLOPT_URL, $accessTok_Url); | |
curl_setopt($accessTok, CURLOPT_HTTPGET, 1); | |
curl_setopt($accessTok, CURLOPT_HEADER, 0); | |
curl_setopt($accessTok, CURLINFO_HEADER_OUT, 0); | |
// curl_setopt($accessTok, CURLOPT_HTTPHEADER, $accessTok_headers); | |
curl_setopt($accessTok, CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt($accessTok, CURLOPT_SSL_VERIFYPEER, false); | |
curl_setopt($accessTok, CURLOPT_POST, 1); | |
curl_setopt($accessTok, CURLOPT_POSTFIELDS,$post_data); | |
$accessTok_response = curl_exec($accessTok); | |
$currentTime=time(); | |
$responseCode=curl_getinfo($accessTok,CURLINFO_HTTP_CODE); | |
if($responseCode==200){ | |
$jsonObj = json_decode($accessTok_response); | |
$accessToken = $jsonObj->{'access_token'};//fetch the access token from the response. | |
$refreshToken = $jsonObj->{'refresh_token'}; | |
$expiresIn = $jsonObj->{'expires_in'}; | |
$refreshTime=$currentTime+(int)($expiresIn); // Time for token refresh | |
$updateTime=$currentTime + ( 24*60*60); // Time to get for a new token update, current time + 24h | |
$fullToken["accessToken"]=$accessToken; | |
$fullToken["refreshToken"]=$refreshToken; | |
$fullToken["refreshTime"]=$refreshTime; | |
$fullToken["updateTime"]=$updateTime; | |
} | |
else{ | |
$fullToken["accessToken"]=null; | |
$fullToken["errorMessage"]=curl_error($accessTok).$accessTok_response; | |
} | |
curl_close ($accessTok); | |
return $fullToken; | |
} | |
function GetAccessToken($FQDN,$api_key,$secret_key,$scope){ | |
$accessTok_Url = $FQDN."/oauth/token"; | |
//http header values | |
$accessTok_headers = array( | |
'Content-Type: application/x-www-form-urlencoded' | |
); | |
//Invoke the URL | |
$post_data = "client_id=".$api_key."&client_secret=".$secret_key."&scope=".$scope."&grant_type=client_credentials"; | |
$accessTok = curl_init(); | |
curl_setopt($accessTok, CURLOPT_URL, $accessTok_Url); | |
curl_setopt($accessTok, CURLOPT_HTTPGET, 1); | |
curl_setopt($accessTok, CURLOPT_HEADER, 0); | |
curl_setopt($accessTok, CURLINFO_HEADER_OUT, 0); | |
// curl_setopt($accessTok, CURLOPT_HTTPHEADER, $accessTok_headers); | |
curl_setopt($accessTok, CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt($accessTok, CURLOPT_SSL_VERIFYPEER, false); | |
curl_setopt($accessTok, CURLOPT_POST, 1); | |
curl_setopt($accessTok, CURLOPT_POSTFIELDS,$post_data); | |
$accessTok_response = curl_exec($accessTok); | |
$responseCode=curl_getinfo($accessTok,CURLINFO_HTTP_CODE); | |
$currentTime=time(); | |
/* | |
If URL invocation is successful fetch the access token and store it in session, | |
else display the error. | |
*/ | |
if($responseCode==200) | |
{ | |
$jsonObj = json_decode($accessTok_response); | |
$accessToken = $jsonObj->{'access_token'};//fetch the access token from the response. | |
$refreshToken = $jsonObj->{'refresh_token'}; | |
$expiresIn = $jsonObj->{'expires_in'}; | |
$refreshTime=$currentTime+(int)($expiresIn); // Time for token refresh | |
$updateTime=$currentTime + ( 24*60*60); // Time to get a new token update, current time + 24h | |
$fullToken["accessToken"]=$accessToken; | |
$fullToken["refreshToken"]=$refreshToken; | |
$fullToken["refreshTime"]=$refreshTime; | |
$fullToken["updateTime"]=$updateTime; | |
}else{ | |
$fullToken["accessToken"]=null; | |
$fullToken["errorMessage"]=curl_error($accessTok).$accessTok_response; | |
} | |
curl_close ($accessTok); | |
return $fullToken; | |
} | |
function SaveToken( $fullToken,$oauth_file ){ | |
$accessToken=$fullToken["accessToken"]; | |
$refreshToken=$fullToken["refreshToken"]; | |
$refreshTime=$fullToken["refreshTime"]; | |
$updateTime=$fullToken["updateTime"]; | |
$tokenfile = $oauth_file; | |
$fh = fopen($tokenfile, 'w'); | |
$tokenfile="<?php \$accessToken=\"".$accessToken."\"; \$refreshToken=\"".$refreshToken."\"; \$refreshTime=".$refreshTime."; \$updateTime=".$updateTime."; ?>"; | |
fwrite($fh,$tokenfile); | |
fclose($fh); | |
} | |
function check_token( $FQDN,$api_key,$secret_key,$scope, $fullToken,$oauth_file){ | |
$currentTime=time(); | |
if ( ($fullToken["updateTime"] == null) || ($fullToken["updateTime"] <= $currentTime)){ | |
$fullToken=GetAccessToken($FQDN,$api_key,$secret_key,$scope); | |
if( $fullToken["accessToken"] == null ){ | |
// echo "GetAccessToken".$fullToken["errorMessage"]; | |
}else{ | |
// echo $fullToken["accessToken"]; | |
SaveToken( $fullToken,$oauth_file ); | |
} | |
} | |
elseif ($fullToken["refreshTime"]<= $currentTime){ | |
$fullToken=RefreshToken($FQDN,$api_key,$secret_key,$scope, $fullToken); | |
if( $fullToken["accessToken"] == null ){ | |
// echo "RefreshToken".$fullToken["errorMessage"]; | |
}else{ | |
// echo $fullToken["accessToken"]; | |
SaveToken( $fullToken,$oauth_file ); | |
} | |
} | |
return $fullToken; | |
} | |
?> | |
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> | |
<html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml" lang="en"><head> | |
<title>AT&T Sample Payment Application - Single Pay Application</title> | |
<meta content="text/html; charset=ISO-8859-1" http-equiv="Content-Type"> | |
<link rel="stylesheet" type="text/css" href="style/common.css"/ > | |
<body> | |
<div id="container"> | |
<!-- open HEADER --><div id="header"> | |
<div> | |
<div id="hcRight"> | |
<?php echo date("D M j G:i:s T Y"); ?> | |
</div> | |
<div id="hcLeft">Server Time:</div> | |
</div> | |
<div> | |
<div id="hcRight"><script language="JavaScript" type="text/javascript"> | |
var myDate = new Date(); | |
document.write(myDate); | |
</script></div> | |
<div id="hcLeft">Client Time:</div> | |
</div> | |
<div> | |
<div id="hcRight"><script language="JavaScript" type="text/javascript"> | |
document.write("" + navigator.userAgent); | |
</script></div> | |
<div id="hcLeft">User Agent:</div> | |
</div> | |
<br clear="all" /> | |
</div><!-- close HEADER --> | |
<div id="wrapper"> | |
<div id="content"> | |
<h1>AT&T Sample Payment Application - Single Pay Application</h1> | |
<h2>Feature 1: Create New Transaction</h2><br/> | |
</div> | |
</div> | |
<form method="post" name="newTransaction" > | |
<div id="navigation"> | |
<table border="0" width="100%"> | |
<tbody> | |
<tr> | |
<td width="50%" valign="top" class="label">Buy product 1 for $0.99:</td> | |
<td class="cell"><input type="radio" name="product" value="1" checked> | |
</td> | |
</tr> | |
<tr> | |
<td width="50%" valign="top" class="label">Buy product 2 for $2.99:</td> | |
<td class="cell"><input type="radio" name="product" value="2"> | |
</td></tr> | |
</tbody></table> | |
</div> | |
<div id="extra"> | |
<table> | |
<tbody> | |
<tr> | |
<td><br /><br /><button type="submit" name="newTransaction" value="newTransaction">Buy Product</button></td> | |
</tr> | |
</tbody></table> | |
</div> | |
<br clear="all" /> | |
<div align="center"></div> | |
</form> | |
<?php | |
if($newTransaction!=null) { | |
$merchantTrxId = "user".rand(1,10000000)."transaction".rand(1,10000000); | |
$_SESSION["pay1_merchantTrxId"] = $merchantTrxId; | |
$_SESSION["pay1_trxId"] = null; | |
$_SESSION["pay1_authCode"] = null; | |
$_SESSION["pay1_consumerId"] = null; | |
$forNotary = "notary.php?signPayload=true&return=singlepay.php&payload={\"Amount\":".$amount.", \"Category\":1, \"Channel\":". | |
"\"MOBILE_WEB\",\"Description\":\"".$description."\",". | |
"\"MerchantTransactionId\":\"".$merchantTrxId ."\", \"MerchantProductId\":\"".$merchantProductId."\",". | |
"\"MerchantPaymentRedirectUrl\":". | |
"\"".$singlepayRedirect."\"}"; | |
header("location:".$forNotary); | |
} | |
if($_REQUEST["TransactionAuthCode"]!=null) { | |
$_SESSION["pay1_authCode"] = $_REQUEST["TransactionAuthCode"] ; | |
?> | |
<div class="successWide"> | |
<strong>SUCCESS:</strong><br /> | |
<strong>Merchant Transaction ID</strong> <?php echo $_SESSION["pay1_merchantTrxId"] ?><br/> | |
<strong>Transaction Auth Code</strong> <?php echo $authCode ?><br /><br/> | |
<form name="getNotaryDetails" action="notary.php"> | |
<input type="submit" name="getNotaryDetails" value="View Notary Details" /> | |
</form> | |
</div><br/> | |
<?php } ?> | |
<?php | |
if( $_REQUEST["signedPayload"]!=null && $_REQUEST["signature"]!=null){ | |
header("location:".$FQDN."/Commerce/Payment/Rest/2/Transactions?clientid=".$api_key."&SignedPaymentDetail=".$_REQUEST["signedPayload"]."&Signature=".$_REQUEST["signature"]); | |
} | |
?> | |
<div id="wrapper"> | |
<div id="content"> | |
<h2><br /> | |
Feature 2: Get Transaction Status</h2> | |
<?php if($getTransactionStatus!=null) { | |
//This application uses the Autonomous Client OAuth consumption model | |
//Check if there is a valid access token that has not expired | |
$fullToken["accessToken"]=$accessToken; | |
$fullToken["refreshToken"]=$refreshToken; | |
$fullToken["refreshTime"]=$refreshTime; | |
$fullToken["updateTime"]=$updateTime; | |
$fullToken=check_token($FQDN,$api_key,$secret_key,$scope,$fullToken,$oauth_file); | |
$accessToken=$fullToken["accessToken"]; | |
$getTransactionType = $_POST["getTransactionType"]; | |
$url = ""; | |
if($getTransactionType==1) | |
$url = $FQDN."/Commerce/Payment/Rest/2/Transactions/MerchantTransactionId/".$merchantTrxId; | |
if($getTransactionType==2) | |
$url = $FQDN."/Commerce/Payment/Rest/2/Transactions/TransactionAuthCode/".$authCode; | |
if($getTransactionType==3) | |
$url = $FQDN."/Commerce/Payment/Rest/2/Transactions/TransactionId/".$trxId; | |
$url=$url."?access_token=".$accessToken; | |
$headers = array( | |
'Accept: application/json' | |
); | |
$request = curl_init(); | |
curl_setopt($request, CURLOPT_URL, $url); | |
curl_setopt($request, CURLOPT_HTTPGET, 1); | |
curl_setopt($request, CURLOPT_HEADER, 0); | |
curl_setopt($request, CURLINFO_HEADER_OUT, 0); | |
curl_setopt($request, CURLOPT_HTTPHEADER, $headers); | |
curl_setopt($request, CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt($request, CURLOPT_SSL_VERIFYPEER, false); | |
$response = curl_exec($request); | |
$responseCode=curl_getinfo($request,CURLINFO_HTTP_CODE); | |
if($responseCode==200) { | |
$jsonResponse = json_decode($response,true); | |
$trxId = $jsonResponse["TransactionId"]; | |
$_SESSION["pay1_trxId"] = $trxId; | |
$consumerId = $jsonResponse["ConsumerId"]; | |
$_SESSION["pay1_consumerId"] = $consumerId; | |
$merchantTrxId = $jsonResponse["MerchantTransactionId"]; | |
$_SESSION["pay1_merchantTrxId"]=$merchantTrxId; | |
If ( $trxId != null && $trxId != ""){ | |
$transaction["trxId"] = $trxId; | |
$transaction["merchantTrxId"] = $merchantTrxId; | |
$transaction["authCode"] = $authCode; | |
$transaction["consumerId"] = $consumerId; | |
if ( file_exists( $db_filename) ){ | |
$transactions = unserialize(file_get_contents($db_filename)); | |
$transaction_exist = false; | |
foreach( $transactions as $tr){ | |
if($tr["merchantTrxId"] == $merchantTrxId){ | |
$transaction_exist = true; | |
} | |
} | |
if(!$transaction_exist){ | |
$stored_tnumber = array_unshift($transactions,$transaction); | |
if ( $stored_tnumber > 5 ){ | |
array_pop($transactions); | |
} | |
} | |
}else{ | |
$transactions = array($transaction); | |
} | |
$fp = fopen($db_filename, 'w+') or die("I could not open $filename."); | |
fwrite($fp, serialize($transactions)); | |
fclose($fp); | |
} | |
} | |
} | |
?> | |
</div> | |
</div> | |
<form method="post" name="getTransactionStatus" action="singlepay.php"> | |
<div id="navigation" align="center"> | |
<table style="width: 750px" cellpadding="1" cellspacing="1" border="0"> | |
<thead> | |
<tr> | |
<th style="width: 150px" class="cell" align="right"></th> | |
<th style="width: 100px" class="cell"></th> | |
<th style="width: 240px" class="cell" align="left"></th> | |
</tr> | |
</thead> | |
<tbody> | |
<tr> | |
<td class="cell" align="left"> | |
<input type="radio" name="getTransactionType" value="1" checked /> Merchant Trans. ID: | |
</td> | |
<td></td> | |
<td class="cell" align="left"><?php echo $merchantTrxId ?></td> | |
</tr> | |
<tr> | |
<td class="cell" align="left"> | |
<input type="radio" name="getTransactionType" value="2" /> Auth Code: | |
<td></td> | |
<td class="cell" align="left"><?php echo $authCode ?></td> | |
</td> | |
</tr> | |
<tr> | |
<td class="cell" align="left"> | |
<input type="radio" name="getTransactionType" value="3" /> Transaction ID: | |
<td></td> | |
<td class="cell" align="left"><?php echo $trxId ?></td> | |
</td> | |
</tr> | |
<tr> | |
<td></td> | |
<td></td> | |
<td></td> | |
<td class="cell"><button type="submit" name="getTransactionStatus" value="getTransactionStatus">Get Transaction Status</button> | |
</td> | |
</tr> | |
</tbody></table> | |
</form> | |
</div> | |
<br clear="all" /> | |
<?php | |
if($getTransactionStatus!=null) { | |
if($responseCode==200) { | |
?> | |
<div class="successWide"> | |
<strong>SUCCESS:</strong><br /> | |
<strong>Transaction ID:</strong><?php echo $trxId; ?><br /> | |
<strong>Merchant Transaction ID:</strong><?php echo $merchantTrxId; ?><br/> | |
</div><br/> | |
<div align="center"><table style="width: 650px" cellpadding="1" cellspacing="1" border="0"> | |
<thead> | |
<tr> | |
<th style="width: 100px" class="cell" align="right"><strong>Parameter</strong></th> | |
<th style="width: 100px" class="cell"><strong></strong></th> | |
<th style="width: 275px" class="cell" align="left"><strong>Value</strong></th> | |
</tr> | |
</thead> | |
<tbody> | |
<?php | |
foreach ( $jsonResponse as $parameter => $value ){ ?> | |
<tr> | |
<td align="right" class="cell"><?php echo $parameter; ?></td> | |
<td align="center" class="cell"></td> | |
<td align="left" class="cell"><?php echo $value; ?></td> | |
</tr> | |
<?php } | |
?> | |
</tbody> | |
</table> | |
</div><br/> | |
<?php } else { ?> | |
<div class="errorWide"> | |
<strong>ERROR:</strong><br /> | |
<?php echo curl_error($request).$response; ?> | |
</div><br/> | |
<?php } }?> | |
<div id="wrapper"> | |
<div id="content"> | |
<h2><br />Feature 3: Refund Transaction</h2> | |
<?php if($refundTransaction!=null) { | |
//This application uses the Autonomous Client OAuth consumption model | |
//Check if there is a valid access token that has not expired | |
$fullToken=check_token($FQDN,$api_key,$secret_key,$scope,$fullToken,$oauth_file); | |
$accessToken=$fullToken["accessToken"]; | |
$trxIdRefund =$_REQUEST["trxIdRefund"]; | |
$url = $FQDN."/Commerce/Payment/Rest/2/Transactions/".$trxIdRefund; | |
$url = $url."?access_token=".$accessToken."&Action=refund"; | |
$headers = array( | |
'Content-Type: application/json', | |
'Accept: application/json' | |
); | |
$payload = "{\"RefundReasonCode\":1,\n \"RefundReasonText\":\"".$refundReasonText."\"}"; | |
$putData = tmpfile(); | |
fwrite($putData, $payload); | |
fseek($putData, 0); | |
$request = curl_init(); | |
curl_setopt($request, CURLOPT_URL, $url); | |
curl_setopt($request, CURLOPT_HTTPGET, 1); | |
curl_setopt($request, CURLOPT_HEADER, 0); | |
curl_setopt($request, CURLINFO_HEADER_OUT, 0); | |
curl_setopt($request, CURLOPT_HTTPHEADER, $headers); | |
curl_setopt($request, CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt($request, CURLOPT_SSL_VERIFYPEER, false); | |
curl_setopt($request, CURLOPT_PUT, 1); | |
curl_setopt($request, CURLOPT_INFILE, $putData); | |
curl_setopt($request, CURLOPT_INFILESIZE, strlen($payload)); | |
$response = curl_exec($request); | |
fclose($putData); | |
$responseCode=curl_getinfo($request,CURLINFO_HTTP_CODE); | |
if($responseCode==200) { | |
if ( file_exists( $db_filename) ){ | |
$transactions = unserialize(file_get_contents($db_filename)); | |
foreach($transactions as $key=>&$transaction){ | |
if($transaction["trxId"] == $trxIdRefund){ | |
unset($transactions[$key]); | |
} | |
} | |
$fp = fopen($db_filename, 'w+') or die("I could not open $filename."); | |
fwrite($fp, serialize($transactions)); | |
fclose($fp); | |
} | |
} | |
} | |
?> | |
</div> | |
</div> | |
<form method="post" name="refundTransaction" action="singlepay.php"> | |
<div id="navigation" align="center"> | |
<table style="width: 750px" cellpadding="1" cellspacing="1" border="0"> | |
<thead> | |
<tr> | |
<th style="width: 150px" class="cell" align="right"><strong>Transaction ID</strong></th> | |
<th style="width: 100px" class="cell"></th> | |
<th style="width: 240px" class="cell" align="left"><strong>Merchant Transaction ID</strong></th> | |
<td><div class="warning"> | |
<strong>WARNING:</strong><br /> | |
You must use Get Transaction Status to get the Transaction ID before you can refund it. | |
</div></td> | |
</tr> | |
</thead> | |
<tbody> | |
<?php | |
if(true) { | |
$transactions = unserialize(file_get_contents($db_filename)); | |
$checked = true; | |
foreach ( $transactions as $transaction ){ | |
?> | |
<tr> | |
<td class="cell" align="right"> | |
<?php if ( $checked ){ | |
$checked = false; | |
?> | |
<input type="radio" name="trxIdRefund" value="<?php echo $transaction["trxId"]; ?>" checked /><?php echo $transaction["trxId"];?> | |
<?php } else { ?> | |
<input type="radio" name="trxIdRefund" value="<?php echo $transaction["trxId"]; ?>" /><?php echo $transaction["trxId"]; ?> | |
<?php } ?> | |
</td> | |
<td></td> | |
<td class="cell" align="left"><?php echo $transaction["merchantTrxId"] ?></td> | |
</tr> | |
<?php | |
} }?> | |
<tr> | |
<td></td> | |
<td></td> | |
<td></td> | |
<td class="cell"><button type="submit" name="refundTransaction" value="refundTransaction">Refund Transaction</button> | |
</td> | |
</tr> | |
</tbody></table> | |
</form> | |
</div> | |
<br clear="all" /> | |
<?php | |
if($refundTransaction!=null) { | |
if($responseCode==200) { | |
?> | |
<div class="successWide"> | |
<strong>SUCCESS:</strong><br /> | |
<strong>Transaction ID:</strong> <?php echo $response ?><br /> | |
</div><br/> | |
<?php } else { ?> | |
<div class="errorWide"> | |
<strong>ERROR:</strong><br /> | |
<?php echo $response ?><br /> | |
</div><br/> | |
<?php } } ?> | |
<div id="wrapper"> | |
<div id="content"> | |
<h2><br />Feature 4: Notifications</h2> | |
</div> | |
</div> | |
<form method="post" name="refreshNotifications" action="singlepay.php"> | |
<div id="navigation"><br/> | |
<div align="center"><table style="width: 650px" cellpadding="1" cellspacing="1" border="0"> | |
<thead> | |
<tr> | |
<th style="width: 100px" class="cell"><strong>Notification ID</strong></th> | |
<th style="width: 100px" class="cell"><strong>Notification Type</strong></th> | |
<th style="width: 125px" class="cell"><strong>Transaction ID</strong></th> | |
<th style="width: 175px" class="cell"><strong>Merchant Transaction ID</strong></th> | |
</tr> | |
</thead> | |
<tbody> | |
<?php | |
if(true) { | |
$transactions = unserialize(file_get_contents($db_filename)); | |
foreach ( $notifications as $notification ){ | |
?> | |
<tr> | |
<td align="center" class="cell"><?php echo $notification["notificationId"]; ?></td> | |
<td align="center" class="cell"><?php echo $notification["notificationType"]; ?></td> | |
<td align="center" class="cell"><?php echo $notification["transactionId"]; ?></td> | |
<td align="center" class="cell"><?php echo $notification["merchantTransactionId"]; ?></td> | |
</tr> | |
<?php } } ?> | |
</tbody> | |
</table> | |
</div> | |
<div id="extra"><br/> | |
<table border="0" width="100%"> | |
<tbody> | |
<tr> | |
<td class="cell"><button type="submit" name="refreshNotifications" value="refreshNotifications">Refresh</button> | |
</td> | |
</tr> | |
</tbody></table> | |
</div> | |
<br clear="all" /> | |
</form></div> | |
<div id="footer"> | |
<div style="float: right; width: 20%; font-size: 9px; text-align: right">Powered by AT&T Virtual Mobile</div> | |
<p>© 2011 AT&T Intellectual Property. All rights reserved. <a href="http://developer.att.com/" target="_blank">http://developer.att.com</a> | |
<br> | |
The Application hosted on this site are working examples intended to be used for reference in creating products to consume AT&T Services and not meant to be used as part of your product. The data in these pages is for test purposes only and intended only for use as a reference in how the services perform. | |
<br> | |
For download of tools and documentation, please go to <a href="https://devconnect-api.att.com/" target="_blank">https://devconnect-api.att.com</a> | |
<br> | |
For more information contact <a href="mailto:[email protected]">[email protected]</a> | |
</div> | |
</div> | |
</body></html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment