INVALID_RESOURCE_ID in paypal - java

I have make payments through PayPal native android mobile sdk. Below is the success response
{"response":{"state":"approved","id":"PAY-someID","create_time":"2017-06-21T18:01:33Z","intent":"sale"},"client":{"platform":"Android","paypal_sdk_version":"2.15.3","product_name":"PayPal-Android-SDK","environment":"sandbox"},"response_type":"payment"}
But when back-end wants to verify with the payment id i.e PAY-someID, it is throwing error json like below every time
[debug] application - verifyPayment mitemreqCppverifpmtrequest(PAY-someID)
[debug] application - verifpmtrequest case mendpointt https://api.sandbox.paypal.com/v1/payments/payment/PAY-someID
[debug] application - tx.get.body{"name":"INVALID_RESOURCE_ID","message":"Requested resource ID was not found.","information_link":"https://developer.paypal.com/webapps/developer/docs/api/#INVALID_RESOURCE_ID","debug_id":"someID"}
Below is the android code
private static final String CONFIG_ENVIRONMENT = PayPalConfiguration.ENVIRONMENT_SANDBOX;
private static PayPalConfiguration config = new PayPalConfiguration()
.environment(CONFIG_ENVIRONMENT)
.clientId(CONFIG_CLIENT_ID)
// The following are only used in PayPalFuturePaymentActivity.
.merchantName("Example Merchant")
.merchantPrivacyPolicyUri(Uri.parse("https://www.example.com/privacy"))
.merchantUserAgreementUri(Uri.parse("https://www.example.com/legal"));
PayPalPayment thingToBuy = getThingToBuy(PayPalPayment.PAYMENT_INTENT_SALE);
Intent intent = new Intent(SampleActivity.this, PaymentActivity.class);
intent.putExtra(PayPalService.EXTRA_PAYPAL_CONFIGURATION, config);
intent.putExtra(PaymentActivity.EXTRA_PAYMENT, thingToBuy);
startActivityForResult(intent, REQUEST_CODE_PAYMENT);
return new PayPalPayment(new BigDecimal("0.01"), "USD", "sample item",
paymentIntent);
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_CODE_PAYMENT) {
if (resultCode == Activity.RESULT_OK) {
PaymentConfirmation confirm =
data.getParcelableExtra(PaymentActivity.EXTRA_RESULT_CONFIRMATION);
if (confirm != null) {
try {
Log.i(TAG, confirm.toJSONObject().toString(4));
}
}
}
The problem is similar to the below
https://github.com/paypal/PayPal-Android-SDK/issues/330
No idea how to solve this.

Try this one this is working code of my Google PlayStore application.
PayPalConfiguration config = new PayPalConfiguration().environment(PayPalConfiguration.ENVIRONMENT_SANDBOX).clientId("Your id");
Intent intent = new Intent(context, PayPalService.class);
intent.putExtra(PayPalService.EXTRA_PAYPAL_CONFIGURATION, config);
startService(intent);
PayPalPayment payment = new PayPalPayment(new BigDecimal(charge), "USD", eventName, PayPalPayment.PAYMENT_INTENT_SALE);
Intent intent = new Intent(activity, PaymentActivity.class);
intent.putExtra(PayPalService.EXTRA_PAYPAL_CONFIGURATION, config);
intent.putExtra(PaymentActivity.EXTRA_PAYMENT, payment);
startActivityForResult(intent, 1089);
Don't Forget to stop service in OnDestroy().
#Override
protected void onDestroy() {
stopService(new Intent(this, PayPalService.class));
super.onDestroy();
}
Also stop service inside OnActivityResult When you perform all your task.
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == Activity.RESULT_OK && requestCode == 1089) {
PaymentConfirmation confirm = data.getParcelableExtra(PaymentActivity.EXTRA_RESULT_CONFIRMATION);
if (confirm != null)
{
try
{
// Your code after successful response.
} catch (JSONException e) {
Log.error(getClass().getName(), e);
}
}
stopService(new Intent(this, PayPalService.class));
} else if (resultCode == Activity.RESULT_CANCELED) {
//
} else if (resultCode == PaymentActivity.RESULT_EXTRAS_INVALID) {
//
}
}

