简体   繁体   中英

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.

I am trying to check for a certain subscription ID, but I can't seem to figure out how.

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. If it was active, then it would launch normally.

Could someone post a C# example for this? I searched all of Google and couldn't find anything for the life of me :)

You can check the Paypal Official Docs

It is not specifically coded in C#, so that it may be coded in multiple languages (Instead of limited to one)

You can also check out the C# Samples on Github

I created some Sample Code, working off of 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!

You need to include the namespace Paypal.Api and Paypal

You can download the Paypal SDK from Nuget

Glad to be of service to you :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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