Android Question Google Pay API conversion

Hari Haran

Member
Licensed User
Hi ,

I want to convert a google pay api for India to B4A as i'm not good in java I want someone to help me,

String GOOGLE_PAY_PACKAGE_NAME = "com.google.android.apps.nbu.paisa.user";
int GOOGLE_PAY_REQUEST_CODE = 123;

Uri uri =
new Uri.Builder()
.scheme("upi")
.authority("pay")
.appendQueryParameter("pa", "your-merchant-vpa@xxx")
.appendQueryParameter("pn", "your-merchant-name")
.appendQueryParameter("mc", "your-merchant-code")
.appendQueryParameter("tr", "your-transaction-ref-id")
.appendQueryParameter("tn", "your-transaction-note")
.appendQueryParameter("am", "your-order-amount")
.appendQueryParameter("cu", "INR")
.appendQueryParameter("url", "your-transaction-url")
.build();
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(uri);
intent.setPackage(GOOGLE_PAY_PACKAGE_NAME);
activity.startActivityForResult(intent, GOOGLE_PAY_REQUEST_CODE);



Thanks in advance and awaiting for the help.
 

Biswajit

Active Member
Licensed User
Longtime User
Code for starting activity for result:
Sub Process_Globals
    Private ion As Object
End Sub

Sub StartActivityForResult(i As Intent)
    Dim jo As JavaObject = GetBA
    ion = jo.CreateEvent("anywheresoftware.b4a.IOnActivityResult", "ion", Null)
    jo.RunMethod("startActivityForResult", Array As Object(ion, i))
End Sub

Sub GetBA As Object
    Dim jo As JavaObject
    Dim cls As String = Me
    cls = cls.SubString("class ".Length)
    jo.InitializeStatic(cls)
    Return jo.GetField("processBA")
End Sub

Code for opening GPay:
Dim GOOGLE_PAY_PACKAGE_NAME As String = "com.google.android.apps.nbu.paisa.user"
Dim GOOGLE_PAY_REQUEST_CODE As Int = 123 'This is not required
Dim intent As Intent
intent.Initialize(intent.ACTION_VIEW,"upi://pay?pa=your-merchant-vpa@xxx&pn=your-merchant-name&mc=your-merchant-code&tr=your-transaction-ref-id&tn=your-transaction-note&am=your-order-amount&cu=INR&url=your-transaction-url")
intent.SetPackage(GOOGLE_PAY_PACKAGE_NAME)
StartActivityForResult(intent)

Code for handling result intent from GPay:
Sub ion_Event (MethodName As String, Args() As Object) As Object
    'Args(0) = resultCode
    'Args(1) = intent
    Dim intent As Intent = Args(1)
    Log(intent.GetExtra("Status"))
    Log(intent.GetExtra("txnRef"))
    Log(intent.GetExtra("ApprovalRefNo"))
    Log(intent.GetExtra("response"))
    Log(intent.GetExtra("txnId"))
    Log(intent.GetExtra("responseCode"))
    Log(intent.GetExtra("TrtxnRef"))
    Return Null
End Sub
 
Upvote 0

Hari Haran

Member
Licensed User
Hi,
as i was held up with some other work, I have just tried it

Iam getting the error

onActivityResult: wi is null

can you please guide me
 
Upvote 0

Hari Haran

Member
Licensed User
Thanks all

it worked on the other mobile as in my mobile google pay is not working or configured due to issue with my phone number on bank account.
 
Upvote 0
Top