Related

startActivityForResult to one class and have that class return the data to a different class?

I have 3 classes: MainActivity, HighScoreActivity, and GameScreenActivity. I want to go to the GameScreenActivity via MainActivity, and then when the game has finished, pass the score to the HighScoreActivity. Everything gets passed to the GameScreenActivity successfully, but it doesn't go to the onActivityResult in HighScoreActivity.
I believe it's because of the MainActivity having the startActivityForResult, so the GameScreenActivity's finishQuiz() is expecting to return its data to the MainActivity. How would I pass the GameScreenActivity's data to the HighScoreActivity?
MainActivity()
MainActivity(){
...
private void startQuiz() {
String difficulty = spinnerDifficulty.getSelectedItem().toString();
Intent intent = new Intent(getBaseContext(), GameScreenActivity.class);
intent.putExtra(EXTRA_DIFFICULTY, difficulty);
startActivityForResult(intent, REQUEST_CODE_QUIZ);
}
}
GameScreenActivity()
GameScreenActivity(){
...
private void finishQuiz(){
Intent resultIntent = new Intent(getBaseContext(),
HighScoreActivity.class);
resultIntent.putExtra(EXTRA_SCORE, score);
resultIntent.putExtra(EXTRA_DIFFICULTY, difficulty);
setResult(RESULT_OK, resultIntent);
startActivity(resultIntent);
}
}
HighScoreActivity()
HighScoreActivity(){
...
#Override
protected void onActivityResult(int requestCode, int resultCode,
Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQUEST_CODE_QUIZ){
if (resultCode == RESULT_OK) {
int score = data.getIntExtra(GameScreenActivity.EXTRA_SCORE, 0);
String difficulty = data.getStringExtra(GameScreenActivity.EXTRA_DIFFICULTY);
if (score > highScore10) {
updateHighscore(score, difficulty);
}
}
}
}
}
-------------------------------------------------------------
Trying with the Broadcast method:
GameScreenActivity() with broadcasting methods
GameScreenActivity(){
...
private void finishQuiz(){
Log.d("sender", "Broadcasting message");
Intent intent = new Intent("scoreEvent");
intent.putExtra(EXTRA_DIFFICULTY, difficulty);
intent.putExtra(EXTRA_SCORE, score);
LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
sendBroadcast(intent);
Intent goToHighScores = new Intent(getBaseContext(), HighScoreActivity.class);
startActivity(goToHighScores);
}
}
HighScoreActivity() with broadcasting methods
HighScoreActivity(){
...
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_high_score);
LocalBroadcastManager.getInstance(this).registerReceiver(mMessageReceiver,
new IntentFilter("scoreEvent"));
}
#Override
protected void onActivityResult(int requestCode, int resultCode,
Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQUEST_CODE_QUIZ){
if (resultCode == RESULT_OK) {
int score = data.getIntExtra(GameScreenActivity.EXTRA_SCORE, 0);
String difficulty = data.getStringExtra(GameScreenActivity.EXTRA_DIFFICULTY);
if (score > highScore10) {
updateHighscore(score, difficulty);
}
}
}
}
private BroadcastReceiver mMessageReceiver = new BroadcastReceiver() {
#Override
public void onReceive(Context context, Intent intent) {
String message = intent.getStringExtra("message");
Log.d("receiver", "Got message: " + message);
}
};
#Override
protected void onDestroy() {
LocalBroadcastManager.getInstance(this).unregisterReceiver(mMessageReceiver);
super.onDestroy();
}
}
Considering HighScoreActivity is running,
You can utilize LocalBroadcastManager to register local broadcastReceiver in HighScoreActivity with IntentFilter. Also, don't forget to unregister in onDestroy()
Now, instead of setResult do sendBroadcast() from GameScreenActivity
Hope this helps. Happy coding!

