xamarin android project payment gateway submit amount, showing amount submission fail error

Bhautik Bhavshar 6 Reputation points
2021-07-27T12:40:17.11+00:00

i am adding payment gateway with xamarin android project but i am getting transaction failed error. The payment gateway opens and runs well but when i submit the amount i got transaction failed error. my code is:

using System;
using System.Net.Http;
using System.Text;
using Android.App;
using Android.OS;
using Android.Runtime;
using Android.Support.V7.App;
using Android.Views;
using System.Threading.Tasks;
using Android.Widget;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Android.Content;
using System.Collections.Generic;
using Android.Content.PM;

namespace androidbindingapp
{
[Activity(Label = "@string/app_name", Theme = "@style/AppTheme.NoActionBar", MainLauncher = true)]
public class MainActivity : AppCompatActivity
{

    protected override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);
        Xamarin.Essentials.Platform.Init(this, savedInstanceState);
        // Set our view from the "main" layout resource
        SetContentView(Resource.Layout.activity_main);
        Button button = (Button)FindViewById(Resource.Id.button1);
        button.Click += BtnOnClick;
     }

     private void BtnOnClick(object sender, EventArgs eventArgs)
    {

            // Create your application here

            string amount = "1";
            string transaction_ref_id = Guid.NewGuid().ToString().Substring(0, 10) + "UPI";
            string transaction_ref = Guid.NewGuid().ToString().Substring(0, 10);
            using (var uri = new Android.Net.Uri.Builder()
                .Scheme("upi")
                .Authority("pay")
                .AppendQueryParameter("pa", "******@SBIN0004875.ifsc.npci")
                .AppendQueryParameter("pn", "vijay shankar tiwari")
                .AppendQueryParameter("mc", "9999")
                .AppendQueryParameter("tn", "pay tips by vijay")
                .AppendQueryParameter("tr", transaction_ref_id)
                .AppendQueryParameter("tid", transaction_ref)
                .AppendQueryParameter("am", amount)
                .AppendQueryParameter("cu", "INR")
                .Build())
            {
                Intent = new Intent(Intent.ActionView);
                Intent.SetData(uri);
            }

            if (IsAppInstalledinDevice("in.org.npci.upiapp"))
            {
                Intent.SetPackage("in.org.npci.upiapp");
                StartActivityForResult(Intent, 9999);
            }
            else
            {
                var packagename = PackageName;
                Toast.MakeText(Android.App.Application.Context, "Bhim is not available in your 
                device", ToastLength.Long).Show();
            }

    }

    private bool IsAppInstalledinDevice(string PackageName)
    {
        PackageManager pm = this.PackageManager;
        bool installed = false;
        try
        {
            pm.GetPackageInfo(PackageName, PackageInfoFlags.Activities);
            installed = true;
        }
        catch (PackageManager.NameNotFoundException ex)
        {
            installed = false;
        }
        return installed;
    }

    public override void OnRequestPermissionsResult(int requestCode, string[] permissions, 
    [GeneratedEnum] Android.Content.PM.Permission[] grantResults)
    {
        Xamarin.Essentials.Platform.OnRequestPermissionsResult(requestCode, permissions, 
        grantResults);

        base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
    }

    protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
    {
        base.OnActivityResult(requestCode, resultCode, data);

        if (data != null)
        {
            TextView textView = FindViewById<TextView>(Resource.Id.textView1);
            String dataString = data.GetStringExtra("txStatus");
            if (dataString != null)
            {
                textView.SetText(dataString, Android.Widget.TextView.BufferType.Normal);
            }
        }

    }
   }
 }

when i run the program then everything works fine, the payment gateway opens, it asks for payment but when i submit the amount then it shows the error transaction failed. i have install the corresponing payment gateway in my mobile device.

Developer technologies .NET Xamarin
0 comments No comments
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.