MK *_*lan 2 android xamarin xamarin.forms google-pay
我已经在 ASP.Net core 支持下成功创建了 Google pay Pass,并且我的其余 api 成功返回了 JWT 令牌。另外,我使用“保存到手机”网络按钮并使用 JWT,工作正常,但我需要将通行证与我的 Xamarin Forms 应用程序集成,在 xamrin 中,我如何添加“保存到手机”按钮以及如何将 JWT 与该按钮绑定?
最后,我找到了解决方案。如果您的后端服务器返回您的 google pay pass 的 JWT,您可以通过依赖项服务在 Xamarin 表单中实现此目的。
如果您可以使用 JWT 链接和意图、JWT POST 请求方法和原生 Android SDK。请参考本指南
我的通行证类型是忠诚卡,所以我使用了JWT 链接和意图方法
在将通行证与您的应用程序集成之前,您可以使用 Chrome 浏览器测试您的 JWT。请在 Chrome 浏览器中使用您的 JWT 点击此(https://pay.google.com/gp/v/save/ {jwt_ generated} )网址,如果 JWT 正常,您将在浏览器中看到该通行证
实现
在您的 PCL 项目中创建一个接口
namespace App.DependencyServices
{
public interface IGPayPass
{
void LoadGPayPass(string JWT);
}
}
Run Code Online (Sandbox Code Playgroud)在您的 Android 项目中创建本机实现
public class GPayImplementation : IGPayPass
{
/// <summary>
/// summary:
/// This methode load the google pay pass from the JWT and open the pay passes in Google pay app
/// To show the pass in google pay we have to create an ACTION_VIEW
/// If pass is the loyality pass we can use the JWT link and intent method(https://developers.google.com/pay/passes/guides/get-started/implementing-the-api/save-to-google-pay#use-jwt-link-and-intent)
/// To load the pass send the https request to google pass class object like https://pay.google.com/gp/v/save/{jwt_generated}
///
/// parameters:
/// JWT : The server return this token for pay passes and pass via dependency service to this native implementation
///
/// returns:
///
/// </summary>
/// <param name="JWT"></param>
public void LoadGPayPass(string JWT)
{
//create context
Context context = Android.App.Application.Context;
string url = "https://pay.google.com/gp/v/save/" + JWT;
//Send the https request to google pay pass class object via Android intent
Intent intent = new Intent(Intent.ActionView, Uri.Parse(url));
//Assign new task Flag for intent otherwise runtime exepption will return
intent.AddFlags(ActivityFlags.NewTask);
context.StartActivity(intent);
}
}
Run Code Online (Sandbox Code Playgroud)通过依赖服务使用 PCL 项目中的本机实现
if (response.HttpCode == HttpStatusCode.OK)
{
ResponseSting = response.Results.ToString();
//Remove quates from the JWT string
MembershipCardAndroidJWT = ResponseSting.TrimStart('"').TrimEnd('"');
//Pass The JWT string via dependency service to the Anroid native Environment
DependencyService.Get<IGPayPass>().LoadGPayPass(MembershipCardAndroidJWT);
}
Run Code Online (Sandbox Code Playgroud)在用户界面中,没有像谷歌网页按钮那样的默认按钮,但您必须遵循品牌指南(https://developers.google.com/pay/passes/guides/get-started/api-guidelines/brand-指南)
您可以使用任何类型的按钮并通过 onclik 或命令触发此方法
此方法消耗来自服务器的 JWT 并传递到谷歌钱包
归档时间: |
|
查看次数: |
1052 次 |
最近记录: |