Payu payement error "Some error occurred, Try again!" - android

I have integrated payu into my android app through official docs at
https://www.payumoney.com/dev-guide/mobilecheckout/android.html#prereq .
The problem i'm facing is that my code works perfectly with test credentials, and fails when i use credentials of my live account that i want to integrate in the app.
public void makePayment(View view) {
String phone = "8882434664";
String productName = "product_name";
String firstName = "piyush";
String txnId = "0nf7" + System.currentTimeMillis();
String email = "piyush.jain#payu.in";
String sUrl = "https://test.payumoney.com/mobileapp/payumoney/success.php";
String fUrl = "https://test.payumoney.com/mobileapp/payumoney/failure.php";
String udf1 = "";
String udf2 = "";
String udf3 = "";
String udf4 = "";
String udf5 = "";
boolean isDebug = true;
String key = "2fcU3pmI";
String merchantId = "4947182";// These credentials are from https://test.payumoney.com/
String salt = "BxA24L2F7Z"; // THIS WORKS
/* String key = "yX8OvWy1"; //These credentials are from https://www.payumoney.com/
String merchantId = "5826688"; //THIS DOESN'T WORK
String salt = "0vciMJBbaa"; //ERROR: "some error occurred, Try again"
*/
PayUmoneySdkInitilizer.PaymentParam.Builder builder = new PayUmoneySdkInitilizer.PaymentParam.Builder();
builder.setAmount(getAmount())
.setTnxId(txnId)
.setPhone(phone)
.setProductName(productName)
.setFirstName(firstName)
.setEmail(email)
.setsUrl(sUrl)
.setfUrl(fUrl)
.setUdf1(udf1)
.setUdf2(udf2)
.setUdf3(udf3)
.setUdf4(udf4)
.setUdf5(udf5)
.setIsDebug(isDebug) //Also can someone clarify if this should be true/false for live mode
.setKey(key)
.setMerchantId(merchantId);
PayUmoneySdkInitilizer.PaymentParam paymentParam = builder.build();
String hash = hashCal(key + "|" + txnId + "|" + getAmount() + "|" + productName + "|"
+ firstName + "|" + email + "|" + udf1 + "|" + udf2 + "|" + udf3 + "|" + udf4 + "|" + udf5 + "|" + salt);
Log.d("app_activity123", hash);
paymentParam.setMerchantHash(hash);
PayUmoneySdkInitilizer.startPaymentActivityForResult(MyActivity.this, paymentParam);
}
Extra Info: Test credentials weren't working initially. I had to contact the payu support team to activate the account after which the code was working fine. My employer said he has activated the live account so i don't know what is the issue here.
There are no other issues like mine here, the closest one is here PayuMoney Integration in Android : Some error occured! Try again and it is unanswered.

setIsDebug(boolean) you need to pass false as parameter in this method to use live payment and true when testing in live mode.
I've set it to false and used Real Merchant id,salt and key and it worked, no errors.
Hope this helps someone.

Debug into PayUmoneyActivity
ErrorResponse contains the actual error.
It may be hash mismatch or wrong key.
#override
public void onFailureResponse(ErrorResponse response, String tag) {
mProgressDialog.dismiss();
Toast.makeText(context, "Some error occured",
Toast.LENGTH_SHORT).show();
finish();
}
this method in PayUmoneyActivity does not show error from errorresponse. just the general error. which is very problematic to debug.

I think your problem is in the line
'PayUmoneySdkInitilizer.startPaymentActivityForResult(MyActivity.this, paymentParam);'.
The official document states that you have to start transaction by using
'PayUmoneyFlowManager.startPayUMoneyFlow(paymentParam,this, R.style.AppTheme_default, false);'

Related

InvalidToken Error when using Rest API for Downloading file in an S3 AWS bucket in Android

