首页 > 解决方案 > Google Pay(Tez) 集成到我的支付网关?(安卓)

问题描述

注意:我知道它还不适用于 iOS,我也不是在寻找 Xamarin.Forms(显然)。

当我意识到没有可用于其集成的指南时,我一直在尝试将Google Pay(Tez)API 集成到我的应用程序中。XamarinXamarin

因此,我访问了Google Pay API页面,该页面似乎有一个很好看的指南,Android(Java)因此我开始将原生 Android 代码转换为Xamarin. 然后我遇到了一个问题, PaymentsClient类似乎在 Xamarin 中不可用,所以我尝试检查它的命名空间,以便我可以了解它是否可用(Xamarin.Android)。但是没有提到这个类的命名空间(我没有注意到)。我在它的信息中所能找到的只是它继承了com.google.android.gms.common.api.GoogleApi它实际上根本没有帮助。

查询

标签: androidxamarinxamarin.androidgoogle-paygoogle-tez

解决方案


Google Pay(不是 Tez):

Package: `Xamarin.GooglePlayServices.Wallet`

metadata确保通过清单中的 或通过应用程序的启用您的应用程序进行电子钱包处理MetaDataAttribute

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

从那里开始using Android.Gms.Wallet;,设置和使用PaymentsClient, 即是一个问题。

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

Google Pay for India(基于 UPI 意图):

要将交易信息传递给“Tez”,您需要定义一个 URI,其中包含您的所有商家信息、交易金额等……此 URI 基于 UNIFIED PAYMENTS INTERFACEUPI方案(这不受 Google 控制,因此您有请参阅 UPI 规范以了解您需要传递的数据)。

回复: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);
}

然后当然你会实现一个覆盖OnActivityResult并处理结果:

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"));
    }
}

推荐阅读