使用 Paypal API / SDK,我将如何检查某个订阅 ID? C#
Posted
技术标签:
【中文标题】使用 Paypal API / SDK,我将如何检查某个订阅 ID? C#【英文标题】:Using the Paypal API / SDK, How would I check for a certain Subscription ID? C# 【发布时间】:2020-04-03 02:39:09 【问题描述】:好的,所以我下载了 Paypal 的 SDK / API,我需要一些帮助。
我正在尝试检查某个订阅 ID,但我似乎无法弄清楚如何。
当用户启动应用程序时,我想检查订阅 ID,如果它不活跃或未付费,那么它会显示一条错误消息,说明错误。如果它处于活动状态,那么它将正常启动。
有人可以为此发布一个 C# 示例吗?我在 Google 上搜索了所有内容,但我一生都找不到任何东西 :)
【问题讨论】:
【参考方案1】:您可以查看Paypal Official Docs
它没有专门用C#编码,所以它可能用多种语言编码(而不是仅限于一种)
您还可以在 Github 上查看 C# 示例
我创建了一些示例代码,使用 InvoiceSend.aspx.cs
/ InvoiceCreate.aspx.cs
:
var config = ConfigManager.Instance.GetProperties();
config.Add("mode", "live");
config.Add("clientId", "get_your_id_from_sandbox");
config.Add("clientSecret", "get_your_secret_from_sandbox");
var accessToken = new OAuthTokenCredential(config).GetAccessToken();
var apiContext = new APIContext(accessToken);
apiContext.Config = config;
// ### Create an invoice
// For demonstration purposes, we will create a new invoice for this sample.
var invoice = new Invoice()
// #### Merchant Information
// Information about the merchant who is sending the invoice.
merchant_info = new MerchantInfo()
email = "example@example.com",
first_name = "Carl",
last_name = "Smithy",
business_name = "Buddy Business Inc.",
phone = new Phone()
country_code = "001",
national_number = "1234567890"
,
address = new InvoiceAddress()
line1 = "1234 Main St.",
city = "Chicago",
state = "IL",
postal_code = "54321",
country_code = "001"
,
// #### Billing Information
// Email address of invoice recipient and optional billing information.
// > Note: PayPal currently only allows one recipient.
billing_info = new List<BillingInfo>()
new BillingInfo()
// **(Required)** Email address of the invoice recipient.
email = "example@example.com",
,
// #### Invoice Items
// List of items to be included in the invoice.
// > Note: 100 max per invoice.
items = new List<InvoiceItem>()
new InvoiceItem()
name = "Item Name",
quantity = 1,
unit_price = new Currency()
currency = "USD",
value = "6.99" // The Price
,
// #### Invoice Note
// Note to the payer. Maximum length is 4000 characters.
note = "Payment for <Your Item Here>",
// #### Payment Term
// **(Optional)** Specifies the payment deadline for the invoice.
// > Note: Either `term_type` or `due_date` can be sent, **but not both.**
payment_term = new PaymentTerm()
term_type = "NET_30"
,
// #### Shipping Information
// Shipping information for entities to whom items are being shipped.
shipping_info = new ShippingInfo()
first_name = "john",
last_name = "smith",
business_name = "Not applicable",
address = new InvoiceAddress()
line1 = "1234 Main St.",
city = "New York City",
state = "New York",
postal_code = "12345",
country_code = "001",
;
var createInvoice = invoice.Create(apiContext);
createInvoice.Send(apiContext);
通过 Paypal 以编程方式发送发票!
您需要包含namespace
Paypal.Api
和Paypal
您可以从 Nuget 下载 Paypal SDK
很高兴为您服务:)
【讨论】:
谢谢!我终于可以创建我的订阅系统了! 没问题! :-)以上是关于使用 Paypal API / SDK,我将如何检查某个订阅 ID? C#的主要内容,如果未能解决你的问题,请参考以下文章
如何使用 PayPal REST API 和 PayPal PHP SDK 保存 PayPal 帐户以备将来付款
PayPal Rest API SDK:如何添加 SOLUTIONTYPE 选项(或等效项)