【发布时间】:2018-12-17 21:41:40
【问题描述】:
我正在尝试将 Stripe 付款合并到我的 Xamarin 应用程序中。我已经安装了最新的 Stripe NuGet 包,并在我的 .cs 中包含了以下代码:
using System;
using System.Collections.Generic;
using Stripe;
using Xamarin.Forms;
namespace CampaignFinanceNew
{
public partial class CreditCardProcess : ContentPage
{
StripeClient paymentClient = new StripeClient("[test key here]");
public CreditCardProcess()
{
InitializeComponent();
CreditCard currentCard = new CreditCard();
currentCard.Number = creditCardNumber.Text;
currentCard.ExpMonth = Convert.ToInt32(ccExpiryMonth.Text);
currentCard.ExpYear = Convert.ToInt32(ccExpiryYear.Text);
StripeObject newToken = paymentClient.CreateCardToken(currentCard);
}
}
}
当我构建项目时,它给了我以下错误:
错误 XA2002:无法解析引用:Stripe,由 CampaignFinanceNew 引用。请为 Stripe 添加 NuGet 包或程序集引用,或删除对 CampaignFinanceNew 的引用。 (XA2002) (CampaignFinanceNew.Android)
我尝试将 Stripe 包添加到我的 iOS 和 Android 项目中,但它告诉我它不兼容。我该怎么办?我会更好地为 iOS 和 Android 单独实现它,然后通过 DependencyService 访问它吗?
【问题讨论】:
-
CreditCardProcess 存在于哪个项目中?它是什么类型的项目?
-
它在主项目中(不是单独的 iOS 或 Android 项目)
-
那是什么类型的项目?如果它不是“共享项目”类型,那么您将需要以某种方式注入条带。正如您建议的那样,DependencyService 将是一种方法。
-
不,它是一个 .NET 项目,这可能意味着 DependencySvc 将是要走的路!谢谢!
-
Stripe nuget 应该支持 netstandard。如果软件包未安装在平台项目中,DI 将无济于事
标签: android ios xamarin mobile stripe-payments