I am trying to use the Rest Api with temporary credentials to download images stored in an S3 bucket in AWS from my Android App. I need to use the rest API instead of the TransferUtility method included in the Android AWS SDK, because I want to use an image downloader for better performance. According to the official AWS docs, I need to add an Authorization header to the HTTP Get request, that is conform like this:
Authorization = "AWS" + " " + AWSAccessKeyId + ":" + Signature;
Signature = Base64( HMAC-SHA1( YourSecretAccessKeyID, UTF-8-Encoding-Of( StringToSign ) ) );
StringToSign = HTTP-Verb + "\n" +
Content-MD5 + "\n" +
Content-Type + "\n" +
Date + "\n" +
CanonicalizedAmzHeaders +
CanonicalizedResource;
https://docs.aws.amazon.com/AmazonS3/latest/dev/RESTAuthentication.html#RESTAuthenticationConstructingCanonicalizedAmzHeaders
So, I obtain the Authorization header like this:
public String AuthorizationHeader (String dirToImageInBucket) throws UnsupportedEncodingException {
final AWSMobileClient mobileClient = AWSMobileClient.defaultMobileClient();
IdentityManager iM = mobileClient.getIdentityManager();
AWSCredentialsProvider sCredProvider= iM.getCredentialsProvider();
String secretKey = sCredProvider.getCredentials().getAWSSecretKey();
String awsAccessKeyId = sCredProvider.getCredentials().getAWSAccessKeyId();
Mac hmac = null;
hmac = Mac.getInstance("HmacSHA1");
hmac.init(new SecretKeySpec(secretKey.getBytes("UTF-8"), "HmacSHA1"));
Date dateT = new Date();
#SuppressLint("SimpleDateFormat") DateFormat dateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z");
String date = dateFormat.format(dateT);
String token = "x-amz-security-token:" + Login_Related.geToken(activity) +"\nx-amz-date:" +date+"\n";
String stringToSign = "GET" + "\n\n\n" + date + "\n" + token + "/" + dirToImageInBucket;
String signature = ( Base64.encodeToString(hmac.doFinal(stringToSign.getBytes("UTF-8")), Base64.DEFAULT)).replaceAll("\n", "");
return "AWS" + " " + awsAccessKeyId + ":" + signature;
}
Then I add the "Authorization" header returned by the previous method to the HTTP GET request, and also I include the headers x-amz-date and x-amz-security-token in the request (with the values of date and temporary access token respectively). I am currently testing the request on Postman to test if I can download the image by adding the mentioned headers to GET request of the image URL, and every time I send it, I get the response :
<Error>
<Code>InvalidToken</Code>
<Message>The provided token is malformed or otherwise invalid.</Message>
<Token-0>eyJraWQiOiJ4TFYxcVZiNG1IY3IrSWUxS....
I am sure I am using the right token, since the others http requests in my app are working properly with that token. Can anyone please help me realize what am I missing or doing wrong? Thanks.
Edited to include the token method:
static public String geToken(Activity act) {
AWSMobileClient.initializeMobileClientIfNecessary(act.getApplicationContext());
final AWSMobileClient mobileClient = AWSMobileClient.defaultMobileClient();
IdentityManager iM = mobileClient.getIdentityManager();
IdentityProvider iP = iM.getCurrentIdentityProvider();
token = iP.refreshToken();
System.out.println("x-amz-security-token check this token: " + token);
return token;
}

Signature mismatch in Payfort payment integration

