|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.jambool.socialgold.api.CurrencyClient
public class CurrencyClient
Sample code to provide convient access to the Social Gold Currency V1.
API methods that make a call to the service:
methods that generate a URL for merchant to render in a page:
Notes:
Changes: note that JSON parsing should be supported in this version using org.json libraries (required), and some proper exceptions are now being thrown. (BRP/2010-6)
Field Summary | |
---|---|
private String |
offerID
WRITEME |
private String |
secretMerchantKey
WRITEME |
private String |
serverName
WRITEME |
private Hashtable<String,String> |
validCreditTypes
WRITEME |
Constructor Summary | |
---|---|
CurrencyClient(String newServerName,
String newOfferID,
String newSecretMerchantKey)
---------------------------------------------------------------- ------------- |
Method Summary | |
---|---|
private String |
_calculateSignature(Hashtable<String,String> signatureParams)
---------------------------------------------------------------- ------------- |
private Hashtable<String,String> |
_getResponse(String cmdURL)
---------------------------------------------------------------- ------------- |
private Hashtable<String,String> |
_getResponse(String cmdURL,
boolean requiresSSL)
WRITEME |
private String |
_getURL(Hashtable<String,String> baseParams,
Hashtable<String,String> requiredParams,
Hashtable<String,String> optionalParams)
================================================================ ============= private methods below this ========================== =================================================== |
private String |
_getURL(Hashtable<String,String> baseParams,
Hashtable<String,String> requiredParams,
Hashtable<String,String> optionalParams,
boolean requiresSSL)
|
private void |
_mergeParams(Hashtable<String,String> requiredParams,
Hashtable<String,String> signatureParams)
---------------------------------------------------------------- ------------- |
private String |
_paramHashToURI(Hashtable<String,String> params)
Convert a parameter hash into an URI |
private String |
_validateCreditType(String type)
_validateCreditType ---------------------------------------------------------------- ------------- |
void |
addValidCreditType(String ident,
String description)
Add a valid credit type |
Map<String,String> |
buyGoods(String userID,
String name,
int pcAmount,
int quantity)
WRITEME |
Hashtable<String,String> |
buyGoods(String userID,
String name,
int pcAmount,
int quantity,
String format,
String externalRefID,
String option_name_0,
String option_value_0,
String option_name_1,
String option_value_1,
String appParams,
String sku,
String sku_category)
WRITEME |
Hashtable<String,String> |
creditUser(String userID,
int pcAmount,
String type,
String externalRefID,
String description)
creditUser: format valid formats = ["json", "xml"] ---------------------- -------------------------------- ----------------------- |
Hashtable<String,String> |
creditUser(String userID,
int pcAmount,
String type,
String externalRefID,
String description,
String format)
creditUser: |
Map<String,String> |
debitUser(String userID,
int pcAmount,
String externalRefID,
String description)
debitUser: valid formats = ["json", "xml"] ---------------------------------------------------------------- ------------- |
Hashtable<String,String> |
debitUser(String userID,
int pcAmount,
String externalRefId,
String description,
String format)
WRITEME |
Hashtable<String,String> |
getBalance(String userID)
getBalance: errorOnUnkownUser = a boolean to determine if service will return a 0 balance, or an error if service has not seen user_id before valid formats = ["json", "xml", "plaintext"] ------ ------------------------------------------------------------ ----------- |
Hashtable<String,String> |
getBalance(String userID,
boolean errorOnUnkownUser)
WRITEME |
Hashtable<String,String> |
getBalance(String userID,
boolean errorOnUnkownUser,
String format)
WRITEME |
String |
getBuyCurrencyURL(String userID)
getBuyCurrencyURL: returns a URL that can be placed into a page as either : - format = html, an a href=" - format = iframe, an iframe src=" valid formats = ["iframe", "html"] Optional: showBalance = boolean to show user their balance during the UI flow appParams = a short String that will be passed back to merchant on postback, can be used identify application, etc ------ ------------------------------------------------------------ ----------- |
String |
getBuyCurrencyURL(String userID,
String appParams)
|
String |
getBuyCurrencyURL(String userID,
String appParams,
boolean showBalance,
String format)
|
String |
getBuyGoodsURL(String userID,
String name,
int pcAmount,
int quantity)
getBuyGoodsURL and buyGoods getBuyGoodsURL returns a URL that can be placed into a page as either : - format = html, an a href=" - format = iframe, an iframe src=" buyGoods is to be used to record a purchase after the fact - formats = json, xml name = short String descibing item for sale pcAmount = a positive int with 2 digits of implied decimal eg: 100 = $1.00 quanity = a positive int Optional: option_name_0 = a short String, such as "Size" option_value_0 = a short String, such as "Large" option_name_1 = a short String, such as "Color" option_value_1 = a short String, such as "Red" sku = a short String, perhaps merchants internal ID for item, eg: "magic sword" sku_catagory = a short String, perhaps merchants internal ID for item catagory eg: "weapons" externalRefID = a unique string that represents the transaction in your systems use a String version of UUID.randomUUID.toString(), if you do not keep track of your own txns, but remember this is the id, you will need to pass into a call to refund appParams = a short String that will be passed back to merchant on postback, can be used identify application, etc -------------------------------------------------------------- --------------- |
String |
getBuyGoodsURL(String userID,
String name,
int pcAmount,
int quantity,
String format,
String externalRefID,
String option_name_0,
String option_value_0,
String option_name_1,
String option_value_1,
String appParams,
String sku,
String sku_category)
|
Hashtable<String,String> |
getTransaction(String userID,
long startTimestamp)
getTransaction: errorOnUnkownUser = a boolean to determine if service will return a 0 balance, valid formats = [ "html", "csv", "json", "xml" ] -------------------------------------------------- --------------------------- |
Hashtable<String,String> |
getTransaction(String userID,
long startTimestamp,
long endTimestamp,
int limit,
String orderByCol0,
String orderByDir0,
String orderByCol1,
String orderByDir1,
String format)
|
Hashtable<String,String> |
getTransactionStatus(String userID,
String externalRefID,
String format)
getTransactionStatus: returns a response like so: {"polling_expiration_seconds" :300,"polling_interval_seconds":3,"transaction_status":-1} externalRefID = a unique string that represents the transaction in your systems use a String version of UUID.randomUUID.toString(), if you do not keep track of your own txns, but remember this is the id, you will need to pass into a call to refund valid formats = ["json", "xml" ] ------------------ ----------------------------------------------------------- |
Hashtable<String,String> |
getValidCreditTypes()
|
static void |
main(String[] args)
================================================================ ============= |
Hashtable<String,String> |
refundUser(String userID,
String socialgoldTransactionID,
String externalRefId)
refundUser: socialgoldTransactionID = id returned from transaction you want to refund externalRefID = a unique string that represents the transaction in your systems use a String version of UUID.randomUUID.toString(), if you do not keep track of your own txns, but remember this is the id, you will need to pass into a call to refund valid formats = ["json", "xml"] Optional: description = a short, but meaningful description of the refund so the user will know what it was about ---------------- ------------------------------------------------------------- |
Hashtable<String,String> |
refundUser(String userID,
String socialgoldTransactionID,
String externalRefId,
String description,
String format)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private String offerID
private String secretMerchantKey
private String serverName
private Hashtable<String,String> validCreditTypes
Constructor Detail |
---|
public CurrencyClient(String newServerName, String newOfferID, String newSecretMerchantKey)
newServerName
- WRITEMEnewOfferID
- WRITEMEnewSecretMerchantKey
- WRITEMEMethod Detail |
---|
public static void main(String[] args) throws org.apache.http.client.ClientProtocolException, IOException
args
- WRITEME
IOException
- WRITEME
org.apache.http.client.ClientProtocolException
- WRITEMEprivate String _calculateSignature(Hashtable<String,String> signatureParams)
signatureParams
- WRITEME
private Hashtable<String,String> _getResponse(String cmdURL) throws org.apache.http.client.ClientProtocolException, IOException
cmdURL
- WRITEME
IOException
- WRITEME
org.apache.http.client.ClientProtocolException
- WRITEMEprivate Hashtable<String,String> _getResponse(String cmdURL, boolean requiresSSL) throws org.apache.http.client.ClientProtocolException, IOException
cmdURL
- WRITEMErequiresSSL
- WRITEME
IOException
- WRITEME
org.apache.http.client.ClientProtocolException
- WRITEMEprivate String _getURL(Hashtable<String,String> baseParams, Hashtable<String,String> requiredParams, Hashtable<String,String> optionalParams)
baseParams
- WRITEMErequiredParams
- WRITEMEoptionalParams
- WRITEME
private String _getURL(Hashtable<String,String> baseParams, Hashtable<String,String> requiredParams, Hashtable<String,String> optionalParams, boolean requiresSSL)
baseParams
- WRITEMErequiredParams
- WRITEMEoptionalParams
- WRITEMErequiresSSL
- WRITEME
private void _mergeParams(Hashtable<String,String> requiredParams, Hashtable<String,String> signatureParams)
requiredParams
- WRITEMEsignatureParams
- WRITEMEprivate String _paramHashToURI(Hashtable<String,String> params)
params
- parameters
private String _validateCreditType(String type)
type
- WRITEME
public void addValidCreditType(String ident, String description)
ident
- the identifier (looks_like_this)description
- the human-readable descriptionpublic Map<String,String> buyGoods(String userID, String name, int pcAmount, int quantity) throws org.apache.http.client.ClientProtocolException, IOException
userID
- WRITEMEname
- WRITEMEpcAmount
- WRITEMEquantity
- WRITEME
IOException
- WRITEME
org.apache.http.client.ClientProtocolException
- WRITEMEpublic Hashtable<String,String> buyGoods(String userID, String name, int pcAmount, int quantity, String format, String externalRefID, String option_name_0, String option_value_0, String option_name_1, String option_value_1, String appParams, String sku, String sku_category) throws org.apache.http.client.ClientProtocolException, IOException
userID
- WRITEME WRITEME.name
- WRITEMEpcAmount
- WRITEMEquantity
- WRITEMEformat
- WRITEMEexternalRefID
- WRITEMEoption_name_0
- WRITEMEoption_value_0
- WRITEMEoption_name_1
- WRITEMEoption_value_1
- WRITEMEappParams
- WRITEMEsku
- WRITEMEsku_category
- WRITEME
IOException
- WRITEME
org.apache.http.client.ClientProtocolException
- WRITEMEpublic Hashtable<String,String> creditUser(String userID, int pcAmount, String type, String externalRefID, String description) throws org.apache.http.client.ClientProtocolException, IOException
pcAmount
- = a positive int with 2 digits of implied decimal
eg: 100 = $1.00type
- = String, one of "new_user_credit" or
"item_sold_credit" merchant can get a list of valid
type strings from getValidCreditTypes();externalRefID
- = a unique string that represents the
transaction in your systems use a String version of
UUID.randomUUID.toString(), if you do not keep track
of your own txns, but remember this is the id, you
will need to pass into a call to refunddescription
- = a short, but meaningful description of the
credit so the user will know what it was aboutuserID
- WRITEME
IOException
- WRITEME
org.apache.http.client.ClientProtocolException
- WRITEMEpublic Hashtable<String,String> creditUser(String userID, int pcAmount, String type, String externalRefID, String description, String format) throws org.apache.http.client.ClientProtocolException, IOException
pcAmount
- = a positive int with 2 digits of implied decimal
eg: 100 = $1.00type
- = String, one of "new_user_credit" or
"item_sold_credit" merchant can get a list of valid
type strings from getValidCreditTypes();externalRefID
- = a unique string that represents the
transaction in your systems use a String version of
UUID.randomUUID.toString(), if you do not keep track
of your own txns, but remember this is the id, you
will need to pass into a call to refunddescription
- = a short, but meaningful description of the
credit so the user will know what it was aboutformat
- valid formats = ["json", "xml"]
----------------------
--------------------------------
-----------------------userID
- WRITEME
IOException
- WRITEME
org.apache.http.client.ClientProtocolException
- WRITEMEpublic Map<String,String> debitUser(String userID, int pcAmount, String externalRefID, String description) throws org.apache.http.client.ClientProtocolException, IOException
userID
- WRITEMEpcAmount
- = a positive int with 2 digits of implied decimal
eg: 100 = $1.00externalRefID
- = a unique string that represents the
transaction in your systems use a String version of
UUID.randomUUID.toString(), if you do not keep track
of your own txns, but remember this is the id, you
will need to pass into a call to refunddescription
- = a short, but meaningful description of the
debit so the user will know what it was about
IOException
- WRITEME
org.apache.http.client.ClientProtocolException
- WRITEMEpublic Hashtable<String,String> debitUser(String userID, int pcAmount, String externalRefId, String description, String format) throws org.apache.http.client.ClientProtocolException, IOException
userID
- WRITEMEpcAmount
- WRITEMEexternalRefId
- WRITEMEdescription
- WRITEMEformat
- WRITEME
IOException
- WRITEME
org.apache.http.client.ClientProtocolException
- WRITEMEpublic Hashtable<String,String> getBalance(String userID) throws org.apache.http.client.ClientProtocolException, IOException
userID
- the user whose balance is being queried
IOException
- WRITEME
org.apache.http.client.ClientProtocolException
- WRITEMEpublic Hashtable<String,String> getBalance(String userID, boolean errorOnUnkownUser) throws org.apache.http.client.ClientProtocolException, IOException
userID
- WRITEMEerrorOnUnkownUser
- WRITEME
IOException
- WRITEME
org.apache.http.client.ClientProtocolException
- WRITEMEpublic Hashtable<String,String> getBalance(String userID, boolean errorOnUnkownUser, String format) throws org.apache.http.client.ClientProtocolException, IOException
userID
- WRITEMEerrorOnUnkownUser
- WRITEMEformat
- WRITEME
IOException
- WRITEME
org.apache.http.client.ClientProtocolException
- WRITEMEpublic String getBuyCurrencyURL(String userID)
userID
- WRITEME
public String getBuyCurrencyURL(String userID, String appParams)
userID
- WRITEMEappParams
- WRITEME
public String getBuyCurrencyURL(String userID, String appParams, boolean showBalance, String format)
userID
- WRITEMEappParams
- WRITEMEshowBalance
- WRITEMEformat
- WRITEME
public String getBuyGoodsURL(String userID, String name, int pcAmount, int quantity)
userID
- WRITEMEname
- WRITEMEpcAmount
- WRITEMEquantity
- WRITEME
public String getBuyGoodsURL(String userID, String name, int pcAmount, int quantity, String format, String externalRefID, String option_name_0, String option_value_0, String option_name_1, String option_value_1, String appParams, String sku, String sku_category)
userID
- WRITEMEname
- WRITEMEpcAmount
- WRITEMEquantity
- WRITEMEformat
- WRITEMEexternalRefID
- WRITEMEoption_name_0
- WRITEMEoption_value_0
- WRITEMEoption_name_1
- WRITEMEoption_value_1
- WRITEMEappParams
- WRITEMEsku
- WRITEMEsku_category
- WRITEME
public Hashtable<String,String> getTransaction(String userID, long startTimestamp) throws org.apache.http.client.ClientProtocolException, IOException
userID
- WRITEME WRITEMEstartTimestamp
- WRITEME
IOException
- WRITEME
org.apache.http.client.ClientProtocolException
- WRITEMEpublic Hashtable<String,String> getTransaction(String userID, long startTimestamp, long endTimestamp, int limit, String orderByCol0, String orderByDir0, String orderByCol1, String orderByDir1, String format) throws org.apache.http.client.ClientProtocolException, IOException
userID
- WRITEMEstartTimestamp
- WRITEMEendTimestamp
- WRITEMElimit
- WRITEMEorderByCol0
- WRITEMEorderByDir0
- WRITEMEorderByCol1
- WRITEMEorderByDir1
- WRITEMEformat
- WRITEME
org.apache.http.client.ClientProtocolException
- WRITEME
IOException
- WRITEMEpublic Hashtable<String,String> getTransactionStatus(String userID, String externalRefID, String format) throws org.apache.http.client.ClientProtocolException, IOException
userID
- WRITEMEexternalRefID
- WRITEMEformat
- WRITEME
IOException
- WRITEME
org.apache.http.client.ClientProtocolException
- WRITEMEpublic Hashtable<String,String> getValidCreditTypes()
public Hashtable<String,String> refundUser(String userID, String socialgoldTransactionID, String externalRefId) throws org.apache.http.client.ClientProtocolException, IOException
userID
- WRITEMEsocialgoldTransactionID
- WRITEMEexternalRefId
- WRITEME
IOException
- WRITEME
org.apache.http.client.ClientProtocolException
- WRITEMEpublic Hashtable<String,String> refundUser(String userID, String socialgoldTransactionID, String externalRefId, String description, String format) throws org.apache.http.client.ClientProtocolException, IOException
userID
- WRITEMEsocialgoldTransactionID
- WRITEMEexternalRefId
- WRITEMEdescription
- WRITEME WRITEMEformat
- WRITEME
IOException
- WRITEME
org.apache.http.client.ClientProtocolException
- WRITEME
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |