android - Google Pay(Tez) 集成到我的支付网关?(安卓)
问题描述
注意:我知道它还不适用于 iOS,我也不是在寻找 Xamarin.Forms(显然)。
当我意识到没有可用于其集成的指南时,我一直在尝试将Google Pay(Tez)
API 集成到我的应用程序中。Xamarin
Xamarin
因此,我访问了Google Pay API页面,该页面似乎有一个很好看的指南,Android(Java)
因此我开始将原生 Android 代码转换为Xamarin
. 然后我遇到了一个问题, PaymentsClient类似乎在 Xamarin 中不可用,所以我尝试检查它的命名空间,以便我可以了解它是否可用(Xamarin.Android
)。但是没有提到这个类的命名空间(我没有注意到)。我在它的信息中所能找到的只是它继承了com.google.android.gms.common.api.GoogleApi
它实际上根本没有帮助。
查询
- 我在这里错过了一些包还是有一些替代品
Xamarin
? - 是否有一些指南可以为
Xamarin
我错过的应用程序集成 Google pay(Tez) API? - Xamarin.Android 中还没有添加 Google pay(Tez) 集成吗?
- 还是我当前的配置有问题?ie
VS17 Pro
version15.6.7
,Xamarin
version4.9.0.753
和Xamarin.Android
version8.2.0.16
Android SDK latest with all the API versions above v 4.0
解决方案
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"));
}
}
推荐阅读
- java - 优化查询-聚合框架mongodb
- javascript - 如何只比较两个对象数组一次?
- javascript - javascript访问模块类型脚本中的全局变量
- xaml - 将 InputTransparent 属性设置为 True 的 ListView 正在影响 ListView 内的按钮
- c++ - 读取 json 文本文件解析失败。ostringstream 对它有什么作用吗?
- sql-server - 如何在 MS SQL 中从年初获取值
- javascript - 使用画布,如何在图像中切割带有嵌入阴影的孔?
- c++ - 运算符 const char* () 和显式复制 ctor
- mysql - 检查 MySQL 中 JSON 数据中是否存在值
- xamarin - Xamarin IOS 或 Xamarin Android 项目能否引用 .NET 5 或 .NET Core 项目