I am integrating Payfort payment gateway in my android application. I am using FORT SDKv1.2.
In the post url for creating token, I am getting error "signature mismatch" always.
Can anybody tell me which signature is to be used?
url - https://sbpaymentservices.payfort.com/FortAPI/paymentApi
Let me guide you step by step:
NOTE: The following is an example for the Merchant Page 2.0 request signature generation:
Step 1: Add these variables on top of your file
private final static String KEY_MERCHANT_IDENTIFIER = "merchant_identifier";
private final static String KEY_SERVICE_COMMAND = "service_command";
private final static String KEY_LANGUAGE = "language";
private final static String KEY_ACCESS_CODE = "access_code";
private final static String KEY_MERCHANT_REFERENCE = "merchant_reference";
private final static String MERCHANT_IDENTIFIER = "YOUR_MERCHANT_IDENTIFIER";
private final static String ACCESS_CODE = "YOUR_ACCESS_CODE";
private final static String SHA_TYPE = "SHA-256";
private final static String SHA_REQUEST_PHRASE = "YOUR_SHA_REQUEST_PHRASE ";
private final static String LANGUAGE_TYPE = "en";
Make sure you are using your given MERCHANT_IDENTIFIER, ACCESS_CODE and SHA_REQUEST_PHRASE by Payfort.
Step 2: Create a string
String concatenatedString = SHA_REQUEST_PHRASE +
KEY_ACCESS_CODE + "=" + ACCESS_CODE +
KEY_LANGUAGE + "=" + LANGUAGE_TYPE +
KEY_MERCHANT_IDENTIFIER + "=" + MERCHANT_IDENTIFIER +
KEY_MERCHANT_REFERENCE + "=" + YOUR_MERCHANT_REFERENCE +
KEY_SERVICE_COMMAND + "=" + "TOKENIZATION" +
SHA_REQUEST_PHRASE;
Here YOUR_MERCHANT_REFERENCE is your unique merchant reference. It should be unique for every request
Step 3: Create a function to generate SHA-256 type signature from your
concatenatedString in Step 2
private String createSignature(String s) {
try {
// Create MD5 Hash
MessageDigest digest = MessageDigest.getInstance(SHA_TYPE);
digest.update(s.getBytes());
byte messageDigest[] = digest.digest();
return String.format("%0" + (messageDigest.length * 2) + 'x', new BigInteger(1, messageDigest));
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return "";
}
Finally
Call the createSignature function by passing your concatenatedString in Step 2.
String signature = createSignature(concatenatedString);
Change 'merchant_reference' value to one you didn't use before. It should be unique. I had the same trouble and it was fixed using it.
Sort your keys in array alphabetically, add before and after the secret phrases and then encrypt the string using your algorythm.
After it, you can use it in your requests.
I have faced same problem and found there is problem in algorithm i hvae used while generating signature. So plz check sequence of parameters while generating signature. and check for algorithm which u have setup in account and use same algorithm while generating signature
also make sure that the merchant reference is alphanumric and if you want to add special chars you can only add . _ -
Here you can find how to generate signature.
I was facing this signature mismatch error due to concatenating wrong SHA Request Phrase to the start and end of the signature.
I have faced same problem and found there is problem in integration settings.Just login into your payfort account and goto payment integration settings then your merchant reference id place check
SHA Type is SHA-256 and SHA Response Parse ,SHA Request Parse will same text.This same text added to your accesscode and sdk-token in the source code parameters.Please check below image once.
Use this code
String concatenatedString = SHA_REQUEST_PHRASE +
KEY_ACCESS_CODE + "=" + ACCESS_CODE +
KEY_DEVICE_ID + "=" + device_id +
KEY_LANGUAGE + "=" + LANGUAGE_TYPE +
KEY_MERCHANT_IDENTIFIER + "=" + MERCHANT_IDENTIFIER +
KEY_SERVICE_COMMAND + "=" + SDK_TOKEN +
SHA_REQUEST_PHRASE;
Then, pass this concatenated string in below method,
private static String getSignatureSHA256(String s) {
try {
// Create MD5 Hash
MessageDigest digest = MessageDigest.getInstance(SHA_TYPE);
digest.update(s.getBytes());
byte messageDigest[] = digest.digest();
return String.format("%0" + (messageDigest.length * 2) + 'x', new BigInteger(1, messageDigest));
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return "";
}
Use below code to get Signature,
String signature = getSignatureSHA256(concatenatedString);
Happy Coding :)

Receiving only default message in Android GCM using Amazon SNS

I am implementing a notification service on the server, to push out notifications to both Android and Iphones.
The problem I am having at the moment is that the Android device which I am testing on, is only receiving the default message.
My code is as follows :-
Main Program
string smsMessageString = "{\"default\": \"This is the default message which must be present when publishing a message to a topic. The default message will only be " +
" used if a message is not present for one of the notification platforms.\"," +
"\"APNS\": {\"aps\": {\"alert\": \"Check out these awesome deals!\",\"url\": \"www.amazon.com\"}}," +
"\"GCM\": {\"data\": {\"message\": \"Check out these awesome deals!\",\"url\": \"www.amazon.com\"}}," +
"\"ADM\": {\"data\": {\"message\": \"Check out these awesome deals!\",\"url\": \"www.amazon.com\"}}}";
var smsMessage = new SmsMessageObj
{
smsMessageSubject = "Test Message",
smsMessageBody = smsMessageString
};
snsClient.SendPush(endpointArn, smsMessage);
and the SendPush is as follows :-
public void SendPush(string endpointArn, SmsMessageObj msg)
{
if (string.IsNullOrEmpty(endpointArn))
throw new Exception("Endpoint ARN was null");
var pushMsg = new PublishRequest
{
Message = msg.smsMessageBody,
MessageStructure = "json",
Subject = msg.smsMessageSubject,
TargetArn = endpointArn
};
_client.Publish(pushMsg);
}
Do I need to include anything more so that I can get the "correct" Android notification?
Do I need anything in the app.config?
Thanks for your help and time
I have resolved this question. All I needed to do was to stringify the Json. Maybe it will help someone else in the future. So what I did was :-
var apns_Json = "{\"aps\": {\"alert\": \"Check out these awesome deals_Apple!\",\"url\": \"www.amazon.com\"}}";
var gcm_Json = "{\"data\": {\"message\": \"Check out these awesome deals_Google!\",\"url\": \"www.amazon.com\"}}";
var adm_Json = "{\"data\": {\"message\": \"Check out these awesome deals!\",\"url\": \"www.amazon.com\"}}";
string smsMessageString = "{\"default\": \"This is the default message which must be present when publishing a message to a topic. The default message will only be " +
" used if a message is not present for one of the notification platforms.\"," +
"\"APNS\": " + JsonConvert.ToString(apns_Json) + "," +
"\"GCM\": " + JsonConvert.ToString(gcm_Json) + "," +
"\"ADM\": " + JsonConvert.ToString(adm_Json) + "}";

Get first and last name of user using Google SignIn API in Android

I'm developing app and using Google SignIn. In the iOS Api, I can get the first name and last name like this:
let GoogleUser = GIDSignIn.sharedInstance().currentUser
let firstName = googleAccount.profile.givenName
let lastName = googleAccount.profile.familyName
But in the Android API, I found only getDisplayName() that returns the full name of the user in one String. I can't find any method that returns only the first or the last name.
The Google SignIn API for Android site
Thanks :)
In android also have,
getFamilyName()
getGivenName()
Refer this,
com.google.android.gms.plus.model.people.Person.Name
//After the signing we are calling this function
private void handleSignInResult(GoogleSignInResult result) {
//If the login succeed
if (result.isSuccess()) {
signInButton.setVisibility(View.GONE);
//Getting google account
GoogleSignInAccount acct = result.getSignInAccount();
String name=acct.getDisplayName();
String email=acct.getEmail();
Log.d("namegoogle",name);
Log.d("emailgoogle",email);
edit_signin_emailid.setText(email);
String fullname = acct.getDisplayName();
String[] parts = fullname.split("\\s+");
Log.d("Length-->",""+parts.length);
if(parts.length==2) {
String firstname = parts[0];
String lastname = parts[1];
Log.d("First-->", "" + firstname);
Log.d("Last-->", "" + lastname);
AppController.setStringPref("firstnamebook", firstname);
AppController.setStringPref("lastnamebook", lastname);
Log.d("FirstApp", "" + AppController.getStringPref("firstnamebook"));
Log.d("LastApp", "" + AppController.getStringPref("lastnamebook"));
}
else if(parts.length==3){
String firstname = parts[0];
String middlename = parts[1];
String lastname = parts[2];
Log.d("First-->", "" + firstname);
Log.d("Last-->", "" + lastname);
AppController.setStringPref("firstnamebook", firstname);
AppController.setStringPref("lastnamebook", lastname);
}
}
}
Try this
String fullname = "Sathish Kumar Jeyasankar";
String[] parts = fullname.split("\\s+");
String firstname = parts[0]; // Sathish
String middlename = parts[1]; // Kumar
String lastname = parts[2]; // Jeyasankar