Android VIEW intent with content Uri

I am creating a App, which should save reference documents, saved on the device.
I am receiving the content URI for these documents in the following way:
private void selectDocument() {
Intent chooseFile;
chooseFile = new Intent(Intent.ACTION_GET_CONTENT);
chooseFile.addCategory(Intent.CATEGORY_OPENABLE);
chooseFile.setType("*/*");
if (chooseFile.resolveActivity(getPackageManager()) != null)
startActivityForResult(chooseFile, ACTIVITY_CHOOSE_FILE);
}
#Override
protected void onActivityResult(int requestCode, int resultCode, #Nullable Intent data) {
if (resultCode != RESULT_OK) return;
if (requestCode == ACTIVITY_CHOOSE_FILE) {
try {
binding.txtLink.setText(URLDecoder.decode(data.getDataString(),"UTF-8"));
binding.btnLink.setTag(false);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
} else {
super.onActivityResult(requestCode, resultCode, data);
}
}
after displaying the url to the user, he should be able to open the document.
And i am not really sure how to do that, since I only get the contentURI.
What i am currently trying is this:
private void openDocument() {
String file = binding.txtLink.getText().toString();
if (file.isEmpty()) {
return;
}
Intent intent;
String extension = file.substring(file.lastIndexOf(".") + 1);
String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(file));
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
} else {
Snackbar.make(binding.root, "Keine Anwendung zum öffnen der Datei installiert", Snackbar.LENGTH_LONG).show();
}
}
This already opens the correct App, but they can't find the files.
What would i need to do, to enable this behavior?
Or do i have to copy the files to my app directory and open them from there?

getting error in backpress when using createConfirmDeviceCredentialIntent()

I am using createConfirmDeviceCredentialIntent() for pin authentication in my android application. If I press back button from my pin authentication intent, the createConfirmDeviceCredentialIntent closes and it displays main activity. I want that from that intent if someone presses back button the app should get closed. `KeyguardManager keyguardManager = (KeyguardManager) getSystemService(KEYGUARD_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Intent i = keyguardManager.createConfirmDeviceCredentialIntent("unlock", "confirm_pattern");
try {
startActivityForResult(i, LOCK_REQUEST_CODE);
} catch (Exception e) {
Log.d("exception occured", e.toString());
}
} #Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case LOCK_REQUEST_CODE:
if (resultCode == RESULT_OK) {
Intent a = new Intent(MainActivity.this, HomeActivity.class);
startActivity(a);
textView.setText("unlock_success");
} else {
textView.setText("unlock_failed");
}
break;
}
}`

android - Google places opens the map on closes after 1 sec

Im creating an intent to an activity by clicking on a button which should open google places, but it closes again really fast and says no location selected, and returns to the main activity, and then nothing happens if i click again.
My api should be fine, I have checked that it's the correct SHA1-fingerprint thats connected to the api key.
The result code is 2
It worked earlier in the activity before this one, but I needed it to open when i click on a button instead, and now when I try to open this new activity as an intent it wont work.
public class MapActivity extends AppCompatActivity {
int PLACE_PICKER_REQUEST = 1;
int status;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_events);
status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
if (status != ConnectionResult.SUCCESS) {
if (GooglePlayServicesUtil.isUserRecoverableError(status)) {
GooglePlayServicesUtil.getErrorDialog(status, this,
100).show();
}
}
if (status == ConnectionResult.SUCCESS) {
int PLACE_PICKER_REQUEST = 199;
PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder();
Context context = this;
try {
startActivityForResult(builder.build(context), PLACE_PICKER_REQUEST);
} catch (GooglePlayServicesRepairableException e) {
e.printStackTrace();
} catch (GooglePlayServicesNotAvailableException e) {
e.printStackTrace();
}
}
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
System.out.println("Result code: " + resultCode);
System.out.println("Request code: " + requestCode);
if (requestCode == 100) {
status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
}
if (requestCode == 199) {
//process Intent......
if (data != null) {
Place place = PlacePicker.getPlace(data, this);
String toastMsg = String.format("Place: %s", place.getName());
Toast.makeText(this, toastMsg, Toast.LENGTH_LONG).show();
} else {
String toastMsg = ("No location selected.");
Toast.makeText(this, toastMsg, Toast.LENGTH_LONG).show();
}
}
}
}
This is from the intent which create the new intent to maps
public void onClick(View view) {
Intent i = new Intent(this, MapActivity.class);
startActivity(i);
}
I think its happening because of you are using old method of getPlace
try to swap the arguments, by changing it from:
Place place = PlacePicker.getPlace(data, this);
to
Place place = PlacePicker.getPlace(getContext(), data);
Update #2
Enable Google places API in the developer console and add these lines to AndroidManifest
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="ADD_YOUR_API_KEY_HERE" />
Update #3
after some search, it looks like there is others having same issue. Look at these links:
https://github.com/zhangtaii/react-native-google-place-picker/issues/21
https://stackoverflow.com/a/32751164/
https://github.com/googlesamples/android-play-places/issues/13

Speech recognition in Android

I am working on speech recognition and need some sample programs.
Can anyone guide me?
Let me cut and paste a bit to show you what code you will need.
EDIT: you can also download a handy abstract class from this project.
You will need this intent (parameterize as you see fit):
public Intent getRecognizeIntent(String promptToUse, int maxResultsToReturn)
{
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, maxResultsToReturn);
intent.putExtra(RecognizerIntent.EXTRA_PROMPT, promptToUse);
return intent;
}
Then you need to send your intent to the speech recognition activity like so,
public void gatherSpeech(String prompt)
{
Intent recognizeIntent = getRecognizeIntent(prompt);
try
{
startActivityForResult(recognizeIntent, SpeechGatherer.VOICE_RECOGNITION_REQUEST_CODE);
}
catch (ActivityNotFoundException actNotFound)
{
Log.w(D_LOG, "did not find the speech activity, not doing it");
}
}
Then you will need to have your activity handle the speech result:
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
Log.d("Speech", "GOT SPEECH RESULT " + resultCode + " req: "
+ requestCode);
if (requestCode == SpeechGatherer.VOICE_RECOGNITION_REQUEST_CODE)
{
if (resultCode == RESULT_OK)
{
ArrayList<String> matches = data
.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
Log.d(D_LOG, "matches: ");
for (String match : matches)
{
Log.d(D_LOG, match);
}
}
}
}
For more info see:
http://developer.android.com/resources/articles/speech-input.html
http://developer.android.com/reference/android/speech/RecognizerIntent.html
http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/app/VoiceRecognition.html
First need to Showing google speech input dialog like so
/**
* Showing google speech input dialog
* */
private void promptSpeechInput() {
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault());
intent.putExtra(RecognizerIntent.EXTRA_PROMPT,
getString(R.string.speech_prompt));
try {
startActivityForResult(intent, REQ_CODE_SPEECH_INPUT);
} catch (ActivityNotFoundException a) {
Toast.makeText(getApplicationContext(),
getString(R.string.speech_not_supported),
Toast.LENGTH_SHORT).show();
}
}
then need to receiving speech input like so.
/**
* Receiving speech input
* */
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case REQ_CODE_SPEECH_INPUT: {
if (resultCode == RESULT_OK && null != data) {
ArrayList<String> result = data
.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
txtSpeechInput.setText(result.get(0));
}
break;
}
}
}
and need to set REQ_CODE_SPEECH_INPUT
private final int REQ_CODE_SPEECH_INPUT = 100;

Categories

Resources