Created
April 9, 2013 03:23
-
-
Save jaredjenkins/5342715 to your computer and use it in GitHub Desktop.
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
void OnUSDCurrencyExchange(long? transactionId, double usDollars, string purchasedCurrencyType, double amountPurchased){ | |
if(!transactionId.HasValue){ | |
//transactionId has no value so generate one | |
transactionId = GetRandomLong(); | |
} | |
var currencies = new TransactionCurrency[2]; | |
currencies[0] = TransactionCurrency.createReal(Math.Abs(usDollars) * -1, CurrencyType.USD); | |
currencies[1] = TransactionCurrency.createVirtual(Math.Abs(amountPurchased), purchasedCurrencyType); | |
Playnomics.instance.transaction(transactionId, TransactionType.CurrencyConvert, currencies, null, null, null); | |
} | |
OnItemPurchasedWithVirtual(long? transactionId, string itemId, int quantity, double itemCost, string currencyType){ | |
if(!transactionId.HasValue){ | |
//transactionId has no value so generate one | |
transactionId = GetRandomLong(); | |
} | |
var currencies = new TransactionCurrency[1]; | |
currencies[0] = TransactionCurrency.createVirtual(Math.Abs(itemCost), currencyType); | |
Playnomics.instance.transaction(transactionId, TransactionType.BuyItem, currencies, quantity, itemId, null); | |
} | |
OnItemPurchasedWithUSD(long? transactionId, string itemId, int quantity, double itemCost){ | |
if(!transactionId.HasValue){ | |
//transactionId has no value so generate one | |
transactionId = GetRandomLong(); | |
} | |
var currencies = new TransactionCurrency[1]; | |
currencies[0] = TransactionCurrency.createReal(Math.Abs(itemCost), CurrencyType.USD); | |
Playnomics.instance.transaction(transactionId, TransactionType.BuyItem, currencies, quantity, itemId, null); | |
} | |
long GetRandomLong(){ | |
var rnd = new System.Random(); | |
var buffer = new byte[8]; | |
rnd.NextBytes(buffer); | |
return BitConverter.ToInt64(buffer, 0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment