简体   繁体   English

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

[英]Using the Paypal API / SDK, How would I check for a certain Subscription ID? C#

Okay, so I downloaded the SDK / APIs for Paypal, and I need some help.好的,所以我下载了 Paypal 的 SDK/API,我需要一些帮助。

I am trying to check for a certain subscription ID, but I can't seem to figure out how.我正在尝试检查某个订阅 ID,但我似乎无法弄清楚如何。

When the user launches the application, I want to check for a subscription ID, and if it is not active or unpaid, then it would show an error-message, stating the error.当用户启动应用程序时,我想检查订阅 ID,如果它不是活动的或未付费的,那么它会显示一条错误消息,说明错误。 If it was active, then it would launch normally.如果它处于活动状态,那么它将正常启动。

Could someone post a C# example for this?有人可以为此发布一个 C# 示例吗? I searched all of Google and couldn't find anything for the life of me :)我搜索了所有谷歌,但找不到适合我一生的任何东西:)

You can check the Paypal Official Docs您可以查看Paypal 官方文档

It is not specifically coded in C#, so that it may be coded in multiple languages (Instead of limited to one)它没有专门用 C# 编码,因此它可以用多种语言进行编码(而不是仅限于一种)

You can also check out the C# Samples on Github您还可以查看Github上的 C# 示例

I created some Sample Code, working off of InvoiceSend.aspx.cs / InvoiceCreate.aspx.cs :我创建了一些示例代码,使用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);
                }

That sends an invoice through Paypal, programmatically!以编程方式通过 Paypal 发送发票!

You need to include the namespace Paypal.Api and Paypal您需要包含namespace Paypal.ApiPaypal

You can download the Paypal SDK from Nuget您可以从 Nuget 下载 Paypal SDK

Glad to be of service to you :)很高兴为您服务:)

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

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