How can I create Android logcat entries that provide a link to source code in Eclipse? [duplicate]

Is there any way to access automatically any Log in Logcat by a double click ?
Actually, when there is an error crashing my Android Application, I can double click on the line saying for instance
at com.myapp.mypackage$Class.function(File.java:117)
And by Double-clicking on this line, I am automatically redirected to the related line of my code.
But, when I try to generate the same line in another Log, example :
Log.e("TAG", "at com.myapp.mypackage$Class.function(File.java:117)");
The Double-Click doesn't work anymore ...
Any ideas ?
If you want to create a log in logcat that can be clicked and go to your line use the following method to create it:
Enjoy!
public static void showLogCat(String tag, String msg) {
StackTraceElement[] stackTraceElement = Thread.currentThread()
.getStackTrace();
int currentIndex = -1;
for (int i = 0; i < stackTraceElement.length; i++) {
if (stackTraceElement[i].getMethodName().compareTo("showLogCat") == 0)
{
currentIndex = i + 1;
break;
}
}
String fullClassName = stackTraceElement[currentIndex].getClassName();
String className = fullClassName.substring(fullClassName
.lastIndexOf(".") + 1);
String methodName = stackTraceElement[currentIndex].getMethodName();
String lineNumber = String
.valueOf(stackTraceElement[currentIndex].getLineNumber());
Log.i(tag, msg);
Log.i(tag + " position", "at " + fullClassName + "." + methodName + "("
+ className + ".java:" + lineNumber + ")");
}
If you don't mind the clutter in your log, you can easily just add a new Exception() to the log message
Log.e("TAG", "Looky here see", new Exception());

Categories

Resources