繁体   English   中英

使用 Paypal API / SDK,我如何检查某个订阅 ID? C#

[英]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.ApiPaypal

您可以从 Nuget 下载 Paypal SDK

很高兴为您服务:)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM