[英]Using the Paypal API / SDK, How would I check for a certain Subscription ID? C#
好的,所以我下載了 Paypal 的 SDK/API,我需要一些幫助。
我正在嘗試檢查某個訂閱 ID,但我似乎無法弄清楚如何。
當用戶啟動應用程序時,我想檢查訂閱 ID,如果它不是活動的或未付費的,那么它會顯示一條錯誤消息,說明錯誤。 如果它處於活動狀態,那么它將正常啟動。
有人可以為此發布一個 C# 示例嗎? 我搜索了所有谷歌,但找不到適合我一生的任何東西:)
您可以查看Paypal 官方文檔
它沒有專門用 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
很高興為您服務:)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.