android - payUmoney integration is giving an error -
after logging in, it's generating hash value, still giving error "some problem occurred! try again".
payumoneysdkinitilizer.paymentparam.builder builder = new payumoneysdkinitilizer.paymentparam.builder(); builder.setamount(10.0) .settnxid("0nf7" + system.currenttimemillis()) .setphone(<my phone>) .setproductname("product_name") .setfirstname(<my name>) .setemail(<my email>) .setsurl("https://www.payumoney.com/mobileapp/payumoney/success.php") .setfurl("https://www.payumoney.com/mobileapp/payumoney/failure.php") .setudf1("").setudf2("").setudf3("").setudf4("").setudf5("") .setisdebug(false) .setkey(<mykey>) .setmerchantid(<my debug merchant id>); string tnxid="0nf7" + system.currenttimemillis(); payumoneysdkinitilizer.paymentparam paymentparam = builder.build(); string hashsequence = "<...>|"+tnxid+"|10.0|product_name|<my name>|<my email>|||||||||||salt"; string servercalculatedhash= hashcal("sha-512", hashsequence); toast.maketext(getapplicationcontext(), servercalculatedhash, toast.length_short).show(); paymentparam.setmerchanthash(servercalculatedhash); // calculateserversidehashandinitiatepayment(paymentparam); payumoneysdkinitilizer.startpaymentactivityforresult(trayactivity.this, paymentparam);
public static string hashcal(string type, string str) { byte[] hashseq = str.getbytes(); stringbuffer hexstring = new stringbuffer(); try { messagedigest algorithm = messagedigest.getinstance(type); algorithm.reset(); algorithm.update(hashseq); byte messagedigest[] = algorithm.digest(); (int = 0; i<messagedigest.length; i++) { string hex = integer.tohexstring(0xff &messagedigest[i]); if (hex.length() == 1) { hexstring.append("0"); } hexstring.append(hex); } } catch (nosuchalgorithmexception e) { e.printstacktrace(); } return hexstring.tostring(); }
you use in code:
.settnxid("0nf7" + system.currenttimemillis())
and later:
string tnxid="0nf7" + system.currenttimemillis();
probably not problem, want use 2 different values these (the time may change between 2 calls)? didn't want same tnxid
in both cases?
transactionidprovider.java:
import java.util.locale; public class transactionidprovider { private final static string default_prefix = "id"; // convenient prime number incrementing counter private final static long id_add = 0xf0ad; // "f*ck off , die" // 64b counter non-trivial start value private static long idcounter = 0x0101f00ddeadbeefl; /** * returns id consisting of prefix string , 64b counter interleaved * 32b per-4s-timestamp. * * may produce identical id (collision) when: * 1) class reloaded within 4s * (to fix: serialize "idcounter" upon shutdown/restart of vm, or * modify prefix per start of vm) * 2) more 2^64 ids requested within 4s (no fix, unexpected) * 3) more 2^64 ids requested after cca. 550 years. * (no fix, unexpected) * 4) more 1 static instance of transactionidprovider used * (two or more vms running app) (to fix put different prefix in * every vm/server running this) * * length of returned id prefix.length() + 24 alphanumeric symbols. */ public static synchronized string getnewid(final string prefix) { idcounter += id_add; // increment counter // 32b timestamp per ~4s (millis/4096) (good ~550 years) final int timestamp = (int)(system.currenttimemillis()>>12); final int idpart1 = (int)(idcounter>>32); final int idpart2 = (int)(idcounter); return string.format(locale.us, "%s%08x%08x%08x", prefix, idpart1, timestamp, idpart2); } public static string getnewid() { return getnewid(default_prefix); } }
not sure how usable one, , if id may long. feel free use/modify way wish.
also wonder, whether didn't forget important, can't recall anything.
the security aspect of 1 still quite weak, within 4s time span id simple addition, @ least it's not producing 1, 2, 3... series.
did found sdk docs, looks txnid may 25 chars long, have 1 char prefix only. or cut down on timestamp, using %07x
in format , masking value 0x0fffffff, make repeat every ~34 years -> 2 letters prefix. or change counter 32b int
, should still more enough, unless expect thousands of transactions per second -> remove 8 chars. or base32/base64 whole id shorten (depends alphabet legal content)...
or whatever... spent enough time this. hire pro.
Comments
Post a Comment