Google Pay(Tez) Integration into my payment gateway ? (Android)

3.2k Views Asked by At

Note : I am aware it is not yet available for iOS, Also i am not looking for Xamarin.Forms(Obviously).

Been trying to integrate Google Pay(Tez) API into my Xamarin Application when I realised that there are no guides available for its integration to Xamarin which is fine.

So, I visited the Google Pay API page, Which seems to have a sweet looking guide for Android(Java) so I started converting the native Android code into Xamarin. And then I hit a bump where the PaymentsClient class seems to be unavailable in Xamarin, So I tried checking for its namespace so maybe I could understand if it was available or not(Xamarin.Android). But there is no mention of the namespace of this class(None that I noticed). All I could find in its info is that it inherits from com.google.android.gms.common.api.GoogleApi which did not help at all actually.

Queries

  • Am I missing some package here or is there some alternative that is used in Xamarin?
  • Is There some guide to integrating Google pay(Tez) API for Xamarin apps that I have missed?
  • Is Google pay(Tez) integration not added in Xamarin.Android yet?
  • Or is there something wrong with my current config? i.e VS17 Pro version 15.6.7 , Xamarin version 4.9.0.753 and Xamarin.Android version 8.2.0.16 Android SDK latest with all the API versions above v 4.0
1

There are 1 best solutions below

0
On BEST ANSWER

Google Pay (not Tez):

Package: `Xamarin.GooglePlayServices.Wallet`

Make sure that you enable your app for Wallet processing via the metadata in the manifest, or via your application's MetaDataAttribute:

[Application]
[MetaData(name: "com.google.android.gms.wallet.api.enabled", Value = "true")]

From there it is a matter of using Android.Gms.Wallet; and setting up and using the PaymentsClient, ie.

PaymentsClient paymentsClient = WalletClass.GetPaymentsClient(
        this, 
        new WalletClass.WalletOptions.Builder()
                .SetEnvironment(WalletConstants.EnvironmentTest)
                .Build()
);

Google Pay for India (UPI Intent-based):

To pass the transaction information to "Tez", you define an URI that includes all of your merchant information, transaction amount, etc... This URI is based upon the UNIFIED PAYMENTS INTERFACE UPI scheme (this is not controlled by Google and thus you have refer to UPI specs for what data you need to pass).

re: https://www.npci.org.in/sites/all/themes/npcl/images/PDF/UPI_Linking_Specs_ver_1.5.1.pdf

using (var uri = new Android.Net.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 = new Intent(Intent.ActionView);
    intent.SetData(uri);
    intent.SetPackage("com.google.android.apps.nbu.paisa.user");
    StartActivityForResult(intent, 9999);
}

Then of course you would implement an override for OnActivityResult and process the result:

protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
{
    base.OnActivityResult(requestCode, resultCode, data);
    if (requestCode == 9999)
    {
        Log.Debug("tez result", data.GetStringExtra("Status"));
    }
}